Native install: mandatory install directory, UI delivered from the repository
- install.sh always asks for the install directory (--prefix or a prompt with confirmation, no default); refuses system directories, the repository checkout itself, paths inside/containing it and non-empty directories (a resumed install is allowed). A preflight refusal says nothing was changed. - UI is part of the repository: committed build in deploy/ui-dist with SOURCE_HASH and a staleness guard (check-ui.sh, loud warning). install.sh and update.sh resolve the UI: --ui-dist FILE|DIR, --build-ui, committed build; install stops without a UI unless --no-ui. update.sh swaps the UI when its hash differs from the installed one (.ui-source-hash). - build-ui.sh: --docker, --local (host Node >= 20.19, temporary copy), --node-download (portable Node, SHA-256 verified), --publish. - Verified on Alpine 3.23: install without UI options installs the real UI; local build equals the Docker build; update skips an unchanged UI and warns on a stale build. --node-download is untested (needs network). - Docs: Scenario 2 guide, change summary, plan, README. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4abd2044f0
commit
8371d889a4
31 files changed
+920
-114
No files matched your search
+43
-12
@@ -1,17 +1,23 @@
|
||||
#!/bin/sh
|
||||
# Update OpenVPN Monitor & Profiler (system services) without touching the data.
|
||||
#
|
||||
# deploy/native/update.sh [--prefix DIR] [--ui-dist FILE] [--source DIR] [--no-pull] [--yes] [--rollback]
|
||||
# deploy/native/update.sh [--prefix DIR] [--ui-dist FILE|DIR | --build-ui [--node-download]] [--source DIR]
|
||||
# [--no-pull] [--yes] [--rollback]
|
||||
#
|
||||
# --prefix install directory (default: from /etc/ovpmon/deploy.state, else /opt/OpenVPN-Monitoring-Simple)
|
||||
# --ui-dist UI tarball from build-ui.sh; without it the UI files are left as they are
|
||||
# --ui-dist UI tarball from build-ui.sh, or a directory with index.html: always installed (highest priority)
|
||||
# --build-ui build the UI now from APP_UI (Docker when it works, otherwise Node >= 20.19 on this host) and
|
||||
# install it; --node-download fetches a temporary official Node 20 for that (checksum verified,
|
||||
# glibc only, needs curl and xz)
|
||||
# Without these the committed build deploy/ui-dist of the source is installed automatically when
|
||||
# it differs from the installed UI (<web root>/.ui-source-hash); no UI source: the UI stays
|
||||
# --source checkout with the new version (default: the repository this script is in)
|
||||
# --no-pull no "git pull --ff-only" of the source checkout (offline hosts, sources already in place)
|
||||
# --yes no confirmation questions
|
||||
# --rollback restore code, databases, configuration, PKI and client profiles from the newest backup
|
||||
#
|
||||
# Phases: 0 preflight, 1 BACKUP (verified, /var/backups/ovpmon/<UTC time>/), 2 git pull, 3 PREPARE the new
|
||||
# code and virtualenvs next to the install dir (old code untouched), 4 STOP the application services (OpenVPN
|
||||
# code, virtualenvs and UI next to the install dir (old code untouched), 4 STOP the application services (OpenVPN
|
||||
# keeps running) and swap the code in, 5 DATABASE MIGRATION as its own step with the new code (nothing is
|
||||
# started on an unmigrated database), 6 UI, nginx, helper, doas rules, service definitions, 7 START and health
|
||||
# checks. A failure after the stop triggers an automatic rollback from the backup of this run.
|
||||
@@ -23,11 +29,14 @@ SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
. "$SCRIPT_DIR/lib.sh"
|
||||
|
||||
usage() {
|
||||
sed -n '2,19p' "$0" | sed 's/^# \{0,1\}//'
|
||||
sed -n '2,/^set -eu$/{/^set -eu$/!p}' "$0" | sed 's/^# \{0,1\}//'
|
||||
}
|
||||
|
||||
PREFIX=""
|
||||
UI_DIST=""
|
||||
UI_BUILD=0
|
||||
UI_NODE_DL=0
|
||||
UI_RESULT="kept as it is (no UI source)"
|
||||
SOURCE=""
|
||||
NO_PULL=0
|
||||
ASSUME_YES=0
|
||||
@@ -206,6 +215,8 @@ main() {
|
||||
case "$1" in
|
||||
--prefix) [ $# -ge 2 ] || die "--prefix needs a value"; PREFIX="$2"; shift 2 ;;
|
||||
--ui-dist) [ $# -ge 2 ] || die "--ui-dist needs a value"; UI_DIST="$2"; shift 2 ;;
|
||||
--build-ui) UI_BUILD=1; shift ;;
|
||||
--node-download) UI_NODE_DL=1; shift ;;
|
||||
--source) [ $# -ge 2 ] || die "--source needs a value"; SOURCE="$2"; shift 2 ;;
|
||||
--no-pull) NO_PULL=1; shift ;;
|
||||
--yes|-y) ASSUME_YES=1; shift ;;
|
||||
@@ -215,6 +226,9 @@ main() {
|
||||
esac
|
||||
done
|
||||
|
||||
[ "$UI_NODE_DL" = 0 ] || [ "$UI_BUILD" = 1 ] || die "--node-download only works together with --build-ui"
|
||||
[ -z "$UI_DIST" ] || [ "$UI_BUILD" = 0 ] || die "use either --ui-dist or --build-ui, not both"
|
||||
|
||||
TMPD=$(mktemp -d /tmp/ovpmon-update.XXXXXX) || die "cannot create a temporary directory"
|
||||
trap on_exit EXIT
|
||||
trap 'exit 130' INT
|
||||
@@ -271,10 +285,13 @@ main() {
|
||||
PULL_TOUCHES_LIVE=0
|
||||
fi
|
||||
if [ -n "$UI_DIST" ]; then
|
||||
check_ui_archive "$UI_DIST"
|
||||
log "UI archive: $UI_DIST"
|
||||
check_ui_source "$UI_DIST"
|
||||
log "UI: $UI_DIST (--ui-dist), will be installed"
|
||||
elif [ "$UI_BUILD" = 1 ]; then
|
||||
ui_build_check
|
||||
log "UI: will be built from APP_UI after the source update (--build-ui) and installed"
|
||||
else
|
||||
log "no --ui-dist: the UI files stay as they are (if APP_UI changed, build and pass a new archive)"
|
||||
log "UI: the committed build deploy/ui-dist of the source is installed after the source update when it differs from the installed UI"
|
||||
fi
|
||||
|
||||
SERVICES_WERE_RUNNING=1
|
||||
@@ -340,7 +357,7 @@ main() {
|
||||
|
||||
# ----- Phase 3: prepare ----------------------------------------------------------------
|
||||
CURRENT_PHASE="3 prepare"
|
||||
phase 3 "PREPARE the new code and virtualenvs (the running system is not touched)"
|
||||
phase 3 "PREPARE the new code, virtualenvs and UI (the running system is not touched)"
|
||||
STAGING="${PREFIX}.new"
|
||||
if [ -e "$STAGING" ]; then
|
||||
[ -f "$STAGING/.ovpmon-staging" ] || die "$STAGING exists and was not created by this script: remove or rename it"
|
||||
@@ -356,10 +373,23 @@ main() {
|
||||
smoke_component "$STAGING/APP_PROFILER" profiler || die "the new APP_PROFILER virtualenv cannot import the application's dependencies"
|
||||
lock_down_code "$STAGING/APP_CORE" "$STAGING/APP_PROFILER"
|
||||
log "new code and virtualenvs are ready in $STAGING (dependencies installed and importable)"
|
||||
if [ -n "$UI_DIST" ]; then
|
||||
stage_ui "$UI_DIST" "$WEB_ROOT.new"
|
||||
UI_STAGED=1
|
||||
log "new UI files are ready in $WEB_ROOT.new"
|
||||
# the UI source is decided here, after the source update (git pull may have brought a new build)
|
||||
ui_resolve "$SOURCE" "$TMPD"
|
||||
if [ -z "$UI_SRC" ]; then
|
||||
log "no UI source found (no --ui-dist or --build-ui, no committed build in $SOURCE/deploy/ui-dist): the installed UI stays as it is"
|
||||
else
|
||||
_have=$(cat "$WEB_ROOT/$UI_HASH_FILE" 2>/dev/null || echo "none")
|
||||
_new=$(ui_hash_of "$UI_SRC")
|
||||
if [ "$UI_KIND" = repo ] && valid_hash "$_new" && [ "$_new" = "$_have" ]; then
|
||||
log "UI: $UI_ORIGIN; the installed UI comes from the same sources (hash $_new): not replaced"
|
||||
UI_RESULT="unchanged (same sources as the installed UI)"
|
||||
else
|
||||
log "UI: $UI_ORIGIN; installed UI: ${_have}, new: ${_new}"
|
||||
stage_ui "$UI_SRC" "$WEB_ROOT.new"
|
||||
UI_STAGED=1
|
||||
UI_RESULT="replaced: $UI_ORIGIN"
|
||||
log "new UI files are ready in $WEB_ROOT.new"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ----- Phase 4: stop and swap ----------------------------------------------------------
|
||||
@@ -477,6 +507,7 @@ main() {
|
||||
printf '\n'
|
||||
log "=== UPDATE SUCCESSFUL: $OLD_VERSION -> $NEW_VERSION ==="
|
||||
printf ' Install dir: %s\n' "$PREFIX"
|
||||
printf ' UI: %s\n' "$UI_RESULT"
|
||||
printf ' Backup: %s (the newest %s backups are kept)\n' "$BACKUP_DIR" "$KEEP_BACKUPS"
|
||||
printf ' Rollback: %s --rollback\n' "$0"
|
||||
printf ' OpenVPN was not restarted by the update: connected VPN users stayed connected.\n'
|
||||
|
||||
Reference in new issue
Block a user