100 lines
3.0 KiB
Bash
Executable File
100 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
httpAddress="${SKALD_HTTP:-:8443}"
|
|
hallName="${SKALD_TEST_HALL:-test}"
|
|
insecure="${SKALD_INSECURE:-0}"
|
|
|
|
staticDir="${SKALD_STATIC_DIR:-static}"
|
|
binary="${SKALD_BINARY:-./skald}"
|
|
|
|
json_string() {
|
|
local value="$1"
|
|
value="${value//\\/\\\\}"
|
|
value="${value//\"/\\\"}"
|
|
value="${value//$'\n'/\\n}"
|
|
value="${value//$'\r'/\\r}"
|
|
value="${value//$'\t'/\\t}"
|
|
printf '%s' "$value"
|
|
}
|
|
|
|
adminUsername="${SKALD_TEST_ADMIN_USER:-admin}"
|
|
adminPassword="${SKALD_TEST_ADMIN_PASSWORD:-password}"
|
|
guestPassword="${SKALD_TEST_GUEST_PASSWORD:-guest}"
|
|
|
|
workDir="$(mktemp -d "${TMPDIR:-/tmp}/skald-local.XXXXXXXXXX")"
|
|
dataDir="$workDir/data"
|
|
hallsDir="$workDir/halls"
|
|
recordingsDir="$workDir/recordings"
|
|
serverPid=""
|
|
|
|
cleanup() {
|
|
if [[ -n "$serverPid" ]] && kill -0 "$serverPid" 2>/dev/null; then
|
|
kill "$serverPid" 2>/dev/null || true
|
|
wait "$serverPid" 2>/dev/null || true
|
|
fi
|
|
rm -rf "$workDir"
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
mkdir -p "$dataDir" "$hallsDir" "$recordingsDir/$hallName"
|
|
|
|
hallFile="$hallsDir/$hallName.json"
|
|
escapedAdminUsername="$(json_string "$adminUsername")"
|
|
escapedAdminPassword="$(json_string "$adminPassword")"
|
|
escapedGuestPassword="$(json_string "$guestPassword")"
|
|
cat > "$hallFile" <<EOF
|
|
{"users":{"$escapedAdminUsername":{"password":"$escapedAdminPassword","permissions":"op"}},"wildcard-user":{"password":"$escapedGuestPassword","permissions":"present"},"allow-recording":true}
|
|
EOF
|
|
|
|
if [[ ! -x "$binary" ]] || find . -name '*.go' -newer "$binary" -print -quit | grep -q .; then
|
|
echo "Building $binary"
|
|
go build -o "$binary" .
|
|
fi
|
|
|
|
if [[ "$httpAddress" == :* ]]; then
|
|
urlPort="$httpAddress"
|
|
else
|
|
urlPort=":${httpAddress##*:}"
|
|
fi
|
|
|
|
protocol="https"
|
|
serverMode="HTTPS with Skald's local self-signed certificate"
|
|
insecureFlag=()
|
|
if [[ "$insecure" == "1" || "$insecure" == "true" || "$insecure" == "yes" ]]; then
|
|
protocol="http"
|
|
serverMode="insecure HTTP"
|
|
insecureFlag=(-insecure)
|
|
fi
|
|
|
|
hostAddress="$(hostname -I 2>/dev/null | awk '{print $1}' || true)"
|
|
echo "Server mode: $serverMode"
|
|
echo "Local URL: $protocol://localhost$urlPort/hall/$hallName/"
|
|
if [[ -n "$hostAddress" ]]; then
|
|
echo "Local network URL: $protocol://$hostAddress$urlPort/hall/$hallName/"
|
|
else
|
|
echo "Local network URL: $protocol://<this-machine-ip>$urlPort/hall/$hallName/"
|
|
fi
|
|
echo "Admin username: $adminUsername"
|
|
echo "Admin password: $adminPassword"
|
|
echo "Guest password: $guestPassword"
|
|
echo "Recording output: $recordingsDir/$hallName/"
|
|
echo "Temporary data: $workDir"
|
|
if [[ "$protocol" == "https" ]]; then
|
|
echo "Browser note: accept the self-signed certificate warning before testing microphone access."
|
|
else
|
|
echo "Browser note: insecure HTTP is only useful for localhost; remote browsers may block microphone access."
|
|
fi
|
|
echo "Press Ctrl+C to stop and clean up the temporary hall."
|
|
|
|
"$binary" \
|
|
"${insecureFlag[@]}" \
|
|
-http "$httpAddress" \
|
|
-data "$dataDir" \
|
|
-halls "$hallsDir" \
|
|
-recordings "$recordingsDir" \
|
|
-static "$staticDir" &
|
|
|
|
serverPid="$!"
|
|
wait "$serverPid"
|