chore: 将 setup.sh 改为中文提示并保持当前部署方法

This commit is contained in:
2025-11-22 21:34:59 +08:00
parent 1c0604fa4a
commit 02d0df4cdf

View File

@@ -1,15 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "${EUID}" -ne 0 ]; then echo "require root"; exit 1; fi
if [ "${EUID}" -ne 0 ]; then echo "需要 root 权限"; exit 1; fi
. /etc/os-release || true
CODENAME=${VERSION_CODENAME:-}
VERSION=${VERSION_ID:-}
echo "更新系统软件源..."
apt-get update -y
echo "安装基础依赖..."
apt-get install -y python3 python3-venv python3-pip nginx git ffmpeg rsync curl gnupg
echo "安装并启动 MongoDB..."
if ! command -v mongod >/dev/null 2>&1; then
if [ -n "$CODENAME" ]; then
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg || true
@@ -19,18 +22,21 @@ if ! command -v mongod >/dev/null 2>&1; then
else
apt-get install -y mongodb
fi
systemctl enable mongod || true
systemctl start mongod || true
fi
systemctl enable mongod || true
systemctl restart mongod || systemctl start mongod || true
echo "安装并启动 Redis..."
apt-get install -y redis-server
systemctl enable redis-server || true
systemctl start redis-server || true
systemctl restart redis-server || systemctl start redis-server || true
echo "同步项目到 /srv/taiko-web..."
mkdir -p /srv/taiko-web
SRC_DIR=$(cd "$(dirname "$0")" && pwd)
rsync -a --delete --exclude '.git' --exclude '.venv' "$SRC_DIR/" /srv/taiko-web/
echo "创建并安装 Python 虚拟环境..."
python3 -m venv /srv/taiko-web/.venv
/srv/taiko-web/.venv/bin/pip install -U pip
/srv/taiko-web/.venv/bin/pip install -r /srv/taiko-web/requirements.txt
@@ -41,6 +47,7 @@ fi
chown -R www-data:www-data /srv/taiko-web
echo "创建 systemd 服务..."
cat >/etc/systemd/system/taiko-web.service <<'EOF'
[Unit]
Description=Taiko Web
@@ -63,6 +70,7 @@ systemctl daemon-reload
systemctl enable taiko-web
systemctl restart taiko-web
echo "配置 Nginx 站点..."
cat >/etc/nginx/sites-available/taiko-web <<'EOF'
server {
listen 80 default_server;
@@ -87,4 +95,4 @@ if command -v ufw >/dev/null 2>&1; then
ufw allow 'Nginx Full' || true
fi
echo "ok"
echo "部署完成"