awesome/deploy.sh

41 lines
1.3 KiB
Bash
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
# Awesome Index 部署脚本(直接部署,不使用 Docker
# 服务器: 114.134.187.170
set -e
REMOTE_HOST="114.134.187.170"
REMOTE_USER="root"
REMOTE_PASS="2VAJgRs8l99Z"
DEPLOY_PATH="/app/awesome"
echo "=== 部署 Awesome Index 到 baihu 服务器 ==="
# 使用 sshpass 安装依赖(如果没有)
if ! command -v sshpass &> /dev/null; then
echo "请先安装 sshpass:"
echo " Ubuntu/Debian: sudo apt-get install sshpass"
echo " macOS: brew install hudochenkov/sshpass/sshpass"
exit 1
fi
echo "1. 创建部署目录..."
sshpass -p "$REMOTE_PASS" ssh -o StrictHostKeyChecking=no "$REMOTE_USER@$REMOTE_HOST" \
"mkdir -p $DEPLOY_PATH/data $DEPLOY_PATH/logs"
echo "2. 上传源码..."
sshpass -p "$REMOTE_PASS" scp -o StrictHostKeyChecking=no -r \
package.json package-lock.json src public .env.example start.sh \
"$REMOTE_USER@$REMOTE_HOST:$DEPLOY_PATH/"
echo "3. 重命名 .env.example 为 .env如不存在..."
sshpass -p "$REMOTE_PASS" ssh -o StrictHostKeyChecking=no "$REMOTE_USER@$REMOTE_HOST" \
"cd $DEPLOY_PATH && [ ! -f .env ] && cp .env.example .env"
echo "4. 在服务器上执行启动脚本..."
sshpass -p "$REMOTE_PASS" ssh -o StrictHostKeyChecking=no "$REMOTE_USER@$REMOTE_HOST" \
"cd $DEPLOY_PATH && chmod +x start.sh && bash start.sh"
echo ""
echo "=== 部署完成 ==="