upgrade_web.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/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 --connect-timeout 2 -m 3 -s http://nginx.org/en/CHANGES-1.22 | awk '/Changes with nginx/{print$0}' | awk '{print $4}' | head -1`
  16. [ -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`
  17. echo
  18. echo "Current Nginx Version: ${CMSG}${OLD_nginx_ver}${CEND}"
  19. while :; do echo
  20. [ "${nginx_flag}" != 'y' ] && read -e -p "Please input upgrade Nginx Version(default: ${Latest_nginx_ver}): " NEW_nginx_ver
  21. 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-${openssl11_ver}.tar.gz && Download_src
  26. src_url=${mirror_link}/oneinstack/src/pcre-${pcre_ver}.tar.gz && Download_src
  27. src_url=${mirror_link}/oneinstack/src/ngx_devel_kit.tar.gz && Download_src
  28. src_url=${mirror_link}/oneinstack/src/lua-nginx-module-${lua_nginx_module_ver}.tar.gz && Download_src
  29. tar xzf openssl-${openssl11_ver}.tar.gz
  30. tar xzf pcre-${pcre_ver}.tar.gz
  31. tar xzf ngx_devel_kit.tar.gz
  32. tar xzf lua-nginx-module-${lua_nginx_module_ver}.tar.gz
  33. echo "Download [${CMSG}nginx-${NEW_nginx_ver}.tar.gz${CEND}] successfully! "
  34. break
  35. else
  36. echo "${CWARNING}Nginx version does not exist! ${CEND}"
  37. fi
  38. else
  39. echo "${CWARNING}input error! Upgrade Nginx version is the same as the old version${CEND}"
  40. exit
  41. fi
  42. done
  43. if [ -e "nginx-${NEW_nginx_ver}.tar.gz" ]; then
  44. echo "[${CMSG}nginx-${NEW_nginx_ver}.tar.gz${CEND}] found"
  45. if [ "${nginx_flag}" != 'y' ]; then
  46. echo "Press Ctrl+c to cancel or Press any key to continue..."
  47. char=`get_char`
  48. fi
  49. ${nginx_install_dir}/sbin/nginx -V &> $$
  50. nginx_configure_args_tmp=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  51. rm -rf $$
  52. 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} @"`
  53. if [ -n "`echo $nginx_configure_args | grep lua-nginx-module`" ]; then
  54. ${oneinstack_dir}/upgrade.sh --oneinstack > /dev/null
  55. src_url=${mirror_link}/oneinstack/src/luajit2-${luajit2_ver}.tar.gz && Download_src
  56. tar xzf luajit2-${luajit2_ver}.tar.gz
  57. pushd luajit2-${luajit2_ver}
  58. make && make install
  59. popd > /dev/null
  60. rm -rf luajit2-${luajit2_ver}
  61. src_url=${mirror_link}/oneinstack/src/lua-resty-core-${lua_resty_core_ver}.tar.gz && Download_src
  62. tar xzf lua-resty-core-${lua_resty_core_ver}.tar.gz
  63. pushd lua-resty-core-${lua_resty_core_ver}
  64. make install
  65. popd > /dev/null
  66. rm -rf lua-resty-core-${lua_resty_core_ver}
  67. src_url=${mirror_link}/oneinstack/src/lua-resty-lrucache-${lua_resty_lrucache_ver}.tar.gz && Download_src
  68. tar xzf lua-resty-lrucache-${lua_resty_lrucache_ver}.tar.gz
  69. pushd lua-resty-lrucache-${lua_resty_lrucache_ver}
  70. make install
  71. popd > /dev/null
  72. rm -rf lua-resty-lrucache-${lua_resty_lrucache_ver}
  73. fi
  74. tar xzf nginx-${NEW_nginx_ver}.tar.gz
  75. pushd nginx-${NEW_nginx_ver}
  76. make clean
  77. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
  78. export LUAJIT_LIB=/usr/local/lib
  79. export LUAJIT_INC=/usr/local/include/luajit-2.1
  80. ./configure ${nginx_configure_args}
  81. make -j ${THREAD}
  82. if [ -f "objs/nginx" ]; then
  83. /bin/mv ${nginx_install_dir}/sbin/nginx{,`date +%m%d`}
  84. /bin/cp objs/nginx ${nginx_install_dir}/sbin/nginx
  85. kill -USR2 `cat /var/run/nginx.pid`
  86. sleep 1
  87. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  88. popd > /dev/null
  89. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_nginx_ver}${CEND} to ${CWARNING}${NEW_nginx_ver}${CEND}"
  90. rm -rf nginx-${NEW_nginx_ver}
  91. else
  92. echo "${CFAILURE}Upgrade Nginx failed! ${CEND}"
  93. fi
  94. fi
  95. popd > /dev/null
  96. }
  97. Upgrade_Tengine() {
  98. pushd ${oneinstack_dir}/src > /dev/null
  99. [ ! -e "${tengine_install_dir}/sbin/nginx" ] && echo "${CWARNING}Tengine is not installed on your system! ${CEND}" && exit 1
  100. OLD_tengine_ver_tmp=`${tengine_install_dir}/sbin/nginx -v 2>&1`
  101. OLD_tengine_ver="`echo ${OLD_tengine_ver_tmp#*/} | awk '{print $1}'`"
  102. Latest_tengine_ver=`curl --connect-timeout 2 -m 3 -s http://tengine.taobao.org/changelog.html | grep -v generator | grep -oE "[0-9]\.[0-9]\.[0-9]+" | head -1`
  103. echo
  104. echo "Current Tengine Version: ${CMSG}${OLD_tengine_ver}${CEND}"
  105. while :; do echo
  106. [ "${tengine_flag}" != 'y' ] && read -e -p "Please input upgrade Tengine Version(default: ${Latest_tengine_ver}): " NEW_tengine_ver
  107. NEW_tengine_ver=${NEW_tengine_ver:-${Latest_tengine_ver}}
  108. if [ "${NEW_tengine_ver}" != "${OLD_tengine_ver}" ]; then
  109. [ ! -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
  110. if [ -e "tengine-${NEW_tengine_ver}.tar.gz" ]; then
  111. src_url=https://www.openssl.org/source/openssl-${openssl11_ver}.tar.gz && Download_src
  112. src_url=${mirror_link}/oneinstack/src/pcre-${pcre_ver}.tar.gz && Download_src
  113. tar xzf openssl-${openssl11_ver}.tar.gz
  114. tar xzf pcre-${pcre_ver}.tar.gz
  115. echo "Download [${CMSG}tengine-${NEW_tengine_ver}.tar.gz${CEND}] successfully! "
  116. break
  117. else
  118. echo "${CWARNING}Tengine version does not exist! ${CEND}"
  119. fi
  120. else
  121. echo "${CWARNING}input error! Upgrade Tengine version is the same as the old version${CEND}"
  122. exit
  123. fi
  124. done
  125. if [ -e "tengine-${NEW_tengine_ver}.tar.gz" ]; then
  126. echo "[${CMSG}tengine-${NEW_tengine_ver}.tar.gz${CEND}] found"
  127. if [ "${tengine_flag}" != 'y' ]; then
  128. echo "Press Ctrl+c to cancel or Press any key to continue..."
  129. char=`get_char`
  130. fi
  131. tar xzf tengine-${NEW_tengine_ver}.tar.gz
  132. pushd tengine-${NEW_tengine_ver}
  133. make clean
  134. ${tengine_install_dir}/sbin/nginx -V &> $$
  135. tengine_configure_args_tmp=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  136. rm -rf $$
  137. tengine_configure_args=`echo ${tengine_configure_args_tmp} | 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} @"`
  138. export LUAJIT_LIB=/usr/local/lib
  139. export LUAJIT_INC=/usr/local/include/luajit-2.1
  140. ./configure ${tengine_configure_args}
  141. make
  142. if [ -f "objs/nginx" ]; then
  143. /bin/mv ${tengine_install_dir}/sbin/nginx{,`date +%m%d`}
  144. /bin/mv ${tengine_install_dir}/modules{,`date +%m%d`}
  145. /bin/cp objs/nginx ${tengine_install_dir}/sbin/nginx
  146. chmod +x ${tengine_install_dir}/sbin/*
  147. make install
  148. kill -USR2 `cat /var/run/nginx.pid`
  149. sleep 1
  150. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  151. popd > /dev/null
  152. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_tengine_ver${CEND} to ${CWARNING}${NEW_tengine_ver}${CEND}"
  153. rm -rf tengine-${NEW_tengine_ver}
  154. else
  155. echo "${CFAILURE}Upgrade Tengine failed! ${CEND}"
  156. fi
  157. fi
  158. popd > /dev/null
  159. }
  160. Upgrade_OpenResty() {
  161. pushd ${oneinstack_dir}/src > /dev/null
  162. [ ! -e "${openresty_install_dir}/nginx/sbin/nginx" ] && echo "${CWARNING}OpenResty is not installed on your system! ${CEND}" && exit 1
  163. OLD_openresy_ver_tmp=`${openresty_install_dir}/nginx/sbin/nginx -v 2>&1`
  164. OLD_openresy_ver="`echo ${OLD_openresy_ver_tmp#*/} | awk '{print $1}'`"
  165. Latest_openresy_ver=`curl --connect-timeout 2 -m 3 -s https://openresty.org/en/download.html | awk '/download\/openresty-/{print $0}' | grep -oE "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | head -1`
  166. echo
  167. echo "Current OpenResty Version: ${CMSG}${OLD_openresy_ver}${CEND}"
  168. while :; do echo
  169. [ "${openresty_flag}" != 'y' ] && read -e -p "Please input upgrade OpenResty Version(default: ${Latest_openresy_ver}): " NEW_openresy_ver
  170. NEW_openresy_ver=${NEW_openresy_ver:-${Latest_openresy_ver}}
  171. if [ "${NEW_openresy_ver}" != "${OLD_openresy_ver}" ]; then
  172. [ ! -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
  173. if [ -e "openresty-${NEW_openresy_ver}.tar.gz" ]; then
  174. src_url=https://www.openssl.org/source/openssl-${openssl11_ver}.tar.gz && Download_src
  175. src_url=${mirror_link}/oneinstack/src/pcre-${pcre_ver}.tar.gz && Download_src
  176. tar xzf openssl-${openssl11_ver}.tar.gz
  177. tar xzf pcre-${pcre_ver}.tar.gz
  178. echo "Download [${CMSG}openresty-${NEW_openresy_ver}.tar.gz${CEND}] successfully! "
  179. break
  180. else
  181. echo "${CWARNING}OpenResty version does not exist! ${CEND}"
  182. fi
  183. else
  184. echo "${CWARNING}input error! Upgrade OpenResty version is the same as the old version${CEND}"
  185. exit
  186. fi
  187. done
  188. if [ -e "openresty-${NEW_openresy_ver}.tar.gz" ]; then
  189. echo "[${CMSG}openresty-${NEW_openresy_ver}.tar.gz${CEND}] found"
  190. if [ "${openresty_flag}" != 'y' ]; then
  191. echo "Press Ctrl+c to cancel or Press any key to continue..."
  192. char=`get_char`
  193. fi
  194. tar xzf openresty-${NEW_openresy_ver}.tar.gz
  195. pushd openresty-${NEW_openresy_ver}
  196. make clean
  197. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' bundle/nginx-${NEW_openresy_ver%.*}/auto/cc/gcc # close debug
  198. ${openresty_install_dir}/nginx/sbin/nginx -V &> $$
  199. ./configure --prefix=${openresty_install_dir} --user=${run_user} --group=${run_user} --with-http_stub_status_module --with-http_sub_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-${openssl11_ver} --with-pcre=../pcre-${pcre_ver} --with-pcre-jit --with-ld-opt='-ljemalloc -Wl,-u,pcre_version' ${nginx_modules_options}
  200. make -j ${THREAD}
  201. if [ -f "build/nginx-${NEW_openresy_ver%.*}/objs/nginx" ]; then
  202. /bin/mv ${openresty_install_dir}/nginx/sbin/nginx{,`date +%m%d`}
  203. make install
  204. kill -USR2 `cat /var/run/nginx.pid`
  205. sleep 1
  206. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  207. popd > /dev/null
  208. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_openresy_ver}${CEND} to ${CWARNING}${NEW_openresy_ver}${CEND}"
  209. rm -rf openresty-${NEW_openresy_ver}
  210. else
  211. echo "${CFAILURE}Upgrade OpenResty failed! ${CEND}"
  212. fi
  213. fi
  214. popd > /dev/null
  215. }
  216. Upgrade_Apache() {
  217. pushd ${oneinstack_dir}/src > /dev/null
  218. [ ! -e "${apache_install_dir}/bin/httpd" ] && echo "${CWARNING}Apache is not installed on your system! ${CEND}" && exit 1
  219. OLD_apache_ver="`${apache_install_dir}/bin/httpd -v | grep version | awk -F'/| ' '{print $4}'`"
  220. Latest_apache_ver=`curl --connect-timeout 2 -m 3 -s http://httpd.apache.org/download.cgi | awk "/#apache24/{print $2}" | head -1 | grep -oE "2\.[24]\.[0-9]+"`
  221. Latest_apache_ver=${Latest_apache_ver:-${apache22_ver}}
  222. echo
  223. echo "Current Apache Version: ${CMSG}${OLD_apache_ver}${CEND}"
  224. while :; do echo
  225. [ "${apache_flag}" != 'y' ] && read -e -p "Please input upgrade Apache Version(Default: ${Latest_apache_ver}): " NEW_apache_ver
  226. NEW_apache_ver=${NEW_apache_ver:-${Latest_apache_ver}}
  227. if [ `echo ${NEW_apache_ver} | awk -F. '{print $1$2}'` == "24" ]; then
  228. if [ "${NEW_apache_ver}" != "${OLD_apache_ver}" ]; then
  229. src_url=http://archive.apache.org/dist/apr/apr-${apr_ver}.tar.gz && Download_src
  230. src_url=http://archive.apache.org/dist/apr/apr-util-${apr_util_ver}.tar.gz && Download_src
  231. [ ! -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
  232. if [ -e "httpd-${NEW_apache_ver}.tar.gz" ]; then
  233. echo "Download [${CMSG}apache-${NEW_apache_ver}.tar.gz${CEND}] successfully! "
  234. break
  235. else
  236. echo "${CWARNING}Apache version does not exist! ${CEND}"
  237. fi
  238. else
  239. echo "${CWARNING}input error! Upgrade Apache version is the same as the old version${CEND}"
  240. exit
  241. fi
  242. else
  243. echo "${CWARNING}input error! ${CEND}Please only input '${CMSG}${OLD_apache_ver%.*}.xx${CEND}'"
  244. [ "${apache_flag}" == 'y' ] && exit
  245. fi
  246. done
  247. if [ -e "httpd-${NEW_apache_ver}.tar.gz" ]; then
  248. echo "[${CMSG}httpd-${NEW_apache_ver}.tar.gz${CEND}] found"
  249. if [ "${apache_flag}" != 'y' ]; then
  250. echo "Press Ctrl+c to cancel or Press any key to continue..."
  251. char=`get_char`
  252. fi
  253. # install apr
  254. if [ ! -e "${apr_install_dir}/bin/apr-1-config" ]; then
  255. tar xzf apr-${apr_ver}.tar.gz
  256. pushd apr-${apr_ver} > /dev/null
  257. ./configure --prefix=${apr_install_dir}
  258. make -j ${THREAD} && make install
  259. popd > /dev/null
  260. rm -rf apr-${apr_ver}
  261. fi
  262. # install apr-util
  263. if [ ! -e "${apr_install_dir}/bin/apu-1-config" ]; then
  264. tar xzf apr-util-${apr_util_ver}.tar.gz
  265. pushd apr-util-${apr_util_ver} > /dev/null
  266. ./configure --prefix=${apr_install_dir} --with-apr=${apr_install_dir}
  267. make -j ${THREAD} && make install
  268. popd > /dev/null
  269. rm -rf apr-util-${apr_util_ver}
  270. fi
  271. tar xzf httpd-${NEW_apache_ver}.tar.gz
  272. pushd httpd-${NEW_apache_ver}
  273. make clean
  274. LDFLAGS=-ldl ./configure --prefix=${apache_install_dir} --enable-mpms-shared=all --with-pcre --with-apr=${apr_install_dir} --with-apr-util=${apr_install_dir} --enable-headers --enable-mime-magic --enable-deflate --enable-proxy --enable-so --enable-dav --enable-rewrite --enable-remoteip --enable-expires --enable-static-support --enable-suexec --enable-mods-shared=most --enable-nonportable-atomics=yes --enable-ssl --with-ssl=${openssl_install_dir} --enable-http2 --with-nghttp2=/usr/local
  275. make -j ${THREAD}
  276. if [ -e 'httpd' ]; then
  277. [[ -d ${apache_install_dir}_bak && -d ${apache_install_dir} ]] && rm -rf ${apache_install_dir}_bak
  278. service httpd stop
  279. /bin/cp -R ${apache_install_dir}{,_bak}
  280. make install && unset LDFLAGS
  281. service httpd start
  282. popd > /dev/null
  283. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_apache_ver}${CEND} to ${CWARNING}${NEW_apache_ver}${CEND}"
  284. rm -rf httpd-${NEW_apache_ver}
  285. else
  286. echo "${CFAILURE}Upgrade Apache failed! ${CEND}"
  287. fi
  288. fi
  289. popd > /dev/null
  290. }
  291. Upgrade_Tomcat() {
  292. pushd ${oneinstack_dir}/src > /dev/null
  293. [ ! -e "${tomcat_install_dir}/conf/server.xml" ] && echo "${CWARNING}Tomcat is not installed on your system! ${CEND}" && exit 1
  294. OLD_tomcat_ver="`${tomcat_install_dir}/bin/version.sh | awk '/Server number/{print $3}' | awk -F. '{print $1"."$2"."$3}'`"
  295. Tomcat_flag="`echo ${OLD_tomcat_ver} | awk -F. '{print $1}'`"
  296. Latest_tomcat_ver=`curl --connect-timeout 2 -m 3 -s https://tomcat.apache.org/download-${Tomcat_flag}0.cgi | grep "README" | head -1 | grep -oE "[6-9]\.[0-9]\.[0-9]+"`
  297. Latest_tomcat_ver=${Latest_tomcat_ver:-${tomcat10_ver}}
  298. echo
  299. echo "Current Tomcat Version: ${CMSG}${OLD_tomcat_ver}${CEND}"
  300. while :; do echo
  301. [ "${tomcat_flag}" != 'y' ] && read -e -p "Please input upgrade Tomcat Version(Default: ${Latest_tomcat_ver}): " NEW_tomcat_ver
  302. NEW_tomcat_ver=${NEW_tomcat_ver:-${Latest_tomcat_ver}}
  303. if [ "`echo ${NEW_tomcat_ver} | awk -F. '{print $1}'`" == "${Tomcat_flag}" ]; then
  304. rm -f catalina-jmx-remote.jar
  305. echo "Download tomcat-${NEW_tomcat_ver}..."
  306. src_url=${mirror_link}/apache/tomcat/v${NEW_tomcat_ver}/apache-tomcat-${NEW_tomcat_ver}.tar.gz && Download_src
  307. [ ! -e "apache-tomcat-${NEW_tomcat_ver}.tar.gz" ] && wget --no-check-certificate -c https://archive.apache.org/dist/tomcat-${OLD_tomcat_ver}/v${NEW_tomcat_ver}/bin/apache-tomcat-${NEW_tomcat_ver}.tar.gz > /dev/null 2>&1
  308. if [ -e "${tomcat_install_dir}/lib/catalina-jmx-remote.jar" ]; then
  309. src_url=${mirror_link}/apache/tomcat/v${NEW_tomcat_ver}/catalina-jmx-remote.jar && Download_src
  310. [ ! -e "catalina-jmx-remote.jar" ] && wget --no-check-certificate -c https://archive.apache.org/dist/tomcat-${OLD_tomcat_ver}/v${NEW_tomcat_ver}/bin/extras/catalina-jmx-remote.jar > /dev/null 2>&1
  311. fi
  312. if [ -e "apache-tomcat-${NEW_tomcat_ver}.tar.gz" ]; then
  313. echo "Download [${CMSG}apache-tomcat-${NEW_tomcat_ver}.tar.gz${CEND}] successfully! "
  314. break
  315. else
  316. echo "${CWARNING}Tomcat version does not exist! ${CEND}"
  317. fi
  318. else
  319. echo "${CWARNING}input error! ${CEND}Please only input '${CMSG}${Tomcat_flag}.xx${CEND}'"
  320. fi
  321. done
  322. if [ -e "apache-tomcat-${NEW_tomcat_ver}.tar.gz" ]; then
  323. echo "[${CMSG}apache-tomcat-${NEW_tomcat_ver}.tar.gz${CEND}] found"
  324. if [ "${tomcat_flag}" != 'y' ]; then
  325. echo "Press Ctrl+c to cancel or Press any key to continue..."
  326. char=`get_char`
  327. fi
  328. tar xzf apache-tomcat-${NEW_tomcat_ver}.tar.gz
  329. /bin/mv apache-tomcat-${NEW_tomcat_ver}/conf/server.xml{,_bk}
  330. /bin/cp ${tomcat_install_dir}/conf/{server.xml,jmxremote.access,jmxremote.password,tomcat-users.xml} apache-tomcat-${NEW_tomcat_ver}/conf/
  331. [ -e "${tomcat_install_dir}/lib/catalina-jmx-remote.jar" ] && /bin/cp catalina-jmx-remote.jar apache-tomcat-${NEW_tomcat_ver}/lib
  332. /bin/cp ${tomcat_install_dir}/bin/setenv.sh apache-tomcat-${NEW_tomcat_ver}/bin/
  333. /bin/cp -R ${tomcat_install_dir}/conf/vhost apache-tomcat-${NEW_tomcat_ver}/conf/
  334. chmod +x apache-tomcat-${NEW_tomcat_ver}/bin/*.sh
  335. [[ -d ${tomcat_install_dir}_bak && -d ${tomcat_install_dir} ]] && rm -rf ${tomcat_install_dir}._bak
  336. service tomcat stop
  337. /bin/mv ${tomcat_install_dir}{,_bak}
  338. /bin/mv apache-tomcat-${NEW_tomcat_ver} ${tomcat_install_dir} && chown -R ${run_user}:${run_group} ${tomcat_install_dir}
  339. if [ -e "${tomcat_install_dir}/conf/server.xml" ]; then
  340. service tomcat start
  341. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_tomcat_ver}${CEND} to ${CWARNING}${NEW_tomcat_ver}${CEND}"
  342. else
  343. echo "${CFAILURE}Upgrade Tomcat failed! ${CEND}"
  344. fi
  345. fi
  346. popd > /dev/null
  347. }