Created
December 21, 2019 18:34
-
-
Save zdev0x/df0a2adae15701de20fe9a26a9e26345 to your computer and use it in GitHub Desktop.
web_proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # 作者: Jsser <jsser AT qq.com> | |
| # | |
| # 日期:2019-09-09 | |
| # | |
| # 说明:基于OneinStack的一键反代环境安装脚本 | |
| # | |
| # 支持系统:CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ | |
| # | |
| # 本脚本安装第三方模块: | |
| # 1. replace-filter-nginx-module (字符串替换,支持正则) | |
| # 2. ngx_cache_purge (URL清理缓存扩展) | |
| # | |
| # 致谢:OneinStack https://oneinstack.com ,以及感谢以上开源模块的作者。 | |
| # | |
| export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin | |
| clear | |
| printf " | |
| ############################################# | |
| # 基于OneinStack的一键反代安装脚本 # | |
| # --------------------------------------- # | |
| # 1. replace-filter-nginx-module # | |
| # 2. ngx_cache_purge # | |
| # 3. ngx_geoip # | |
| # --------------------------------------- # | |
| ############################################# | |
| " | |
| [ $(id -u) != "0" ] && { echo "Error: 请使用root用户执行该脚本"; exit 1; } | |
| WORKER_DIR=$(dirname "`readlink -f $0`") | |
| NGX_MODULE_DIR=${WORKER_DIR}/ngx_module | |
| # COLORS | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[0;33m' | |
| SKYBLUE='\033[0;36m' | |
| PLAIN='\033[0m' | |
| # 下载资源 | |
| download_package() { | |
| pushd ${WORKER_DIR} > /dev/null | |
| ## DownLoad Oneinstack | |
| echo "Download lnmp-full.tar.gz..." | |
| src_url=http://mirrors.linuxeye.com/lnmp-full.tar.gz && download_src | |
| ## Download ngx_module | |
| pushd ${NGX_MODULE_DIR} > /dev/null | |
| echo "Git Clone sregex..." | |
| git clone https://github.com/openresty/sregex.git | |
| echo "Git Clone replace-filter-nginx-module..." | |
| git clone https://github.com/openresty/replace-filter-nginx-module.git | |
| echo "Download ngx_cache_purge..." | |
| src_url=http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz && download_src | |
| } | |
| # 安装 | |
| pre_install() { | |
| pushd ${WORKER_DIR} > /dev/null | |
| echo "解压缩:lnmp-full.tar.gz" | |
| tar zxf lnmp-full.tar.gz | |
| echo "安装:sregex正则库" | |
| pushd ${NGX_MODULE_DIR}/sregex > /dev/null | |
| make && make install | |
| pushd ${NGX_MODULE_DIR} | |
| echo '解压缩:ngx_cache_purge-2.3.tar.gz' | |
| tar zxf ngx_cache_purge-2.3.tar.gz | |
| echo "更新nginx_modules_options配置项"; | |
| sed -i "s@nginx_modules_options=''@nginx_modules_options='--with-http_geoip_module --add-module=${NGX_MODULE_DIR}/ngx_cache_purge-2.3 --add-module=${NGX_MODULE_DIR}/replace-filter-nginx-module '@g" ${WORKER_DIR}/lnmp/options.conf | |
| } | |
| # 安装openrestry | |
| install_openresty() { | |
| pushd ${WORKER_DIR}/lnmp > /dev/null | |
| echo "安装openrestry" | |
| ./install.sh --nginx_option 3 | |
| } | |
| # 下载 | |
| download_src() { | |
| [ -s "${src_url##*/}" ] && echo "[${CMSG}${src_url##*/}${CEND}] found" || { wget -4 --tries=6 -c --no-check-certificate ${src_url}; sleep 1; } | |
| if [ ! -e "${src_url##*/}" ]; then | |
| echo "${CFAILURE}Auto download failed! You can manually download ${src_url} into the oneinstack/src directory.${CEND}" | |
| kill -9 $$ | |
| fi | |
| } | |
| # 检测目录 | |
| check_dir() { | |
| if [ ! -d $NGX_MODULE_DIR ]; then | |
| mkdir -p ${NGX_MODULE_DIR} | |
| fi | |
| } | |
| install_check() { | |
| if check_os packageManager yum || check_os packageManager apt; then | |
| return 0 | |
| else | |
| return 1 | |
| fi | |
| } | |
| # 预处理 | |
| pre_init() { | |
| if [ -e "/usr/bin/yum" ]; then | |
| PM=yum | |
| command -v lsb_release >/dev/null 2>&1 || { [ -e "/etc/euleros-release" ] && yum -y install euleros-lsb || yum -y install redhat-lsb-core; clear; } | |
| fi | |
| if [ -e "/usr/bin/apt-get" ]; then | |
| PM=apt-get | |
| command -v lsb_release >/dev/null 2>&1 || { apt-get -y update; apt-get -y install lsb-release; clear; } | |
| fi | |
| command -v lsb_release >/dev/null 2>&1 || { echo "${PM} source failed! "; kill -9 $$; } | |
| [ "${PM}" == 'apt-get' ] && apt-get -y update | |
| [ "${PM}" == 'yum' ] && yum clean all | |
| ${PM} -y install wget gcc curl python git bison geoip-devel libuuid-devel | |
| } | |
| init() { | |
| pre_init | |
| check_dir | |
| download_package | |
| pre_install | |
| read -p "$(echo -e ${SKYBLUE}扩展包已经下载完成,是否直接安装openresty${PLAIN} [y/n]?)" -n 1 -r | |
| if [[ $REPLY =~ ^[Yy]$ ]];then | |
| install_openresty | |
| else | |
| printf "\n" | |
| exit 1 | |
| fi | |
| } | |
| init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment