24 lines
631 B
Bash
24 lines
631 B
Bash
# Start T3 Code on the interface's current IPv4 address. The address changes
|
|
# with the NetBird profile, so it cannot be a Nix value.
|
|
# Usage: t3code-serve.sh <interface> <t3 binary>
|
|
interface="$1"
|
|
t3="$2"
|
|
timeout="${T3CODE_ADDR_TIMEOUT:-60}"
|
|
|
|
address=""
|
|
for ((waited = 0; waited < timeout; waited++)); do
|
|
line="$(ip -4 -o addr show dev "$interface" 2>/dev/null || true)"
|
|
if [[ "$line" =~ inet[[:space:]]+([0-9.]+)/ ]]; then
|
|
address="${BASH_REMATCH[1]}"
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
if [[ -z "$address" ]]; then
|
|
echo "no IPv4 address on $interface after ${timeout}s" >&2
|
|
exit 1
|
|
fi
|
|
|
|
exec "$t3" serve --host "$address"
|