diff --git a/setup.sh b/setup.sh index 6308efc..d464002 100644 --- a/setup.sh +++ b/setup.sh @@ -15,7 +15,7 @@ apt-get install -y python3 python3-venv python3-pip git ffmpeg rsync curl gnupg echo "安装并启动 MongoDB..." MONGO_READY=false if ! command -v mongod >/dev/null 2>&1; then - if [ -n "$CODENAME" ]; then + if [ -n "$CODENAME" ] && echo "$CODENAME" | grep -Eq '^(focal|jammy)$'; then curl -fsSL https://pgp.mongodb.com/server-7.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg || true echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu ${CODENAME}/mongodb-org/7.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-7.0.list || true if apt-get update -y; then @@ -25,7 +25,8 @@ if ! command -v mongod >/dev/null 2>&1; then fi fi if [ "$MONGO_READY" = false ]; then - echo "APT 仓库不可用,改用 Docker 部署 MongoDB..." + echo "APT 仓库不可用或版本不支持,改用 Docker 部署 MongoDB..." + rm -f /etc/apt/sources.list.d/mongodb-org-7.0.list || true apt-get install -y docker.io systemctl enable --now docker || true mkdir -p /var/lib/mongo @@ -43,7 +44,7 @@ if ! command -v mongod >/dev/null 2>&1; then else MONGO_READY=true fi -if [ "$MONGO_READY" = true ]; then +if [ "$MONGO_READY" = true ] && systemctl list-unit-files | grep -q '^mongod\.service'; then systemctl enable mongod || true systemctl restart mongod || systemctl start mongod || true fi