#!/data/data/com.termux/files/usr/bin/bash # Tailscale start helper for Termux (Android, userspace networking) # Usage: # ./ts-up.sh -> start tailscaled + tailscale up with your key # ./ts-up.sh -> if no key, prints the login URL from tailscaled log TS=${TS_DIR:-$HOME/ts-build} DAEMON="$TS/tailscaled" LOG="$TS/tailscaled.log" SOCK="$TS/tailscaled.sock" STATE="$TS/state" mkdir -p "$STATE" # If authkey was provided via env or arg, use it AUTHKEY="${1:-$TS_AUTHKEY}" # Start tailscaled if not already running if ! TAILSCALE_SOCKET="$SOCK" "$TS/tailscale" status >/dev/null 2>&1; then echo "[ts-up] starting tailscaled (userspace)…" # --statedir takes a DIRECTORY (-> /tailscaled.state); a directory under --state breaks # the CLI with "state store is unhealthy". No --logdir flag exists in the Android build. # (In-Hermes: start this daemon with the terminal tool's background=true instead of nohup.) nohup "$DAEMON" \ --statedir="$STATE" \ --socket="$SOCK" \ --tun=userspace-networking \ --verbose=1 \ >>"$LOG" 2>&1 & TSPID=$! disown echo "[ts-up] tailscaled pid=$TSPID, log=$LOG" sleep 2 fi # Point the CLI at our socket export TAILSCALE_SOCKET="$SOCK" if [ -n "$AUTHKEY" ]; then echo "[ts-up] running: tailscale up --auth-key=… (masked)" "$TS/tailscale" up --auth-key="$AUTHKEY" else echo "[ts-up] no auth key given; running 'tailscale up' to print login URL" "$TS/tailscale" up fi "$TS/tailscale" status