#!/usr/bin/env bash # Build (if needed) and start funknetz against the local svxlink-docker lab. # Does not start Docker — run: (cd svxlink-docker && docker compose up -d) set -euo pipefail ROOT="$(cd "$(dirname "$0")" && pwd)" LAB="$ROOT/svxlink-docker" ENV_FILE="$LAB/.env" CONF="$LAB/config/svxreflector.conf" GENERATED="$LAB/.funknetz.generated.json" LOG_DIR="$LAB/logs" LOG_FILE="$LOG_DIR/funknetz-lab.log" APP_BIN="$ROOT/build/bin/funknetz.app/Contents/MacOS/funknetz" die() { echo "teststart: $*" >&2 exit 1 } [[ -f "$ENV_FILE" ]] || die "missing $ENV_FILE (copy from .env.example and edit; this script will not copy it)" # shellcheck disable=SC1090 set -a # shellcheck source=/dev/null source "$ENV_FILE" set +a missing=() [[ -n "${FUNKNETZ_HOST:-}" ]] || missing+=(FUNKNETZ_HOST) [[ -n "${FUNKNETZ_PORT:-}" ]] || missing+=(FUNKNETZ_PORT) [[ -n "${FUNKNETZ_CALLSIGN:-}" ]] || missing+=(FUNKNETZ_CALLSIGN) [[ -n "${FUNKNETZ_AUTH_KEY:-}" ]] || missing+=(FUNKNETZ_AUTH_KEY) [[ -n "${FUNKNETZ_TALK_GROUP:-}" ]] || missing+=(FUNKNETZ_TALK_GROUP) if ((${#missing[@]})); then die "missing in .env: ${missing[*]}" fi [[ -f "$CONF" ]] || die "missing $CONF" # Resolve FUNKNETZ_CALLSIGN → password group in [USERS], then secret in [PASSWORDS]. callsign_upper="$(printf '%s' "$FUNKNETZ_CALLSIGN" | tr '[:lower:]' '[:upper:]')" section="" password_group="" auth_secret="" while IFS= read -r line || [[ -n "$line" ]]; do line="${line%%#*}" line="$(printf '%s' "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" [[ -z "$line" ]] && continue if [[ "$line" =~ ^\[(.+)\]$ ]]; then section="${BASH_REMATCH[1]}" continue fi case "$section" in USERS) key="${line%%=*}" val="${line#*=}" key="$(printf '%s' "$key" | sed -e 's/[[:space:]]*$//' | tr '[:lower:]' '[:upper:]')" val="$(printf '%s' "$val" | sed -e 's/^[[:space:]]*//')" if [[ "$key" == "$callsign_upper" ]]; then password_group="$val" fi ;; PASSWORDS) key="${line%%=*}" val="${line#*=}" key="$(printf '%s' "$key" | sed -e 's/[[:space:]]*$//')" val="$(printf '%s' "$val" | sed -e 's/^[[:space:]]*//' -e 's/^"//' -e 's/"$//')" if [[ -n "$password_group" && "$key" == "$password_group" ]]; then auth_secret="$val" fi ;; esac done <"$CONF" [[ -n "$password_group" ]] || die "callsign $FUNKNETZ_CALLSIGN is not in [USERS] in $CONF" [[ -n "$auth_secret" ]] || die "password group $password_group has no [PASSWORDS] entry in $CONF" [[ "$FUNKNETZ_AUTH_KEY" == "$auth_secret" ]] || die "FUNKNETZ_AUTH_KEY does not match [PASSWORDS] for $FUNKNETZ_CALLSIGN" mkdir -p "$LOG_DIR" # JSON-escape a string value. json_str() { python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "$1" } host_json="$(json_str "$FUNKNETZ_HOST")" call_json="$(json_str "$callsign_upper")" key_json="$(json_str "$FUNKNETZ_AUTH_KEY")" log_json="$(json_str "$LOG_FILE")" umask 077 cat >"$GENERATED" </dev/null | head -n 1 || true)" [[ -n "$newer" ]] && needs_build=1 fi if ((needs_build)); then echo "teststart: building funknetz.app…" (cd "$ROOT" && GOWORK=off wails build) [[ -x "$APP_BIN" ]] || die "build finished but binary missing: $APP_BIN" fi echo "teststart: starting with -c $GENERATED" exec "$APP_BIN" -c "$GENERATED"