Z User commited on
Commit
b820b36
·
1 Parent(s): ca5e3fb

fix: persist WebUI credentials + auto-setup on startup

Browse files

- Symlink ~/.hermes-webui/ to /data/hermes/webui/ for persistence
- Auto-migrate existing credentials to persistent storage
- Auto-setup credentials after BFF starts if not configured
- Default: admin / Hermes2026 (configurable via env vars)

Files changed (1) hide show
  1. start.sh +39 -0
start.sh CHANGED
@@ -21,6 +21,23 @@ done
21
 
22
  echo "Persistent storage ready."
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # ── Clean up stale PID/lock files from previous crash ──
25
  echo "Cleaning up stale state..."
26
  rm -f "$HERMES_HOME/gateway.pid" 2>/dev/null
@@ -88,6 +105,28 @@ for i in $(seq 1 15); do
88
  sleep 2
89
  done
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  echo ""
92
  echo "=== All services started ==="
93
  echo " Gateway: http://127.0.0.1:8642 (with Python watchdog in entry.py)"
 
21
 
22
  echo "Persistent storage ready."
23
 
24
+ # ── Persist WebUI credentials across rebuilds ──
25
+ WEBUI_HOME="/root/.hermes-web-ui"
26
+ WEBUI_DATA="/data/hermes/webui"
27
+ mkdir -p "$WEBUI_DATA"
28
+ if [ ! -L "$WEBUI_HOME" ] && [ -d "$WEBUI_HOME" ]; then
29
+ # Migrate existing credentials to persistent storage
30
+ if [ -f "$WEBUI_HOME/.credentials" ] && [ ! -f "$WEBUI_DATA/.credentials" ]; then
31
+ cp "$WEBUI_HOME/.credentials" "$WEBUI_DATA/.credentials"
32
+ echo "Migrated WebUI credentials to persistent storage"
33
+ fi
34
+ rm -rf "$WEBUI_HOME"
35
+ fi
36
+ if [ ! -L "$WEBUI_HOME" ]; then
37
+ ln -sf "$WEBUI_DATA" "$WEBUI_HOME"
38
+ echo "Symlink: hermes-web-ui -> $WEBUI_DATA"
39
+ fi
40
+
41
  # ── Clean up stale PID/lock files from previous crash ──
42
  echo "Cleaning up stale state..."
43
  rm -f "$HERMES_HOME/gateway.pid" 2>/dev/null
 
105
  sleep 2
106
  done
107
 
108
+ # ── Auto-setup WebUI credentials if not configured ──
109
+ AUTH_TOKEN="${AUTH_TOKEN:-hermes-bot-2026}"
110
+ WEBUI_USER="${WEBUI_USERNAME:-admin}"
111
+ WEBUI_PASS="${WEBUI_PASSWORD:-Hermes2026}"
112
+ AUTH_STATUS=$(curl -s http://127.0.0.1:6060/api/auth/status 2>/dev/null)
113
+ HAS_PW=$(echo "$AUTH_STATUS" | python3 -c "import json,sys; print(json.load(sys.stdin).get('hasPasswordLogin',False))" 2>/dev/null)
114
+ if [ "$HAS_PW" = "False" ]; then
115
+ echo "[$(date)] WebUI: No credentials configured, auto-setting up..."
116
+ SETUP_RESULT=$(curl -s -w "\n%{http_code}" -X POST http://127.0.0.1:6060/api/auth/setup \
117
+ -H "Content-Type: application/json" \
118
+ -H "Authorization: Bearer $AUTH_TOKEN" \
119
+ -d "{\"username\":\"$WEBUI_USER\",\"password\":\"$WEBUI_PASS\"}" 2>/dev/null)
120
+ SETUP_CODE=$(echo "$SETUP_RESULT" | tail -1)
121
+ if [ "$SETUP_CODE" = "200" ]; then
122
+ echo "[$(date)] WebUI: Credentials auto-configured (user: $WEBUI_USER)"
123
+ else
124
+ echo "[$(date)] WebUI: Auto-setup failed: $SETUP_RESULT"
125
+ fi
126
+ else
127
+ echo "[$(date)] WebUI: Credentials already configured"
128
+ fi
129
+
130
  echo ""
131
  echo "=== All services started ==="
132
  echo " Gateway: http://127.0.0.1:8642 (with Python watchdog in entry.py)"