#!/bin/bash

PING_TARGET="8.8.8.8"
MAX_WAIT=120

echo "🌍 Waiting for internet connectivity..."
for i in $(seq 1 $MAX_WAIT); do
    if ping -c 1 -W 2 "$PING_TARGET" >/dev/null 2>&1; then
        echo "✅ Internet is reachable!"
        exit 0
    fi
    sleep 1
done

echo "❌ Internet not reachable after $MAX_WAIT seconds. Aborting tailscale startup."
exit 1