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. $nginx_install_dir/sbin/nginx -V &> $$
  41. nginx_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  42. rm -rf $$
  43. ./configure $nginx_configure_arguments
  44. make
  45. if [ -f "objs/nginx" ];then
  46. /bin/mv $nginx_install_dir/sbin/nginx $nginx_install_dir/sbin/nginx$(date +%m%d)
  47. /bin/cp objs/nginx $nginx_install_dir/sbin/nginx
  48. kill -USR2 `cat /var/run/nginx.pid`
  49. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  50. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_Nginx_version${CEND} to ${CWARNING}$NEW_Nginx_version${CEND}"
  51. else
  52. echo "${CFAILURE}Upgrade Nginx failed! ${CEND}"
  53. fi
  54. cd ..
  55. fi
  56. cd ..
  57. }
  58. Upgrade_Tengine() {
  59. cd $oneinstack_dir/src
  60. [ ! -e "$tengine_install_dir/sbin/nginx" ] && echo "${CWARNING}The Tengine is not installed on your system! ${CEND}" && exit 1
  61. OLD_Tengine_version_tmp=`$tengine_install_dir/sbin/nginx -v 2>&1`
  62. OLD_Tengine_version="`echo ${OLD_Tengine_version_tmp#*/} | awk '{print $1}'`"
  63. echo
  64. echo "Current Tengine Version: ${CMSG}$OLD_Tengine_version${CEND}"
  65. while :
  66. do
  67. echo
  68. read -p "Please input upgrade Tengine Version(example: 2.1.15): " NEW_Tengine_version
  69. if [ "$NEW_Tengine_version" != "$OLD_Tengine_version" ];then
  70. [ ! -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
  71. if [ -e "tengine-$NEW_Tengine_version.tar.gz" ];then
  72. echo "Download [${CMSG}tengine-$NEW_Tengine_version.tar.gz${CEND}] successfully! "
  73. break
  74. else
  75. echo "${CWARNING}Tengine version does not exist! ${CEND}"
  76. fi
  77. else
  78. echo "${CWARNING}input error! The upgrade Tengine version is the same as the old version${CEND}"
  79. fi
  80. done
  81. if [ -e "tengine-$NEW_Tengine_version.tar.gz" ];then
  82. echo "[${CMSG}tengine-$NEW_Tengine_version.tar.gz${CEND}] found"
  83. echo "Press Ctrl+c to cancel or Press any key to continue..."
  84. char=`get_char`
  85. tar xzf tengine-$NEW_Tengine_version.tar.gz
  86. cd tengine-$NEW_Tengine_version
  87. make clean
  88. # close debug
  89. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc
  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. }