upgrade_web.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # Blog: http://blog.linuxeye.com
  4. Upgrade_Nginx()
  5. {
  6. cd $oneinstack_dir/src
  7. [ ! -e "$nginx_install_dir/sbin/nginx" ] && echo -e "\033[31mThe Nginx is not installed on your system!\033[0m " && exit 1
  8. Old_nginx_version_tmp=`$web_install_dir/sbin/nginx -v 2>&1`
  9. Old_nginx_version=${Old_nginx_version_tmp##*/}
  10. echo
  11. echo -e "Current Nginx Version: \033[32m$Old_nginx_version\033[0m"
  12. while :
  13. do
  14. echo
  15. read -p "Please input upgrade Nginx Version(example: 1.4.3): " nginx_version
  16. if [ "$nginx_version" != "$Old_nginx_version" ];then
  17. [ ! -e "nginx-$nginx_version.tar.gz" ] && wget -c http://nginx.org/download/nginx-$nginx_version.tar.gz > /dev/null 2>&1
  18. if [ -e "nginx-$nginx_version.tar.gz" ];then
  19. echo -e "Download \033[32mnginx-$nginx_version.tar.gz\033[0m successfully! "
  20. break
  21. else
  22. echo -e "\033[31mNginx version does not exist!\033[0m"
  23. fi
  24. else
  25. echo -e "\033[31minput error! The upgrade Nginx version is the same as the old version\033[0m"
  26. fi
  27. done
  28. if [ -e "nginx-$nginx_version.tar.gz" ];then
  29. echo -e "\033[32mnginx-$nginx_version.tar.gz\033[0m [found]"
  30. echo "Press Ctrl+c to cancel or Press any key to continue..."
  31. char=`get_char`
  32. tar xzf nginx-$nginx_version.tar.gz
  33. cd nginx-$nginx_version
  34. make clean
  35. $web_install_dir/sbin/nginx -V &> $$
  36. nginx_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  37. rm -rf $$
  38. ./configure $nginx_configure_arguments
  39. make
  40. if [ -f "objs/nginx" ];then
  41. /bin/mv $web_install_dir/sbin/nginx $web_install_dir/sbin/nginx$(date +%m%d)
  42. /bin/cp objs/nginx $web_install_dir/sbin/nginx
  43. kill -USR2 `cat /var/run/nginx.pid`
  44. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  45. echo -e "You have \033[32msuccessfully\033[0m upgrade from \033[32m$Old_nginx_version\033[0m to \033[32m$nginx_version\033[0m"
  46. #echo "Restarting Nginx..."
  47. #/etc/init.d/nginx restart
  48. else
  49. echo -e "\033[31mUpgrade Nginx failed! \033[0m"
  50. fi
  51. cd ..
  52. fi
  53. }
  54. Upgrade_Tengine()
  55. {
  56. cd $oneinstack_dir/src
  57. [ ! -e "$web_install_dir/sbin/nginx" ] && echo -e "\033[31mThe Tengine is not installed on your system!\033[0m " && exit 1
  58. Old_tengine_version_tmp=`$web_install_dir/sbin/nginx -v 2>&1`
  59. Old_tengine_version="`echo ${Old_tengine_version_tmp#*/} | awk '{print $1}'`"
  60. echo
  61. echo -e "Current Tengine Version: \033[32m$Old_tengine_version\033[0m"
  62. while :
  63. do
  64. echo
  65. read -p "Please input upgrade Tengine Version(example: 1.5.1): " tengine_version
  66. if [ "$tengine_version" != "$Old_tengine_version" ];then
  67. [ ! -e "tengine-$tengine_version.tar.gz" ] && wget -c http://tengine.taobao.org/download/tengine-$tengine_version.tar.gz > /dev/null 2>&1
  68. if [ -e "tengine-$tengine_version.tar.gz" ];then
  69. echo -e "Download \033[32mtengine-$tengine_version.tar.gz\033[0m successfully! "
  70. break
  71. else
  72. echo -e "\033[31mTengine version does not exist!\033[0m"
  73. fi
  74. else
  75. echo -e "\033[31minput error! The upgrade Tengine version is the same as the old version\033[0m"
  76. fi
  77. done
  78. if [ -e "tengine-$tengine_version.tar.gz" ];then
  79. echo -e "\033[32mtengine-$tengine_version.tar.gz\033[0m [found]"
  80. echo "Press Ctrl+c to cancel or Press any key to continue..."
  81. char=`get_char`
  82. tar xzf tengine-$tengine_version.tar.gz
  83. cd tengine-$tengine_version
  84. make clean
  85. # make[1]: *** [objs/src/event/ngx_event_openssl.o] Error 1
  86. sed -i 's@\(.*\)this option allow a potential SSL 2.0 rollback (CAN-2005-2969)\(.*\)@#ifdef SSL_OP_MSIE_SSLV2_RSA_PADDING\n\1this option allow a potential SSL 2.0 rollback (CAN-2005-2969)\2@' src/event/ngx_event_openssl.c
  87. sed -i 's@\(.*\)SSL_CTX_set_options(ssl->ctx, SSL_OP_MSIE_SSLV2_RSA_PADDING)\(.*\)@\1SSL_CTX_set_options(ssl->ctx, SSL_OP_MSIE_SSLV2_RSA_PADDING)\2\n#endif@' src/event/ngx_event_openssl.c
  88. $web_install_dir/sbin/nginx -V &> $$
  89. tengine_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  90. rm -rf $$
  91. ./configure $tengine_configure_arguments
  92. make
  93. if [ -f "objs/nginx" ];then
  94. /bin/mv $web_install_dir/sbin/nginx $web_install_dir/sbin/nginx$(date +%m%d)
  95. /bin/mv $web_install_dir/sbin/dso_tool $web_install_dir/sbin/dso_tool$(date +%m%d)
  96. /bin/mv $web_install_dir/modules $web_install_dir/modules$(date +%m%d)
  97. /bin/cp objs/nginx $web_install_dir/sbin/nginx
  98. /bin/cp objs/dso_tool $web_install_dir/sbin/dso_tool
  99. chmod +x $web_install_dir/sbin/*
  100. make install
  101. kill -USR2 `cat /var/run/nginx.pid`
  102. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  103. echo -e "You have \033[32msuccessfully\033[0m upgrade from \033[32m$Old_tengine_version\033[0m to \033[32m$tengine_version\033[0m"
  104. #echo "Restarting Tengine..."
  105. #/etc/init.d/nginx restart
  106. else
  107. echo -e "\033[31mUpgrade Tengine failed! \033[0m"
  108. fi
  109. cd ..
  110. fi
  111. }