Refactor: Manage My Damn Life (#6403)

This commit is contained in:
Slaviša Arežina 2025-08-01 07:26:11 +02:00 committed by GitHub
parent b9408ef06f
commit 52e08e5474
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 29 deletions

View File

@ -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}"

View File

@ -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 <<EOF >/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"