From 8584c36a8031b7ed9883ad423be6f6f70cae62fd Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Sun, 7 Sep 2025 23:16:10 +0330 Subject: [PATCH] feat: upgrade MongoDB to v8.0 --- upgrade.sh | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/upgrade.sh b/upgrade.sh index ddab18f..6275d20 100644 --- a/upgrade.sh +++ b/upgrade.sh @@ -47,15 +47,36 @@ for SERVICE in "${ALL_SERVICES[@]}"; do fi done -# ========== New Function to Install MongoDB ========== +# ========== Install MongoDB ========== install_mongodb() { info "Checking for MongoDB..." if ! command -v mongod &>/dev/null; then - warn "MongoDB not found. Attempting to install from official repository..." + warn "MongoDB not found. Installing from official repository..." + + local os_name os_version + os_name=$(grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') + os_version=$(grep '^VERSION_ID=' /etc/os-release | cut -d= -f2 | tr -d '"') + apt-get update -qq >/dev/null - apt-get install -y gnupg curl >/dev/null - curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor - echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" > /etc/apt/sources.list.d/mongodb-org-7.0.list + apt-get install -y gnupg curl lsb-release >/dev/null + + curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor + + if [[ "$os_name" == "ubuntu" ]]; then + if [[ "$os_version" == "24.04" ]]; then + echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-8.0.list + elif [[ "$os_version" == "22.04" ]]; then + echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-8.0.list + else + echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-8.0.list + fi + elif [[ "$os_name" == "debian" && "$os_version" == "12" ]]; then + echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" > /etc/apt/sources.list.d/mongodb-org-8.0.list + else + error "Unsupported OS for MongoDB installation: $os_name $os_version" + exit 1 + fi + apt-get update -qq >/dev/null apt-get install -y mongodb-org >/dev/null systemctl start mongod @@ -66,7 +87,7 @@ install_mongodb() { fi } -# ========== New Function to Migrate users.json to MongoDB ========== +# ========== Migrate users.json to MongoDB ========== migrate_users_to_mongodb() { info "Checking for user data to migrate..." if [ ! -f "$USERS_FILE" ]; then @@ -127,7 +148,6 @@ EOF success "users.json has been migrated and renamed to users.json.migrated." } - # ========== Install Go and Compile Auth Binary ========== install_go_and_compile_auth() { info "Checking for Go and compiling authentication binary..." @@ -274,7 +294,6 @@ else done fi - # ========== Final Check ========== if systemctl is-active --quiet hysteria-server.service; then success "🎉 Upgrade completed successfully!"