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 bash2
# 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).4
set -Eeuo pipefail5
umask 0776
error(){ printf '[ERROR] %s\n' "$*" >&2; }7
info(){ printf '[INFO] %s\n' "$*"; }8
fail(){ error "$*"; return 1; }9
trap 'error "Branding repair stopped on line $LINENO; your SQLite database was not erased."' ERR11
if [[ $EUID -ne 0 ]]; then error 'Run as root (or sudo bash ./fix-status-branding.sh).'; exit 1; fi12
ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)13
cd "$ROOT"14
if [[ ! -f package.json || ! -f scripts/deploy.sh || ! -f src/branding.js ]]; then15
error 'Missing release files. Push the full External Status 1.0.9 project to Git, then pull it on VPS 2.'16
exit 117
fi18
if [[ ! -x /usr/bin/node ]]; then error 'Node.js is not installed at /usr/bin/node.'; exit 1; fi19
VERSION=$(/usr/bin/node -p "require('./package.json').version")20
if [[ "$VERSION" != '1.0.9' ]]; then21
error "Your Git checkout is v$VERSION; expected v1.0.9. Upload/commit the new files to ArchForge, git pull, then retry."22
exit 123
fi24
if ! grep -Fq "label:'ArchForge SSH'" src/probes.js || ! grep -Fq "label:'ArchForge HTTPS'" src/probes.js; then25
error 'Git checkout still contains older probe names. Commit/push/pull all v1.0.9 files.'26
exit 127
fi28
info 'Deploying verified v1.0.9 source and backing up the existing database...'29
bash "$ROOT/scripts/deploy.sh" "$ROOT"30
INSTALLED=/opt/archforge-status/app31
if [[ ! -f "$INSTALLED/package.json" || ! -f "$INSTALLED/src/branding.js" ]]; then32
error 'The installed application still lacks v1.0.9 files. Inspect systemd and deploy output.'33
exit 134
fi35
if ! cmp -s "$ROOT/src/database.js" "$INSTALLED/src/database.js" || ! cmp -s "$ROOT/src/branding.js" "$INSTALLED/src/branding.js"; then36
error 'Installed source differs from v1.0.9 checkout. Check deploy location and permissions.'37
exit 138
fi39
if ! systemctl is-active --quiet archforge-status; then40
error 'archforge-status is not active after deployment. Check journalctl -u archforge-status -n 40.'41
exit 142
fi43
info 'Checking actual running application (not only the Git checkout)...'44
HEALTH=$(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 147
}48
if ! 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)}})' ; then49
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 152
fi53
info "Health endpoint confirms $HEALTH"54
if command -v sqlite3 >/dev/null 2>&1 && [[ -f /var/lib/archforge-status/status.db ]]; then55
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'* ]]; then59
error 'Old labels are still in SQLite after successful v1.0.9 boot. Check for an alternate database or another running process.'60
exit 161
fi62
fi63
info 'Done: new branding is active. Refresh https://status.archforge.nl with Ctrl+F5.'