#!/bin/bash set -euo pipefail PACKAGE=${1:?usage: smoke-fnos-package.sh package.fpk [temporary-directory]} SMOKE_TMP_ROOT="${2:-${LIVERECORDER_SMOKE_TMPDIR:-${TMPDIR:-/tmp}}}" mkdir -p "$SMOKE_TMP_ROOT" SMOKE_TMP_ROOT=$(CDPATH= cd -- "$SMOKE_TMP_ROOT" && pwd) WORK_DIR=$(mktemp -d "${SMOKE_TMP_ROOT%/}/liverecorder-fnos-smoke.XXXXXX") PACKAGE_ROOT="$WORK_DIR/package" APP_ROOT="$WORK_DIR/app" DATA_ROOT="$WORK_DIR/var" VOLUME_ROOT="$WORK_DIR/volume" PORT=${LIVERECORDER_SMOKE_PORT:-19180} CONTROL="$PACKAGE_ROOT/cmd/main" cleanup() { status=$? if [ -x "$CONTROL" ]; then TRIM_APPDEST="$APP_ROOT" \ TRIM_PKGVAR="$DATA_ROOT" \ TRIM_APPDEST_VOL="$VOLUME_ROOT" \ TRIM_SERVICE_PORT="$PORT" \ "$CONTROL" stop >/dev/null 2>&1 || true fi if [ "$status" -ne 0 ]; then printf '%s\n' 'fnOS smoke test failed; application logs follow:' >&2 for log_file in "$DATA_ROOT/log/postgresql.log" "$DATA_ROOT/log/liverecorder.log"; do if [ -f "$log_file" ]; then printf '%s\n' "--- $log_file ---" >&2 tail -n 120 "$log_file" >&2 || true fi done fi rm -rf -- "$WORK_DIR" return "$status" } trap cleanup EXIT HUP INT TERM command -v ffmpeg >/dev/null 2>&1 || { printf 'system ffmpeg is required for the fnOS smoke test\n' >&2; exit 1; } command -v ffprobe >/dev/null 2>&1 || { printf 'system ffprobe is required for the fnOS smoke test\n' >&2; exit 1; } mkdir -p "$PACKAGE_ROOT" "$APP_ROOT" "$VOLUME_ROOT" tar -xzf "$PACKAGE" -C "$PACKAGE_ROOT" tar -xzf "$PACKAGE_ROOT/app.tgz" -C "$APP_ROOT" export TRIM_APPDEST="$APP_ROOT" export TRIM_PKGVAR="$DATA_ROOT" export TRIM_APPDEST_VOL="$VOLUME_ROOT" export TRIM_SERVICE_PORT="$PORT" SMOKE_PASSWORD='LiveRecorder-Smoke-2026!' wizard_admin_password="$SMOKE_PASSWORD" \ wizard_admin_password_confirm="$SMOKE_PASSWORD" \ "$PACKAGE_ROOT/cmd/install_callback" "$CONTROL" start "$CONTROL" status BASE_URL="http://127.0.0.1:$PORT" curl -fsS "$BASE_URL/" >"$WORK_DIR/index.html" grep -q '
' "$WORK_DIR/index.html" curl -fsS "$BASE_URL/health/ready" | grep -q '"status":"ready"' login_response=$(curl -fsS \ -H 'Content-Type: application/json' \ --data "{\"username\":\"admin\",\"password\":\"$SMOKE_PASSWORD\"}" \ "$BASE_URL/api/auth/login") token=$(printf '%s' "$login_response" | sed -n 's/.*"token":"\([^"]*\)".*/\1/p') test -n "$token" settings_response=$(curl -fsS -H "Authorization: Bearer $token" "$BASE_URL/api/settings") expected_record_root="$VOLUME_ROOT/@appshare/liverecorder/records" printf '%s' "$settings_response" | grep -Fq "\"outputRoot\":\"$expected_record_root\"" runtime_libs="$APP_ROOT/runtime/lib:$APP_ROOT/runtime/usr/lib/postgresql/15/lib" ca_bundle="$APP_ROOT/runtime/etc/ssl/certs/ca-certificates.crt" node_bin="$APP_ROOT/runtime/bin/node" curl_bin="$APP_ROOT/runtime/bin/curl" signer="$APP_ROOT/server/Platforms/Douyin/Signing/sign-xbogus.js" LD_LIBRARY_PATH="$runtime_libs" "$node_bin" --version | grep -q '^v22\.18\.0$' signature=$(LD_LIBRARY_PATH="$runtime_libs" "$node_bin" "$signer" \ 'aid=6383&device_platform=web&room_id=1' \ 'Mozilla/5.0 LiveRecorder fnOS package smoke test') test -n "$signature" LD_LIBRARY_PATH="$runtime_libs" SSL_CERT_FILE="$ca_bundle" CURL_CA_BUNDLE="$ca_bundle" \ "$curl_bin" -fsS "$BASE_URL/health/ready" >/dev/null ffmpeg -version >/dev/null 2>&1 ffprobe -version >/dev/null 2>&1 "$CONTROL" stop "$CONTROL" start "$CONTROL" status curl -fsS "$BASE_URL/health/ready" | grep -q '"status":"ready"' printf 'fnOS native smoke test passed: frontend, API, PostgreSQL, packaged Node/curl and system FFmpeg/FFprobe are ready\n'