-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis
executable file
·89 lines (72 loc) · 1.69 KB
/
redis
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
#!/usr/bin/env bash
SYSTEM_DIR="/usr/local"
INSTALL_DIR="/opt/local"
VERSION=$2
APP_NAME="redis"
URL="http://redis.googlecode.com/files/redis-$VERSION.tar.gz"
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 "$APP_NAME-$VERSION"
make
mkdir -p "$PREFIX/bin"
names=(redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server)
for file in ${names[@]}
do
cp "src/$file" "$PREFIX/bin/$file"
done
;;
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
: