#!/usr/bin/env bash set -euo pipefail # One-command deploy script: # 1) Build production bundle locally # 2) Upload archive to server # 3) Extract into target directory and fix ownership SERVER_HOST="47.83.117.213" SERVER_USER="root" SERVER_PASSWORD='Bkr!Srv#Mt5@Xoh_9KpL2' REMOTE_ARCHIVE="/tmp/manager-service-font-dist.tar.gz" REMOTE_DIR="/usr/local/golden/manager-service/front" LOCAL_ARCHIVE="dist.tar.gz" if ! command -v expect >/dev/null 2>&1; then echo "Error: expect is required but not installed." exit 1 fi echo "==> Installing dependencies" npm install echo "==> Building production bundle" # Pin production env (Vite does not override env vars already set). export VITE_API_BASE="https://ad.jinclab.com" export VITE_USE_HASH_HISTORY="true" npm run build echo "==> Verifying API base in bundle (no old API origin)" # 合法包内可能含主机名字面量(如 resolveMediaUrl 用于把旧图站迁到线上),只拦截「整段 URL / 旧端口」误打进 axios 等配置 if [[ -d dist/assets ]] && grep -l -E 'https?://103\.158\.191\.66|103\.158\.191\.66:8505' dist/assets/*.js 2>/dev/null | grep -q .; then echo "Error: dist still embeds old API origin (http(s)://103.158... or :8505). Check .env / build mode. Aborting deploy." exit 1 fi echo "==> Packaging dist/" COPYFILE_DISABLE=1 tar -czf "${LOCAL_ARCHIVE}" dist echo "==> Uploading package to server" expect < Deploying on remote server" expect < Verifying remote files" expect <