From 275beab907c7508910195b97e8460b16153e1541 Mon Sep 17 00:00:00 2001 From: zenaku Date: Fri, 2 Oct 2026 20:05:12 +0000 Subject: [PATCH] Update migration and peers --- migration.sh | 5 +++++ steps/02-peers.sh | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/migration.sh b/migration.sh index 50e49b6..28d68e3 100755 --- a/migration.sh +++ b/migration.sh @@ -9,6 +9,7 @@ if [ "$EUID" -eq 0 ]; then fi SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +sudo chown -R "$USER:$USER" "$SCRIPT_DIR" 2>/dev/null || true OPERATOR_DIR="$HOME/operator-docker" BACKUP_DIR="$HOME/.wg-migration" LOG="$BACKUP_DIR/migration.log" @@ -20,6 +21,8 @@ if [ -f "$OPERATOR_DIR/lib/ui.sh" ]; then source "$OPERATOR_DIR/lib/ui.sh" source "$OPERATOR_DIR/lib/log.sh" source "$OPERATOR_DIR/lib/steps.sh" + +fail() { log_error "$1"; exit 1; } else RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; RESET='\033[0m' ok() { echo -e "${GREEN}[OK]${RESET} $1"; [ -f "$LOG" ] && echo "[OK] $1" >> "$LOG"; } @@ -76,7 +79,9 @@ if [ -f "$OPERATOR_DIR/lib/ui.sh" ]; then source "$OPERATOR_DIR/lib/ui.sh" source "$OPERATOR_DIR/lib/log.sh" source "$OPERATOR_DIR/lib/steps.sh" + fi +fail() { log_error "$1"; exit 1; } # ─── STEP 2: Backup & cleanup (needs root) ──────────────────────────────────── print_section "Step 2/$TOTAL_STEPS — Backup & cleanup" diff --git a/steps/02-peers.sh b/steps/02-peers.sh index 16c4fc7..3ecd8e9 100644 --- a/steps/02-peers.sh +++ b/steps/02-peers.sh @@ -195,14 +195,17 @@ ok "Existing users will reconnect automatically." # ─── VERIFY API ─────────────────────────────────────────────────────────────── sep info "Verifying API..." -for i in $(seq 1 10); do - HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \ - -H "Authorization: Bearer $API_TOKEN" \ - "$API_URL/wireguard/peers" 2>/dev/null || echo "000") - [ "$HTTP_CODE" = "200" ] && break - warn "API not ready (HTTP $HTTP_CODE) — retry $i/10..." - sleep 5 -done +DEADLINE=$(( $(date +%s) + 180 )) + i=0 + while [ $(date +%s) -lt $DEADLINE ]; do + HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \ + -H "Authorization: Bearer $API_TOKEN" \ + "$API_URL/wireguard/peers" 2>/dev/null || echo "000") + [ "$HTTP_CODE" = "200" ] && break + i=$(( i + 1 )) + warn "API not ready (HTTP $HTTP_CODE) — waited ${i}x5s..." + sleep 5 + done [ "$HTTP_CODE" = "200" ] || fail "API not responding after retries (HTTP $HTTP_CODE)." ok "API responding."