summaryrefslogtreecommitdiff
path: root/playbooks/roles/outbound/templates/proxy/nginx/wait-for-bridge.sh
blob: da273a946466f2617a4bd97892ed6e76ff150aaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

set -e

echo "[+] Waiting for headscale-client to be resolvable..."

# Loop until headscale-client IP is found or timeout
timeout=30
start_time=$(date +%s)

HEADSCALE_IP=""
while [ -z "$HEADSCALE_IP" ]; do
   HEADSCALE_IP=$(getent hosts headscale-client | awk '{ print $1 }' | head -n 1)
   current_time=$(date +%s)
   if [ $((current_time - start_time)) -ge $timeout ]; then
     echo "[-] Timeout waiting for headscale-client DNS resolution." >&2
     exit 1
   fi
   if [ -z "$HEADSCALE_IP" ]; then
     sleep 1
   fi
done

echo "[+] Found headscale-client IP: $HEADSCALE_IP"
echo "[+] Attempting to modify routing table..."

apt update && apt install -y iproute2
ip route del default || echo "[-] Warning: Failed to delete default route (maybe none existed)."
ip route add default via $HEADSCALE_IP
echo "[+] Default route set via $HEADSCALE_IP."

echo "[+] Starting Nginx..."
nginx -g "daemon off;"