-
Notifications
You must be signed in to change notification settings - Fork 31
/
install
executable file
·103 lines (87 loc) · 2.77 KB
/
install
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
#!/usr/bin/env bash
### BEGIN ###
# Author: idevz
# Since: 2018/03/12
# Description: Motan OpenResty installation
### END ###
set -ex
# base conf
MOTAN_SRC_ROOT=$(dirname $(cd $(dirname "$0") && pwd -P)/$(basename "$0"))
BUILD=${MOTAN_SRC_ROOT}/build
mkdir -p ${BUILD}
# OpenResty ROOT
OR=openresty
TMP=${BUILD}/tmp
OR_ROOT=$(${OR} -V &>${TMP} && cat ${TMP} |
grep prefix | grep -Eo 'prefix=(.*?)/nginx' | grep -Eo '/.*/')
SITE_LUALIB_ROOT=${OR_ROOT}/site/lualib
rm ${TMP}
RESTY_TIMEER_VERSION="v0.0.2"
RESTY_HTTP_VERSION="v0.12"
RESTY_CONSUL_VERSION="v0.2"
do_require() {
local dependence="
https://github.com/pintsized/lua-resty-http/archive/${RESTY_HTTP_VERSION}.tar.gz
https://github.com/idevz/lua-resty-timer/archive/${RESTY_TIMEER_VERSION}.tar.gz
https://github.com/hamishforbes/lua-resty-consul/archive/${RESTY_CONSUL_VERSION}.tar.gz
"
local require=${MOTAN_SRC_ROOT}/build/require
mkdir -p "$require/src"
mkdir -p "$require/resty"
for dep in ${dependence}; do
cd "$require/src"
FILE_NAME=$(echo $dep | sed 's/.*\(lua-resty[^\/]*\)\/.*/\1/g')
# wget --no-check-certificate $dep -O $FILE_NAME
curl -fSL "$dep" -o "$FILE_NAME"
tar zxf "$FILE_NAME"
cp -fR $FILE_NAME*/lib/resty/* $require/resty/
done
}
do_app_create() {
DAPP_NAME=motan-demo
DAPP_ROOT=${MOTAN_SRC_ROOT}/app
APP_NAME=${APP_NAME=$DAPP_NAME}
APP_ROOT=${APP_ROOT=$DAPP_ROOT}
DEMO_APP_SRC=${MOTAN_SRC_ROOT}/build/app
DEMO_APP_GIT="https://github.com/motan-ecosystem/motan-openresty-demo/archive/v0.0.1.tar.gz"
mkdir -p $DEMO_APP_SRC ${APP_ROOT}/${APP_NAME}
cd $DEMO_APP_SRC
rm -rf $APP_NAME #clean last mv result
wget --no-check-certificate $DEMO_APP_GIT -O $APP_NAME
tar zxf $APP_NAME
rm $APP_NAME #rm tar.gz
mv ./motan-openresty-demo* $APP_NAME
cp -fR ${DEMO_APP_SRC}/${APP_NAME}/* ${APP_ROOT}/${APP_NAME}/
}
build_motan_libs() {
cd ${SITE_LUALIB_ROOT}/motan/libs &&
gcc -g -o libmotan_tools.so -fpic -shared motan_tools.c &&
[ ! -z libmotan_tools.so ] &&
LIB_MOTAN_TOOLS_SO_FILE=libmotan_tools.so &&
LIB_MOTAN_TOOLS_SO=/lib/libmotan_tools.so &&
ln -sf ${SITE_LUALIB_ROOT}/motan/libs/${LIB_MOTAN_TOOLS_SO_FILE} ${LIB_MOTAN_TOOLS_SO} &&
ldconfig
cp cmotan.so ${SITE_LUALIB_ROOT}/
}
# dependence:
echo "get motan dependences libs start."
echo "get motan dependences libs."
do_require
echo "motan dependences libs get done."
# build:
echo "build motan start."
mkdir -p ${SITE_LUALIB_ROOT}/motan/
cp -fR ${MOTAN_SRC_ROOT}/lib/motan/* ${SITE_LUALIB_ROOT}/motan/
mkdir -p ${SITE_LUALIB_ROOT}/resty/
cp ${BUILD}/require/resty/* ${SITE_LUALIB_ROOT}/resty/
build_motan_libs
echo "build motan success."
# create:
if [ -n "$APP_NAME" ]; then
echo ${APP_NAME}
echo "create motan demo start."
do_app_create
echo "create app: "${APP_NAME}" success."
fi
rm -rf ${BUILD}
echo "build clean success."