Files
soul-yongping/部署永平到Kr宝塔.sh
2026-03-07 22:58:43 +08:00

90 lines
3.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 从「一场soul的创业实验-永平」部署到 Kr宝塔 (43.139.27.93)
# 部署 next-project (Next.js 应用) + miniprogram (小程序)
set -e
YONGPING_ROOT="/Users/karuo/Documents/开发/3、自营项目/一场soul的创业实验-永平"
MAIN_PROJECT="/Users/karuo/Documents/开发/3、自营项目/一场soul的创业实验"
SSH_PORT="22022"
BT_HOST="43.139.27.93"
PROJECT_PATH="/www/wwwroot/soul"
SSH_KEY="$HOME/.ssh/id_ed25519_soul_kr"
if [ -f "$SSH_KEY" ]; then
SSH_CMD="ssh -i $SSH_KEY -p $SSH_PORT -o StrictHostKeyChecking=no"
SCP_CMD="scp -i $SSH_KEY -P $SSH_PORT -o StrictHostKeyChecking=no"
else
SSH_CMD="sshpass -p 'Zhiqun1984' ssh -p $SSH_PORT -o StrictHostKeyChecking=no"
SCP_CMD="sshpass -p 'Zhiqun1984' scp -P $SSH_PORT -o StrictHostKeyChecking=no"
echo "提示: 运行 scripts/本机配置SSH免密登录.sh 可改为密钥登录"
fi
echo "===== 1. 同步主项目到永平/soul ====="
mkdir -p "$YONGPING_ROOT/soul"
rsync -a --delete \
--exclude='node_modules' --exclude='.next' --exclude='.git' --exclude='*.sh' \
"$MAIN_PROJECT/" "$YONGPING_ROOT/soul/"
echo "同步完成"
echo "===== 2. 打包 next-project ====="
cd "$YONGPING_ROOT/soul/next-project"
tar --exclude='node_modules' --exclude='.next' --exclude='.git' -czf /tmp/soul_nextjs.tar.gz .
echo "打包完成: $(du -h /tmp/soul_nextjs.tar.gz | awk '{print $1}')"
echo "===== 3. 上传到 Kr宝塔 ====="
$SCP_CMD /tmp/soul_nextjs.tar.gz root@${BT_HOST}:/tmp/soul_nextjs.tar.gz
rm -f /tmp/soul_nextjs.tar.gz
echo "上传完成"
echo "===== 4. SSH: 解压 + 安装 + 构建 + 重启 ====="
$SSH_CMD root@${BT_HOST} '
set -e
PROJECT="/www/wwwroot/soul"
cd "$PROJECT"
echo "[4.1] 备份 .env..."
cp .env /tmp/soul_env_bak 2>/dev/null || true
echo "[4.2] 清理旧文件..."
rm -rf app components lib public styles prisma scripts addons api *.ts *.tsx *.mjs *.json .next
echo "[4.3] 解压新文件..."
tar -xzf /tmp/soul_nextjs.tar.gz
rm -f /tmp/soul_nextjs.tar.gz
echo "[4.4] 恢复 .env..."
cp /tmp/soul_env_bak .env 2>/dev/null || true
echo "[4.5] 安装依赖..."
export PATH=/www/server/nodejs/v22.14.0/bin:$PATH
pnpm install --frozen-lockfile 2>/dev/null || pnpm install 2>&1 | tail -3
echo "[4.6] 生成 Prisma Client..."
npx prisma generate 2>&1 | tail -3
echo "[4.7] 构建..."
rm -rf .next
pnpm run build 2>&1 | tail -5
echo "[4.8] 移除 turbopack (如有)..."
rm -f .next/static/chunks/turbopack-*.js
node scripts/prepare-standalone.js 2>&1 | tail -3
echo "[4.9] 重启服务..."
pm2 restart soul 2>/dev/null || pm2 start .next/standalone/server.js --name soul -- -p 3006
sleep 3
echo "[4.10] 验证..."
STATUS=$(curl -sI http://localhost:3006 2>&1 | head -1)
echo "状态: $STATUS"
'
echo ""
echo "===== 部署完成(永平 → Kr宝塔====="
echo "网站: https://soul.quwanzhi.com"
echo "后台: https://soul.quwanzhi.com/admin"
echo ""
echo "===== 5. 上传小程序? ====="
echo "执行: /Applications/wechatwebdevtools.app/Contents/MacOS/cli upload --project \"$YONGPING_ROOT/soul/miniprogram\" -v \"1.19\" -d \"永平同步部署\""