Skip to content

Repository files, collaboration, releases and project activity.

archforge-external-status / migrate-archforge-remote.shmain
▤ migrate-archforge-remote.sh2447 bytes
50 lines · Select a line number for a permalink
1#!/usr/bin/env bash
2set -Eeuo pipefail
3ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
4cd "$ROOT"
5ENV_FILE=/etc/archforge-status/status.env
6if [[ "${1:-}" == '--env-only' ]]; then
7 [[ "$EUID" == 0 ]] || { echo '[ERROR] Run env update with sudo.' >&2; exit 1; }
8 [[ -f "$ENV_FILE" ]] || { echo '[INFO] No existing status.env file found.'; exit 0; }
9 if ! grep -Eq '^TARGET_GIT_HTTP_URL=https://archforge\.nl/[A-Za-z0-9_-]+/[A-Za-z0-9_-]+\.git/info/refs$' "$ENV_FILE"; then
10 echo '[INFO] ArchForge HTTPS monitor already updated or not configured.'; exit 0
11 fi
12 bak="$ENV_FILE.before-archforge-$(date -u +%Y%m%d%H%M%S)"
13 cp -p -- "$ENV_FILE" "$bak"
14 python3 - "$ENV_FILE" <<'PYIN'
15import pathlib,re,sys,os
16p=pathlib.Path(sys.argv[1])
17s=p.read_text()
18s,n=re.subn(r'(?m)^(TARGET_GIT_HTTP_URL=https://archforge\.nl/[A-Za-z0-9_-]+/[A-Za-z0-9_-]+)\.git(/info/refs)$',r'\1.archforge\2',s)
19if n != 1: raise SystemExit('Unexpected ArchForge HTTPS target format; not changing file')
20p.write_text(s)
21PYIN
22 chmod 600 "$ENV_FILE"
23 systemctl restart archforge-status
24 echo '[OK] ArchForge HTTPS monitoring endpoint changed to .archforge.'
25 exit 0
26fi
27[[ -d .git ]] || { echo '[ERROR] Run from a ArchForge checkout, not a copied installation.' >&2; exit 1; }
28CURRENT=$(git remote get-url origin)
29if [[ "$CURRENT" =~ ^https://archforge\.nl/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+\.git$ || "$CURRENT" =~ ^git@archforge\.nl:[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+\.git$ ]]; then
30 NEXT="${CURRENT%.git}.archforge"
31 echo "Old remote: $CURRENT"
32 echo "New remote: $NEXT"
33 echo 'Checking the NEW ArchForge endpoint first (requires ArchForge Website 11.3.7)...'
34 if ! git ls-remote "$NEXT" HEAD >/dev/null; then
35 echo '[ERROR] New .archforge ArchForge endpoint is not accessible. Remote unchanged.' >&2; exit 1
36 fi
37 git remote set-url origin "$NEXT"
38 echo '[OK] Local origin updated without touching commits or working files.'
39elif [[ "$CURRENT" =~ ^https://archforge\.nl/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+\.archforge$ || "$CURRENT" =~ ^git@archforge\.nl:[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+\.archforge$ ]]; then
40 echo '[OK] Origin already uses .archforge.'
41else
42 echo '[ERROR] Remote is not a recognized safe ArchForge URL. No modifications made.' >&2; exit 1
43fi
44if [[ $EUID == 0 ]]; then
45 bash "$0" --env-only
46else
47 echo 'To change an existing ArchForge HTTPS probe target (if configured), run:'
48 echo " sudo bash $ROOT/migrate-archforge-remote.sh --env-only"
49fi