Deploy scripts: compose version check, ovpmon_backup.db in native backups

Docker: variant B needs Docker Compose 2.17+ (additional_contexts); install.sh
and update.sh check it in the preflight. Native: backup.sh, update.sh,
restore.sh and --rollback now copy and restore ovpmon_backup.db (Backup and
Restore settings) as an optional file. Verified install, update, backup,
restore and rollback on Debian 12 (systemd), Alpine 3.23 (OpenRC) and both
container variants.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-07 12:58:42 +03:00
1 parent f8cdcd0fc6
commit 3fac8d70d8
11 files changed
+178 -7

No files matched your search

+39
View File
@@ -63,6 +63,45 @@ need_docker() {
fi
}
# Variant B (docker-compose.yml) uses additional_contexts: Docker Compose v2.17.0 or newer
MIN_COMPOSE_VERSION="2.17.0"
# version_ge FOUND REQUIRED: pure comparison of MAJOR.MINOR[.PATCH] versions, no docker involved.
# A leading 'v' and any suffix after the numbers (-desktop.1, +build, -rc1) are ignored.
# Returns 0 if FOUND >= REQUIRED, 1 if FOUND < REQUIRED, 2 if either value cannot be parsed.
version_ge() {
local f r fa fb fc ra rb rc
f=$(printf '%s' "$1" | sed -n 's/^[vV]\{0,1\}\([0-9][0-9]*\)\.\([0-9][0-9]*\)\(\.\([0-9][0-9]*\)\)\{0,1\}.*$/\1 \2 \4/p')
r=$(printf '%s' "$2" | sed -n 's/^[vV]\{0,1\}\([0-9][0-9]*\)\.\([0-9][0-9]*\)\(\.\([0-9][0-9]*\)\)\{0,1\}.*$/\1 \2 \4/p')
[ -n "$f" ] && [ -n "$r" ] || return 2
set -- $f; fa=$1; fb=$2; fc=${3:-0}
set -- $r; ra=$1; rb=$2; rc=${3:-0}
[ "$fa" -gt "$ra" ] && return 0
[ "$fa" -lt "$ra" ] && return 1
[ "$fb" -gt "$rb" ] && return 0
[ "$fb" -lt "$rb" ] && return 1
[ "$fc" -ge "$rc" ] && return 0
return 1
}
# need_compose_version: variant B needs Docker Compose v2.17+ (additional_contexts). Variant A works
# with any compose. Call after need_docker (DC_BIN) and set_variant (VARIANT).
need_compose_version() {
local v rc
[ "$VARIANT" = b ] || return 0
if [ "$DC_BIN" != "docker compose" ]; then
die "variant B needs the Docker Compose plugin v$MIN_COMPOSE_VERSION or newer ('docker compose', the build uses additional_contexts), but only the legacy 'docker-compose' (v1) was found. Install the plugin (docker-compose-plugin package, see https://docs.docker.com/compose/install/) or use variant A (--variant a), which works with any compose"
fi
v=$(docker compose version --short 2>/dev/null | head -n 1 || true)
rc=0
version_ge "$v" "$MIN_COMPOSE_VERSION" || rc=$?
case "$rc" in
0) log "docker compose version $v (required for variant B: $MIN_COMPOSE_VERSION or newer)" ;;
1) die "variant B needs Docker Compose v$MIN_COMPOSE_VERSION or newer (the build uses additional_contexts), found v${v#v}. Update the Docker Compose plugin (docker-compose-plugin package, see https://docs.docker.com/compose/install/) or use variant A (--variant a), which works with any compose" ;;
*) warn "cannot parse the docker compose version ('$v'); variant B needs v$MIN_COMPOSE_VERSION or newer, continuing without the check" ;;
esac
}
# set_variant a|b: compose file, service and container names of the variant
set_variant() {
case "$1" in