From 52e08e547407fb2468ad9963b725fc5dbcadbb53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slavi=C5=A1a=20Are=C5=BEina?= <58952836+tremor021@users.noreply.github.com> Date: Fri, 1 Aug 2025 07:26:11 +0200 Subject: [PATCH] Refactor: Manage My Damn Life (#6403) --- ct/managemydamnlife.sh | 32 ++++++++++++----------------- install/managemydamnlife-install.sh | 14 ++++--------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/ct/managemydamnlife.sh b/ct/managemydamnlife.sh index ee198b3d4..34eda87da 100644 --- a/ct/managemydamnlife.sh +++ b/ct/managemydamnlife.sh @@ -28,39 +28,33 @@ function update_script() { msg_error "No ${APP} Installation Found!" exit fi + if ! command -v jq &>/dev/null; then + $STD apt-get install -y jq + fi - RELEASE=$(curl -fsSL https://api.github.com/repos/intri-in/manage-my-damn-life-nextjs/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') - if [[ "${RELEASE}" != "$(cat /opt/mmdl_version.txt)" ]] || [[ ! -f /opt/mmdl_version.txt ]]; then - msg_info "Stopping $APP" + RELEASE=$(curl -fsSL https://api.github.com/repos/intri-in/manage-my-damn-life-nextjs/releases/latest | jq -r '.tag_name' | sed 's/^v//') + if [[ "${RELEASE}" != "$(cat ~/.mmdl)" ]] || [[ ! -f ~/.mmdl ]]; then + msg_info "Stopping service" systemctl stop mmdl - msg_ok "Stopped $APP" + msg_ok "Stopped service" msg_info "Creating Backup" cp /opt/mmdl/.env /opt/mmdl.env msg_ok "Backup Created" - msg_info "Updating $APP to v${RELEASE}" - curl -fsSLO "https://github.com/intri-in/manage-my-damn-life-nextjs/archive/refs/tags/v${RELEASE}.zip" - rm -r /opt/mmdl - unzip -q v"$RELEASE".zip - mv manage-my-damn-life-nextjs-"$RELEASE"/ /opt/mmdl - mv /opt/mmdl.env /opt/mmdl/.env + fetch_and_deploy_gh_release "mmdl" "intri-in/manage-my-damn-life-nextjs" "tarball" + + msg_info "Configuring ${APP}" cd /opt/mmdl $STD npm install $STD npm run migrate $STD npm run build - msg_ok "Updated $APP to v${RELEASE}" + msg_ok "Configured ${APP}" - msg_info "Starting $APP" + msg_info "Starting service" systemctl start mmdl - msg_ok "Started $APP" + msg_ok "Started service" - msg_info "Cleaning Up" - rm -f ~/v"$RELEASE".zip - msg_ok "Cleanup Completed" - - # Last Action - echo "$RELEASE" >/opt/mmdl_version.txt msg_ok "Update Successful" else msg_ok "No update required. ${APP} is already at v${RELEASE}" diff --git a/install/managemydamnlife-install.sh b/install/managemydamnlife-install.sh index 1c1b1ccc0..81cb2cb85 100644 --- a/install/managemydamnlife-install.sh +++ b/install/managemydamnlife-install.sh @@ -31,13 +31,10 @@ $STD mysql -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUSH } >>~/mmdl.creds msg_ok "Set up Database" -msg_info "Installing ${APPLICATION}" -RELEASE=$(curl -fsSL https://api.github.com/repos/intri-in/manage-my-damn-life-nextjs/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') -curl -fsSLO "https://github.com/intri-in/manage-my-damn-life-nextjs/archive/refs/tags/v${RELEASE}.zip" -unzip -q v"$RELEASE".zip -mv manage-my-damn-life-nextjs-"$RELEASE"/ /opt/mmdl -cp /opt/mmdl/sample.env.local /opt/mmdl/.env +fetch_and_deploy_gh_release "mmdl" "intri-in/manage-my-damn-life-nextjs" "tarball" +msg_info "Configuring ${APPLICATION}" +cp /opt/mmdl/sample.env.local /opt/mmdl/.env sed -i -e 's|db|localhost|' \ -e "s|myuser|${DB_USER}|" \ -e "s|mypassword|${DB_PASS}|" \ @@ -46,15 +43,13 @@ sed -i -e 's|db|localhost|' \ -e "s|sample_install_mmdm|${DB_NAME}|" \ -e "s|=PASSWORD|=$(openssl rand -base64 40 | tr -dc 'a-zA-Z0-9' | head -c40)|" \ /opt/mmdl/.env - cd /opt/mmdl export NEXT_TELEMETRY_DISABLE=1 export CI="true" $STD npm install $STD npm run migrate $STD npm run build -echo "${RELEASE}" >/opt/mmdl_version.txt -msg_ok "Installed ${APPLICATION}" +msg_ok "Configured ${APPLICATION}" msg_info "Creating Service" cat </etc/systemd/system/mmdl.service @@ -78,7 +73,6 @@ motd_ssh customize msg_info "Cleaning up" -rm -f ~/v${RELEASE}.zip $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned"