1
0

upgrade_web.sh 18 KB

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