upgrade_web.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Version: 1.0-Alpha Jun 15,2015 lj2007331 AT gmail.com
  6. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  7. #
  8. # Project home page:
  9. # http://oneinstack.com
  10. # Check if user is root
  11. [ $(id -u) != "0" ] && { echo -e "\033[31mError: You must be root to run this script\033[0m"; exit 1; }
  12. export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  13. clear
  14. printf "
  15. #######################################################################
  16. # OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+ #
  17. # Upgrade Nginx/Tengine for OneinStack #
  18. # For more information please visit http://oneinstack.com #
  19. #######################################################################
  20. "
  21. cd src
  22. . ../options.conf
  23. . ../functions/download.sh
  24. [ ! -e "$web_install_dir/sbin/nginx" ] && echo -e "\033[31mThe Nginx/Tengine is not installed on your system!\033[0m " && exit 1
  25. get_char()
  26. {
  27. SAVEDSTTY=`stty -g`
  28. stty -echo
  29. stty cbreak
  30. dd if=/dev/tty bs=1 count=1 2> /dev/null
  31. stty -raw
  32. stty echo
  33. stty $SAVEDSTTY
  34. }
  35. echo
  36. Upgrade_Nginx()
  37. {
  38. Old_nginx_version_tmp=`$web_install_dir/sbin/nginx -v 2>&1`
  39. Old_nginx_version=${Old_nginx_version_tmp##*/}
  40. echo -e "Current Nginx Version: \033[32m$Old_nginx_version\033[0m"
  41. while :
  42. do
  43. echo
  44. read -p "Please input upgrade Nginx Version(example: 1.4.3): " nginx_version
  45. if [ "$nginx_version" != "$Old_nginx_version" ];then
  46. [ ! -e "nginx-$nginx_version.tar.gz" ] && wget -c http://nginx.org/download/nginx-$nginx_version.tar.gz > /dev/null 2>&1
  47. if [ -e "nginx-$nginx_version.tar.gz" ];then
  48. echo -e "Download \033[32mnginx-$nginx_version.tar.gz\033[0m successfully! "
  49. break
  50. else
  51. echo -e "\033[31mNginx version does not exist!\033[0m"
  52. fi
  53. else
  54. echo -e "\033[31minput error! The upgrade Nginx version is the same as the old version\033[0m"
  55. fi
  56. done
  57. if [ -e "nginx-$nginx_version.tar.gz" ];then
  58. echo -e "\033[32mnginx-$nginx_version.tar.gz\033[0m [found]"
  59. echo "Press Ctrl+c to cancel or Press any key to continue..."
  60. char=`get_char`
  61. tar xzf nginx-$nginx_version.tar.gz
  62. cd nginx-$nginx_version
  63. make clean
  64. $web_install_dir/sbin/nginx -V &> $$
  65. nginx_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  66. rm -rf $$
  67. ./configure $nginx_configure_arguments
  68. make
  69. if [ -f "objs/nginx" ];then
  70. /bin/mv $web_install_dir/sbin/nginx $web_install_dir/sbin/nginx$(date +%m%d)
  71. /bin/cp objs/nginx $web_install_dir/sbin/nginx
  72. kill -USR2 `cat /var/run/nginx.pid`
  73. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  74. echo -e "You have \033[32msuccessfully\033[0m upgrade from \033[32m$Old_nginx_version\033[0m to \033[32m$nginx_version\033[0m"
  75. #echo "Restarting Nginx..."
  76. #/etc/init.d/nginx restart
  77. else
  78. echo -e "\033[31mUpgrade Nginx failed! \033[0m"
  79. fi
  80. cd ..
  81. fi
  82. }
  83. Upgrade_Tengine()
  84. {
  85. Old_tengine_version_tmp=`$web_install_dir/sbin/nginx -v 2>&1`
  86. Old_tengine_version="`echo ${Old_tengine_version_tmp#*/} | awk '{print $1}'`"
  87. echo -e "Current Tengine Version: \033[32m$Old_tengine_version\033[0m"
  88. while :
  89. do
  90. echo
  91. read -p "Please input upgrade Tengine Version(example: 1.5.1): " tengine_version
  92. if [ "$tengine_version" != "$Old_tengine_version" ];then
  93. [ ! -e "tengine-$tengine_version.tar.gz" ] && wget -c http://tengine.taobao.org/download/tengine-$tengine_version.tar.gz > /dev/null 2>&1
  94. if [ -e "tengine-$tengine_version.tar.gz" ];then
  95. echo -e "Download \033[32mtengine-$tengine_version.tar.gz\033[0m successfully! "
  96. break
  97. else
  98. echo -e "\033[31mTengine version does not exist!\033[0m"
  99. fi
  100. else
  101. echo -e "\033[31minput error! The upgrade Tengine version is the same as the old version\033[0m"
  102. fi
  103. done
  104. if [ -e "tengine-$tengine_version.tar.gz" ];then
  105. echo -e "\033[32mtengine-$tengine_version.tar.gz\033[0m [found]"
  106. echo "Press Ctrl+c to cancel or Press any key to continue..."
  107. char=`get_char`
  108. tar xzf tengine-$tengine_version.tar.gz
  109. cd tengine-$tengine_version
  110. make clean
  111. # make[1]: *** [objs/src/event/ngx_event_openssl.o] Error 1
  112. 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
  113. 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
  114. $web_install_dir/sbin/nginx -V &> $$
  115. tengine_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  116. rm -rf $$
  117. ./configure $tengine_configure_arguments
  118. make
  119. if [ -f "objs/nginx" ];then
  120. /bin/mv $web_install_dir/sbin/nginx $web_install_dir/sbin/nginx$(date +%m%d)
  121. /bin/mv $web_install_dir/sbin/dso_tool $web_install_dir/sbin/dso_tool$(date +%m%d)
  122. /bin/mv $web_install_dir/modules $web_install_dir/modules$(date +%m%d)
  123. /bin/cp objs/nginx $web_install_dir/sbin/nginx
  124. /bin/cp objs/dso_tool $web_install_dir/sbin/dso_tool
  125. chmod +x $web_install_dir/sbin/*
  126. make install
  127. kill -USR2 `cat /var/run/nginx.pid`
  128. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  129. echo -e "You have \033[32msuccessfully\033[0m upgrade from \033[32m$Old_tengine_version\033[0m to \033[32m$tengine_version\033[0m"
  130. #echo "Restarting Tengine..."
  131. #/etc/init.d/nginx restart
  132. else
  133. echo -e "\033[31mUpgrade Tengine failed! \033[0m"
  134. fi
  135. cd ..
  136. fi
  137. }
  138. if [ ! -e "$web_install_dir/sbin/dso_tool" ];then
  139. Upgrade_Nginx
  140. elif [ -e "$web_install_dir/sbin/dso_tool" ];then
  141. Upgrade_Tengine
  142. fi