#!/bin/bash # Author: yeho # BLOG: https://linuxeye.com # # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+ # # Project home page: # https://oneinstack.com # https://github.com/oneinstack/oneinstack Upgrade_Nginx() { pushd ${oneinstack_dir}/src > /dev/null [ ! -e "${nginx_install_dir}/sbin/nginx" ] && echo "${CWARNING}Nginx is not installed on your system! ${CEND}" && exit 1 OLD_nginx_ver_tmp=`${nginx_install_dir}/sbin/nginx -v 2>&1` OLD_nginx_ver=${OLD_nginx_ver_tmp##*/} Latest_nginx_ver=`curl --connect-timeout 2 -m 3 -s http://nginx.org/en/CHANGES-1.22 | awk '/Changes with nginx/{print$0}' | awk '{print $4}' | head -1` [ -z "${Latest_nginx_ver}" ] && Latest_nginx_ver=`curl --connect-timeout 2 -m 3 -s http://nginx.org/en/CHANGES | awk '/Changes with nginx/{print$0}' | awk '{print $4}' | head -1` echo echo "Current Nginx Version: ${CMSG}${OLD_nginx_ver}${CEND}" while :; do echo [ "${nginx_flag}" != 'y' ] && read -e -p "Please input upgrade Nginx Version(default: ${Latest_nginx_ver}): " NEW_nginx_ver NEW_nginx_ver=${NEW_nginx_ver:-${Latest_nginx_ver}} if [ "${NEW_nginx_ver}" != "${OLD_nginx_ver}" ]; then [ ! -e "nginx-${NEW_nginx_ver}.tar.gz" ] && wget --no-check-certificate -c http://nginx.org/download/nginx-${NEW_nginx_ver}.tar.gz > /dev/null 2>&1 if [ -e "nginx-${NEW_nginx_ver}.tar.gz" ]; then src_url=https://www.openssl.org/source/openssl-${openssl11_ver}.tar.gz && Download_src src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-${pcre_ver}.tar.gz && Download_src src_url=http://mirrors.linuxeye.com/oneinstack/src/ngx_devel_kit.tar.gz && Download_src src_url=http://mirrors.linuxeye.com/oneinstack/src/lua-nginx-module-${lua_nginx_module_ver}.tar.gz && Download_src tar xzf openssl-${openssl11_ver}.tar.gz tar xzf pcre-${pcre_ver}.tar.gz tar xzf ngx_devel_kit.tar.gz tar xzf lua-nginx-module-${lua_nginx_module_ver}.tar.gz echo "Download [${CMSG}nginx-${NEW_nginx_ver}.tar.gz${CEND}] successfully! " break else echo "${CWARNING}Nginx version does not exist! ${CEND}" fi else echo "${CWARNING}input error! Upgrade Nginx version is the same as the old version${CEND}" exit fi done if [ -e "nginx-${NEW_nginx_ver}.tar.gz" ]; then echo "[${CMSG}nginx-${NEW_nginx_ver}.tar.gz${CEND}] found" if [ "${nginx_flag}" != 'y' ]; then echo "Press Ctrl+c to cancel or Press any key to continue..." char=`get_char` fi ${nginx_install_dir}/sbin/nginx -V &> $$ nginx_configure_args_tmp=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'` rm -rf $$ nginx_configure_args=`echo ${nginx_configure_args_tmp} | sed "s@lua-nginx-module-\w.\w\+.\w\+ @lua-nginx-module-${lua_nginx_module_ver} @" | sed "s@lua-nginx-module @lua-nginx-module-${lua_nginx_module_ver} @" | sed "s@--with-openssl=../openssl-\w.\w.\w\+ @--with-openssl=../openssl-${openssl11_ver} @" | sed "s@--with-pcre=../pcre-\w.\w\+ @--with-pcre=../pcre-${pcre_ver} @"` if [ -n `echo $nginx_configure_args | grep lua-nginx-module` ]; then ${oneinstack_dir}/upgrade.sh --oneinstack > /dev/null src_url=http://mirrors.linuxeye.com/oneinstack/src/luajit2-${luajit2_ver}.tar.gz && Download_src tar xzf luajit2-${luajit2_ver}.tar.gz pushd luajit2-${luajit2_ver} make && make install popd > /dev/null rm -rf luajit2-${luajit2_ver} src_url=http://mirrors.linuxeye.com/oneinstack/src/lua-resty-core-${lua_resty_core_ver}.tar.gz && Download_src tar xzf lua-resty-core-${lua_resty_core_ver}.tar.gz pushd lua-resty-core-${lua_resty_core_ver} make install popd > /dev/null rm -rf lua-resty-core-${lua_resty_core_ver} src_url=http://mirrors.linuxeye.com/oneinstack/src/lua-resty-lrucache-${lua_resty_lrucache_ver}.tar.gz && Download_src tar xzf lua-resty-lrucache-${lua_resty_lrucache_ver}.tar.gz pushd lua-resty-lrucache-${lua_resty_lrucache_ver} make install popd > /dev/null rm -rf lua-resty-lrucache-${lua_resty_lrucache_ver} fi tar xzf nginx-${NEW_nginx_ver}.tar.gz pushd nginx-${NEW_nginx_ver} make clean sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug export LUAJIT_LIB=/usr/local/lib export LUAJIT_INC=/usr/local/include/luajit-2.1 ./configure ${nginx_configure_args} make -j ${THREAD} if [ -f "objs/nginx" ]; then /bin/mv ${nginx_install_dir}/sbin/nginx{,`date +%m%d`} /bin/cp objs/nginx ${nginx_install_dir}/sbin/nginx kill -USR2 `cat /var/run/nginx.pid` sleep 1 kill -QUIT `cat /var/run/nginx.pid.oldbin` popd > /dev/null echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_nginx_ver}${CEND} to ${CWARNING}${NEW_nginx_ver}${CEND}" rm -rf nginx-${NEW_nginx_ver} else echo "${CFAILURE}Upgrade Nginx failed! ${CEND}" fi fi popd > /dev/null }