fix: rename OPERATOR_API_TOKEN to API_TOKEN, remove redundant token injection, fix user HOME for sudo context

This commit is contained in:
Zenaku 2026-09-26 17:40:21 +02:00
parent 09fd80ca34
commit cecd50d62b
2 changed files with 5 additions and 16 deletions

View file

@ -245,5 +245,3 @@ echo " Installation complete"
echo " Next: bash 02-migrate-peers.sh"
echo "========================================="
echo ""
SCRIPT
echo "done"

View file

@ -94,7 +94,7 @@ sep
info "Loading credentials..."
set -a; source "$OPERATOR_DIR/.env"; set +a
[ -z "${OPERATOR_API_TOKEN:-}" ] && fail "OPERATOR_API_TOKEN not found in .env"
[ -z "${API_TOKEN:-}" ] && fail "API_TOKEN not found in .env"
[ -z "${BASE_DOMAIN:-}" ] && fail "BASE_DOMAIN not found in .env"
[ -z "${API_SUBDOMAIN:-}" ] && fail "API_SUBDOMAIN not found in .env"
@ -142,15 +142,6 @@ echo "$LEGACY_PRIVATE_KEY" > "$WG_SERVER_KEY"
echo "$LEGACY_PUBLIC_KEY" > "$WG_SERVER_PUB"
ok "Private key written to server keyfile."
# ─── INJECT API TOKEN ────────────────────────────────────────────────────────
sep
info "Injecting legacy API token..."
LEGACY_API_TOKEN=$(grep -E '^API_TOKEN=' "$BACKUP_DIR/legacy.env" | cut -d= -f2 | tr -d '[:space:]')
[ -z "$LEGACY_API_TOKEN" ] && warn "No legacy API token found, keeping generated one." || {
sed -i "s|^OPERATOR_API_TOKEN=.*|OPERATOR_API_TOKEN=$LEGACY_API_TOKEN|" "$OPERATOR_DIR/.env"
ok "API token injected from legacy."
}
# ─── START NEW WIREGUARD ──────────────────────────────────────────────────────
sep
info "Starting new WireGuard with legacy identity..."
@ -192,7 +183,7 @@ ok "Existing users will reconnect automatically."
sep
info "Verifying API..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 15 \
-H "Authorization: Bearer $OPERATOR_API_TOKEN" \
-H "Authorization: Bearer $API_TOKEN" \
"$API_URL/wireguard/peers" 2>/dev/null || echo "000")
[ "$HTTP_CODE" = "200" ] || fail "API not responding (HTTP $HTTP_CODE)."
ok "API responding."
@ -218,7 +209,7 @@ migrate_peer() {
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 15 \
-X POST "$API_URL/wireguard/peers" \
-H "Authorization: Bearer $OPERATOR_API_TOKEN" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"public_key\": \"$PUBKEY\", \"allowed_ips\": $IPS_JSON}" 2>/dev/null || echo "000")