upgrade_web.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 6+ Debian 7+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Upgrade_Nginx() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. [ ! -e "${nginx_install_dir}/sbin/nginx" ] && echo "${CWARNING}Nginx is not installed on your system! ${CEND}" && exit 1
  13. OLD_nginx_ver_tmp=`${nginx_install_dir}/sbin/nginx -v 2>&1`
  14. OLD_nginx_ver=${OLD_nginx_ver_tmp##*/}
  15. Latest_nginx_ver=`curl -s http://nginx.org/en/CHANGES-1.14 | awk '/Changes with nginx/{print$0}' | awk '{print $4}' | head -1`
  16. [ -z "${Latest_nginx_ver}" ] && Latest_nginx_ver=`curl -s http://nginx.org/en/CHANGES | awk '/Changes with nginx/{print$0}' | awk '{print $4}' | head -1`
  17. echo
  18. echo "Current Nginx Version: ${CMSG}${OLD_nginx_ver}${CEND}"
  19. while :; do echo
  20. read -p "Please input upgrade Nginx Version(default: ${Latest_nginx_ver}): " NEW_nginx_ver
  21. [ -z "${NEW_nginx_ver}" ] && NEW_nginx_ver=${Latest_nginx_ver}
  22. if [ "${NEW_nginx_ver}" != "${OLD_nginx_ver}" ]; then
  23. [ ! -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
  24. if [ -e "nginx-${NEW_nginx_ver}.tar.gz" ]; then
  25. src_url=https://www.openssl.org/source/openssl-${openssl_ver}.tar.gz && Download_src
  26. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-${pcre_ver}.tar.gz && Download_src
  27. tar xzf openssl-${openssl_ver}.tar.gz
  28. tar xzf pcre-${pcre_ver}.tar.gz
  29. echo "Download [${CMSG}nginx-${NEW_nginx_ver}.tar.gz${CEND}] successfully! "
  30. break
  31. else
  32. echo "${CWARNING}Nginx version does not exist! ${CEND}"
  33. fi
  34. else
  35. echo "${CWARNING}input error! Upgrade Nginx version is the same as the old version${CEND}"
  36. fi
  37. done
  38. if [ -e "nginx-${NEW_nginx_ver}.tar.gz" ]; then
  39. echo "[${CMSG}nginx-${NEW_nginx_ver}.tar.gz${CEND}] found"
  40. echo "Press Ctrl+c to cancel or Press any key to continue..."
  41. char=`get_char`
  42. tar xzf nginx-${NEW_nginx_ver}.tar.gz
  43. [ "${Fedora_ver}" == '28' ] && patch -d nginx-${nginx_ver} -p1 < 0001-unix-ngx_user-Apply-fix-for-really-old-bug-in-glibc-.patch
  44. patch -d nginx-${nginx_ver} -p0 < nginx-auto-cc-gcc.patch
  45. pushd nginx-${NEW_nginx_ver}
  46. make clean
  47. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
  48. ${nginx_install_dir}/sbin/nginx -V &> $$
  49. nginx_configure_args_tmp=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  50. rm -rf $$
  51. nginx_configure_args=`echo ${nginx_configure_args_tmp} | sed "s@--with-openssl=../openssl-...... @--with-openssl=../openssl-${openssl_ver} @" | sed "s@--with-pcre=../pcre-.... @--with-pcre=../pcre-${pcre_ver} @"`
  52. ./configure ${nginx_configure_args}
  53. make -j ${THREAD}
  54. if [ -f "objs/nginx" ]; then
  55. /bin/mv ${nginx_install_dir}/sbin/nginx{,`date +%m%d`}
  56. /bin/cp objs/nginx ${nginx_install_dir}/sbin/nginx
  57. kill -USR2 `cat /var/run/nginx.pid`
  58. sleep 1
  59. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  60. popd > /dev/null
  61. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_nginx_ver}${CEND} to ${CWARNING}${NEW_nginx_ver}${CEND}"
  62. rm -rf nginx-${NEW_nginx_ver}
  63. else
  64. echo "${CFAILURE}Upgrade Nginx failed! ${CEND}"
  65. fi
  66. fi
  67. popd > /dev/null
  68. }
  69. Upgrade_Tengine() {
  70. pushd ${oneinstack_dir}/src > /dev/null
  71. [ ! -e "${tengine_install_dir}/sbin/nginx" ] && echo "${CWARNING}Tengine is not installed on your system! ${CEND}" && exit 1
  72. OLD_tengine_ver_tmp=`${tengine_install_dir}/sbin/nginx -v 2>&1`
  73. OLD_tengine_ver="`echo ${OLD_tengine_ver_tmp#*/} | awk '{print $1}'`"
  74. Latest_tengine_ver=`curl -s http://tengine.taobao.org/changelog.html | grep -oE "[0-9]\.[0-9]\.[0-9]+" | head -1`
  75. echo
  76. echo "Current Tengine Version: ${CMSG}${OLD_tengine_ver}${CEND}"
  77. while :; do echo
  78. read -p "Please input upgrade Tengine Version(default: ${Latest_tengine_ver}): " NEW_tengine_ver
  79. [ -z "${NEW_tengine_ver}" ] && NEW_tengine_ver=${Latest_tengine_ver}
  80. if [ "${NEW_tengine_ver}" != "${OLD_tengine_ver}" ]; then
  81. [ ! -e "tengine-${NEW_tengine_ver}.tar.gz" ] && wget --no-check-certificate -c http://tengine.taobao.org/download/tengine-${NEW_tengine_ver}.tar.gz > /dev/null 2>&1
  82. if [ -e "tengine-${NEW_tengine_ver}.tar.gz" ]; then
  83. src_url=https://www.openssl.org/source/openssl-${openssl_ver}.tar.gz && Download_src
  84. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-${pcre_ver}.tar.gz && Download_src
  85. tar xzf openssl-${openssl_ver}.tar.gz
  86. tar xzf pcre-${pcre_ver}.tar.gz
  87. echo "Download [${CMSG}tengine-${NEW_tengine_ver}.tar.gz${CEND}] successfully! "
  88. break
  89. else
  90. echo "${CWARNING}Tengine version does not exist! ${CEND}"
  91. fi
  92. else
  93. echo "${CWARNING}input error! Upgrade Tengine version is the same as the old version${CEND}"
  94. fi
  95. done
  96. if [ -e "tengine-${NEW_tengine_ver}.tar.gz" ]; then
  97. echo "[${CMSG}tengine-${NEW_tengine_ver}.tar.gz${CEND}] found"
  98. echo "Press Ctrl+c to cancel or Press any key to continue..."
  99. char=`get_char`
  100. tar xzf tengine-${NEW_tengine_ver}.tar.gz
  101. [ "${Fedora_ver}" == '28' ] && patch -d tengine-${tengine_ver} -p1 < 0001-unix-ngx_user-Apply-fix-for-really-old-bug-in-glibc-.patch
  102. patch -d tengine-${tengine_ver} -p0 < nginx-auto-cc-gcc.patch
  103. pushd tengine-${NEW_tengine_ver}
  104. make clean
  105. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
  106. ${tengine_install_dir}/sbin/nginx -V &> $$
  107. tengine_configure_args_tmp=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  108. rm -rf $$
  109. tengine_configure_args=`echo ${tengine_configure_args_tmp} | sed "s@--with-openssl=../openssl-...... @--with-openssl=../openssl-${openssl_ver} @" | sed "s@--with-pcre=../pcre-.... @--with-pcre=../pcre-${pcre_ver} @"`
  110. ./configure ${tengine_configure_args}
  111. make -j ${THREAD}
  112. if [ -f "objs/nginx" ]; then
  113. /bin/mv ${tengine_install_dir}/sbin/nginx{,`date +%m%d`}
  114. /bin/mv ${tengine_install_dir}/sbin/dso_tool{,`date +%m%d`}
  115. /bin/mv ${tengine_install_dir}/modules{,`date +%m%d`}
  116. /bin/cp objs/nginx ${tengine_install_dir}/sbin/nginx
  117. /bin/cp objs/dso_tool ${tengine_install_dir}/sbin/dso_tool
  118. chmod +x ${tengine_install_dir}/sbin/*
  119. make install
  120. kill -USR2 `cat /var/run/nginx.pid`
  121. sleep 1
  122. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  123. popd > /dev/null
  124. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_tengine_ver${CEND} to ${CWARNING}${NEW_tengine_ver}${CEND}"
  125. rm -rf tengine-${NEW_tengine_ver}
  126. else
  127. echo "${CFAILURE}Upgrade Tengine failed! ${CEND}"
  128. fi
  129. fi
  130. popd > /dev/null
  131. }
  132. Upgrade_OpenResty() {
  133. pushd ${oneinstack_dir}/src > /dev/null
  134. [ ! -e "${openresty_install_dir}/nginx/sbin/nginx" ] && echo "${CWARNING}OpenResty is not installed on your system! ${CEND}" && exit 1
  135. OLD_openresy_ver_tmp=`${openresty_install_dir}/nginx/sbin/nginx -v 2>&1`
  136. OLD_openresy_ver="`echo ${OLD_openresy_ver_tmp#*/} | awk '{print $1}'`"
  137. Latest_openresy_ver=`curl -s https://openresty.org/en/download.html | awk '/download\/openresty-/{print $0}' | grep -oE "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | head -1`
  138. echo
  139. echo "Current OpenResty Version: ${CMSG}${OLD_openresy_ver}${CEND}"
  140. while :; do echo
  141. read -p "Please input upgrade OpenResty Version(default: ${Latest_openresy_ver}): " NEW_openresy_ver
  142. [ -z "${NEW_openresy_ver}" ] && NEW_openresy_ver=${Latest_openresy_ver}
  143. if [ "${NEW_openresy_ver}" != "${OLD_openresy_ver}" ]; then
  144. [ ! -e "openresty-${NEW_openresy_ver}.tar.gz" ] && wget --no-check-certificate -c https://openresty.org/download/openresty-${NEW_openresy_ver}.tar.gz > /dev/null 2>&1
  145. if [ -e "openresty-${NEW_openresy_ver}.tar.gz" ]; then
  146. src_url=https://www.openssl.org/source/openssl-${openssl_ver}.tar.gz && Download_src
  147. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-${pcre_ver}.tar.gz && Download_src
  148. tar xzf openssl-${openssl_ver}.tar.gz
  149. tar xzf pcre-${pcre_ver}.tar.gz
  150. echo "Download [${CMSG}openresty-${NEW_openresy_ver}.tar.gz${CEND}] successfully! "
  151. break
  152. else
  153. echo "${CWARNING}OpenResty version does not exist! ${CEND}"
  154. fi
  155. else
  156. echo "${CWARNING}input error! Upgrade OpenResty version is the same as the old version${CEND}"
  157. fi
  158. done
  159. if [ -e "openresty-${NEW_openresy_ver}.tar.gz" ]; then
  160. echo "[${CMSG}openresty-${NEW_openresy_ver}.tar.gz${CEND}] found"
  161. echo "Press Ctrl+c to cancel or Press any key to continue..."
  162. char=`get_char`
  163. tar xzf openresty-${NEW_openresy_ver}.tar.gz
  164. [ "${Fedora_ver}" == '28' ] && patch -d openresty-${openresty_ver}/bundle/nginx-1.13.6 -p1 < 0001-unix-ngx_user-Apply-fix-for-really-old-bug-in-glibc-.patch
  165. patch -d openresty-${openresty_ver}/bundle/nginx-1.13.6 -p0 < nginx-auto-cc-gcc.patch
  166. pushd openresty-${NEW_openresy_ver}
  167. make clean
  168. openresty_ver_tmp=${NEW_openresy_ver%.*}
  169. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' bundle/nginx-${openresty_ver_tmp}/auto/cc/gcc # close debug
  170. ${openresty_install_dir}/nginx/sbin/nginx -V &> $$
  171. ./configure --prefix=${openresty_install_dir} --user=${run_user} --group=${run_user} --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-${openssl_ver} --with-pcre=../pcre-${pcre_ver} --with-pcre-jit --with-ld-opt='-ljemalloc' ${nginx_modules_options}
  172. make -j ${THREAD}
  173. if [ -f "build/nginx-${openresty_ver_tmp}/objs/nginx" ]; then
  174. /bin/mv ${openresty_install_dir}/nginx/sbin/nginx{,`date +%m%d`}
  175. make install
  176. kill -USR2 `cat /var/run/nginx.pid`
  177. sleep 1
  178. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  179. popd > /dev/null
  180. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_openresy_ver}${CEND} to ${CWARNING}${NEW_openresy_ver}${CEND}"
  181. rm -rf openresty-${NEW_openresy_ver}
  182. else
  183. echo "${CFAILURE}Upgrade OpenResty failed! ${CEND}"
  184. fi
  185. fi
  186. popd > /dev/null
  187. }
  188. Upgrade_Apache() {
  189. pushd ${oneinstack_dir}/src > /dev/null
  190. [ ! -e "${apache_install_dir}/bin/httpd" ] && echo "${CWARNING}Apache is not installed on your system! ${CEND}" && exit 1
  191. OLD_apache_ver="`/usr/local/apache/bin/httpd -v | grep version | awk -F'/| ' '{print $4}'`"
  192. Apache_flag="`echo ${OLD_apache_ver} | awk -F. '{print $1 $2}'`"
  193. Latest_apache_ver=`curl -s http://httpd.apache.org/download.cgi | awk "/#apache${Apache_flag}/{print $2}" | head -1 | grep -oE "2\.[24]\.[0-9]+"`
  194. [ -z "${Latest_apache_ver}" ] && Latest_apache_ver=${apache22_ver}
  195. echo
  196. echo "Current Apache Version: ${CMSG}${OLD_apache_ver}${CEND}"
  197. while :; do echo
  198. read -p "Please input upgrade Apache Version(Default: ${Latest_apache_ver}): " NEW_apache_ver
  199. if [ `echo ${NEW_apache_ver} | awk -F. '{print $1$2}'` == "${Apache_flag}" ]; then
  200. [ -z "${NEW_apache_ver}" ] && NEW_apache_ver=${Latest_apache_ver}
  201. if [ "${NEW_apache_ver}" != "${OLD_apache_ver}" ]; then
  202. if [ "${Apache_flag}" == '24' ]; then
  203. src_url=http://archive.apache.org/dist/apr/apr-${apr_ver}.tar.gz && Download_src
  204. src_url=http://archive.apache.org/dist/apr/apr-util-${apr_util_ver}.tar.gz && Download_src
  205. tar xzf apr-${apr_ver}.tar.gz
  206. tar xzf apr-util-${apr_util_ver}.tar.gz
  207. fi
  208. [ ! -e "httpd-${NEW_apache_ver}.tar.gz" ] && wget --no-check-certificate -c http://archive.apache.org/dist/httpd/httpd-${NEW_apache_ver}.tar.gz > /dev/null 2>&1
  209. if [ -e "httpd-${NEW_apache_ver}.tar.gz" ]; then
  210. echo "Download [${CMSG}apache-${NEW_apache_ver}.tar.gz${CEND}] successfully! "
  211. break
  212. else
  213. echo "${CWARNING}Apache version does not exist! ${CEND}"
  214. fi
  215. else
  216. echo "${CWARNING}input error! Upgrade Apache version is the same as the old version${CEND}"
  217. fi
  218. else
  219. echo "${CWARNING}input error! ${CEND}Please only input '${CMSG}${OLD_apache_ver%.*}.xx${CEND}'"
  220. fi
  221. done
  222. if [ -e "httpd-${NEW_apache_ver}.tar.gz" ]; then
  223. echo "[${CMSG}httpd-${NEW_apache_ver}.tar.gz${CEND}] found"
  224. echo "Press Ctrl+c to cancel or Press any key to continue..."
  225. char=`get_char`
  226. tar xzf httpd-${NEW_apache_ver}.tar.gz
  227. pushd httpd-${NEW_apache_ver}
  228. make clean
  229. if [ "${Apache_flag}" == '24' ]; then
  230. /bin/cp -R ../apr-${apr_ver} ./srclib/apr
  231. /bin/cp -R ../apr-util-${apr_util_ver} ./srclib/apr-util
  232. [ -e "${php_install_dir}/bin/phpize" ] && { PHP_detail_ver=`${php_install_dir}/bin/php -r 'echo PHP_VERSION;'`; PHP_master_ver=${PHP_detail_ver%%.*}; }
  233. [ "${PHP_master_ver}" == '5' ] && Apache_mpm_arg='--with-mpm=prefork'
  234. LDFLAGS=-ldl ./configure --prefix=${apache_install_dir} ${Apache_mpm_arg} --enable-mpms-shared=all --with-included-apr --enable-headers --enable-deflate --enable-so --enable-dav --enable-rewrite --enable-ssl --with-ssl=${openssl_install_dir} --enable-http2 --with-nghttp2=/usr/local --enable-expires --enable-static-support --enable-suexec --enable-modules=all --enable-mods-shared=all
  235. elif [ "${Apache_flag}" == '22' ]; then
  236. [ "${Ubuntu_ver}" == "12" ] && sed -i '@SSL_PROTOCOL_SSLV2@d' modules/ssl/ssl_engine_io.c
  237. LDFLAGS=-ldl ./configure --prefix=${apache_install_dir} --with-mpm=prefork --with-included-apr --enable-headers --enable-deflate --enable-so --enable-rewrite --enable-ssl--with-ssl=${openssl_install_dir} --enable-expires --enable-static-support --enable-suexec --enable-modules=all --enable-mods-shared=all
  238. fi
  239. make -j ${THREAD}
  240. if [ -e 'httpd' ]; then
  241. [[ -d ${apache_install_dir}.bak && -d ${apache_install_dir} ]] && rm -rf ${apache_install_dir}.bak
  242. /etc/init.d/httpd stop
  243. /bin/cp -R ${apache_install_dir}{,bak}
  244. make install && unset LDFLAGS
  245. /etc/init.d/httpd start
  246. popd > /dev/null
  247. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_apache_ver}${CEND} to ${CWARNING}${NEW_apache_ver}${CEND}"
  248. rm -rf httpd-${NEW_apache_ver} apr-${apr_ver} apr-util-${apr_util_ver}
  249. else
  250. echo "${CFAILURE}Upgrade Apache failed! ${CEND}"
  251. fi
  252. fi
  253. popd > /dev/null
  254. }