upgrade_web.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. # http://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Upgrade_Nginx() {
  11. cd $oneinstack_dir/src
  12. [ ! -e "$nginx_install_dir/sbin/nginx" ] && echo "${CWARNING}The 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. echo
  16. echo "Current Nginx Version: ${CMSG}$OLD_Nginx_version${CEND}"
  17. while :
  18. do
  19. echo
  20. read -p "Please input upgrade Nginx Version(example: 1.9.15): " NEW_Nginx_version
  21. if [ "$NEW_Nginx_version" != "$OLD_Nginx_version" ];then
  22. [ ! -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
  23. if [ -e "nginx-$NEW_Nginx_version.tar.gz" ];then
  24. echo "Download [${CMSG}nginx-$NEW_Nginx_version.tar.gz${CEND}] successfully! "
  25. break
  26. else
  27. echo "${CWARNING}Nginx version does not exist! ${CEND}"
  28. fi
  29. else
  30. echo "${CWARNING}input error! The upgrade Nginx version is the same as the old version${CEND}"
  31. fi
  32. done
  33. if [ -e "nginx-$NEW_Nginx_version.tar.gz" ];then
  34. echo "[${CMSG}nginx-$NEW_Nginx_version.tar.gz${CEND}] found"
  35. echo "Press Ctrl+c to cancel or Press any key to continue..."
  36. char=`get_char`
  37. tar xzf nginx-$NEW_Nginx_version.tar.gz
  38. cd nginx-$NEW_Nginx_version
  39. make clean
  40. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
  41. $nginx_install_dir/sbin/nginx -V &> $$
  42. nginx_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  43. rm -rf $$
  44. ./configure $nginx_configure_arguments
  45. make
  46. if [ -f "objs/nginx" ];then
  47. /bin/mv $nginx_install_dir/sbin/nginx $nginx_install_dir/sbin/nginx$(date +%m%d)
  48. /bin/cp objs/nginx $nginx_install_dir/sbin/nginx
  49. kill -USR2 `cat /var/run/nginx.pid`
  50. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  51. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_Nginx_version${CEND} to ${CWARNING}$NEW_Nginx_version${CEND}"
  52. else
  53. echo "${CFAILURE}Upgrade Nginx failed! ${CEND}"
  54. fi
  55. cd ..
  56. fi
  57. cd ..
  58. }
  59. Upgrade_Tengine() {
  60. cd $oneinstack_dir/src
  61. [ ! -e "$tengine_install_dir/sbin/nginx" ] && echo "${CWARNING}The Tengine is not installed on your system! ${CEND}" && exit 1
  62. OLD_Tengine_version_tmp=`$tengine_install_dir/sbin/nginx -v 2>&1`
  63. OLD_Tengine_version="`echo ${OLD_Tengine_version_tmp#*/} | awk '{print $1}'`"
  64. echo
  65. echo "Current Tengine Version: ${CMSG}$OLD_Tengine_version${CEND}"
  66. while :
  67. do
  68. echo
  69. read -p "Please input upgrade Tengine Version(example: 2.1.15): " NEW_Tengine_version
  70. if [ "$NEW_Tengine_version" != "$OLD_Tengine_version" ];then
  71. [ ! -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
  72. if [ -e "tengine-$NEW_Tengine_version.tar.gz" ];then
  73. echo "Download [${CMSG}tengine-$NEW_Tengine_version.tar.gz${CEND}] successfully! "
  74. break
  75. else
  76. echo "${CWARNING}Tengine version does not exist! ${CEND}"
  77. fi
  78. else
  79. echo "${CWARNING}input error! The upgrade Tengine version is the same as the old version${CEND}"
  80. fi
  81. done
  82. if [ -e "tengine-$NEW_Tengine_version.tar.gz" ];then
  83. echo "[${CMSG}tengine-$NEW_Tengine_version.tar.gz${CEND}] found"
  84. echo "Press Ctrl+c to cancel or Press any key to continue..."
  85. char=`get_char`
  86. tar xzf tengine-$NEW_Tengine_version.tar.gz
  87. cd tengine-$NEW_Tengine_version
  88. make clean
  89. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
  90. $tengine_install_dir/sbin/nginx -V &> $$
  91. tengine_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  92. rm -rf $$
  93. ./configure $tengine_configure_arguments
  94. make
  95. if [ -f "objs/nginx" ];then
  96. /bin/mv $tengine_install_dir/sbin/nginx $tengine_install_dir/sbin/nginx$(date +%m%d)
  97. /bin/mv $tengine_install_dir/sbin/dso_tool $tengine_install_dir/sbin/dso_tool$(date +%m%d)
  98. /bin/mv $tengine_install_dir/modules $tengine_install_dir/modules$(date +%m%d)
  99. /bin/cp objs/nginx $tengine_install_dir/sbin/nginx
  100. /bin/cp objs/dso_tool $tengine_install_dir/sbin/dso_tool
  101. chmod +x $tengine_install_dir/sbin/*
  102. make install
  103. kill -USR2 `cat /var/run/nginx.pid`
  104. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  105. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_Tengine_version${CEND} to ${CWARNING}$NEW_Tengine_version${CEND}"
  106. else
  107. echo "${CFAILURE}Upgrade Tengine failed! ${CEND}"
  108. fi
  109. cd ..
  110. fi
  111. cd ..
  112. }