#!/usr/bin/env bash # douyinWEB one-click bootstrap for a shared Ubuntu VPS. # # Safety: # - Does NOT modify existing Nginx/BaoTa vhosts, Docker, Gitea, or other systemd units # - Does NOT apt-upgrade, change timezone, install Caddy, or open extra public ports # - Binds app ports to 127.0.0.1 only; public entry is one new server_name # - Aborts if chosen ports are already in use # - Nginx: test config first; reload only if test passes; rolls back new vhost on failure # # Usage (on the target VPS as root): # DOMAIN=ypp.example.com \ # ADMIN_USER=dsx2016 ADMIN_PASS='***' \ # GIT_URL='https://user:pass@git.example/eric/douyinWEB.git' \ # GIT_BRANCH=test1 FRESH=1 \ # bash scripts/bootstrap_vps.sh # # Interactive (prompts when DOMAIN/ADMIN/GIT missing): # bash scripts/install.sh # choose "vps" # bash scripts/bootstrap_vps.sh # same wizard if vars empty # # Or copy scripts/install.env.example → /etc/douyinweb.install.env # # Optional: # APP_DIR=/opt/douyinWEB # PUBLIC_SCHEME=https # WEB_PORT=4015 API_PORT=8014 PB_PORT=8092 YT_PORT=8020 S3_PORT=8333 # SW_MASTER_PORT=19333 SW_VOLUME_PORT=18080 SW_FILER_PORT=18888 set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # shellcheck disable=SC1091 source "$ROOT/scripts/lib/install_common.sh" load_install_env_files wizard_vps() { echo echo "=== VPS 本机部署向导(应用 + Nginx TLS 同机)===" ask DOMAIN "对外域名 DOMAIN(DNS 已指向本机)" ask ADMIN_USER "管理员用户名" "admin" ask_secret ADMIN_PASS "管理员密码" ask GIT_URL "Git 仓库 URL(已有代码在 APP_DIR 可填 skip)" "skip" if [[ "$GIT_URL" == "skip" ]]; then GIT_URL="" fi ask GIT_BRANCH "Git 分支" "main" ask APP_DIR "安装目录" "/opt/douyinWEB" ask_yn FRESH "清空本机 app 数据(covers/clips/pb,不含其它站点)?" "n" ask WEB_PORT "Next 端口" "4015" ask API_PORT "API 端口" "8014" export DOMAIN ADMIN_USER ADMIN_PASS GIT_URL GIT_BRANCH APP_DIR FRESH WEB_PORT API_PORT } if [[ -z "${DOMAIN:-}" || -z "${ADMIN_USER:-}" || -z "${ADMIN_PASS:-}" ]]; then wizard_vps fi DOMAIN="${DOMAIN:?set DOMAIN, e.g. ypp.smallzhiyuns.com}" ADMIN_USER="${ADMIN_USER:?set ADMIN_USER}" ADMIN_PASS="${ADMIN_PASS:?set ADMIN_PASS}" # GIT_URL optional if APP_DIR already has .git or tree GIT_URL="${GIT_URL:-}" GIT_BRANCH="${GIT_BRANCH:-main}" APP_DIR="${APP_DIR:-/opt/douyinWEB}" FRESH="${FRESH:-0}" PUBLIC_SCHEME="${PUBLIC_SCHEME:-https}" PUBLIC_BASE="${PUBLIC_BASE:-${PUBLIC_SCHEME}://${DOMAIN}}" WEB_PORT="${WEB_PORT:-4015}" API_PORT="${API_PORT:-8014}" PB_PORT="${PB_PORT:-8092}" YT_PORT="${YT_PORT:-8020}" S3_PORT="${S3_PORT:-8333}" SW_MASTER_PORT="${SW_MASTER_PORT:-19333}" SW_VOLUME_PORT="${SW_VOLUME_PORT:-18080}" SW_FILER_PORT="${SW_FILER_PORT:-18888}" PB_ADMIN_EMAIL="${PB_ADMIN_EMAIL:-${ADMIN_USER}@${DOMAIN}}" S3_ACCESS="${S3_ACCESS:-douyin}" S3_BUCKET="${S3_BUCKET:-douyin-covers}" WEED_VER="${WEED_VER:-3.80}" PB_VER="${PB_VER:-0.25.8}" ENV_FILE="/etc/douyinweb.env" SW_DATA="/data/douyinweb-seaweed" BAOTA_NGINX="/www/server/nginx/sbin/nginx" BAOTA_VHOST_DIR="/www/server/panel/vhost/nginx" log() { printf '\n[%s] %s\n' "$(date '+%F %T')" "$*"; } die() { printf 'ERROR: %s\n' "$*" >&2; exit 1; } [[ "$(id -u)" -eq 0 ]] || die "run as root" port_in_use() { local p="$1" ss -lnt | awk '{print $4}' | grep -E "[:.]${p}$" >/dev/null 2>&1 } assert_ports_free() { local p if systemctl is-active --quiet douyinweb-api 2>/dev/null; then log "douyinweb already running — skip port occupancy check" return fi for p in "$WEB_PORT" "$API_PORT" "$PB_PORT" "$YT_PORT" "$S3_PORT" "$SW_MASTER_PORT" "$SW_VOLUME_PORT" "$SW_FILER_PORT"; do if port_in_use "$p"; then die "port ${p} is already in use — pick another via env, do not kill existing services" fi done } detect_nginx() { if [[ -x "$BAOTA_NGINX" ]]; then NGINX_BIN="$BAOTA_NGINX" NGINX_MODE="baota" return fi if command -v nginx >/dev/null 2>&1; then NGINX_BIN="$(command -v nginx)" NGINX_MODE="system" return fi die "nginx not found; this script adds a vhost to existing nginx and will not install Caddy" } persist_secrets() { if [[ -f "$ENV_FILE" ]]; then # shellcheck disable=SC1090 source "$ENV_FILE" log "loaded existing $ENV_FILE (secrets reused)" return fi SESSION_SECRET="$(openssl rand -hex 24)" S3_SECRET="$(openssl rand -hex 18)" cat >"$ENV_FILE" </etc/seaweedfs/douyinweb-s3.json </etc/systemd/system/douyinweb-pb.service </etc/systemd/system/douyinweb-yt.service </etc/systemd/system/douyinweb-api.service </etc/systemd/system/douyinweb-web.service </etc/systemd/system/douyinweb-sw-master.service </etc/systemd/system/douyinweb-sw-volume.service </etc/systemd/system/douyinweb-sw-filer.service </etc/systemd/system/douyinweb-s3.service < "/www/server/panel/vhost/nginx/well-known/${DOMAIN}.conf" : > "/www/server/panel/vhost/rewrite/${DOMAIN}.conf" echo "# douyinweb extension placeholder" > "/www/server/panel/vhost/nginx/extension/${DOMAIN}/placeholder.conf" cat >"/www/server/panel/vhost/nginx/proxy/${DOMAIN}/douyinweb.conf" <"$vhost" <