Skip to content

Repository files, collaboration, releases and project activity.

archforge-external-status / fix-status-branding.shmain
▤ fix-status-branding.sh3415 bytes
64 lines · Select a line number for a permalink
1#!/usr/bin/env bash
2# Safe standalone script: run with `bash ./fix-status-branding.sh` from the Git checkout.
3# Do not source this script (it is intentionally a standalone command).
4set -Eeuo pipefail
5umask 077
6error(){ printf '[ERROR] %s\n' "$*" >&2; }
7info(){ printf '[INFO] %s\n' "$*"; }
8fail(){ error "$*"; return 1; }
9trap 'error "Branding repair stopped on line $LINENO; your SQLite database was not erased."' ERR
11if [[ $EUID -ne 0 ]]; then error 'Run as root (or sudo bash ./fix-status-branding.sh).'; exit 1; fi
12ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
13cd "$ROOT"
14if [[ ! -f package.json || ! -f scripts/deploy.sh || ! -f src/branding.js ]]; then
15 error 'Missing release files. Push the full External Status 1.0.9 project to Git, then pull it on VPS 2.'
16 exit 1
17fi
18if [[ ! -x /usr/bin/node ]]; then error 'Node.js is not installed at /usr/bin/node.'; exit 1; fi
19VERSION=$(/usr/bin/node -p "require('./package.json').version")
20if [[ "$VERSION" != '1.0.9' ]]; then
21 error "Your Git checkout is v$VERSION; expected v1.0.9. Upload/commit the new files to ArchForge, git pull, then retry."
22 exit 1
23fi
24if ! grep -Fq "label:'ArchForge SSH'" src/probes.js || ! grep -Fq "label:'ArchForge HTTPS'" src/probes.js; then
25 error 'Git checkout still contains older probe names. Commit/push/pull all v1.0.9 files.'
26 exit 1
27fi
28info 'Deploying verified v1.0.9 source and backing up the existing database...'
29bash "$ROOT/scripts/deploy.sh" "$ROOT"
30INSTALLED=/opt/archforge-status/app
31if [[ ! -f "$INSTALLED/package.json" || ! -f "$INSTALLED/src/branding.js" ]]; then
32 error 'The installed application still lacks v1.0.9 files. Inspect systemd and deploy output.'
33 exit 1
34fi
35if ! cmp -s "$ROOT/src/database.js" "$INSTALLED/src/database.js" || ! cmp -s "$ROOT/src/branding.js" "$INSTALLED/src/branding.js"; then
36 error 'Installed source differs from v1.0.9 checkout. Check deploy location and permissions.'
37 exit 1
38fi
39if ! systemctl is-active --quiet archforge-status; then
40 error 'archforge-status is not active after deployment. Check journalctl -u archforge-status -n 40.'
41 exit 1
42fi
43info 'Checking actual running application (not only the Git checkout)...'
44HEALTH=$(curl --silent --show-error --max-time 6 --fail http://127.0.0.1:3000/healthz) || {
45 error 'Local status server does not respond. Check journalctl -u archforge-status -n 40.'
46 exit 1
48if ! printf '%s' "$HEALTH" | /usr/bin/node -e 'let t="";process.stdin.on("data",c=>t+=c).on("end",()=>{try{const d=JSON.parse(t);if(d.version!=="1.0.9"||d.ok!==true)process.exit(1)}catch{process.exit(1)}})' ; then
49 error "Running status server is NOT v1.0.9. Health response: $HEALTH"
50 error 'Check systemctl cat archforge-status and inspect other services on port 3000.'
51 exit 1
52fi
53info "Health endpoint confirms $HEALTH"
54if command -v sqlite3 >/dev/null 2>&1 && [[ -f /var/lib/archforge-status/status.db ]]; then
55 LABELS=$(sqlite3 -separator '|' /var/lib/archforge-status/status.db \
56 "SELECT id,label FROM services WHERE id IN ('git_http','git_ssh') ORDER BY id;")
57 printf '[INFO] Persisted labels:\n%s\n' "$LABELS"
58 if [[ "$LABELS" == *'Git Smart HTTP'* || "$LABELS" == *'Git SSH'* ]]; then
59 error 'Old labels are still in SQLite after successful v1.0.9 boot. Check for an alternate database or another running process.'
60 exit 1
61 fi
62fi
63info 'Done: new branding is active. Refresh https://status.archforge.nl with Ctrl+F5.'