2019-09-24 16:13:46 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
2019-09-26 15:08:21 +08:00
|
|
|
OR_EXEC=`which openresty 2>&1`
|
2019-09-24 16:13:46 +08:00
|
|
|
echo $OR_EXEC
|
2019-10-23 15:27:20 +08:00
|
|
|
APISIX_VER="https://raw.githubusercontent.com/iresty/apisix/master/rockspec/apisix-master-0.rockspec"
|
2019-09-24 16:13:46 +08:00
|
|
|
|
2019-09-26 15:08:21 +08:00
|
|
|
# check the openresty exist
|
|
|
|
CHECK_OR_EXIST=`echo $OR_EXEC | grep ": no openresty" | wc -l`
|
|
|
|
if [ $CHECK_OR_EXIST -eq 1 ];then
|
|
|
|
echo "can not find the openresty, install failed"
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
2019-09-26 15:19:29 +08:00
|
|
|
LUA_JIT_DIR=`$OR_EXEC -V 2>&1 | grep prefix | grep -Eo 'prefix=(.*?)/nginx' | grep -Eo '/.*/'`
|
2019-09-24 16:13:46 +08:00
|
|
|
LUA_JIT_DIR="${LUA_JIT_DIR}luajit"
|
|
|
|
echo $LUA_JIT_DIR
|
|
|
|
|
|
|
|
LUAROCKS_VER=`luarocks --version | grep -E -o "luarocks [0-9]+."`
|
|
|
|
echo $LUAROCKS_VER
|
|
|
|
|
|
|
|
UNAME=`uname`
|
|
|
|
echo $UNAME
|
|
|
|
|
|
|
|
|
|
|
|
do_install() {
|
|
|
|
if [ "$UNAME" == "Darwin" ]; then
|
2019-10-23 15:27:20 +08:00
|
|
|
luarocks install --lua-dir=$LUA_JIT_DIR $APISIX_VER --tree=/usr/local/apisix/deps --local
|
2019-09-24 16:13:46 +08:00
|
|
|
|
|
|
|
elif [ "$LUAROCKS_VER" == 'luarocks 3.' ]; then
|
2019-10-23 15:27:20 +08:00
|
|
|
luarocks install --lua-dir=$LUA_JIT_DIR $APISIX_VER --tree=/usr/local/apisix/deps --local
|
2019-09-24 16:13:46 +08:00
|
|
|
|
|
|
|
else
|
2019-10-23 15:27:20 +08:00
|
|
|
luarocks install $APISIX_VER --tree=/usr/local/apisix/deps --local
|
2019-09-24 16:13:46 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
sudo rm -f /usr/local/bin/apisix
|
|
|
|
sudo ln -s /usr/local/apisix/deps/bin/apisix /usr/local/bin/apisix
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
do_remove() {
|
|
|
|
sudo rm -f /usr/local/bin/apisix
|
|
|
|
luarocks purge /usr/local/apisix/deps --tree=/usr/local/apisix/deps
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case_opt=$1
|
|
|
|
if [ ! $case_opt ]; then
|
|
|
|
case_opt='install'
|
|
|
|
fi
|
|
|
|
echo $case_opt
|
|
|
|
|
|
|
|
case ${case_opt} in
|
|
|
|
install)
|
|
|
|
do_install "$@"
|
|
|
|
;;
|
|
|
|
remove)
|
|
|
|
do_remove "$@"
|
|
|
|
;;
|
|
|
|
esac
|