summaryrefslogtreecommitdiff
path: root/status.sh
diff options
context:
space:
mode:
Diffstat (limited to 'status.sh')
-rwxr-xr-xstatus.sh103
1 files changed, 103 insertions, 0 deletions
diff --git a/status.sh b/status.sh
new file mode 100755
index 0000000..5f58329
--- /dev/null
+++ b/status.sh
@@ -0,0 +1,103 @@
+#!/bin/bash
+# mirror-status.sh
+# Generate a status page for FailZero mirrors
+
+MIRROR_BASE="/mnt/brimstone/mirror"
+STATUS_DIR="/mnt/brimstone/mirror/status"
+STATUS_FILE="$STATUS_DIR/index.html"
+LOG_DIR="/var/log/mirrors"
+
+# List your mirrors (folder name => display name)
+declare -A MIRRORS=(
+ ["archlinux"]="Arch Linux"
+ ["debian"]="Debian"
+ ["gentoo"]="Gentoo"
+ ["hardenedbsd"]="HardenedBSD"
+ ["slackware"]="Slackware"
+ ["void"]="Void Linux"
+ ["rocky"]="Rocky Linux"
+ ["alma"]="AlmaLinux"
+)
+
+mkdir -p "$STATUS_DIR"
+
+cat > "$STATUS_FILE" <<EOF
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>FailZero Mirror Status</title>
+ <style>
+ body { font-family: monospace; background: #111; color: #eee; }
+ h1 { color: #f33; }
+ table { border-collapse: collapse; width: 100%; }
+ th, td { padding: 8px 12px; border: 1px solid #444; }
+ th { background: #222; }
+ tr.ok { background: #1a2; }
+ tr.warn { background: #662; }
+ tr.fail { background: #a22; }
+ </style>
+</head>
+<body>
+ <h1>FailZero Mirror Status</h1>
+ <p>Updated: $(date)</p>
+ <table>
+ <tr><th>Distro</th><th>Last Sync (log)</th></tr>
+EOF
+
+for key in "${!MIRRORS[@]}"; do
+ DISTRO="${MIRRORS[$key]}"
+ DIR="$MIRROR_BASE/$key"
+ LOG="$LOG_DIR/${key}-mirror-sync.log"
+
+ STATUS="FAIL"
+ CLASS="fail"
+ LASTSYNC="no log"
+ FRESHNESS="unknown"
+
+ # 1. Parse rsync log exitcode
+ if [ -f "$LOG" ]; then
+ LASTSYNC=$(stat -c %y "$LOG" | cut -d. -f1)
+ EXITCODE=$(grep "EXITCODE:" "$LOG" | tail -n1 | cut -d: -f2)
+
+ if [ -n "$EXITCODE" ]; then
+ if [ "$EXITCODE" = "0" ]; then
+ STATUS="OK"
+ CLASS="ok"
+ else
+ STATUS="RSYNC FAIL ($EXITCODE)"
+ CLASS="fail"
+ fi
+ else
+ STATUS="NO EXITCODE"
+ CLASS="warn"
+ fi
+ fi
+
+ # 2. Check lastupdate if present (for freshness)
+# if [ -f "$DIR/lastupdate" ]; then
+# TS=$(tr -d '[:space:]' < "$DIR/lastupdate" 2>/dev/null)
+# if [[ "$TS" =~ ^[0-9]+$ ]]; then
+# NOW=$(date +%s)
+# AGE=$(( NOW - TS ))
+# if [ "$AGE" -lt 7200 ]; then
+# FRESHNESS="$((AGE/60)) min ago"
+# elif [ "$AGE" -lt 86400 ]; then
+# FRESHNESS="$((AGE/3600)) hr ago"
+# [ "$STATUS" = "OK" ] && CLASS="warn"
+# else
+# FRESHNESS="$((AGE/86400)) days ago"
+# [ "$STATUS" = "OK" ] && CLASS="warn"
+# fi
+# fi
+# fi
+
+ echo " <tr class=\"$CLASS\"><td>$DISTRO</td><td>$LASTSYNC</td>" >> "$STATUS_FILE"
+done
+
+cat >> "$STATUS_FILE" <<EOF
+ </table>
+ <p style="margin-top:20px;font-size:smaller;">FailZero Infrastructure – Mirror Ops</p>
+</body>
+</html>
+EOF