Update gitea-mirror.sh

This commit is contained in:
Tobias 2025-06-27 06:50:49 +02:00 committed by GitHub
parent 1ba1344b72
commit 6b605f4123
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,51 +44,52 @@ function update_script() {
whiptail --backtitle "Gitea Mirror Update" --title "Update Cancelled" --msgbox "Update process cancelled. Please backup your configuration before proceeding." 8 60 whiptail --backtitle "Gitea Mirror Update" --title "Update Cancelled" --msgbox "Update process cancelled. Please backup your configuration before proceeding." 8 60
exit 0 exit 0
fi fi
whiptail --backtitle "Gitea Mirror Update" --title "Proceeding with Update" --msgbox \ whiptail --backtitle "Gitea Mirror Update" --title "Proceeding with Update" --msgbox \
"Proceeding with version $APP_VERSION update.\n\nAll configuration will be cleared as warned." 8 50 "Proceeding with version $APP_VERSION update.\n\nAll configuration will be cleared as warned." 8 50
else else
RELEASE=$(curl -fsSL https://api.github.com/repos/arunavo4/gitea-mirror/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') RELEASE=$(curl -fsSL https://api.github.com/repos/arunavo4/gitea-mirror/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
if [[ "${RELEASE}" != "$(cat ~/.${APP} 2>/dev/null || cat /opt/${APP}_version.txt 2>/dev/null)" ]]; then if [[ "${RELEASE}" != "$(cat ~/.${APP} 2>/dev/null || cat /opt/${APP}_version.txt 2>/dev/null)" ]]; then
msg_info "Stopping Services" msg_info "Stopping Services"
systemctl stop gitea-mirror systemctl stop gitea-mirror
msg_ok "Services Stopped" msg_ok "Services Stopped"
msg_info "Backup Data" msg_info "Backup Data"
mkdir -p /opt/gitea-mirror-backup/data mkdir -p /opt/gitea-mirror-backup/data
cp /opt/gitea-mirror/data/* /opt/gitea-mirror-backup/data/ cp /opt/gitea-mirror/data/* /opt/gitea-mirror-backup/data/
msg_ok "Backup Data" msg_ok "Backup Data"
msg_info "Installing Bun" msg_info "Installing Bun"
export BUN_INSTALL=/opt/bun export BUN_INSTALL=/opt/bun
curl -fsSL https://bun.sh/install | $STD bash curl -fsSL https://bun.sh/install | $STD bash
ln -sf /opt/bun/bin/bun /usr/local/bin/bun ln -sf /opt/bun/bin/bun /usr/local/bin/bun
ln -sf /opt/bun/bin/bun /usr/local/bin/bunx ln -sf /opt/bun/bin/bun /usr/local/bin/bunx
msg_ok "Installed Bun" msg_ok "Installed Bun"
rm -rf /opt/gitea-mirror rm -rf /opt/gitea-mirror
fetch_and_deploy_gh_release "gitea-mirror" "arunavo4/gitea-mirror" fetch_and_deploy_gh_release "gitea-mirror" "arunavo4/gitea-mirror"
msg_info "Updating and rebuilding ${APP} to v${RELEASE}" msg_info "Updating and rebuilding ${APP} to v${RELEASE}"
cd /opt/gitea-mirror cd /opt/gitea-mirror
$STD bun run setup $STD bun run setup
$STD bun run build $STD bun run build
APP_VERSION=$(grep -o '"version": *"[^"]*"' package.json | cut -d'"' -f4) APP_VERSION=$(grep -o '"version": *"[^"]*"' package.json | cut -d'"' -f4)
sudo sed -i.bak "s|^Environment=npm_package_version=.*|Environment=npm_package_version=${APP_VERSION}|" /etc/systemd/system/gitea-mirror.service sudo sed -i.bak "s|^Environment=npm_package_version=.*|Environment=npm_package_version=${APP_VERSION}|" /etc/systemd/system/gitea-mirror.service
msg_ok "Updated and rebuilt ${APP} to v${RELEASE}" msg_ok "Updated and rebuilt ${APP} to v${RELEASE}"
msg_info "Restoring Data" msg_info "Restoring Data"
cp /opt/gitea-mirror-backup/data/* /opt/gitea-mirror/data cp /opt/gitea-mirror-backup/data/* /opt/gitea-mirror/data
echo "${RELEASE}" >/opt/${APP}_version.txt echo "${RELEASE}" >/opt/${APP}_version.txt
msg_ok "Restored Data" msg_ok "Restored Data"
msg_info "Starting Service" msg_info "Starting Service"
systemctl daemon-reload systemctl daemon-reload
systemctl start gitea-mirror systemctl start gitea-mirror
msg_ok "Service Started" msg_ok "Service Started"
else else
msg_ok "No update required. ${APP} is already at v${RELEASE}" msg_ok "No update required. ${APP} is already at v${RELEASE}"
fi
fi fi
exit exit
} }