From 02d0df4cdf1ab630241d69e878e226a41e11a188 Mon Sep 17 00:00:00 2001 From: AnthonyDuan Date: Sat, 22 Nov 2025 21:34:59 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=B0=86=20setup.sh=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E4=B8=AD=E6=96=87=E6=8F=90=E7=A4=BA=E5=B9=B6=E4=BF=9D?= =?UTF-8?q?=E6=8C=81=E5=BD=93=E5=89=8D=E9=83=A8=E7=BD=B2=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/setup.sh b/setup.sh index 4d62b0a..d6d2255 100644 --- a/setup.sh +++ b/setup.sh @@ -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" \ No newline at end of file +echo "部署完成" \ No newline at end of file