upgrade_web.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ 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_version_tmp=`$nginx_install_dir/sbin/nginx -v 2>&1`
  14. OLD_Nginx_version=${OLD_Nginx_version_tmp##*/}
  15. Latest_Nginx_version=`curl -s http://nginx.org/en/CHANGES-1.12 | awk '/Changes with nginx/{print$0}' | awk '{print $4}' | head -1`
  16. [ -z "$Latest_Nginx_version" ] && Latest_Nginx_version=`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_version${CEND}"
  19. while :; do echo
  20. read -p "Please input upgrade Nginx Version(default: $Latest_Nginx_version): " NEW_Nginx_version
  21. [ -z "$NEW_Nginx_version" ] && NEW_Nginx_version=$Latest_Nginx_version
  22. if [ "$NEW_Nginx_version" != "$OLD_Nginx_version" ]; then
  23. [ ! -e "nginx-$NEW_Nginx_version.tar.gz" ] && wget --no-check-certificate -c http://nginx.org/download/nginx-$NEW_Nginx_version.tar.gz > /dev/null 2>&1
  24. if [ -e "nginx-$NEW_Nginx_version.tar.gz" ]; then
  25. src_url=https://www.openssl.org/source/openssl-$openssl_version.tar.gz && Download_src
  26. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
  27. tar xzf openssl-$openssl_version.tar.gz
  28. tar xzf pcre-$pcre_version.tar.gz
  29. echo "Download [${CMSG}nginx-$NEW_Nginx_version.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_version.tar.gz" ]; then
  39. echo "[${CMSG}nginx-$NEW_Nginx_version.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_version.tar.gz
  43. pushd nginx-$NEW_Nginx_version
  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_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  48. rm -rf $$
  49. ./configure $nginx_configure_arguments
  50. make -j ${THREAD}
  51. if [ -f "objs/nginx" ]; then
  52. /bin/mv $nginx_install_dir/sbin/nginx{,`date +%m%d`}
  53. /bin/cp objs/nginx $nginx_install_dir/sbin/nginx
  54. kill -USR2 `cat /var/run/nginx.pid`
  55. sleep 1
  56. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  57. popd > /dev/null
  58. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_Nginx_version${CEND} to ${CWARNING}$NEW_Nginx_version${CEND}"
  59. rm -rf nginx-$NEW_Nginx_version
  60. else
  61. echo "${CFAILURE}Upgrade Nginx failed! ${CEND}"
  62. fi
  63. fi
  64. popd > /dev/null
  65. }
  66. Upgrade_Tengine() {
  67. pushd ${oneinstack_dir}/src > /dev/null
  68. [ ! -e "$tengine_install_dir/sbin/nginx" ] && echo "${CWARNING}Tengine is not installed on your system! ${CEND}" && exit 1
  69. OLD_Tengine_version_tmp=`$tengine_install_dir/sbin/nginx -v 2>&1`
  70. OLD_Tengine_version="`echo ${OLD_Tengine_version_tmp#*/} | awk '{print $1}'`"
  71. Latest_Tengine_version=`curl -s http://tengine.taobao.org/changelog.html | grep -oE "[0-9]\.[0-9]\.[0-9]+" | head -1`
  72. echo
  73. echo "Current Tengine Version: ${CMSG}$OLD_Tengine_version${CEND}"
  74. while :; do echo
  75. read -p "Please input upgrade Tengine Version(default: $Latest_Tengine_version): " NEW_Tengine_version
  76. [ -z "$NEW_Tengine_version" ] && NEW_Tengine_version=$Latest_Tengine_version
  77. if [ "$NEW_Tengine_version" != "$OLD_Tengine_version" ]; then
  78. [ ! -e "tengine-$NEW_Tengine_version.tar.gz" ] && wget --no-check-certificate -c http://tengine.taobao.org/download/tengine-$NEW_Tengine_version.tar.gz > /dev/null 2>&1
  79. if [ -e "tengine-$NEW_Tengine_version.tar.gz" ]; then
  80. src_url=https://www.openssl.org/source/openssl-$openssl_version.tar.gz && Download_src
  81. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
  82. tar xzf openssl-$openssl_version.tar.gz
  83. tar xzf pcre-$pcre_version.tar.gz
  84. echo "Download [${CMSG}tengine-$NEW_Tengine_version.tar.gz${CEND}] successfully! "
  85. break
  86. else
  87. echo "${CWARNING}Tengine version does not exist! ${CEND}"
  88. fi
  89. else
  90. echo "${CWARNING}input error! Upgrade Tengine version is the same as the old version${CEND}"
  91. fi
  92. done
  93. if [ -e "tengine-$NEW_Tengine_version.tar.gz" ]; then
  94. echo "[${CMSG}tengine-$NEW_Tengine_version.tar.gz${CEND}] found"
  95. echo "Press Ctrl+c to cancel or Press any key to continue..."
  96. char=`get_char`
  97. tar xzf tengine-$NEW_Tengine_version.tar.gz
  98. pushd tengine-$NEW_Tengine_version
  99. make clean
  100. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
  101. $tengine_install_dir/sbin/nginx -V &> $$
  102. tengine_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  103. rm -rf $$
  104. ./configure $tengine_configure_arguments
  105. make -j ${THREAD}
  106. if [ -f "objs/nginx" ]; then
  107. /bin/mv $tengine_install_dir/sbin/nginx{,`date +%m%d`}
  108. /bin/mv $tengine_install_dir/sbin/dso_tool{,`date +%m%d`}
  109. /bin/mv $tengine_install_dir/modules{,`date +%m%d`}
  110. /bin/cp objs/nginx $tengine_install_dir/sbin/nginx
  111. /bin/cp objs/dso_tool $tengine_install_dir/sbin/dso_tool
  112. chmod +x $tengine_install_dir/sbin/*
  113. make install
  114. kill -USR2 `cat /var/run/nginx.pid`
  115. sleep 1
  116. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  117. popd > /dev/null
  118. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_Tengine_version${CEND} to ${CWARNING}$NEW_Tengine_version${CEND}"
  119. rm -rf tengine-$NEW_Tengine_version
  120. else
  121. echo "${CFAILURE}Upgrade Tengine failed! ${CEND}"
  122. fi
  123. fi
  124. popd > /dev/null
  125. }
  126. Upgrade_OpenResty() {
  127. pushd ${oneinstack_dir}/src > /dev/null
  128. [ ! -e "$openresty_install_dir/nginx/sbin/nginx" ] && echo "${CWARNING}OpenResty is not installed on your system! ${CEND}" && exit 1
  129. OLD_OpenResty_version_tmp=`$openresty_install_dir/nginx/sbin/nginx -v 2>&1`
  130. OLD_OpenResty_version="`echo ${OLD_OpenResty_version_tmp#*/} | awk '{print $1}'`"
  131. Latest_OpenResty_version=`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`
  132. echo
  133. echo "Current OpenResty Version: ${CMSG}$OLD_OpenResty_version${CEND}"
  134. while :; do echo
  135. read -p "Please input upgrade OpenResty Version(default: $Latest_OpenResty_version): " NEW_OpenResty_version
  136. [ -z "$NEW_OpenResty_version" ] && NEW_OpenResty_version=$Latest_OpenResty_version
  137. if [ "$NEW_OpenResty_version" != "$OLD_OpenResty_version" ]; then
  138. [ ! -e "openresty-$NEW_OpenResty_version.tar.gz" ] && wget --no-check-certificate -c https://openresty.org/download/openresty-$NEW_OpenResty_version.tar.gz > /dev/null 2>&1
  139. if [ -e "openresty-$NEW_OpenResty_version.tar.gz" ]; then
  140. src_url=https://www.openssl.org/source/openssl-$openssl_version.tar.gz && Download_src
  141. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
  142. tar xzf openssl-$openssl_version.tar.gz
  143. tar xzf pcre-$pcre_version.tar.gz
  144. echo "Download [${CMSG}openresty-$NEW_OpenResty_version.tar.gz${CEND}] successfully! "
  145. break
  146. else
  147. echo "${CWARNING}OpenResty version does not exist! ${CEND}"
  148. fi
  149. else
  150. echo "${CWARNING}input error! Upgrade OpenResty version is the same as the old version${CEND}"
  151. fi
  152. done
  153. if [ -e "openresty-$NEW_OpenResty_version.tar.gz" ]; then
  154. echo "[${CMSG}openresty-$NEW_OpenResty_version.tar.gz${CEND}] found"
  155. echo "Press Ctrl+c to cancel or Press any key to continue..."
  156. char=`get_char`
  157. tar xzf openresty-$NEW_OpenResty_version.tar.gz
  158. pushd openresty-$NEW_OpenResty_version
  159. make clean
  160. openresty_version_tmp=${NEW_OpenResty_version%.*}
  161. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' bundle/nginx-$openresty_version_tmp/auto/cc/gcc # close debug
  162. $openresty_install_dir/nginx/sbin/nginx -V &> $$
  163. ./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_version --with-pcre=../pcre-$pcre_version --with-pcre-jit --with-ld-opt='-ljemalloc' $nginx_modules_options
  164. make -j ${THREAD}
  165. if [ -f "build/nginx-$openresty_version_tmp/objs/nginx" ]; then
  166. /bin/mv $openresty_install_dir/nginx/sbin/nginx{,`date +%m%d`}
  167. make install
  168. kill -USR2 `cat /var/run/nginx.pid`
  169. sleep 1
  170. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  171. popd > /dev/null
  172. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_OpenResty_version${CEND} to ${CWARNING}$NEW_OpenResty_version${CEND}"
  173. rm -rf openresty-$NEW_OpenResty_version
  174. else
  175. echo "${CFAILURE}Upgrade OpenResty failed! ${CEND}"
  176. fi
  177. fi
  178. popd > /dev/null
  179. }
  180. Upgrade_Apache() {
  181. pushd ${oneinstack_dir}/src > /dev/null
  182. [ ! -e "$apache_install_dir/bin/httpd" ] && echo "${CWARNING}Apache is not installed on your system! ${CEND}" && exit 1
  183. OLD_Apache_version="`/usr/local/apache/bin/httpd -v | grep version | awk -F'/| ' '{print $4}'`"
  184. Apache_flag="`echo $OLD_Apache_version | awk -F. '{print $1 $2}'`"
  185. Latest_Apache_version=`curl -s http://httpd.apache.org/download.cgi | awk "/#apache$Apache_flag/{print $2}" | head -1 | grep -oE "2\.[24]\.[0-9]+"`
  186. echo
  187. echo "Current Apache Version: ${CMSG}$OLD_Apache_version${CEND}"
  188. while :; do echo
  189. read -p "Please input upgrade Apache Version(Default: $Latest_Apache_version): " NEW_Apache_version
  190. [ -z "$NEW_Apache_version" ] && NEW_Apache_version=$Latest_Apache_version
  191. if [ "$NEW_Apache_version" != "$OLD_Apache_version" ]; then
  192. if [ "$Apache_flag" == '24' ]; then
  193. src_url=http://archive.apache.org/dist/apr/apr-${apr_version}.tar.gz && Download_src
  194. src_url=http://archive.apache.org/dist/apr/apr-util-${apr_util_version}.tar.gz && Download_src
  195. tar xzf apr-${apr_version}.tar.gz
  196. tar xzf apr-util-${apr_util_version}.tar.gz
  197. fi
  198. [ ! -e "httpd-$NEW_Apache_version.tar.gz" ] && wget --no-check-certificate -c http://mirrors.linuxeye.com/apache/httpd/httpd-$NEW_Apache_version.tar.gz > /dev/null 2>&1
  199. if [ -e "httpd-$NEW_Apache_version.tar.gz" ]; then
  200. echo "Download [${CMSG}apache-$NEW_Apache_version.tar.gz${CEND}] successfully! "
  201. break
  202. else
  203. echo "${CWARNING}Apache version does not exist! ${CEND}"
  204. fi
  205. else
  206. echo "${CWARNING}input error! Upgrade Apache version is the same as the old version${CEND}"
  207. fi
  208. done
  209. if [ -e "httpd-$NEW_Apache_version.tar.gz" ]; then
  210. echo "[${CMSG}httpd-$NEW_Apache_version.tar.gz${CEND}] found"
  211. echo "Press Ctrl+c to cancel or Press any key to continue..."
  212. char=`get_char`
  213. tar xzf httpd-$NEW_Apache_version.tar.gz
  214. pushd httpd-$NEW_Apache_version
  215. make clean
  216. if [ "$Apache_flag" == '24' ]; then
  217. /bin/cp -R ../apr-${apr_version} ./srclib/apr
  218. /bin/cp -R ../apr-util-${apr_util_version} ./srclib/apr-util
  219. LDFLAGS=-ldl LD_LIBRARY_PATH=${openssl_install_dir}/lib ./configure --prefix=${apache_install_dir} --with-mpm=prefork --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
  220. elif [ "$Apache_flag" == '22' ]; then
  221. [ "${Ubuntu_version}" == "12" ] && sed -i '@SSL_PROTOCOL_SSLV2@d' modules/ssl/ssl_engine_io.c
  222. 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
  223. fi
  224. make -j ${THREAD}
  225. if [ -e 'httpd' ]; then
  226. [[ -d ${apache_install_dir}.bak && -d ${apache_install_dir} ]] && rm -rf ${apache_install_dir}.bak
  227. /etc/init.d/httpd stop
  228. /bin/cp -R ${apache_install_dir}{,bak}
  229. make install && unset LDFLAGS
  230. /etc/init.d/httpd start
  231. popd > /dev/null
  232. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_Apache_version${CEND} to ${CWARNING}$NEW_Apache_version${CEND}"
  233. rm -rf httpd-$NEW_Apache_version apr-${apr_version} apr-util-${apr_util_version}
  234. else
  235. echo "${CFAILURE}Upgrade Apache failed! ${CEND}"
  236. fi
  237. fi
  238. popd > /dev/null
  239. }