diff --git a/install.sh b/install.sh index e69de29..9297fa4 100644 --- a/install.sh +++ b/install.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +# 获取当前目录 +BASE_DIR=$(cd "$(dirname "$0")"; pwd) +USER_NAME=$(whoami) + +echo "项目路径: $BASE_DIR" + +# ========= 自动检测 Python ========= +detect_python() { + if command -v python >/dev/null 2>&1; then + PY=python + elif command -v python3 >/dev/null 2>&1; then + PY=python3 + else + echo "❌ 未检测到 Python,请先安装 Python 3.6+" + exit 1 + fi + + # 获取版本号 + VERSION=$($PY -c 'import sys; print(".".join(map(str, sys.version_info[:3])))') + + echo "检测到 Python: $PY ($VERSION)" + + # 校验版本 >= 3.6 + MAJOR=$(echo $VERSION | cut -d. -f1) + MINOR=$(echo $VERSION | cut -d. -f2) + + if [ "$MAJOR" -lt 3 ] || { [ "$MAJOR" -eq 3 ] && [ "$MINOR" -lt 6 ]; }; then + echo "❌ Python 版本过低(需要 >= 3.6)" + exit 1 + fi + + PYTHON_CMD=$PY +} + +detect_python + +# ========= 创建 PyBot 服务 ========= +sudo bash -c "cat > /etc/systemd/system/PyBot.service" < /etc/systemd/system/PyBot_Web.service" <