2019-05-20 08:53:44 +00:00
|
|
|
|
#!/usr/bin/env bash
|
2019-05-14 09:08:37 +00:00
|
|
|
|
|
2019-05-20 08:53:44 +00:00
|
|
|
|
CDN=https://cdn.jsdelivr.net/gh/etherdream/jsproxy-bin@master
|
2019-05-14 09:08:37 +00:00
|
|
|
|
|
2019-05-20 13:33:27 +00:00
|
|
|
|
JSPROXY_VER=0.0.9
|
2019-05-20 08:53:44 +00:00
|
|
|
|
PCRE_VER=8.43
|
|
|
|
|
ZLIB_VER=1.2.11
|
|
|
|
|
OPENSSL_VER=1.1.1b
|
|
|
|
|
OPENRESTY_VER=1.15.8.1
|
2019-05-14 09:08:37 +00:00
|
|
|
|
|
2019-05-20 08:53:44 +00:00
|
|
|
|
SUPPORTED_OS="Linux-x86_64"
|
|
|
|
|
OS="$(uname)-$(uname -m)"
|
2019-05-14 09:08:37 +00:00
|
|
|
|
|
2019-05-20 08:53:44 +00:00
|
|
|
|
NGX_DIR="$HOME/openresty"
|
|
|
|
|
|
|
|
|
|
COLOR_RESET="\033[0m"
|
|
|
|
|
COLOR_RED="\033[31m"
|
|
|
|
|
COLOR_GREEN="\033[32m"
|
|
|
|
|
COLOR_YELLOW="\033[33m"
|
|
|
|
|
|
|
|
|
|
output() {
|
|
|
|
|
color=$1
|
|
|
|
|
shift 1
|
|
|
|
|
sdata="$@"
|
|
|
|
|
stime=$(date "+%H:%M:%S")
|
|
|
|
|
printf "$color[jsproxy $stime]$COLOR_RESET $sdata\n"
|
|
|
|
|
}
|
|
|
|
|
log() {
|
|
|
|
|
output $COLOR_GREEN $1
|
|
|
|
|
}
|
|
|
|
|
warn() {
|
|
|
|
|
output $COLOR_YELLOW $1
|
|
|
|
|
}
|
|
|
|
|
err() {
|
|
|
|
|
output $COLOR_RED $1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check_nginx() {
|
|
|
|
|
NGX_EXE="$NGX_DIR/nginx/sbin/nginx"
|
|
|
|
|
NGX_VER=$($NGX_EXE -v 2>&1)
|
|
|
|
|
|
|
|
|
|
if [[ "$NGX_VER" != *"nginx version:"* ]]; then
|
|
|
|
|
err "$NGX_EXE 无法执行!尝试编译安装"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2019-05-20 10:04:50 +00:00
|
|
|
|
log "$NGX_VER"
|
|
|
|
|
log "nginx path: $NGX_DIR"
|
2019-05-20 08:53:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
install_jsproxy() {
|
2019-05-20 10:04:50 +00:00
|
|
|
|
log "下载代理服务 ..."
|
2019-05-20 08:53:44 +00:00
|
|
|
|
curl -s -O $CDN/server-$JSPROXY_VER.tar.gz
|
|
|
|
|
|
2019-05-20 13:11:51 +00:00
|
|
|
|
if [ -x ./server/run.sh ]; then
|
|
|
|
|
warn "尝试停止当前服务 ..."
|
2019-05-20 10:04:50 +00:00
|
|
|
|
./server/run.sh quit
|
|
|
|
|
fi
|
|
|
|
|
|
2019-05-20 08:53:44 +00:00
|
|
|
|
if [ -d "server" ]; then
|
2019-05-20 10:04:50 +00:00
|
|
|
|
backup="$PWD/bak/$(date +%Y_%m_%d_%H_%M_%S)"
|
2019-05-20 08:53:44 +00:00
|
|
|
|
warn "当前 server 目录备份到 $backup"
|
|
|
|
|
mkdir -p $backup
|
|
|
|
|
mv server $backup
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
tar zxf server-$JSPROXY_VER.tar.gz
|
|
|
|
|
rm -f server-$JSPROXY_VER.tar.gz
|
|
|
|
|
|
|
|
|
|
log "启动服务 ..."
|
|
|
|
|
./server/run.sh
|
|
|
|
|
|
|
|
|
|
log "服务已开启。后续维护参考 https://github.com/EtherDream/jsproxy"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
compile() {
|
|
|
|
|
TMP_DIR="$PWD/__tmp__"
|
|
|
|
|
|
|
|
|
|
mkdir -p $TMP_DIR
|
|
|
|
|
cd $TMP_DIR
|
|
|
|
|
|
|
|
|
|
log "下载 pcre 源码 ..."
|
|
|
|
|
curl -O https://ftp.pcre.org/pub/pcre/pcre-$PCRE_VER.tar.gz
|
|
|
|
|
tar zxf pcre-$PCRE_VER.tar.gz
|
|
|
|
|
|
|
|
|
|
log "下载 zlib 源码 ..."
|
|
|
|
|
curl -O https://zlib.net/zlib-$ZLIB_VER.tar.gz
|
|
|
|
|
tar zxf zlib-$ZLIB_VER.tar.gz
|
|
|
|
|
|
|
|
|
|
log "下载 openssl 源码 ..."
|
|
|
|
|
curl -O https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz
|
|
|
|
|
tar zxf openssl-$OPENSSL_VER.tar.gz
|
|
|
|
|
|
|
|
|
|
log "下载 nginx 源码 ..."
|
|
|
|
|
curl -O https://openresty.org/download/openresty-$OPENRESTY_VER.tar.gz
|
|
|
|
|
tar zxf openresty-$OPENRESTY_VER.tar.gz
|
|
|
|
|
|
|
|
|
|
cd openresty-$OPENRESTY_VER
|
|
|
|
|
|
|
|
|
|
export PATH=$PATH:/sbin
|
|
|
|
|
|
|
|
|
|
log "配置中 ..."
|
|
|
|
|
./configure \
|
|
|
|
|
--with-openssl=../openssl-$OPENSSL_VER \
|
|
|
|
|
--with-pcre=../pcre-$PCRE_VER \
|
|
|
|
|
--with-zlib=../zlib-$ZLIB_VER \
|
|
|
|
|
--with-http_v2_module \
|
|
|
|
|
--with-http_ssl_module \
|
|
|
|
|
--with-pcre-jit \
|
|
|
|
|
--prefix=$NGX_DIR
|
|
|
|
|
|
|
|
|
|
log "编译中 ..."
|
|
|
|
|
make
|
|
|
|
|
make install
|
|
|
|
|
|
|
|
|
|
log "编译完成"
|
|
|
|
|
rm -rf $TMP_DIR
|
|
|
|
|
|
|
|
|
|
check_nginx
|
|
|
|
|
install_jsproxy
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
install() {
|
|
|
|
|
log "下载 nginx 程序 ..."
|
|
|
|
|
curl -O $CDN/$OS/openresty-$OPENRESTY_VER.tar.gz
|
|
|
|
|
tar zxf openresty-$OPENRESTY_VER.tar.gz
|
|
|
|
|
rm -f openresty-$OPENRESTY_VER.tar.gz
|
|
|
|
|
|
|
|
|
|
check_nginx
|
|
|
|
|
install_jsproxy
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 13:11:51 +00:00
|
|
|
|
update() {
|
|
|
|
|
install_jsproxy
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 08:53:44 +00:00
|
|
|
|
pack() {
|
|
|
|
|
log "压缩 openresty ..."
|
|
|
|
|
GZIP=-9
|
|
|
|
|
tar cvzf openresty.tar.gz openresty
|
2019-05-20 13:11:51 +00:00
|
|
|
|
log "done"
|
|
|
|
|
ls -la
|
2019-05-20 08:53:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main() {
|
|
|
|
|
if [[ "$SUPPORTED_OS" != *"$OS"* ]]; then
|
|
|
|
|
err "当前系统 $OS 不支持自动安装。尝试编译安装"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ "$USER" != "root" ]]; then
|
|
|
|
|
err "自动安装需要 root 权限。如果无法使用 root,尝试编译安装"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2019-05-20 10:04:50 +00:00
|
|
|
|
if ! id -u jsproxy > /dev/null 2>&1 ; then
|
|
|
|
|
log "创建用户 jsproxy ..."
|
|
|
|
|
groupadd nobody > /dev/null 2>&1
|
|
|
|
|
useradd jsproxy -g nobody --create-home
|
|
|
|
|
fi
|
2019-05-20 08:53:44 +00:00
|
|
|
|
|
|
|
|
|
src=$0
|
|
|
|
|
dst=/home/jsproxy/i.sh
|
2019-05-20 10:04:50 +00:00
|
|
|
|
warn "当前脚本移动到 $dst"
|
2019-05-20 08:53:44 +00:00
|
|
|
|
|
|
|
|
|
mv -f $src $dst
|
|
|
|
|
chmod +x $dst
|
|
|
|
|
|
2019-05-20 10:04:50 +00:00
|
|
|
|
log "切换到 jsproxy 用户,执行安装脚本 ..."
|
2019-05-20 08:53:44 +00:00
|
|
|
|
su - jsproxy -c "$dst install"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
|
"install") install
|
|
|
|
|
exit;;
|
|
|
|
|
"compile") compile
|
|
|
|
|
exit;;
|
2019-05-20 13:11:51 +00:00
|
|
|
|
"update") update
|
|
|
|
|
exit;;
|
2019-05-20 08:53:44 +00:00
|
|
|
|
"pack") pack
|
|
|
|
|
exit;;
|
|
|
|
|
*) main
|
|
|
|
|
exit;;
|
|
|
|
|
esac
|