-
Notifications
You must be signed in to change notification settings - Fork 3
/
update_pkg.sh
executable file
·79 lines (68 loc) · 2.1 KB
/
update_pkg.sh
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
#!/bin/bash
#
# Note that this script installs the packages in this project directory,
# not in your $GOPATH. This is intended to keep the project cleanly outside
# of your personal golang dev environment.
PACKAGES="
gopkg.in/gcfg.v1
github.com/jmhodges/levigo
"
print_usage_and_exit() {
cat << __EOF__
Usage:
$0 {setup|install|clean}
__EOF__
exit $1
}
do_setup() {
cd src
[[ ! -d leveldb ]] && git clone https://github.com/google/leveldb.git && (cd leveldb; git checkout v1.20; make)
cd ../
[[ ! -f /usr/lib64/libleveldb.so ]] && [[ ! -f /usr/lib/libleveldb.so ]] && echo "Need to install dependent libraries first." && echo "Run 'sudo make install-deps' then re-run this." && exit 1
source env.sh
for PACKAGE in $PACKAGES; do
[[ -d src/$PACKAGE ]] && continue
echo -n "Getting $PACKAGE... "
CGO_CFLAGS="-I../../../leveldb/include/" go get -u $PACKAGE
echo ""
done
}
do_install() {
[[ -f /usr/lib64/libleveldb.so ]] || [[ -f /usr/lib/libleveldb.so ]] && echo "leveldb already installed." && return
[[ $UID != 0 ]] && echo "must be root permission to install" && exit 1
for DIR in /usr/lib64 /usr/lib; do
[[ -d $DIR ]] && echo "Installing leveldb into $DIR/" && cp -v src/leveldb/out-shared/libleveldb.* src/leveldb/out-static/libleveldb.* $DIR/ && break
done
}
do_uninstall() {
[[ $UID != 0 ]] && echo "must be root permission to remove" && exit 1
for DIR in /usr/lib64 /usr/lib; do
[[ -f $DIR/libleveldb.so ]] && echo "Removing leveldb from $DIR/" && rm -v $DIR/libleveldb.*
done
}
do_clean() {
CLEAN_DIRS="pkg src/github.com src/gopkg.in src/leveldb"
for DIR in $CLEAN_DIRS; do
[[ -d $DIR ]] && echo "Removing $DIR... " && rm -rf $DIR
done
}
[[ $# < 1 ]] && print_usage_and_exit 1
while [[ $# > 0 ]]; do
option="$1"
case $option in
--help|-h)
print_usage_and_exit 0;;
setup)
do_setup;;
install)
do_install;;
uninstall)
do_uninstall;;
clean)
do_clean;;
*)
error_exit "Unknown option: $option";;
esac
shift
done
exit 0