upgrade_web.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 6+ 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. pushd nginx-${NEW_nginx_ver}
  44. make clean
  45. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
  46. ${nginx_install_dir}/sbin/nginx -V &> $$
  47. nginx_configure_args_tmp=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  48. rm -rf $$
  49. 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} @"`
  50. ./configure ${nginx_configure_args}
  51. make -j ${THREAD}
  52. if [ -f "objs/nginx" ]; then
  53. /bin/mv ${nginx_install_dir}/sbin/nginx{,`date +%m%d`}
  54. /bin/cp objs/nginx ${nginx_install_dir}/sbin/nginx
  55. kill -USR2 `cat /var/run/nginx.pid`
  56. sleep 1
  57. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  58. popd > /dev/null
  59. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_nginx_ver}${CEND} to ${CWARNING}${NEW_nginx_ver}${CEND}"
  60. rm -rf nginx-${NEW_nginx_ver}
  61. else
  62. echo "${CFAILURE}Upgrade Nginx failed! ${CEND}"
  63. fi
  64. fi
  65. popd > /dev/null
  66. }
  67. Upgrade_Tengine() {
  68. pushd ${oneinstack_dir}/src > /dev/null
  69. [ ! -e "${tengine_install_dir}/sbin/nginx" ] && echo "${CWARNING}Tengine is not installed on your system! ${CEND}" && exit 1
  70. OLD_tengine_ver_tmp=`${tengine_install_dir}/sbin/nginx -v 2>&1`
  71. OLD_tengine_ver="`echo ${OLD_tengine_ver_tmp#*/} | awk '{print $1}'`"
  72. Latest_tengine_ver=`curl -s http://tengine.taobao.org/changelog.html | grep -oE "[0-9]\.[0-9]\.[0-9]+" | head -1`
  73. echo
  74. echo "Current Tengine Version: ${CMSG}${OLD_tengine_ver}${CEND}"
  75. while :; do echo
  76. read -p "Please input upgrade Tengine Version(default: ${Latest_tengine_ver}): " NEW_tengine_ver
  77. [ -z "${NEW_tengine_ver}" ] && NEW_tengine_ver=${Latest_tengine_ver}
  78. if [ "${NEW_tengine_ver}" != "${OLD_tengine_ver}" ]; then
  79. [ ! -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
  80. if [ -e "tengine-${NEW_tengine_ver}.tar.gz" ]; then
  81. src_url=https://www.openssl.org/source/openssl-${openssl_ver}.tar.gz && Download_src
  82. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-${pcre_ver}.tar.gz && Download_src
  83. tar xzf openssl-${openssl_ver}.tar.gz
  84. tar xzf pcre-${pcre_ver}.tar.gz
  85. echo "Download [${CMSG}tengine-${NEW_tengine_ver}.tar.gz${CEND}] successfully! "
  86. break
  87. else
  88. echo "${CWARNING}Tengine version does not exist! ${CEND}"
  89. fi
  90. else
  91. echo "${CWARNING}input error! Upgrade Tengine version is the same as the old version${CEND}"
  92. fi
  93. done
  94. if [ -e "tengine-${NEW_tengine_ver}.tar.gz" ]; then
  95. echo "[${CMSG}tengine-${NEW_tengine_ver}.tar.gz${CEND}] found"
  96. echo "Press Ctrl+c to cancel or Press any key to continue..."
  97. char=`get_char`
  98. tar xzf tengine-${NEW_tengine_ver}.tar.gz
  99. pushd tengine-${NEW_tengine_ver}
  100. make clean
  101. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
  102. ${tengine_install_dir}/sbin/nginx -V &> $$
  103. tengine_configure_args_tmp=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  104. rm -rf $$
  105. 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} @"`
  106. ./configure ${tengine_configure_args}
  107. make -j ${THREAD}
  108. if [ -f "objs/nginx" ]; then
  109. /bin/mv ${tengine_install_dir}/sbin/nginx{,`date +%m%d`}
  110. /bin/mv ${tengine_install_dir}/sbin/dso_tool{,`date +%m%d`}
  111. /bin/mv ${tengine_install_dir}/modules{,`date +%m%d`}
  112. /bin/cp objs/nginx ${tengine_install_dir}/sbin/nginx
  113. /bin/cp objs/dso_tool ${tengine_install_dir}/sbin/dso_tool
  114. chmod +x ${tengine_install_dir}/sbin/*
  115. make install
  116. kill -USR2 `cat /var/run/nginx.pid`
  117. sleep 1
  118. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  119. popd > /dev/null
  120. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_tengine_ver${CEND} to ${CWARNING}${NEW_tengine_ver}${CEND}"
  121. rm -rf tengine-${NEW_tengine_ver}
  122. else
  123. echo "${CFAILURE}Upgrade Tengine failed! ${CEND}"
  124. fi
  125. fi
  126. popd > /dev/null
  127. }
  128. Upgrade_OpenResty() {
  129. pushd ${oneinstack_dir}/src > /dev/null
  130. [ ! -e "${openresty_install_dir}/nginx/sbin/nginx" ] && echo "${CWARNING}OpenResty is not installed on your system! ${CEND}" && exit 1
  131. OLD_openresy_ver_tmp=`${openresty_install_dir}/nginx/sbin/nginx -v 2>&1`
  132. OLD_openresy_ver="`echo ${OLD_openresy_ver_tmp#*/} | awk '{print $1}'`"
  133. 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`
  134. echo
  135. echo "Current OpenResty Version: ${CMSG}${OLD_openresy_ver}${CEND}"
  136. while :; do echo
  137. read -p "Please input upgrade OpenResty Version(default: ${Latest_openresy_ver}): " NEW_openresy_ver
  138. [ -z "${NEW_openresy_ver}" ] && NEW_openresy_ver=${Latest_openresy_ver}
  139. if [ "${NEW_openresy_ver}" != "${OLD_openresy_ver}" ]; then
  140. [ ! -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
  141. if [ -e "openresty-${NEW_openresy_ver}.tar.gz" ]; then
  142. src_url=https://www.openssl.org/source/openssl-${openssl_ver}.tar.gz && Download_src
  143. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-${pcre_ver}.tar.gz && Download_src
  144. tar xzf openssl-${openssl_ver}.tar.gz
  145. tar xzf pcre-${pcre_ver}.tar.gz
  146. echo "Download [${CMSG}openresty-${NEW_openresy_ver}.tar.gz${CEND}] successfully! "
  147. break
  148. else
  149. echo "${CWARNING}OpenResty version does not exist! ${CEND}"
  150. fi
  151. else
  152. echo "${CWARNING}input error! Upgrade OpenResty version is the same as the old version${CEND}"
  153. fi
  154. done
  155. if [ -e "openresty-${NEW_openresy_ver}.tar.gz" ]; then
  156. echo "[${CMSG}openresty-${NEW_openresy_ver}.tar.gz${CEND}] found"
  157. echo "Press Ctrl+c to cancel or Press any key to continue..."
  158. char=`get_char`
  159. tar xzf openresty-${NEW_openresy_ver}.tar.gz
  160. pushd openresty-${NEW_openresy_ver}
  161. make clean
  162. openresty_ver_tmp=${NEW_openresy_ver%.*}
  163. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' bundle/nginx-${openresty_ver_tmp}/auto/cc/gcc # close debug
  164. ${openresty_install_dir}/nginx/sbin/nginx -V &> $$
  165. ./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}
  166. make -j ${THREAD}
  167. if [ -f "build/nginx-${openresty_ver_tmp}/objs/nginx" ]; then
  168. /bin/mv ${openresty_install_dir}/nginx/sbin/nginx{,`date +%m%d`}
  169. make install
  170. kill -USR2 `cat /var/run/nginx.pid`
  171. sleep 1
  172. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  173. popd > /dev/null
  174. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_openresy_ver}${CEND} to ${CWARNING}${NEW_openresy_ver}${CEND}"
  175. rm -rf openresty-${NEW_openresy_ver}
  176. else
  177. echo "${CFAILURE}Upgrade OpenResty failed! ${CEND}"
  178. fi
  179. fi
  180. popd > /dev/null
  181. }
  182. Upgrade_Apache() {
  183. pushd ${oneinstack_dir}/src > /dev/null
  184. [ ! -e "${apache_install_dir}/bin/httpd" ] && echo "${CWARNING}Apache is not installed on your system! ${CEND}" && exit 1
  185. OLD_apache_ver="`/usr/local/apache/bin/httpd -v | grep version | awk -F'/| ' '{print $4}'`"
  186. Apache_flag="`echo ${OLD_apache_ver} | awk -F. '{print $1 $2}'`"
  187. 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]+"`
  188. [ -z "${Latest_apache_ver}" ] && Latest_apache_ver=${apache22_ver}
  189. echo
  190. echo "Current Apache Version: ${CMSG}${OLD_apache_ver}${CEND}"
  191. while :; do echo
  192. read -p "Please input upgrade Apache Version(Default: ${Latest_apache_ver}): " NEW_apache_ver
  193. if [ `echo ${NEW_apache_ver} | awk -F. '{print $1$2}'` == "${Apache_flag}" ]; then
  194. [ -z "${NEW_apache_ver}" ] && NEW_apache_ver=${Latest_apache_ver}
  195. if [ "${NEW_apache_ver}" != "${OLD_apache_ver}" ]; then
  196. if [ "${Apache_flag}" == '24' ]; then
  197. src_url=http://archive.apache.org/dist/apr/apr-${apr_ver}.tar.gz && Download_src
  198. src_url=http://archive.apache.org/dist/apr/apr-util-${apr_util_ver}.tar.gz && Download_src
  199. tar xzf apr-${apr_ver}.tar.gz
  200. tar xzf apr-util-${apr_util_ver}.tar.gz
  201. fi
  202. [ ! -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
  203. if [ -e "httpd-${NEW_apache_ver}.tar.gz" ]; then
  204. echo "Download [${CMSG}apache-${NEW_apache_ver}.tar.gz${CEND}] successfully! "
  205. break
  206. else
  207. echo "${CWARNING}Apache version does not exist! ${CEND}"
  208. fi
  209. else
  210. echo "${CWARNING}input error! Upgrade Apache version is the same as the old version${CEND}"
  211. fi
  212. else
  213. echo "${CWARNING}input error! ${CEND}Please only input '${CMSG}${OLD_apache_ver%.*}.xx${CEND}'"
  214. fi
  215. done
  216. if [ -e "httpd-${NEW_apache_ver}.tar.gz" ]; then
  217. echo "[${CMSG}httpd-${NEW_apache_ver}.tar.gz${CEND}] found"
  218. echo "Press Ctrl+c to cancel or Press any key to continue..."
  219. char=`get_char`
  220. tar xzf httpd-${NEW_apache_ver}.tar.gz
  221. pushd httpd-${NEW_apache_ver}
  222. make clean
  223. if [ "${Apache_flag}" == '24' ]; then
  224. /bin/cp -R ../apr-${apr_ver} ./srclib/apr
  225. /bin/cp -R ../apr-util-${apr_util_ver} ./srclib/apr-util
  226. [ -e "${php_install_dir}/bin/phpize" ] && { PHP_detail_ver=`${php_install_dir}/bin/php -r 'echo PHP_VERSION;'`; PHP_master_ver=${PHP_detail_ver%%.*}; }
  227. [ "${PHP_master_ver}" == '5' ] && Apache_mpm_arg='--with-mpm=prefork'
  228. 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
  229. elif [ "${Apache_flag}" == '22' ]; then
  230. [ "${Ubuntu_ver}" == "12" ] && sed -i '@SSL_PROTOCOL_SSLV2@d' modules/ssl/ssl_engine_io.c
  231. 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
  232. fi
  233. make -j ${THREAD}
  234. if [ -e 'httpd' ]; then
  235. [[ -d ${apache_install_dir}.bak && -d ${apache_install_dir} ]] && rm -rf ${apache_install_dir}.bak
  236. /etc/init.d/httpd stop
  237. /bin/cp -R ${apache_install_dir}{,bak}
  238. make install && unset LDFLAGS
  239. /etc/init.d/httpd start
  240. popd > /dev/null
  241. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_apache_ver}${CEND} to ${CWARNING}${NEW_apache_ver}${CEND}"
  242. rm -rf httpd-${NEW_apache_ver} apr-${apr_ver} apr-util-${apr_util_ver}
  243. else
  244. echo "${CFAILURE}Upgrade Apache failed! ${CEND}"
  245. fi
  246. fi
  247. popd > /dev/null
  248. }