feat: add shared PostgreSQL fnOS service and refresh UI

This commit is contained in:
2026-08-02 20:14:39 +08:00
parent de9f5ae110
commit e5b50ea85c
52 changed files with 3577 additions and 338 deletions
+110 -57
View File
@@ -1,95 +1,148 @@
#!/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}}}"
LIVE_PACKAGE=${1:?usage: smoke-fnos-package.sh liverecorder.fpk postgresql-service.fpk [temporary-directory]}
POSTGRES_PACKAGE=${2:?usage: smoke-fnos-package.sh liverecorder.fpk postgresql-service.fpk [temporary-directory]}
SMOKE_TMP_ROOT="${3:-${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"
WORK_DIR=$(mktemp -d "${SMOKE_TMP_ROOT%/}/liverecorder-shared-stack-smoke.XXXXXX")
STATE_DIR=$(mktemp -d "${TMPDIR:-/tmp}/liverecorder-stack-state.XXXXXX")
LIVE_PACKAGE_ROOT="$WORK_DIR/live-package"
LIVE_APP_ROOT="$WORK_DIR/live-app"
LIVE_DATA_ROOT="$STATE_DIR/live-var"
LIVE_VOLUME_ROOT="$WORK_DIR/live-volume"
PG_PACKAGE_ROOT="$WORK_DIR/postgres-package"
PG_APP_ROOT="$WORK_DIR/postgres-app"
PG_DATA_ROOT="$STATE_DIR/postgres-var"
PG_VOLUME_ROOT="$WORK_DIR/postgres-volume"
LIVE_PORT=${LIVERECORDER_SMOKE_PORT:-19580}
PG_API_PORT=${POSTGRES_SERVICE_SMOKE_API_PORT:-19533}
PG_PORT=${POSTGRES_SERVICE_SMOKE_PG_PORT:-19532}
LIVE_CONTROL="$LIVE_PACKAGE_ROOT/cmd/main"
PG_CONTROL="$PG_PACKAGE_ROOT/cmd/main"
ADMIN_PASSWORD='LiveRecorder-Smoke-2026!'
PG_ADMIN_PASSWORD='Postgres-Admin-Smoke-2026!'
ENROLLMENT_TOKEN='Postgres-Enrollment-Smoke-2026!'
MEDIA_PATH="${PATH:-/usr/local/bin:/usr/bin:/bin}"
if ! PATH="$MEDIA_PATH" command -v ffmpeg >/dev/null 2>&1 || \
! PATH="$MEDIA_PATH" command -v ffprobe >/dev/null 2>&1; then
mkdir -p "$WORK_DIR/system-media-stubs"
ln -s "$(type -P true)" "$WORK_DIR/system-media-stubs/ffmpeg"
ln -s "$(type -P true)" "$WORK_DIR/system-media-stubs/ffprobe"
MEDIA_PATH="$WORK_DIR/system-media-stubs:$MEDIA_PATH"
fi
run_live_control() {
TRIM_APPDEST="$LIVE_APP_ROOT" TRIM_PKGVAR="$LIVE_DATA_ROOT" \
TRIM_APPDEST_VOL="$LIVE_VOLUME_ROOT" TRIM_SERVICE_PORT="$LIVE_PORT" \
POSTGRES_SERVICE_API="http://127.0.0.1:$PG_API_PORT" PATH="$MEDIA_PATH" "$LIVE_CONTROL" "$@"
}
run_postgres_control() {
TRIM_APPDEST="$PG_APP_ROOT" TRIM_PKGVAR="$PG_DATA_ROOT" \
TRIM_APPDEST_VOL="$PG_VOLUME_ROOT" TRIM_SERVICE_PORT="$PG_API_PORT" \
POSTGRES_SERVICE_PORT="$PG_PORT" "$PG_CONTROL" "$@"
}
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 [ -x "$LIVE_CONTROL" ]; then run_live_control stop >/dev/null 2>&1 || true; fi
if [ -x "$PG_CONTROL" ]; then run_postgres_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
printf '%s\n' 'fnOS shared-stack smoke test failed; service logs follow:' >&2
for log_file in \
"$PG_DATA_ROOT/log/postgresql.log" "$PG_DATA_ROOT/log/postgres-service.log" \
"$LIVE_DATA_ROOT/log/postgresql.log" "$LIVE_DATA_ROOT/log/liverecorder.log"; do
if [ -f "$log_file" ]; then
printf '%s\n' "--- $log_file ---" >&2
tail -n 120 "$log_file" >&2 || true
tail -n 160 "$log_file" >&2 || true
fi
done
fi
rm -rf -- "$WORK_DIR"
rm -rf -- "$STATE_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 "$LIVE_PACKAGE_ROOT" "$LIVE_APP_ROOT" "$LIVE_VOLUME_ROOT" \
"$PG_PACKAGE_ROOT" "$PG_APP_ROOT" "$PG_VOLUME_ROOT"
tar -xzf "$POSTGRES_PACKAGE" -C "$PG_PACKAGE_ROOT"
tar -xzf "$PG_PACKAGE_ROOT/app.tgz" -C "$PG_APP_ROOT"
rm -f "$PG_PACKAGE_ROOT/app.tgz"
tar -xzf "$LIVE_PACKAGE" -C "$LIVE_PACKAGE_ROOT"
tar -xzf "$LIVE_PACKAGE_ROOT/app.tgz" -C "$LIVE_APP_ROOT"
rm -f "$LIVE_PACKAGE_ROOT/app.tgz"
mkdir -p "$PACKAGE_ROOT" "$APP_ROOT" "$VOLUME_ROOT"
tar -xzf "$PACKAGE" -C "$PACKAGE_ROOT"
tar -xzf "$PACKAGE_ROOT/app.tgz" -C "$APP_ROOT"
TRIM_PKGVAR="$PG_DATA_ROOT" \
wizard_postgres_admin_password="$PG_ADMIN_PASSWORD" \
wizard_postgres_admin_password_confirm="$PG_ADMIN_PASSWORD" \
wizard_postgres_enrollment_token="$ENROLLMENT_TOKEN" \
wizard_postgres_enrollment_token_confirm="$ENROLLMENT_TOKEN" \
"$PG_PACKAGE_ROOT/cmd/install_callback"
TRIM_PKGVAR="$LIVE_DATA_ROOT" \
wizard_admin_password="$ADMIN_PASSWORD" \
wizard_admin_password_confirm="$ADMIN_PASSWORD" \
wizard_postgres_enrollment_token="$ENROLLMENT_TOKEN" \
"$LIVE_PACKAGE_ROOT/cmd/install_callback"
export TRIM_APPDEST="$APP_ROOT"
export TRIM_PKGVAR="$DATA_ROOT"
export TRIM_APPDEST_VOL="$VOLUME_ROOT"
export TRIM_SERVICE_PORT="$PORT"
run_postgres_control start
run_postgres_control status
curl -fsS "http://127.0.0.1:$PG_API_PORT/health/ready" | grep -q '"status":"ready"'
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 '<div id="app"></div>' "$WORK_DIR/index.html"
run_live_control start
run_live_control status
BASE_URL="http://127.0.0.1:$LIVE_PORT"
curl -fsS "$BASE_URL/health/ready" | grep -q '"status":"ready"'
curl -fsS "$BASE_URL/" | grep -q '<div id="app"></div>'
login_response=$(curl -fsS \
-H 'Content-Type: application/json' \
--data "{\"username\":\"admin\",\"password\":\"$SMOKE_PASSWORD\"}" \
CREDENTIALS="$LIVE_DATA_ROOT/postgres-client.conf"
MARKER="$LIVE_DATA_ROOT/postgres-migration/shared-database.active"
test -s "$CREDENTIALS"
test "$(stat -c '%a' "$CREDENTIALS")" = "600"
grep -q '^host=127\.0\.0\.1$' "$CREDENTIALS"
grep -q "^port=$PG_PORT$" "$CREDENTIALS"
grep -q '^database=appdb_liverecorder_' "$CREDENTIALS"
grep -q '^username=app_liverecorder_' "$CREDENTIALS"
test -s "$MARKER"
grep -q '^fresh_install_at=' "$MARKER"
test ! -f "$LIVE_DATA_ROOT/postgres/PG_VERSION"
test ! -e "$LIVE_DATA_ROOT/postgres-enrollment-token.seed"
login_response=$(curl -fsS -H 'Content-Type: application/json' \
--data "{\"username\":\"admin\",\"password\":\"$ADMIN_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"
expected_record_root="$LIVE_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"
runtime_libs="$LIVE_APP_ROOT/runtime/lib:$LIVE_APP_ROOT/runtime/usr/lib/postgresql/15/lib"
ca_bundle="$LIVE_APP_ROOT/runtime/etc/ssl/certs/ca-certificates.crt"
node_bin="$LIVE_APP_ROOT/runtime/bin/node"
curl_bin="$LIVE_APP_ROOT/runtime/bin/curl"
signer="$LIVE_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')
'aid=6383&device_platform=web&room_id=1' 'Mozilla/5.0 LiveRecorder fnOS shared-stack 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
run_live_control stop
if run_live_control status; then
printf '%s\n' 'Live Recorder remained running after stop' >&2
exit 1
fi
run_postgres_control status
curl -fsS "http://127.0.0.1:$PG_API_PORT/health/ready" | grep -q '"status":"ready"'
run_live_control start
run_live_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'
printf '%s\n' 'fnOS shared-stack smoke test passed: independent PostgreSQL stayed running, Live Recorder enrolled, persisted credentials and restarted without Docker'