forked from MongoEngine/mongoengine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_mongo.sh
More file actions
52 lines (42 loc) · 1.32 KB
/
Copy pathinstall_mongo.sh
File metadata and controls
52 lines (42 loc) · 1.32 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status
set -u # Treat unset variables as an error
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <mongodb-version>"
echo "Example: $0 8.0.5"
exit 1
fi
MONGODB="$1"
# Determine build name based on version
if [[ "${MONGODB}" =~ ^(7.0|8.0) ]]; then
mongo_build="mongodb-linux-x86_64-ubuntu2004-${MONGODB}"
elif [[ "${MONGODB}" =~ ^(4.0|4.2|4.4|5.0|6.0) ]]; then
mongo_build="mongodb-linux-x86_64-ubuntu1804-${MONGODB}"
elif [[ "${MONGODB}" =~ ^3.6 ]]; then
mongo_build="mongodb-linux-x86_64-${MONGODB}"
else
echo "Error: Unsupported MongoDB version: ${MONGODB}"
usage
fi
download_url="http://fastdl.mongodb.org/linux/${mongo_build}.tgz"
tarball="${mongo_build}.tgz"
echo "Downloading MongoDB from ${download_url}..."
if ! wget --quiet "${download_url}"; then
echo "Error: Failed to download MongoDB."
exit 1
fi
echo "Extracting ${tarball}..."
if ! tar xzf "${tarball}"; then
echo "Error: Failed to extract ${tarball}"
exit 1
fi
mongodb_dir=$(find "${PWD}/" -type d -name "mongodb-linux-x86_64*" | head -n 1)
if [ -z "${mongodb_dir}" ]; then
echo "Error: Could not find MongoDB directory after extraction."
exit 1
fi
echo "MongoDB installed at: ${mongodb_dir}"
"${mongodb_dir}/bin/mongod" --version
# Cleanup
echo "Cleaning up..."
rm -f "${tarball}"