Files
environment/sample/install_sample.sh
T
warren 205566a0f0 feat: portable sample package (100 videos w/ deep scan); clean-install wipes ALL Qdrant collections + legacy storage dirs
- sample/: build_package.sh (pack from pre-clean backup), install_sample.sh (上架), uninstall_sample.sh (下架), README
- clean-install.sh: delete every collection via /collections API + rm legacy qdrant storage dirs (~/qdrant/storage/collections etc.)
2026-11-08 22:11:50 +08:00

78 lines
3.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# =============================================================
# momentry sample package (上架)
# 將 100 支 deep scan 已完成的 sample 影片上架到本機 momentry 系統
# 可在任何 momentry 機器上使用(可攜)
#
# 用法:
# bash install_sample.sh # 上架(在 203 上)
# MOMENTRY_DIR=~momentry bash install_sample.sh
# =============================================================
set -euo pipefail
PKG="$(cd "$(dirname "$0")" && pwd)"
MOMENTRY_DIR="${MOMENTRY_DIR:-$HOME/momentry}"
DEMO_DIR="$MOMENTRY_DIR/var/sftpgo/data/demo"
OUT_DIR="$MOMENTRY_DIR/output"
DB="${MOMENTRY_DB:-momentry}"
# psql 路徑探測(203=/opt/homebrew, 部分機器=~/opt_pgsql)
if [ -x /opt/homebrew/bin/psql ]; then
PSQL=/opt/homebrew/bin/psql
elif [ -x "$HOME/opt_pgsql/bin/psql" ]; then
PSQL="$HOME/opt_pgsql/bin/psql"
else
PSQL=$(command -v psql || true)
[ -n "$PSQL" ] || { echo "!! 找不到 psql"; exit 1; }
fi
if [ ! -f "$PKG/db/sample_data.sql" ]; then
echo "!! 找不到 $PKG/db/sample_data.sql — 這不是完整的 sample package"
exit 1
fi
echo "=== 上架 sample data 到 $MOMENTRY_DIR ==="
echo "[1/4] 複製影片($(ls "$PKG"/videos/*.mp4 2>/dev/null | wc -l | tr -d ' ') 支)→ $DEMO_DIR"
mkdir -p "$DEMO_DIR"
cp -f "$PKG"/videos/*.mp4 "$DEMO_DIR"/
echo "[2/4] 複製 deep scan 輸出 JSON → $OUT_DIR"
mkdir -p "$OUT_DIR"
cp -a "$PKG"/output/. "$OUT_DIR"/
echo "[3/4] 匯入 DB sample data → $DB"
"$PSQL" -U "${MOMENTRY_PGUSER:-accusys}" -d "$DB" -v ON_ERROR_STOP=1 -f "$PKG/db/sample_data.sql"
echo "[4/4] 校正 id sequences"
"$PSQL" -U "${MOMENTRY_PGUSER:-accusys}" -d "$DB" -q <<'SQL'
SELECT format(
'SELECT CASE WHEN %L IS NOT NULL THEN setval(%L, COALESCE((SELECT max(id) FROM %I), 1), false) END;',
pg_get_serial_sequence(c.oid::regclass::text, 'id'),
pg_get_serial_sequence(c.oid::regclass::text, 'id'),
c.oid::regclass::text
)
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'public'
AND c.relname IN ('videos','processor_results','monitor_jobs','scenes','chunk',
'speaker_detections','trace_profiles','trace_operation_history',
'tkg_nodes','tkg_edges','tkg_operation_log','pipeline_progress')
AND EXISTS (SELECT 1 FROM information_schema.columns ic
WHERE ic.table_schema='public' AND ic.table_name=c.relname AND ic.column_name='id')
\gexec
SQL
echo ""
echo "=== 上架完成。摘要 ==="
"$PSQL" -U "${MOMENTRY_PGUSER:-accusys}" -d "$DB" -t -A -c "
SELECT 'videos='||COUNT(*) FROM videos
UNION ALL SELECT 'processor_results='||COUNT(*) FROM processor_results
UNION ALL SELECT 'monitor_jobs='||COUNT(*) FROM monitor_jobs
UNION ALL SELECT 'scenes='||COUNT(*) FROM scenes
UNION ALL SELECT 'chunk='||COUNT(*) FROM chunk
UNION ALL SELECT 'speaker_detections='||COUNT(*) FROM speaker_detections
UNION ALL SELECT 'trace_profiles='||COUNT(*) FROM trace_profiles
UNION ALL SELECT 'tkg_nodes='||COUNT(*) FROM tkg_nodes;"
echo "影片檔案: $(ls "$DEMO_DIR"/*.mp4 2>/dev/null | wc -l | tr -d ' ') 支 | output JSON: $(find "$OUT_DIR" -maxdepth 1 -type f | wc -l | tr -d ' ') 個"