From d531771829dfc4417f6afe7439362005f4bff6a9 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Wed, 8 Jan 2025 20:41:47 +0100 Subject: [PATCH 1/8] refactor: move installation for backup and maintain media and env files --- ct/adventurelog.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ct/adventurelog.sh b/ct/adventurelog.sh index 5c168ce4..ac2cbef5 100644 --- a/ct/adventurelog.sh +++ b/ct/adventurelog.sh @@ -34,25 +34,28 @@ function update_script() { fi RELEASE=$(curl -s https://api.github.com/repos/seanmorley15/AdventureLog/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + LAST_VERSION=$(cat /opt/${APP}_version.txt) msg_info "Stopping Services" systemctl stop adventurelog-backend systemctl stop adventurelog-frontend msg_ok "Services Stopped" msg_info "Updating ${APP} to ${RELEASE}" - cp /opt/adventurelog/backend/server/.env /opt/server.env - cp /opt/adventurelog/frontend/.env /opt/frontend.env + mv /opt/adventurelog/ /opt/adventurelog-backup/ wget -q "https://github.com/seanmorley15/AdventureLog/archive/refs/tags/v${RELEASE}.zip" unzip -q v${RELEASE}.zip mv AdventureLog-${RELEASE} /opt/adventurelog - mv /opt/server.env /opt/adventurelog/backend/server/.env + + mv /opt/adventurelog-backup/backend/server/.env /opt/adventurelog/backend/server/.env + mv /opt/adventurelog-backup/backend/server/media /opt/adventurelog/backend/server/media cd /opt/adventurelog/backend/server pip install --upgrade pip &>/dev/null pip install -r requirements.txt &>/dev/null python3 manage.py collectstatic --noinput &>/dev/null python3 manage.py migrate &>/dev/null - mv /opt/frontend.env /opt/adventurelog/frontend/.env + + mv /opt/adventurelog-backup/frontend/.env /opt/adventurelog/frontend/.env cd /opt/adventurelog/frontend pnpm install &>/dev/null pnpm run build &>/dev/null @@ -66,6 +69,7 @@ function update_script() { msg_info "Cleaning Up" rm -rf v${RELEASE}.zip + mv /opt/adventurelog-backup/ adventurelog-backup-$LAST_VERSION/ # Keep backup, since AdventureLog moves quickly and we want to avoid breaking changes with rm -rf msg_ok "Cleaned" msg_ok "Updated Successfully" else @@ -81,4 +85,4 @@ description msg_ok "Completed Successfully!\n" echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" echo -e "${INFO}${YW} Access it using the following URL:${CL}" -echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}" \ No newline at end of file +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}" From 550efb5e303bbe22b940df1ae2cd40c789af6754 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Wed, 8 Jan 2025 20:42:07 +0100 Subject: [PATCH 2/8] fix: return to working directory --- ct/adventurelog.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ct/adventurelog.sh b/ct/adventurelog.sh index ac2cbef5..b8fe4ff5 100644 --- a/ct/adventurelog.sh +++ b/ct/adventurelog.sh @@ -41,6 +41,7 @@ function update_script() { msg_ok "Services Stopped" msg_info "Updating ${APP} to ${RELEASE}" + WORKDIR="$PWD" mv /opt/adventurelog/ /opt/adventurelog-backup/ wget -q "https://github.com/seanmorley15/AdventureLog/archive/refs/tags/v${RELEASE}.zip" unzip -q v${RELEASE}.zip @@ -60,6 +61,7 @@ function update_script() { pnpm install &>/dev/null pnpm run build &>/dev/null echo "${RELEASE}" >/opt/${APP}_version.txt + cd "$WORKDIR" msg_ok "Updated ${APP}" msg_info "Starting Services" From a11c5d86ec4f65c7214e797973e7f00c9e95bdb5 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Thu, 9 Jan 2025 10:50:17 +0100 Subject: [PATCH 3/8] Workdir Co-authored-by: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> --- ct/adventurelog.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ct/adventurelog.sh b/ct/adventurelog.sh index b8fe4ff5..056e38c7 100644 --- a/ct/adventurelog.sh +++ b/ct/adventurelog.sh @@ -41,7 +41,6 @@ function update_script() { msg_ok "Services Stopped" msg_info "Updating ${APP} to ${RELEASE}" - WORKDIR="$PWD" mv /opt/adventurelog/ /opt/adventurelog-backup/ wget -q "https://github.com/seanmorley15/AdventureLog/archive/refs/tags/v${RELEASE}.zip" unzip -q v${RELEASE}.zip From 0235b1385b154b0587c56b8e5ca1dd581d11b712 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Thu, 9 Jan 2025 10:50:25 +0100 Subject: [PATCH 4/8] Workdir Co-authored-by: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> --- ct/adventurelog.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ct/adventurelog.sh b/ct/adventurelog.sh index 056e38c7..ac2cbef5 100644 --- a/ct/adventurelog.sh +++ b/ct/adventurelog.sh @@ -60,7 +60,6 @@ function update_script() { pnpm install &>/dev/null pnpm run build &>/dev/null echo "${RELEASE}" >/opt/${APP}_version.txt - cd "$WORKDIR" msg_ok "Updated ${APP}" msg_info "Starting Services" From 7e766cdf8ea260da5a07b69c4927f9aa8f00152e Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Thu, 9 Jan 2025 10:50:50 +0100 Subject: [PATCH 5/8] Avoid Workdir Co-authored-by: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> --- ct/adventurelog.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ct/adventurelog.sh b/ct/adventurelog.sh index ac2cbef5..f4087d61 100644 --- a/ct/adventurelog.sh +++ b/ct/adventurelog.sh @@ -42,9 +42,9 @@ function update_script() { msg_info "Updating ${APP} to ${RELEASE}" mv /opt/adventurelog/ /opt/adventurelog-backup/ - wget -q "https://github.com/seanmorley15/AdventureLog/archive/refs/tags/v${RELEASE}.zip" - unzip -q v${RELEASE}.zip - mv AdventureLog-${RELEASE} /opt/adventurelog + wget -qO /opt/v${RELEASE}.zip "https://github.com/seanmorley15/AdventureLog/archive/refs/tags/v${RELEASE}.zip" + unzip -q /opt/v${RELEASE}.zip + mv /opt/AdventureLog-${RELEASE} /opt/adventurelog mv /opt/adventurelog-backup/backend/server/.env /opt/adventurelog/backend/server/.env mv /opt/adventurelog-backup/backend/server/media /opt/adventurelog/backend/server/media From 45ccdeef3f168be655bfabaa5576b44dab1ce96f Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Thu, 9 Jan 2025 10:51:07 +0100 Subject: [PATCH 6/8] Avoid Workdir Co-authored-by: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> --- ct/adventurelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ct/adventurelog.sh b/ct/adventurelog.sh index f4087d61..4ed7db09 100644 --- a/ct/adventurelog.sh +++ b/ct/adventurelog.sh @@ -68,7 +68,7 @@ function update_script() { msg_ok "Started Services" msg_info "Cleaning Up" - rm -rf v${RELEASE}.zip + rm -rf /opt/v${RELEASE}.zip mv /opt/adventurelog-backup/ adventurelog-backup-$LAST_VERSION/ # Keep backup, since AdventureLog moves quickly and we want to avoid breaking changes with rm -rf msg_ok "Cleaned" msg_ok "Updated Successfully" From c5d7608a783ec4cc3f062ab2ac3ba46f1e4e2208 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Thu, 9 Jan 2025 10:54:02 +0100 Subject: [PATCH 7/8] Remove old installation (at request of @michelroegl-brunner) Co-authored-by: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> --- ct/adventurelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ct/adventurelog.sh b/ct/adventurelog.sh index 4ed7db09..92ede2f7 100644 --- a/ct/adventurelog.sh +++ b/ct/adventurelog.sh @@ -69,7 +69,7 @@ function update_script() { msg_info "Cleaning Up" rm -rf /opt/v${RELEASE}.zip - mv /opt/adventurelog-backup/ adventurelog-backup-$LAST_VERSION/ # Keep backup, since AdventureLog moves quickly and we want to avoid breaking changes with rm -rf + rm -rf /opt/adventurelog-backup msg_ok "Cleaned" msg_ok "Updated Successfully" else From 4ddac3c1a674997713ce7c2c672f6b23730b126a Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Thu, 9 Jan 2025 10:58:31 +0100 Subject: [PATCH 8/8] rm newline --- ct/adventurelog.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ct/adventurelog.sh b/ct/adventurelog.sh index 92ede2f7..36585439 100644 --- a/ct/adventurelog.sh +++ b/ct/adventurelog.sh @@ -54,7 +54,6 @@ function update_script() { python3 manage.py collectstatic --noinput &>/dev/null python3 manage.py migrate &>/dev/null - mv /opt/adventurelog-backup/frontend/.env /opt/adventurelog/frontend/.env cd /opt/adventurelog/frontend pnpm install &>/dev/null