-
Notifications
You must be signed in to change notification settings - Fork 176
/
build.sh.in
205 lines (172 loc) · 4.84 KB
/
build.sh.in
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
set -e
export PATH=/bin:/usr/bin:/usr/sbin:/sbin:${PATH}
export HUSTSTORE_TOP=@@HUSTSTORE_TOP@@
export PREFIX_3RD=@@PREFIX_3RD@@
export PREFIX_HUSTDB=@@PREFIX_HUSTDB@@
export PREFIX_HUSTDBSYNC=@@PREFIX_HUSTDBSYNC@@
export PREFIX_HUSTDBHA=@@PREFIX_HUSTDBHA@@
export PREFIX_HUSTMQ=@@PREFIX_HUSTMQ@@
export PREFIX_HUSTMQHA=@@PREFIX_HUSTMQHA@@
export topdir=$(dirname $(readlink -fn $0))
help(){
cat<<HELP
usage:
$0 [option]
[option]
--help show the manual
--module=3rd build and generate installation package for third-party libs.
It should be installed FIRST to build other modules.
--module=hustdb build and generate installation package for hustdb
--module=hustdbha build and generate installation package for hustdbha
--module=hustmq build and generate installation package for hustmq
--module=hustmqha build and generate installation package for hustmqha
sample:
$0 --help
$0 --module=3rd,hustdb
$0 --module=3rd,hustdb,hustdbha
$0 --module=3rd,hustmq,hustmqha
$0
HELP
return 1
}
pkg_name(){
local srv=$1
printf 'elf_%s.tar.gz' ${srv}
}
mk_pkg(){
local dir=$1
shift
local srv
declare -a srv=("$@")
cd ${dir} && tar --exclude=DATA --exclude=EXPORT --exclude=LOG --exclude='*.log' --exclude='*.pid' \
-cvzf ${topdir}/$(pkg_name ${srv[0]}) -- ${srv[@]}
}
build_3rd(){
if [[ ! -d ${PREFIX_3RD} ]]; then
cd ${topdir}/third_party/ && bash -e build.sh;
fi
mk_pkg ${HUSTSTORE_TOP} 3rd
}
build_hustdb(){
cd ${topdir}/hustdb/db && make -j$(nproc) && make prefix=${PREFIX_HUSTDB} install ;
cp -v ${topdir}/hustdb/db/start.sh ${PREFIX_HUSTDB}
cp -v ${topdir}/hustdb/db/stop.sh ${PREFIX_HUSTDB}
mk_pkg ${HUSTSTORE_TOP} hustdb
}
build_hustdbha(){
cd ${topdir}/hustdb/sync && make -j$(nproc) && make prefix=${PREFIX_HUSTDBSYNC} install ;
cp -v ${topdir}/hustdb/sync/start.sh ${PREFIX_HUSTDBSYNC}
cp -v ${topdir}/hustdb/sync/stop.sh ${PREFIX_HUSTDBSYNC}
cd ${topdir}/hustdb/ha/nginx && \
bash -e ./Config.sh && \
make -j$(nproc) && \
make install && \
echo "ok" > ${PREFIX_HUSTDBHA}/html/status.html && \
cp ../upgrade.sh ${PREFIX_HUSTDBHA}/sbin/ && \
cp conf/genconf.py ${PREFIX_HUSTDBHA}/conf/ && \
cp conf/nginx.json ${PREFIX_HUSTDBHA}/conf/ && \
cp conf/gen_table.py ${PREFIX_HUSTDBHA}/conf/
cp -v ${topdir}/hustdb/ha/start.sh ${PREFIX_HUSTDBHA}/sbin/
cp -v ${topdir}/hustdb/ha/stop.sh ${PREFIX_HUSTDBHA}/sbin/
mk_pkg ${HUSTSTORE_TOP} hustdbha hustdbsync
}
build_hustmq(){
if [[ ! -x ${PREFIX_HUSTDB}/hustdb ]] ; then
build_hustdb
fi
test -d ${PREFIX_HUSTMQ} || mkdir ${PREFIX_HUSTMQ}
cp -a ${PREFIX_HUSTDB}/hustdb ${PREFIX_HUSTMQ}/
cp -a ${PREFIX_HUSTDB}/hustdb.conf* ${PREFIX_HUSTMQ}/
cp -a ${PREFIX_HUSTDB}/*.sh ${PREFIX_HUSTMQ}/
mk_pkg ${HUSTSTORE_TOP} hustmq
}
build_hustmqha(){
cd ${topdir}/hustmq/ha/nginx && \
bash -e ./Config.sh && \
make -j$(nproc) && \
make install && \
echo "ok" > ${PREFIX_HUSTMQHA}/html/status.html && \
cp ../upgrade.sh ${PREFIX_HUSTMQHA}/sbin/ && \
cp conf/genconf.py ${PREFIX_HUSTMQHA}/conf/ && \
cp conf/nginx.json ${PREFIX_HUSTMQHA}/conf/
cp -v ${topdir}/hustmq/ha/start.sh ${PREFIX_HUSTMQHA}/sbin/
cp -v ${topdir}/hustmq/ha/stop.sh ${PREFIX_HUSTMQHA}/sbin/
mk_pkg ${HUSTSTORE_TOP} hustmqha
}
make_clean(){
set +e
for prjdir in \
${topdir}/hustdb/db \
${topdir}/hustdb/sync \
${topdir}/hustdb/ha/nginx \
${topdir}/hustmq/ha/nginx
do
echo "#### Cleaning ${prjdir} ####"
cd ${prjdir} ; make clean
done
set -e
}
if ! options=$(getopt -o hcm: -l help,clean,module: -- "$@")
then
help
exit 1
fi
eval set -- $options
export MODULES=''
export CLEAN=false
while [ $# -gt 0 ]
do
case $1 in
-h|--help) help; exit 1 ;;
-c|--clean) CLEAN=true ;;
-m|--module) MODULES="$2" ; shift;;
(--) shift; break;;
(-*) echo "$0: error - unknown option $1" 1>&2; help; exit 1;;
(*) break;;
esac
shift
done
if [[ ${CLEAN} == true ]]; then
make_clean
exit 0
fi
if [[ "x" == x"${MODULES}" ]]; then
MODULES='3rd,hustdb,hustdbha,hustmq,hustmqha'
fi
if [[ ! -d ${HUSTSTORE_TOP} ]]; then
echo "Error: Plese ensure ${HUSTSTORE_TOP} exists, and you have permission to change it."
echo "Tips: maybe you need to do this, before executing $0"
echo ""
echo " sudo mkdir -p ${HUSTSTORE_TOP}"
echo " sudo chown -R myOWNER:myGROUP ${HUSTSTORE_TOP}"
echo ""
exit 1
fi
declare -a exec_cmds=()
OLDIFS=$IFS
IFS=','
for mod in ${MODULES}; do
case $mod in
3rd )
exec_cmds=(build_3rd ${exec_cmds[@]})
;;
hustdb )
exec_cmds+=(build_hustdb)
;;
hustdbha )
exec_cmds+=(build_hustdbha)
;;
hustmq )
exec_cmds+=(build_hustmq)
;;
hustmqha )
exec_cmds+=(build_hustmqha)
;;
esac
done
IFS=${OLDIFS}
for cmd in ${exec_cmds[@]}; do
eval $cmd
done
echo "Success."