LibrePortal/scripts/update/backup/reset_git_backup.sh
librelad d5fe1bc56b feat(webui): out-of-date detection + one-click update
Surface when LibrePortal is behind upstream and let users update from the
WebUI, reusing the proven git-update path instead of reinventing it.

Detection (host): webuiSystemUpdateCheck writes
frontend/data/system/update_status.json from a throttled git fetch +
behind-count + VERSION compare, off the existing per-minute
`webui generate system` cron. A new /VERSION file is the canonical version.

Display (frontend): update-notifier.js/.css render a global topbar badge
(every page) and a dashboard banner (prominent when behind, subtle "up to
date" with a manual check otherwise), plus a details panel.

Actions go through the task pipeline:
- `libreportal update apply` -> webuiRunUpdate (non-interactive: guards,
  forced check, gitPerformUpdate, then dockerInstallApp libreportal)
- `libreportal update check` -> forced recheck

gitFolderResetAndBackup's body is extracted into gitPerformUpdate (no exit)
so the WebUI path can reuse it; the interactive CLI flow is unchanged.

Detection JSON verified against the repo (up-to-date and behind cases).
webuiRunUpdate's re-clone + redeploy still needs validation on a live host.

The latest-version source is git for now and is the single swap point for
get.libreportal.org later — the JSON contract and frontend stay unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-21 23:33:43 +01:00

55 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# gitPerformUpdate — the proven, file-level LibrePortal update.
#
# Backs up the user's configs/logs, re-clones the repo fresh (gitReset), then
# restores the configs/logs over the clean checkout, zips a snapshot, prunes
# old backups, and stops tracking ignored files. This is the historical update
# body that "worked great" — extracted out of gitFolderResetAndBackup so it can
# be reused non-interactively by the WebUI updater (webuiRunUpdate) WITHOUT the
# trailing `exit` the interactive CLI flow relies on.
#
# Does NOT exit, restart, or redeploy — the caller decides what happens next.
gitPerformUpdate()
{
isHeader "Updating LibrePortal"
update_done=false
if [ ! -d "$backup_install_dir/$backupFolder" ]; then
local result=$(createFolders "loud" $sudo_user_name "$backup_install_dir/$backupFolder")
checkSuccess "Create the backup folder"
fi
local result=$(cd $backup_install_dir)
checkSuccess "Going into the backup install folder"
local result=$(copyFolder "$configs_dir" "$backup_install_dir/$backupFolder" "$sudo_user_name")
checkSuccess "Copy the configs to the backup folder"
local result=$(copyFolder "$logs_dir" "$backup_install_dir/$backupFolder" "$sudo_user_name")
checkSuccess "Copy the logs to the backup folder"
gitReset;
local result=$(copyFolders "$backup_install_dir/$backupFolder/" "$docker_dir" "$sudo_user_name")
checkSuccess "Copy the backed up folders back into the installation directory"
local result=$(sudo -u $sudo_user_name zip -r "$backup_install_dir/$backupFolder.zip" "$backup_install_dir/$backupFolder")
checkSuccess "Zipping up the the backup folder for safe keeping"
gitCleanInstallBackups;
gitUntrackFiles;
}
gitFolderResetAndBackup()
{
gitPerformUpdate;
isSuccessful "Custom changes have been discarded successfully"
echo ""
isNotice "You have updated your version of LibrePortal."
isNotice "To avoid any issues please rerun the 'libreportal'."
echo ""
exit
update_done=true
}