12# Deploy the Airwaves server to a Docker host over SSH.3# AIRWAVES_ZIP=12345 scripts/deploy.sh nas4# Creates ~/airwaves on the host; .env there holds host-specific settings,5# written on the first deploy: the name, the tailnet address to listen on,6# the host's time zone and the antenna's ZIP code (AIRWAVES_ZIP).7set -eu8host=${1:?usage: deploy.sh <ssh-host>}9root=$(cd "$(dirname "$0")/.." && pwd)10stage=$(mktemp -d)11trap 'rm -rf "$stage"' EXIT1213mkdir -p "$stage/airwavesd"14GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -C "$root" -trimpath -ldflags="-s -w" -o "$stage/airwavesd/airwavesd" ./cmd/airwavesd15cp "$root/deploy/Dockerfile" "$stage/airwavesd/"16cp "$root/deploy/compose.yml" "$root/deploy/up.sh" "$stage/"17cp -R "$root/deploy/weatherstar" "$stage/"1819ssh "$host" 'mkdir -p ~/airwaves'20rsync -a "$stage/" "$host:airwaves/"21ssh "$host" "ZIP='${AIRWAVES_ZIP:-}' sh -s" <<'EOF'22set -eu23cd ~/airwaves24if [ ! -f .env ]; then25 ip=$(tailscale ip -4 2>/dev/null | head -1)26 tz=$(readlink /etc/localtime 2>/dev/null | sed 's|.*/zoneinfo/||')27 printf "AIRWAVES_NAME=%s\nAIRWAVES_BIND=%s\nTZ=%s\nAIRWAVES_ZIP=%s\n" "$(hostname)" "${ip:-127.0.0.1}" "${tz:-UTC}" "$ZIP" > .env28 echo "wrote .env:"; cat .env29fi30for key in TZ AIRWAVES_ZIP; do31 if ! grep -q "^$key=." .env; then32 echo "~/airwaves/.env needs $key (the time zone, like America/Chicago; the antenna's ZIP code)" >&233 exit 134 fi35done36./up.sh37EOF