#!/bin/bash
# 管理台：水印覆盖编辑器上线（Nuxt .output 滚动替换）
set -e
TAR=/data/tmp-deploy/admin-output-wm7-20261104.tar.gz
EXPECT_TAR=0755e5d24f7858895de3819f368b32c4
ACT=$(md5sum "$TAR" | awk '{print $1}')
[ "$ACT" = "$EXPECT_TAR" ] || { echo "TAR_MD5_FAIL got=$ACT"; exit 1; }
cd /cloud/videosite/frontend
rm -rf .output.new && mkdir .output.new
tar -xzf "$TAR" -C .output.new
[ -f .output.new/server/index.mjs ] || { echo NO_INDEX; exit 1; }
rm -rf .output.bak-wm7-20261104
[ -d .output ] && mv .output .output.bak-wm7-20261104
mv .output.new .output
supervisorctl -c /cloud/supervisor/supervisord.conf restart videosite-frontend
sleep 12
supervisorctl -c /cloud/supervisor/supervisord.conf status videosite-frontend
curl -s -o /dev/null -w 'nitro3100 %{http_code}\n' http://127.0.0.1:3100/admin/login
curl -s -o /dev/null -w 'nginx3000 %{http_code}\n' http://127.0.0.1:3000/admin/login
echo ADMIN_ROLL_OK
