Update gitea-mirror.sh

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

View File

@ -31,6 +31,8 @@ function update_script() {
fi fi
APP_VERSION=$(grep -o '"version": *"[^"]*"' package.json | cut -d'"' -f4) APP_VERSION=$(grep -o '"version": *"[^"]*"' package.json | cut -d'"' -f4)
# Check if version 2.x and show warnings
if [[ $APP_VERSION =~ ^2\. ]]; then if [[ $APP_VERSION =~ ^2\. ]]; then
if ! whiptail --backtitle "Gitea Mirror Update" --title "⚠️ VERSION 2.x DETECTED" --yesno \ if ! whiptail --backtitle "Gitea Mirror Update" --title "⚠️ VERSION 2.x DETECTED" --yesno \
"WARNING: Version $APP_VERSION detected!\n\nUpdating from version 2.x will CLEAR ALL CONFIGURATION.\n\nThis includes:\n• API tokens\n• User settings\n• Repository configurations\n• All custom settings\n\nDo you want to continue with the update process?" 15 70 --defaultno "WARNING: Version $APP_VERSION detected!\n\nUpdating from version 2.x will CLEAR ALL CONFIGURATION.\n\nThis includes:\n• API tokens\n• User settings\n• Repository configurations\n• All custom settings\n\nDo you want to continue with the update process?" 15 70 --defaultno
@ -44,10 +46,11 @@ 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 rm -rf /opt/gitea-mirror
fi
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
@ -55,10 +58,12 @@ function update_script() {
systemctl stop gitea-mirror systemctl stop gitea-mirror
msg_ok "Services Stopped" msg_ok "Services Stopped"
msg_info "Backup Data" if [[ -d /opt/gitea-mirror/data]]; then
msg_info "Backing up 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 "Backed up Data"
fi
msg_info "Installing Bun" msg_info "Installing Bun"
export BUN_INSTALL=/opt/bun export BUN_INSTALL=/opt/bun
@ -79,8 +84,8 @@ function update_script() {
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 || true
echo "${RELEASE}" >/opt/${APP}_version.txt echo "${RELEASE}" >~/.${APP}_version.txt
msg_ok "Restored Data" msg_ok "Restored Data"
msg_info "Starting Service" msg_info "Starting Service"
@ -90,7 +95,6 @@ function update_script() {
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
} }