-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-mongodb.sh
More file actions
executable file
·29 lines (26 loc) · 1.05 KB
/
setup-mongodb.sh
File metadata and controls
executable file
·29 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
function installMongoDB() {
echo "Installing MongoDB v8..."
curl -fsSL https://pgp.mongodb.com/server-8.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo systemctl enable mongod.service
mongod --version | grep "db version" | cut -d" " -f3 | cut -d"v" -f2 > .mongodb.version
}
if command -v mongod &> /dev/null
then
MONGO_VERSION=$(mongod --version | grep "db version" | cut -d" " -f3 | cut -d"v" -f2);
MONGO_MAJOR=$(echo "$MONGO_VERSION" | cut -d. -f1);
if [ "$MONGO_MAJOR" -eq "8" ]; then
echo "MongoDB detected!"
echo "Version: $MONGO_VERSION"
echo "Skipping setup..."
else
echo "MongoDB version mismatch, installing v8..."
installMongoDB
fi
else
echo "MongoDB not found, installing..."
installMongoDB
fi