#!/usr/bin/env bash
# 视频播客文案提取 —— 网络安装引导
# 下载项目 → 解压 → 运行交互式安装。用法见文件末尾注释。
set -euo pipefail

# 基址：优先环境变量 VTP_BASE_URL，其次第一个参数，最后内置默认（发布时替换）
BASE_URL="${VTP_BASE_URL:-${1:-https://sttinstall.677699.xyz}}"
DEST="${VTP_DEST:-video-transcribe-portable}"
TARBALL="video-transcribe-portable.tar.gz"

command -v curl >/dev/null 2>&1 || { echo "✗ 需要 curl" >&2; exit 1; }
command -v tar  >/dev/null 2>&1 || { echo "✗ 需要 tar" >&2; exit 1; }

echo "▸ 从 ${BASE_URL} 下载项目…"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
curl -fsSL "${BASE_URL}/${TARBALL}" -o "${tmp}/${TARBALL}"

mkdir -p "$DEST"
tar -xzf "${tmp}/${TARBALL}" -C "$DEST"
echo "▸ 已解压到 ./${DEST}"

cd "$DEST"
exec bash ./install.sh

# ── 远程一键安装 ──────────────────────────────────────────────────────────────
#   curl -fsSL https://你的域名/install.sh -o vtp-install.sh && bash vtp-install.sh
# 或直接管道（依赖脚本内 tty 守卫，需终端环境）：
#   curl -fsSL https://你的域名/install.sh | bash
