feat: add --upgrade one-liner and improve upgrade.sh

get.sh --upgrade:
- Re-downloads installer files (compose.yaml, upgrade.sh, etc.) so the
  on-disk scripts are always current before upgrading
- Then execs upgrade.sh with any passthrough flags (e.g. --image TAG)

upgrade.sh improvements:
- Platform-aware backup dir (Linux: /var/backups/triton,
  macOS: ~/Library/Application Support/triton/backups)
- Reads POSTGRES_USER/POSTGRES_DB from .env instead of hardcoding
- Uses detected runtime (podman/docker) for pg_dump exec
- Explicit messaging that DB migrations run automatically on startup
- Health check success confirms migrations applied
- Prints rollback command pointing at the backup file

Usage:
  curl -fsSL .../get.sh | sudo bash -s -- --upgrade
  curl -fsSL .../get.sh | sudo bash -s -- --upgrade --image ...:1.2.0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
amir-climy 2026-05-19 19:19:57 +08:00
parent ffa10f9171
commit bacccd9550
2 changed files with 64 additions and 14 deletions

29
get.sh
View file

@ -12,6 +12,14 @@
# curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh \
# | sudo bash -s -- --gateway-hostname manage.example.com --manage-host-ip 10.0.0.5
#
# Upgrade (pull latest image, run DB migrations, keep data):
# curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh \
# | sudo bash -s -- --upgrade
#
# Upgrade to a specific image tag:
# curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh \
# | sudo bash -s -- --upgrade --image ghcr.io/primatekuntech/triton-manage-server:1.2.0
#
# Uninstall (stop containers, keep data):
# curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh \
# | sudo bash -s -- --uninstall
@ -36,10 +44,12 @@ banner() { printf "\n${BOLD}%s${RESET}\n\n" "$*"; }
# ── arg pre-scan (before any output) ─────────────────────────────────────
UNINSTALL=0
UPGRADE=0
PASSTHROUGH=()
for arg in "$@"; do
case "$arg" in
--uninstall) UNINSTALL=1 ;;
--upgrade) UPGRADE=1 ;;
*) PASSTHROUGH+=("$arg") ;;
esac
done
@ -70,6 +80,25 @@ if [[ $UNINSTALL -eq 1 ]]; then
exec bash "${INSTALL_DIR}/uninstall.sh" "${PASSTHROUGH[@]}"
fi
# ── upgrade shortcut ──────────────────────────────────────────────────────
if [[ $UPGRADE -eq 1 ]]; then
banner "▶ Triton Manage Server — Upgrade"
info "platform: $PLATFORM"
if [[ "$PLATFORM" == "linux" && $EUID -ne 0 ]]; then
die "run as root on Linux:\n\n curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh | sudo bash -s -- --upgrade"
fi
[[ -d "$INSTALL_DIR" ]] \
|| die "Triton Manage Server does not appear to be installed (${INSTALL_DIR} not found)"
info "refreshing installer files..."
for f in "${INSTALLER_FILES[@]}"; do
curl -fsSL "${REPO_BASE}/${f}" -o "${INSTALL_DIR}/${f}"
done
chmod +x "${INSTALL_DIR}/install.sh" "${INSTALL_DIR}/upgrade.sh" "${INSTALL_DIR}/uninstall.sh"
ok "installer files refreshed"
echo ""
exec bash "${INSTALL_DIR}/upgrade.sh" "${PASSTHROUGH[@]}"
fi
banner "▶ Triton Manage Server — Installer"
info "platform: $PLATFORM"

View file

