Files
proxmox/scripts/operator/upgrade-gitea-lxc.sh
defiQUG dbd517b279 Sync workspace: config, docs, scripts, CI, operator rules, and submodule pointers.
- Update dbis_core, cross-chain-pmm-lps, explorer-monorepo, metamask-integration, pr-workspace/chains
- Omit embedded publish git dirs and empty placeholders from index

Made-with: Cursor
2026-04-12 06:12:20 -07:00

115 lines
4.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Upgrade Gitea binary inside LXC VMID 104 (infra forge) via Proxmox pct.
# Prerequisites: SSH root@PROXMOX host, CT running, tteck-style paths (/usr/local/bin/gitea, /etc/gitea/app.ini).
#
# Usage:
# ./scripts/operator/upgrade-gitea-lxc.sh [--dry-run] [--version=1.22.6]
# Env:
# PROXMOX_GITEA_HOST (default: PROXMOX_HOST_R630_01 from config/ip-addresses.conf)
# GITEA_VMID (default: 104)
# GITEA_VERSION (default: empty = resolve "latest" from GitHub API on the CT)
# GITEA_ARCH (default: linux-amd64; use linux-arm64 on aarch64 LXCs)
#
# See: docs/04-configuration/GITEA_PLATFORM_AND_UPGRADE_RUNBOOK.md
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# shellcheck source=/dev/null
source "$PROJECT_ROOT/config/ip-addresses.conf" 2>/dev/null || true
# shellcheck source=/dev/null
source "$PROJECT_ROOT/scripts/lib/load-project-env.sh" 2>/dev/null || true
GITEA_VMID="${GITEA_VMID:-104}"
PROXMOX_GITEA_HOST="${PROXMOX_GITEA_HOST:-${PROXMOX_HOST_R630_01:-192.168.11.11}}"
GITEA_VERSION="${GITEA_VERSION:-}"
GITEA_ARCH="${GITEA_ARCH:-linux-amd64}"
DRY_RUN=0
for arg in "$@"; do
case "$arg" in
--dry-run) DRY_RUN=1 ;;
--version=*) GITEA_VERSION="${arg#--version=}" ;;
--help|-h)
grep '^#' "$0" | grep -v '^#!/' | sed 's/^# \{0,1\}//'
exit 0
;;
esac
done
ssh_exec() {
ssh -o ConnectTimeout=20 -o StrictHostKeyChecking=no "root@${PROXMOX_GITEA_HOST}" "$@"
}
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Gitea LXC upgrade"
echo " Proxmox: ${PROXMOX_GITEA_HOST}"
echo " VMID: ${GITEA_VMID}"
echo " Arch: ${GITEA_ARCH}"
echo " Version: ${GITEA_VERSION:-<latest from GitHub API>}"
echo " Dry-run: ${DRY_RUN}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if ! ssh_exec "pct status '${GITEA_VMID}'" >/dev/null 2>&1; then
echo "ERROR: pct status ${GITEA_VMID} failed on ${PROXMOX_GITEA_HOST} (SSH or VMID)." >&2
exit 1
fi
# Pass safe quoted env into CT
_ver_q=$(printf '%q' "$GITEA_VERSION")
_arch_q=$(printf '%q' "$GITEA_ARCH")
ssh_exec "pct exec ${GITEA_VMID} -- env GITEA_TARGET_VERSION=${_ver_q} GITEA_ARCH=${_arch_q} DRY_RUN=${DRY_RUN} bash -s" <<'REMOTE'
set -euo pipefail
if [[ ! -f /usr/local/bin/gitea ]]; then
echo "ERROR: /usr/local/bin/gitea not found (expected standard LXC layout)." >&2
exit 1
fi
echo "--- Current binary ---"
/usr/local/bin/gitea --version 2>&1 || true
VER="${GITEA_TARGET_VERSION:-}"
if [[ -z "${VER}" ]]; then
VER="$(curl -fsSL https://api.github.com/repos/go-gitea/gitea/releases/latest \
| sed -n 's/.*"tag_name": "v\{0,1\}\([^"]*\)".*/\1/p' | head -1)"
fi
if [[ -z "${VER}" ]]; then
echo "ERROR: Could not determine Gitea version (set GITEA_VERSION on host)." >&2
exit 1
fi
echo "--- Target version: ${VER} (${GITEA_ARCH}) ---"
if [[ "${DRY_RUN}" -eq 1 ]]; then
echo "[dry-run] Would: systemctl stop gitea; backup /usr/local/bin/gitea;"
echo " curl https://dl.gitea.com/gitea/${VER}/gitea-${VER}-${GITEA_ARCH};"
echo " gitea migrate; systemctl start gitea"
exit 0
fi
systemctl stop gitea
cp -a /usr/local/bin/gitea "/usr/local/bin/gitea.bak.$(date +%Y%m%d%H%M%S)"
TMP="$(mktemp)"
curl -fsSL -o "${TMP}" "https://dl.gitea.com/gitea/${VER}/gitea-${VER}-${GITEA_ARCH}"
chmod +x "${TMP}"
install -m 755 "${TMP}" /usr/local/bin/gitea
rm -f "${TMP}"
if [[ -f /etc/gitea/app.ini ]]; then
sudo -u gitea env GITEA_WORK_DIR=/var/lib/gitea HOME=/var/lib/gitea/data \
/usr/local/bin/gitea migrate --config /etc/gitea/app.ini
else
echo "WARN: /etc/gitea/app.ini missing; skipping migrate" >&2
fi
systemctl start gitea
sleep 2
systemctl is-active --quiet gitea
echo "--- Upgraded ---"
/usr/local/bin/gitea --version
REMOTE
echo ""
echo "Done. Verify UI and git over SSH/HTTPS. See docs/04-configuration/GITEA_PLATFORM_AND_UPGRADE_RUNBOOK.md"