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 bash2
set -Eeuo pipefail3
ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)4
cd "$ROOT"5
ENV_FILE=/etc/archforge-status/status.env6
if [[ "${1:-}" == '--env-only' ]]; then7
[[ "$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"; then10
echo '[INFO] ArchForge HTTPS monitor already updated or not configured.'; exit 011
fi12
bak="$ENV_FILE.before-archforge-$(date -u +%Y%m%d%H%M%S)"13
cp -p -- "$ENV_FILE" "$bak"14
python3 - "$ENV_FILE" <<'PYIN'15
import pathlib,re,sys,os16
p=pathlib.Path(sys.argv[1])17
s=p.read_text()18
s,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)19
if n != 1: raise SystemExit('Unexpected ArchForge HTTPS target format; not changing file')20
p.write_text(s)21
PYIN22
chmod 600 "$ENV_FILE"23
systemctl restart archforge-status24
echo '[OK] ArchForge HTTPS monitoring endpoint changed to .archforge.'25
exit 026
fi27
[[ -d .git ]] || { echo '[ERROR] Run from a ArchForge checkout, not a copied installation.' >&2; exit 1; }28
CURRENT=$(git remote get-url origin)29
if [[ "$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$ ]]; then30
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; then35
echo '[ERROR] New .archforge ArchForge endpoint is not accessible. Remote unchanged.' >&2; exit 136
fi37
git remote set-url origin "$NEXT"38
echo '[OK] Local origin updated without touching commits or working files.'39
elif [[ "$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$ ]]; then40
echo '[OK] Origin already uses .archforge.'41
else42
echo '[ERROR] Remote is not a recognized safe ArchForge URL. No modifications made.' >&2; exit 143
fi44
if [[ $EUID == 0 ]]; then45
bash "$0" --env-only46
else47
echo 'To change an existing ArchForge HTTPS probe target (if configured), run:'48
echo " sudo bash $ROOT/migrate-archforge-remote.sh --env-only"49
fi