@ -1,11 +1,12 @@
#!/usr/bin/env bash
# upgrade.sh — pull the latest manage-server image and restart.
#
# Takes a pre-upgrade pg_dump. DB schema migrations run on startup.
# Takes a pre-upgrade pg_dump backup. DB schema migrations run automatically
# on container startup — no manual migration step required.
#
# Usage:
# sudo bash upgrade.sh # latest from ghcr.io
# sudo bash upgrade.sh --image TAG # pin a specific image
# sudo bash upgrade.sh --image TAG # pin a specific image tag
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
@ -17,6 +18,7 @@ die() { printf '[manage-server] error: %s\n' "$*" >&2; exit 1; }
[[ $EUID -eq 0 ]] || die "must run as root"
[[ -f .env ]] || die ".env not found — run install.sh first"
# ── arg parsing ───────────────────────────────────────────────────────────
IMAGE=""
while [[ $# -gt 0 ]]; do
case "$1" in
@ -26,39 +28,58 @@ while [[ $# -gt 0 ]]; do
esac
done
# ── runtime detection ─────────────────────────────────────────────────────
if command -v podman-compose >/dev/null 2>&1; then COMPOSE=(podman-compose); RUNTIME=podman
elif podman compose version >/dev/null 2>&1; then COMPOSE=(podman compose); RUNTIME=podman
elif docker compose version >/dev/null 2>&1; then COMPOSE=(docker compose); RUNTIME=docker
else die "no compose runtime found"; fi
# ── pin image if requested ────────────────────────────────────────────────
if [[ -n "$IMAGE" ]]; then
sed -i "s|^TRITON_MANAGE_IMAGE=.*|TRITON_MANAGE_IMAGE=$IMAGE|" .env
info "pinned image to $IMAGE"
fi
if command -v podman-compose >/dev/null 2>&1; then COMPOSE=(podman-compose)
elif podman compose version >/dev/null 2>&1; then COMPOSE=(podman compose)
elif docker compose version >/dev/null 2>&1; then COMPOSE=(docker compose)
else die "no compose runtime found"; fi
# ── pre-upgrade DB backup ─────────────────────────────────────────────────
case "$(uname -s)" in
Linux) BACKUP_DIR="/var/backups/triton" ;;
Darwin) BACKUP_DIR="${HOME}/Library/Application Support/triton/backups" ;;
*) BACKUP_DIR="$SCRIPT_DIR/backups" ;;
esac
mkdir -p "$BACKUP_DIR"
DUMP_FILE="${BACKUP_DIR}/manage-pre-upgrade-$(date +%F-%H%M%S).sql.gz"
info "pre-upgrade DB backup..."
mkdir -p /var/backups/triton
DUMP_FILE="/var/backups/triton/manage-pre-upgrade-$(date +%F-%H%M%S).sql.gz"
podman exec triton-manage-db pg_dump -U triton triton_manage 2>/dev/null \
| gzip > "$DUMP_FILE" || die "pg_dump failed — aborting upgrade"
info " saved: $DUMP_FILE"
PG_USER=$(grep -E '^POSTGRES_USER=' .env | cut -d= -f2)
PG_USER=${PG_USER:-triton}
PG_DB=$(grep -E '^POSTGRES_DB=' .env | cut -d= -f2)
PG_DB=${PG_DB:-triton_manage}
"$RUNTIME" exec triton-manage-db pg_dump -U "$PG_USER" "$PG_DB" 2>/dev/null \
| gzip > "$DUMP_FILE" || die "pg_dump failed — aborting upgrade (DB container may not be running)"
info " backup saved: $DUMP_FILE"
# ── pull new image ────────────────────────────────────────────────────────
info "pulling latest image..."
"${COMPOSE[@]}" --env-file .env pull manage-server
# ── recreate container (DB migrations run on startup) ─────────────────────
info "recreating manage-server container..."
info " DB schema migrations will run automatically on startup"
"${COMPOSE[@]}" --env-file .env up -d --no-deps manage-server
# ── wait for healthy (confirms migrations succeeded) ──────────────────────
HOST_PORT=$(grep -E '^TRITON_MANAGE_HOST_PORT=' .env | cut -d= -f2)
HOST_PORT=${HOST_PORT:-8082}
info "waiting for new container to become healthy..."
info "waiting for server to become healthy on :${HOST_PORT}..."
for i in $(seq 1 30); do
CODE=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:${HOST_PORT}/" || echo "000")
if [[ "$CODE" == "302" || "$CODE" == "200" ]]; then
info "upgrade complete"
info "upgrade complete — server is healthy (migrations applied)"
info " rollback if needed: gunzip -c ${DUMP_FILE} | $RUNTIME exec -i triton-manage-db psql -U ${PG_USER} ${PG_DB}"
exit 0
fi
sleep 2
done
die "new container did not become healthy in 60s — check logs"
die "server did not become healthy in 60s — check logs: $RUNTIME logs triton-manageserver"