-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo
executable file
·109 lines (87 loc) · 2.32 KB
/
mongo
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env bash
SYSTEM_DIR="/usr/local"
INSTALL_DIR="/opt/local"
VERSION=$2
APP_NAME="mongo"
URL="http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$VERSION.tgz"
PREFIX="$INSTALL_DIR/$APP_NAME/$VERSION"
CURRENT="$INSTALL_DIR/$APP_NAME/current"
TGZ="$INSTALL_DIR/src/$(basename $URL)"
COMMAND=$1
if [ $UID != 0 ]; then
echo "Sorry, you are not root."
exit 1
elif [[ -z "$COMMAND" ]]; then
${0} help
exit 1
elif [[ -z "$VERSION" && "$COMMAND" != "help" && "$COMMAND" != "deactivate" ]]; then
${0} help
fi
case "$COMMAND" in
install)
mkdir -p /opt/local/src
cd /opt/local/src
[ ! -f "$TGZ" ] && wget $URL
tar xvf $TGZ
cd "mongodb-linux-x86_64-$VERSION"
mkdir -p "$PREFIX/bin"
for file in `ls bin`
do
cp "bin/$file" "$PREFIX/bin/$file"
done
mkdir -p /opt/local/bin
cd /opt/local/bin
wget https://raw.github.com/willian/server-recipes/master/mongodb-start
wget https://raw.github.com/willian/server-recipes/master/mongodb-stop
chmod +x mongodb-st*
mkdir -p /opt/local/mongo/config
cd /opt/local/mongo/config
wget -O mongodb https://raw.github.com/willian/server-recipes/master/mongo.conf
/bin/egrep -i "^mongod" /etc/passwd
if [ $? -eq 0 ]; then
echo "User $USERID exists in /etc/passwd"
else
adduser --system --no-create-home --disabled-login --disabled-password --group mongodb
fi
mkdir -p /opt/local/mongo/db
chown mongodb:mongodb -R /opt/local/mongo/db
mkdir -p /var/log/mongodb
;;
activate)
if [[ ! -d $PREFIX ]]; then
${0} install $VERSION
fi
${0} deactivate
ln -s "$PREFIX" "$CURRENT"
for dir in bin sbin
do
[ ! -d "$CURRENT/$dir" ] && continue
mkdir -p "$SYSTEM_DIR/$dir"
for file in `ls $CURRENT/$dir`
do
bin=$(basename $file)
ln -s "$CURRENT/$dir/$bin" "$SYSTEM_DIR/$dir/$bin"
done
done
;;
deactivate)
if [[ ! -L "$CURRENT" ]]; then
exit
fi
for dir in bin sbin
do
[ ! -d "$CURRENT/$dir" ] && continue
for file in `ls $CURRENT/$dir`
do
bin=$(basename $file)
[ -L "$SYSTEM_DIR/$dir/$bin" ] && rm "$SYSTEM_DIR/$dir/$bin"
done
done
rm "$CURRENT"
;;
*)
echo "Usage: ${0} {install|uninstall|activate|deactivate|help} {version}" >&2
exit 3
;;
esac
: