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
+110
-23
@@ -1,12 +1,22 @@
|
||||
#!/bin/sh
|
||||
# Install OpenVPN Monitor & Profiler as system services (no containers): Alpine (OpenRC), Debian, Ubuntu (systemd).
|
||||
#
|
||||
# deploy/native/install.sh [--prefix DIR] [--ui-dist FILE] [--https-port N] [--host-name NAME]
|
||||
# [--admin-user NAME] [--force]
|
||||
# deploy/native/install.sh [--prefix DIR] [--ui-dist FILE|DIR | --build-ui [--node-download] | --no-ui]
|
||||
# [--https-port N] [--host-name NAME] [--admin-user NAME] [--force]
|
||||
#
|
||||
# --prefix install directory (default /opt/OpenVPN-Monitoring-Simple): APP_CORE, APP_PROFILER, venvs
|
||||
# --ui-dist UI tarball made by deploy/native/build-ui.sh (the host needs no Node). Without it a
|
||||
# placeholder page is installed; add the UI later with update.sh --ui-dist
|
||||
# --prefix install directory (APP_CORE, APP_PROFILER, venvs). REQUIRED: without the option the script
|
||||
# asks for it (no default is assumed). It must be a new or empty directory, different from
|
||||
# this repository checkout (the checkout is only the source) and not a system directory
|
||||
# --ui-dist UI tarball made by deploy/native/build-ui.sh, or a directory with index.html (the host
|
||||
# needs no Node). Highest priority
|
||||
# --build-ui build the UI now from APP_UI (Docker when it works, otherwise Node >= 20.19 on this host);
|
||||
# for a host where the committed build is stale or missing
|
||||
# --node-download with --build-ui: fetch a temporary official Node 20 (checksum verified, glibc only,
|
||||
# needs curl and xz) instead of the system Node; nothing is installed
|
||||
# --no-ui install a placeholder page instead of the UI (on purpose)
|
||||
# Without these options the committed build deploy/ui-dist of the repository is installed
|
||||
# automatically (a warning is printed when it is older than APP_UI); when there is no UI
|
||||
# source at all the install stops
|
||||
# --https-port HTTPS port of the web UI (default 8088)
|
||||
# --host-name DNS name or IP of this host: certificate name and CORS origin (default: detected address)
|
||||
# --admin-user login of the initial administrator (default: admin); the password is generated
|
||||
@@ -22,11 +32,14 @@ SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
. "$SCRIPT_DIR/lib.sh"
|
||||
|
||||
usage() {
|
||||
sed -n '2,18p' "$0" | sed 's/^# \{0,1\}//'
|
||||
sed -n '2,/^set -eu$/{/^set -eu$/!p}' "$0" | sed 's/^# \{0,1\}//'
|
||||
}
|
||||
|
||||
PREFIX="$DEFAULT_PREFIX"
|
||||
PREFIX=""
|
||||
UI_DIST=""
|
||||
UI_BUILD=0
|
||||
UI_NODE_DL=0
|
||||
NO_UI=0
|
||||
HTTPS_PORT=8088
|
||||
HOST_NAME=""
|
||||
ADMIN_USER="admin"
|
||||
@@ -37,6 +50,9 @@ while [ $# -gt 0 ]; do
|
||||
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 ;;
|
||||
--no-ui) NO_UI=1; shift ;;
|
||||
--https-port) [ $# -ge 2 ] || die "--https-port needs a value"; HTTPS_PORT="$2"; shift 2 ;;
|
||||
--host-name) [ $# -ge 2 ] || die "--host-name needs a value"; HOST_NAME="$2"; shift 2 ;;
|
||||
--admin-user) [ $# -ge 2 ] || die "--admin-user needs a value"; ADMIN_USER="$2"; shift 2 ;;
|
||||
@@ -46,7 +62,68 @@ while [ $# -gt 0 ]; do
|
||||
esac
|
||||
done
|
||||
|
||||
valid_prefix "$PREFIX" || die "invalid --prefix '$PREFIX' (absolute path of letters, digits, . _ - and /)"
|
||||
SRC="$ROOT_DIR"
|
||||
|
||||
# prefix_problem DIR: prints why DIR cannot be the install directory (nothing = acceptable).
|
||||
# The install directory gets mkdir/chmod 755 and root-owned code: it must be a dedicated place.
|
||||
prefix_problem() {
|
||||
local d n sabs
|
||||
d="$1"
|
||||
valid_prefix "$d" || { echo "not an absolute path of letters, digits, . _ - and /"; return; }
|
||||
# normalise: no trailing slash, no double slash, no . or .. segments
|
||||
case "$d" in *//*|*/./*|*/../*|*/.|*/..|*/) echo "write the path without //, ., .. or a trailing /"; return ;; esac
|
||||
case "$d" in
|
||||
/|/bin|/boot|/dev|/etc|/home|/lib|/lib64|/media|/mnt|/opt|/proc|/root|/run|/sbin|/srv|/sys|/tmp|/usr|/var|/usr/local|/usr/lib|/var/lib|/var/log|/var/www|/etc/openvpn|/etc/ovpmon)
|
||||
echo "a system directory (the installer changes its permissions); choose a dedicated directory, e.g. $DEFAULT_PREFIX"; return ;;
|
||||
esac
|
||||
sabs=$(abs_dir "$SRC")
|
||||
[ "$d" != "$sabs" ] || { echo "this is the repository checkout itself ($sabs): the checkout is only the source of the installation. Choose another directory, or move/clone the repository elsewhere"; return; }
|
||||
case "$d/" in "$sabs"/*) echo "inside the repository checkout ($sabs): choose a directory outside of it"; return ;; esac
|
||||
case "$sabs/" in "$d"/*) echo "the repository checkout ($sabs) is inside it: choose a directory that does not contain the checkout"; return ;; esac
|
||||
if [ -e "$d" ] && [ ! -d "$d" ]; then echo "exists and is not a directory"; return; fi
|
||||
if [ -d "$d" ] && [ ! -f "$INCOMPLETE_MARK" ]; then
|
||||
n=$(ls -A "$d" 2>/dev/null | wc -l)
|
||||
[ "$n" -eq 0 ] || { echo "already exists and is not empty (an installation, or other data). To upgrade an installation use update.sh; otherwise choose a new directory"; return; }
|
||||
fi
|
||||
}
|
||||
|
||||
# The install directory is always asked for: it decides where the code, the PKI and the client profiles
|
||||
# live, and it is not something to guess. Without a terminal it must be given with --prefix.
|
||||
ask_prefix() {
|
||||
local ans tries p
|
||||
[ -t 0 ] || die "--prefix DIR is required (no terminal to ask on). Example: --prefix $DEFAULT_PREFIX"
|
||||
echo "Install directory: where APP_CORE, APP_PROFILER and their virtualenvs are installed."
|
||||
echo "The PKI and the client profiles live below it. It must be a new or empty directory outside"
|
||||
echo "this repository checkout ($ROOT_DIR). Suggestion: $DEFAULT_PREFIX"
|
||||
tries=0
|
||||
while [ "$tries" -lt 3 ]; do
|
||||
printf 'Install directory (absolute path): '
|
||||
read -r ans || die "no input: --prefix DIR is required"
|
||||
if [ -z "$ans" ]; then
|
||||
echo " an install directory is required (type the path; there is no default)"
|
||||
else
|
||||
p=$(prefix_problem "$ans")
|
||||
if [ -z "$p" ]; then
|
||||
PREFIX="$ans"
|
||||
printf 'Install into %s ? [y/N] ' "$PREFIX"
|
||||
read -r ans || die "no input"
|
||||
case "$ans" in y|Y|yes|YES) return 0 ;; esac
|
||||
echo " not confirmed"
|
||||
else
|
||||
echo " not accepted: $p"
|
||||
fi
|
||||
fi
|
||||
tries=$((tries + 1))
|
||||
done
|
||||
die "no valid install directory given"
|
||||
}
|
||||
|
||||
if [ -z "$PREFIX" ]; then
|
||||
ask_prefix
|
||||
else
|
||||
_problem=$(prefix_problem "$PREFIX")
|
||||
[ -z "$_problem" ] || die "invalid --prefix '$PREFIX': $_problem"
|
||||
fi
|
||||
valid_port "$HTTPS_PORT" || die "invalid --https-port '$HTTPS_PORT'"
|
||||
case "$ADMIN_USER" in
|
||||
""|*[!A-Za-z0-9._-]*) die "invalid --admin-user (letters, digits, . _ - only)" ;;
|
||||
@@ -55,14 +132,19 @@ case "$HOST_NAME" in
|
||||
*[!A-Za-z0-9.-]*) die "invalid --host-name (letters, digits, . and - only)" ;;
|
||||
esac
|
||||
[ -z "$UI_DIST" ] || case "$UI_DIST" in /*) ;; *) UI_DIST="$PWD/$UI_DIST" ;; esac
|
||||
SRC="$ROOT_DIR"
|
||||
[ "$UI_NODE_DL" = 0 ] || [ "$UI_BUILD" = 1 ] || die "--node-download only works together with --build-ui"
|
||||
[ "$NO_UI" = 0 ] || { [ -z "$UI_DIST" ] && [ "$UI_BUILD" = 0 ]; } || die "--no-ui excludes --ui-dist and --build-ui"
|
||||
[ -z "$UI_DIST" ] || [ "$UI_BUILD" = 0 ] || die "use either --ui-dist or --build-ui, not both"
|
||||
|
||||
on_exit() {
|
||||
_rc=$?
|
||||
set +e
|
||||
trap '' INT TERM
|
||||
if [ "$_rc" -ne 0 ]; then
|
||||
log "install stopped in phase '$CURRENT_PHASE'. Nothing is lost: fix the cause and run the script again (it resumes; existing secrets, certificates and data are kept)" >&2
|
||||
case "$CURRENT_PHASE" in
|
||||
start|0*) log "install stopped in phase '$CURRENT_PHASE': nothing was changed on this system" >&2 ;;
|
||||
*) log "install stopped in phase '$CURRENT_PHASE'. Nothing is lost: fix the cause and run the script again with the same --prefix (it resumes; existing secrets, certificates and data are kept)" >&2 ;;
|
||||
esac
|
||||
fi
|
||||
[ -z "${TMPD:-}" ] || rm -rf "$TMPD"
|
||||
release_lock
|
||||
@@ -95,15 +177,9 @@ fi
|
||||
|
||||
[ -f "$SRC/APP_CORE/openvpn_api_v3.py" ] && [ -f "$SRC/APP_PROFILER/main.py" ] \
|
||||
|| die "run the script from a complete checkout of the repository (APP_CORE and APP_PROFILER not found in $SRC)"
|
||||
if [ -z "$UI_DIST" ] && [ -f "$SCRIPT_DIR/ui-dist.tar.gz" ]; then
|
||||
UI_DIST="$SCRIPT_DIR/ui-dist.tar.gz"
|
||||
log "using the UI archive $UI_DIST"
|
||||
fi
|
||||
if [ -n "$UI_DIST" ]; then
|
||||
check_ui_archive "$UI_DIST"
|
||||
else
|
||||
warn "no --ui-dist: a placeholder page is installed instead of the web UI (build it with deploy/native/build-ui.sh, then update.sh --ui-dist FILE)"
|
||||
fi
|
||||
# UI source order (ui_resolve, run below after the cheap checks): --ui-dist, --build-ui, the committed
|
||||
# deploy/ui-dist, an archive next to the scripts. Nothing found: stop, unless --no-ui
|
||||
UI_FALLBACK="$SCRIPT_DIR/ui-dist.tar.gz"
|
||||
|
||||
# ports: ours may already be bound when the script is resumed
|
||||
if svc_active ovpmon-api 2>/dev/null; then
|
||||
@@ -119,6 +195,16 @@ if port_in_use 1194 udp; then log "note: 1194/udp is in use; OpenVPN uses the po
|
||||
check_free "$PREFIX" "$MIN_FREE_PREFIX_MB" "the installation (code and virtualenvs)"
|
||||
check_free /var/lib 256 "data"
|
||||
|
||||
if [ "$NO_UI" = 1 ]; then
|
||||
warn "--no-ui: only a placeholder page is installed instead of the web UI (update.sh installs the UI from the repository later)"
|
||||
else
|
||||
ui_resolve "$SRC" "$TMPD"
|
||||
if [ -z "$UI_SRC" ]; then
|
||||
die "no UI source found: there is no --ui-dist, no committed build in $SRC/deploy/ui-dist and no archive $UI_FALLBACK. Choose one: --build-ui (builds from APP_UI with Docker or Node 20.19+, add --node-download for a temporary Node), --ui-dist FILE|DIR (built elsewhere with deploy/native/build-ui.sh), or --no-ui (placeholder page on purpose). A complete clone of the repository contains deploy/ui-dist"
|
||||
fi
|
||||
log "UI: $UI_ORIGIN"
|
||||
fi
|
||||
|
||||
mkdir -p "$ETC_DIR"
|
||||
chmod 755 "$ETC_DIR"
|
||||
: > "$INCOMPLETE_MARK"
|
||||
@@ -300,16 +386,16 @@ log "services enabled at boot: $SERVICES"
|
||||
|
||||
# UI files
|
||||
mkdir -p "$(dirname "$WEB_ROOT")"
|
||||
if [ -n "$UI_DIST" ]; then
|
||||
stage_ui "$UI_DIST" "$WEB_ROOT.new"
|
||||
if [ -n "$UI_SRC" ]; then
|
||||
stage_ui "$UI_SRC" "$WEB_ROOT.new"
|
||||
swap_dir "$WEB_ROOT.new" "$WEB_ROOT" "$WEB_ROOT.old"
|
||||
rm -rf "$WEB_ROOT.old"
|
||||
log "UI files installed to $WEB_ROOT from $UI_DIST"
|
||||
log "UI files installed to $WEB_ROOT: $UI_ORIGIN"
|
||||
elif [ ! -f "$WEB_ROOT/index.html" ]; then
|
||||
mkdir -p "$WEB_ROOT"
|
||||
cat > "$WEB_ROOT/index.html" <<'EOF'
|
||||
<!doctype html><meta charset="utf-8"><title>OpenVPN Monitor</title>
|
||||
<h1>OpenVPN Monitor</h1><p>The web UI is not installed yet. Build it with deploy/native/build-ui.sh and run deploy/native/update.sh --ui-dist FILE.</p>
|
||||
<h1>OpenVPN Monitor</h1><p>The web UI is not installed (install.sh --no-ui). Run deploy/native/update.sh: it installs the UI from the repository; or pass --ui-dist FILE|DIR or --build-ui.</p>
|
||||
EOF
|
||||
chmod -R a+rX "$WEB_ROOT"
|
||||
log "placeholder page written to $WEB_ROOT"
|
||||
@@ -417,6 +503,7 @@ FP=$(openssl x509 -noout -fingerprint -sha256 -in "$TLS_DIR/ovpmon.crt" 2>/dev/n
|
||||
printf '\n'
|
||||
log "=== INSTALLED: $OS_ID $OS_VERSION_ID, $INIT, prefix $PREFIX ==="
|
||||
printf ' Web UI: https://%s:%s/ (self-signed certificate; SHA-256 %s)\n' "${HOST_NAME:-${HOST_IP:-<server-address>}}" "$HTTPS_PORT" "${FP:-n/a}"
|
||||
printf ' UI files: %s (%s)\n' "$WEB_ROOT" "${UI_ORIGIN:-placeholder page (--no-ui)}"
|
||||
printf ' Config: %s (root:root 600), helper: %s, %s\n' "$ENV_FILE" "$HELPER_CONF" "$HELPER_DEST"
|
||||
printf ' Data: %s (databases), %s/APP_PROFILER/easy-rsa (PKI), %s/APP_PROFILER/client-config\n' "$DATA_DIR" "$PREFIX" "$PREFIX"
|
||||
printf ' Logs: %s, %s\n' "$APP_LOG_DIR" "$OVPN_LOG_DIR"
|
||||
|
||||
Reference in new issue
Block a user