fix: rename OPERATOR_API_TOKEN to API_TOKEN, remove redundant token injection, fix user HOME for sudo context
This commit is contained in:
parent
09fd80ca34
commit
cecd50d62b
2 changed files with 5 additions and 16 deletions
|
|
@ -245,5 +245,3 @@ echo " Installation complete"
|
||||||
echo " Next: bash 02-migrate-peers.sh"
|
echo " Next: bash 02-migrate-peers.sh"
|
||||||
echo "========================================="
|
echo "========================================="
|
||||||
echo ""
|
echo ""
|
||||||
SCRIPT
|
|
||||||
echo "done"
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ sep
|
||||||
info "Loading credentials..."
|
info "Loading credentials..."
|
||||||
set -a; source "$OPERATOR_DIR/.env"; set +a
|
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 "${BASE_DOMAIN:-}" ] && fail "BASE_DOMAIN not found in .env"
|
||||||
[ -z "${API_SUBDOMAIN:-}" ] && fail "API_SUBDOMAIN 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"
|
echo "$LEGACY_PUBLIC_KEY" > "$WG_SERVER_PUB"
|
||||||
ok "Private key written to server keyfile."
|
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 ──────────────────────────────────────────────────────
|
# ─── START NEW WIREGUARD ──────────────────────────────────────────────────────
|
||||||
sep
|
sep
|
||||||
info "Starting new WireGuard with legacy identity..."
|
info "Starting new WireGuard with legacy identity..."
|
||||||
|
|
@ -192,7 +183,7 @@ ok "Existing users will reconnect automatically."
|
||||||
sep
|
sep
|
||||||
info "Verifying API..."
|
info "Verifying API..."
|
||||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 15 \
|
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")
|
"$API_URL/wireguard/peers" 2>/dev/null || echo "000")
|
||||||
[ "$HTTP_CODE" = "200" ] || fail "API not responding (HTTP $HTTP_CODE)."
|
[ "$HTTP_CODE" = "200" ] || fail "API not responding (HTTP $HTTP_CODE)."
|
||||||
ok "API responding."
|
ok "API responding."
|
||||||
|
|
@ -218,7 +209,7 @@ migrate_peer() {
|
||||||
|
|
||||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 15 \
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 15 \
|
||||||
-X POST "$API_URL/wireguard/peers" \
|
-X POST "$API_URL/wireguard/peers" \
|
||||||
-H "Authorization: Bearer $OPERATOR_API_TOKEN" \
|
-H "Authorization: Bearer $API_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"public_key\": \"$PUBKEY\", \"allowed_ips\": $IPS_JSON}" 2>/dev/null || echo "000")
|
-d "{\"public_key\": \"$PUBKEY\", \"allowed_ips\": $IPS_JSON}" 2>/dev/null || echo "000")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue