forked from dualface/gbc-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·311 lines (262 loc) · 8.24 KB
/
install.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/bash
function showHelp()
{
echo "Usage: [sudo] ./install.sh [--prefix=absolute_path] [OPTIONS]"
echo "Options:"
echo -e "\t-h | --help\t\t show this help"
echo "if the \"--prefix\" is not specified, default path is \"/opt/gbc-core\"."
}
function checkOSType()
{
type "apt-get" > /dev/null 2> /dev/null
if [ $? -eq 0 ]; then
echo "UBUNTU"
exit 0
fi
type "yum" > /dev/null 2> /dev/null
if [ $? -eq 0 ]; then
echo "CENTOS"
exit 0
fi
RES=$(uname -s)
if [ $RES == "Darwin" ]; then
echo "MACOS"
exit 0
fi
echo "UNKNOW"
exit 1
}
if [ $UID -ne 0 ]; then
echo "Superuser privileges are required to run this script."
echo "e.g. \"sudo $0\""
exit 1
fi
OSTYPE=$(checkOSType)
CUR_DIR=$(cd "$(dirname $0)" && pwd)
BUILD_DIR=/tmp/install-gbc-core
DEST_DIR=/opt/gbc-core
# dists
OPENRESTY_VER=1.9.3.2
REDIS_VER=3.0.5
BEANSTALKD_VER=1.10
SUPERVISOR_VER=3.1.3
# https://github.com/diegonehab/luasocket
LUASOCKET_VER=3.0-rc1
# https://github.com/cloudwu/lua-bson
LUABSON_VER=20151114
# https://github.com/cloudwu/pbc
LUAPBC_VER=20150714
# https://github.com/mah0x211/lua-process
LUAPROCESS_VER=1.5.0
if [ $OSTYPE == "MACOS" ]; then
gcc -o $CUR_DIR/shells/getopt_long $CUR_DIR/shells/src/getopt_long.c
ARGS=$($CUR_DIR/shells/getopt_long "$@")
else
ARGS=$(getopt -o h --long help,prefix: -n 'Install GameBox Cloud Core' -- "$@")
fi
if [ $? != 0 ] ; then
echo "Install GameBox Cloud Core Terminating..." >&2;
exit 1;
fi
eval set -- "$ARGS"
while true ; do
case "$1" in
--prefix)
DEST_DIR=$2
shift 2
;;
-h|--help)
showHelp;
exit 0
;;
--)
shift;
break
;;
*)
echo "invalid option: $1"
exit 1
;;
esac
done
DEST_BIN_DIR=$DEST_DIR/bin
OPENRESETY_CONFIGURE_ARGS=""
if [ $OSTYPE == "UBUNTU" ] ; then
apt-get install -y build-essential libpcre3-dev libssl-dev git-core unzip supervisor
elif [ $OSTYPE == "CENTOS" ]; then
yum groupinstall -y "Development Tools"
yum install -y pcre-devel zlib-devel openssl-devel unzip supervisor
elif [ $OSTYPE == "MACOS" ]; then
type "brew" > /dev/null 2> /dev/null
if [ $? -ne 0 ]; then
echo "Please install brew, with this command:"
echo -e "\033[33mruby -e \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\" \033[0m"
exit 0
else
sudo -u $SUDO_USER brew install pcre openssl
sudo -u $SUDO_USER brew link openssl --force
fi
type "gcc" > /dev/null 2> /dev/null
if [ $? -ne 0 ]; then
echo "Please install xcode."
exit 0
fi
else
echo "Unsupport current OS."
exit 1
fi
if [ $OSTYPE == "MACOS" ]; then
SED_BIN='sed -i --'
else
SED_BIN='sed -i'
fi
set -e
rm -rf $BUILD_DIR
mkdir -p $BUILD_DIR
cp -f $CUR_DIR/dists/*.tar.gz $BUILD_DIR
mkdir -p $DEST_DIR
mkdir -p $DEST_BIN_DIR
mkdir -p $DEST_DIR/logs
mkdir -p $DEST_DIR/tmp
mkdir -p $DEST_DIR/conf
mkdir -p $DEST_DIR/db
# ----
# install openresty and lua extensions
cd $BUILD_DIR
tar zxf ngx_openresty-$OPENRESTY_VER.tar.gz
cd ngx_openresty-$OPENRESTY_VER
mkdir -p $DEST_BIN_DIR/openresty
echo ./configure $OPENRESETY_CONFIGURE_ARGS \
--prefix=$DEST_BIN_DIR/openresty \
--with-luajit \
--with-http_stub_status_module \
--with-cc-opt="-I/usr/local/include" \
--with-ld-opt="-L/usr/local/lib"
./configure $OPENRESETY_CONFIGURE_ARGS \
--prefix=$DEST_BIN_DIR/openresty \
--with-luajit \
--with-http_stub_status_module \
--with-cc-opt="-I/usr/local/include" \
--with-ld-opt="-L/usr/local/lib"
make && make install
ln -f -s $DEST_BIN_DIR/openresty/luajit/bin/luajit-2.1.0-beta1 $DEST_BIN_DIR/openresty/luajit/bin/lua
# install cjson
cp -f $DEST_BIN_DIR/openresty/lualib/cjson.so $DEST_BIN_DIR/openresty/luajit/lib/lua/5.1
# install luasocket
cd $BUILD_DIR
tar zxf luasocket-$LUASOCKET_VER.tar.gz
cd luasocket-$LUASOCKET_VER
if [ $OSTYPE == "MACOS" ]; then
$SED_BIN "s#PLAT?= linux#PLAT?= macosx#g" makefile
$SED_BIN "s#PLAT?=linux#PLAT?=macosx#g" src/makefile
$SED_BIN "s#LUAPREFIX_macosx?=/opt/local#LUAPREFIX_macosx?=$DEST_BIN_DIR/openresty/luajit#g" src/makefile
$SED_BIN "s#LUAINC_macosx_base?=/opt/local/include#LUAINC_macosx_base?=$DEST_BIN_DIR/openresty/luajit/include#g" src/makefile
$SED_BIN "s#\$(LUAINC_macosx_base)/lua/\$(LUAV)#\$(LUAINC_macosx_base)/luajit-2.1#g" src/makefile
else
$SED_BIN "s#LUAPREFIX_linux?=/usr/local#LUAPREFIX_linux?=$DEST_BIN_DIR/openresty/luajit#g" src/makefile
$SED_BIN "s#LUAINC_linux_base?=/usr/include#LUAINC_linux_base?=$DEST_BIN_DIR/openresty/luajit/include#g" src/makefile
$SED_BIN "s#\$(LUAINC_linux_base)/lua/\$(LUAV)#\$(LUAINC_linux_base)/luajit-2.1#g" src/makefile
fi
make && make install-unix
cp -f src/serial.so src/unix.so $DEST_BIN_DIR/openresty/luajit/lib/lua/5.1/socket/.
# install luabson
cd $BUILD_DIR
tar zxf luabson-$LUABSON_VER.tar.gz
cd lua-bson
if [ $OSTYPE == "MACOS" ]; then
$SED_BIN "s#-I/usr/local/include -L/usr/local/bin -llua53#-I$DEST_BIN_DIR/openresty/luajit/include/luajit-2.1 -L$DEST_BIN_DIR/openresty/luajit/lib -lluajit-5.1#g" Makefile
else
$SED_BIN "s#-I/usr/local/include -L/usr/local/bin -llua53#-I$DEST_BIN_DIR/openresty/luajit/include/luajit-2.1 -L$DEST_BIN_DIR/openresty/luajit/lib#g" Makefile
fi
make linux
cp -f bson.so $DEST_BIN_DIR/openresty/lualib
cp -f bson.so $DEST_BIN_DIR/openresty/luajit/lib/lua/5.1
#install luapbc
cd $BUILD_DIR
tar zxf luapbc-$LUAPBC_VER.tar.gz
cd pbc
make lib
cd binding/lua
if [ $OSTYPE == "MACOS" ]; then
$SED_BIN "s#/usr/local/include#$DEST_BIN_DIR/openresty/luajit/include/luajit-2.1 -L$DEST_BIN_DIR/openresty/luajit/lib -lluajit-5.1#g" Makefile
else
$SED_BIN "s#/usr/local/include#$DEST_BIN_DIR/openresty/luajit/include/luajit-2.1#g" Makefile
fi
make
cp -f protobuf.so $DEST_BIN_DIR/openresty/lualib
cp -f protobuf.lua $DEST_BIN_DIR/openresty/lualib
cp -f protobuf.so $DEST_BIN_DIR/openresty/luajit/lib/lua/5.1
cp -f protobuf.lua $DEST_BIN_DIR/openresty/luajit/lib/lua/5.1
# install luaprocess
cd $BUILD_DIR
tar zxf lua-process-$LUAPROCESS_VER.tar.gz
cd lua-process-$LUAPROCESS_VER
cp Makefile Makefile_
echo "PACKAGE=process" > Makefile
echo "LIB_EXTENSION=so" >> Makefile
echo "SRCDIR=src" >> Makefile
echo "TMPLDIR=tmpl" >> Makefile
echo "VARDIR=var" >> Makefile
echo "CFLAGS=-Wall -fPIC -O2 -I_GBC_CORE_ROOT_/bin/openresty/luajit/include/luajit-2.1" >> Makefile
echo "LDFLAGS=--shared -Wall -fPIC -O2 -L_GBC_CORE_ROOT_/bin/openresty/luajit/lib" >> Makefile
if [ $OSTYPE == "MACOS" ]; then
echo "LIBS=-lluajit-5.1" >> Makefile
fi
echo "" >> Makefile
cat Makefile_ >> Makefile
rm Makefile_
$SED_BIN "s#_GBC_CORE_ROOT_#$DEST_DIR#g" Makefile
$SED_BIN "s#lua ./codegen.lua#$DEST_BIN_DIR/openresty/luajit/bin/lua ./codegen.lua#g" Makefile
make
cp -f process.so $DEST_BIN_DIR/openresty/lualib
cp -f process.so $DEST_BIN_DIR/openresty/luajit/lib/lua/5.1
# ----
# install supervisor
if [ $OSTYPE == "MACOS" ]; then
cd $BUILD_DIR
tar zxf supervisor-$SUPERVISOR_VER.tar.gz
cd supervisor-$SUPERVISOR_VER
python setup.py install
fi
# ----
#install redis
cd $BUILD_DIR
tar zxf redis-$REDIS_VER.tar.gz
cd redis-$REDIS_VER
mkdir -p $DEST_BIN_DIR/redis/bin
make
cp src/redis-server $DEST_BIN_DIR/redis/bin
cp src/redis-cli $DEST_BIN_DIR/redis/bin
cp src/redis-sentinel $DEST_BIN_DIR/redis/bin
cp src/redis-benchmark $DEST_BIN_DIR/redis/bin
cp src/redis-check-aof $DEST_BIN_DIR/redis/bin
cp src/redis-check-dump $DEST_BIN_DIR/redis/bin
# ----
# install beanstalkd
cd $BUILD_DIR
tar zxf beanstalkd-$BEANSTALKD_VER.tar.gz
cd beanstalkd-$BEANSTALKD_VER
mkdir -p $DEST_BIN_DIR/beanstalkd/bin
make
cp beanstalkd $DEST_BIN_DIR/beanstalkd/bin
# ----
# install apps
cp -rf $CUR_DIR/src $DEST_DIR
cp -rf $CUR_DIR/apps $DEST_DIR
cd $CUR_DIR/shells/
cp -f start_server stop_server check_server $DEST_DIR
cp -f shell_func.sh shell_func.lua start_worker.lua $DEST_BIN_DIR
# if it in Mac OS X, getopt_long should be deployed.
if [ $OSTYPE == "MACOS" ]; then
cp -f $CUR_DIR/shells/getopt_long $DEST_DIR/bin
rm $CUR_DIR/shells/getopt_long
fi
# copy all configuration files
cp -f $CUR_DIR/conf/* $DEST_DIR/conf/
# done
echo ""
echo ""
echo ""
echo "DONE!"
echo ""
echo ""