@@ -358,76 +358,46 @@ function mongodb_check() {
358
358
}
359
359
360
360
if [ $# -eq 0 ]; then
361
+ # install latest mongodb
361
362
if [ -f /etc/redhat-release ]; then
362
- # install latest mongodb
363
+ CENTOS_RELEASE= " $( rpm --eval ' %{centos_ver} ' ) "
363
364
364
- # select source based on release
365
- if grep -q -i " release 6" /etc/redhat-release ; then
366
- echo " [mongodb-org-4.4]
367
- name=MongoDB Repository
368
- baseurl=https://repo.mongodb.org/yum/redhat/6/mongodb-org/4.4/x86_64/
369
- gpgcheck=1
370
- enabled=1
371
- gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc" > /etc/yum.repos.d/mongodb-org-4.4.repo
372
- elif grep -q -i " release 7" /etc/redhat-release ; then
373
- echo " [mongodb-org-4.4]
374
- name=MongoDB Repository
375
- baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/
376
- gpgcheck=1
377
- enabled=1
378
- gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc" > /etc/yum.repos.d/mongodb-org-4.4.repo
379
- elif grep -q -i " release 8" /etc/redhat-release ; then
380
- echo " [mongodb-org-4.4]
365
+ if [[ " $CENTOS_RELEASE " != " 7" && " $CENTOS_RELEASE " != " 8" ]]; then
366
+ echo " Unsupported OS version, only support CentOS/RHEL 8 and 7"
367
+ exit 1
368
+ fi
369
+
370
+ echo " [mongodb-org-4.4]
381
371
name=MongoDB Repository
382
- baseurl=https://repo.mongodb.org/yum/redhat/8 /mongodb-org/4.4/x86_64/
372
+ baseurl=https://repo.mongodb.org/yum/redhat/${CENTOS_RELEASE} /mongodb-org/4.4/x86_64/
383
373
gpgcheck=1
384
374
enabled=1
385
375
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc" > /etc/yum.repos.d/mongodb-org-4.4.repo
386
- fi
376
+
387
377
yum install -y mongodb-org
388
378
fi
389
379
390
380
if [ -f /etc/lsb-release ]; then
391
- # install latest mongodb
392
- wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
393
381
UBUNTU_YEAR=" $( lsb_release -sr | cut -d ' .' -f 1) " ;
394
382
395
- if [ " $UBUNTU_YEAR " == " 16" ]; then
396
- echo " deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ;
397
- elif [ " $UBUNTU_YEAR " == " 18" ]; then
398
- echo " deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ;
399
- elif [ " $UBUNTU_YEAR " == " 22" ]; then
400
- wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb ;
401
- dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb ;
402
- rm -rf libssl1.1_1.1.1f-1ubuntu2_amd64.deb
403
- echo " deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ;
404
- else
405
- echo " deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ;
383
+ if [[ " $UBUNTU_YEAR " != " 18" && " $UBUNTU_YEAR " != " 20" && " $UBUNTU_YEAR " != " 22" ]]; then
384
+ echo " Unsupported OS version, only support Ubuntu 22, 20 and 18"
385
+ exit 1
406
386
fi
387
+
388
+ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
389
+ UBUNTU_RELEASE=" $( lsb_release -cs) "
390
+ echo " deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu ${UBUNTU_RELEASE} /mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ;
391
+
407
392
apt-get update
408
- # install mongodb
409
393
DEBIAN_FRONTEND=" noninteractive" apt-get -y install mongodb-org || (echo " Failed to install mongodb." ; exit)
410
394
fi
411
395
412
396
# backup config and remove configuration to prevent duplicates
413
397
mongodb_configure
414
398
415
- if [ -f /etc/redhat-release ]; then
416
- # mongodb might need to be started
417
- if grep -q -i " release 6" /etc/redhat-release ; then
418
- service mongod restart > /dev/null || echo " mongodb service does not exist"
419
- else
420
- systemctl restart mongod > /dev/null || echo " mongodb systemctl job does not exist"
421
- fi
422
- fi
423
-
424
- if [ -f /etc/lsb-release ]; then
425
- if [[ " $( /sbin/init --version) " =~ upstart ]]; then
426
- restart mongod > /dev/null || echo " mongodb upstart job does not exist"
427
- else
428
- systemctl restart mongod || echo " mongodb systemctl job does not exist"
429
- fi 2> /dev/null
430
- fi
399
+ # mongodb might need to be restarted
400
+ systemctl restart mongod > /dev/null || echo " mongodb systemctl job does not exist"
431
401
432
402
mongodb_check
433
403
elif [ " $1 " == " check" ]; then
0 commit comments