#!/usr/bin/env bash
# 把 xiangqin 本地 .vault/secrets.json 推到 alpha（staging）并重启服务。
# 依赖：本地有 ~/.ssh 免密到 alpha；本地已跑 vault install 生成 secrets.json。
set -euo pipefail

HOST="root@120.27.148.143"
REMOTE="/opt/xiangqin/.vault/secrets.json"
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"

cd "$REPO_ROOT"

# 1. 确保 secrets.json 最新
~/vault/.venv/bin/vault install

# 2. 推到远端
ssh "$HOST" "mkdir -p /opt/xiangqin/.vault"
scp .vault/secrets.json "$HOST:$REMOTE"

# 3. 修权限 + 重启
ssh "$HOST" "chmod 600 $REMOTE && chown xiangqin:xiangqin $REMOTE && systemctl restart xiangqin"

echo "✓ deployed xiangqin secrets to alpha"
