upgrade.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  11. clear
  12. printf "
  13. #######################################################################
  14. # OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+ #
  15. # Upgrade Software versions for OneinStack #
  16. # For more information please visit https://oneinstack.com #
  17. #######################################################################
  18. "
  19. # Check if user is root
  20. [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  21. oneinstack_dir=$(dirname "`readlink -f $0`")
  22. pushd ${oneinstack_dir} > /dev/null
  23. . ./versions.txt
  24. . ./options.conf
  25. . ./include/color.sh
  26. . ./include/check_os.sh
  27. . ./include/check_dir.sh
  28. . ./include/download.sh
  29. . ./include/get_char.sh
  30. . ./include/upgrade_web.sh
  31. . ./include/upgrade_db.sh
  32. . ./include/upgrade_php.sh
  33. . ./include/upgrade_redis.sh
  34. . ./include/upgrade_memcached.sh
  35. . ./include/upgrade_phpmyadmin.sh
  36. . ./include/upgrade_oneinstack.sh
  37. # get the IP information
  38. PUBLIC_IPADDR=$(./include/get_public_ipaddr.py)
  39. IPADDR_COUNTRY=$(./include/get_ipaddr_state.py ${PUBLIC_IPADDR})
  40. Show_Help() {
  41. echo
  42. echo "Usage: $0 command ...[version]....
  43. --help, -h Show this help message
  44. --nginx [version] Upgrade Nginx
  45. --tengine [version] Upgrade Tengine
  46. --openresty [version] Upgrade OpenResty
  47. --apache [version] Upgrade Apache
  48. --tomcat [version] Upgrade Tomcat
  49. --db [version] Upgrade MySQL/MariaDB/Percona
  50. --php [version] Upgrade PHP
  51. --redis [version] Upgrade Redis
  52. --memcached [version] Upgrade Memcached
  53. --phpmyadmin [version] Upgrade phpMyAdmin
  54. --oneinstack Upgrade OneinStack latest
  55. --acme.sh Upgrade acme.sh latest
  56. "
  57. }
  58. ARG_NUM=$#
  59. TEMP=`getopt -o h --long help,nginx:,tengine:,openresty:,apache:,tomcat:,db:,php:,redis:,memcached:,phpmyadmin:,oneinstack,acme.sh -- "$@" 2>/dev/null`
  60. [ $? != 0 ] && echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
  61. eval set -- "${TEMP}"
  62. while :; do
  63. [ -z "$1" ] && break;
  64. case "$1" in
  65. -h|--help)
  66. Show_Help; exit 0
  67. ;;
  68. --nginx)
  69. nginx_flag=y; NEW_nginx_ver=$2; shift 2
  70. ;;
  71. --tengine)
  72. tengine_flag=y; NEW_tengine_ver=$2; shift 2
  73. ;;
  74. --openresty)
  75. openresty_flag=y; NEW_openresy_ver=$2; shift 2
  76. ;;
  77. --apache)
  78. apache_flag=y; NEW_apache_ver=$2; shift 2
  79. ;;
  80. --tomcat)
  81. tomcat_flag=y; NEW_tomcat_ver=$2; shift 2
  82. ;;
  83. --db)
  84. db_flag=y; NEW_db_ver=$2; shift 2
  85. ;;
  86. --php)
  87. php_flag=y; NEW_php_ver=$2; shift 2
  88. ;;
  89. --redis)
  90. redis_flag=y; NEW_redis_ver=$2; shift 2
  91. ;;
  92. --memcached)
  93. memcached_flag=y; NEW_memcached_ver=$2; shift 2
  94. ;;
  95. --phpmyadmin)
  96. phpmyadmin_flag=y; NEW_phpmyadmin_ver=$2; shift 2
  97. ;;
  98. --oneinstack)
  99. NEW_oneinstack_ver=latest; shift 1
  100. ;;
  101. --acme.sh)
  102. NEW_acme_ver=latest; shift 1
  103. ;;
  104. --)
  105. shift
  106. ;;
  107. *)
  108. echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
  109. ;;
  110. esac
  111. done
  112. Menu() {
  113. while :; do
  114. printf "
  115. What Are You Doing?
  116. \t${CMSG} 1${CEND}. Upgrade Nginx/Tengine/OpenResty
  117. \t${CMSG} 2${CEND}. Upgrade Apache
  118. \t${CMSG} 3${CEND}. Upgrade Tomcat
  119. \t${CMSG} 4${CEND}. Upgrade MySQL/MariaDB/Percona
  120. \t${CMSG} 5${CEND}. Upgrade PHP
  121. \t${CMSG} 6${CEND}. Upgrade Redis
  122. \t${CMSG} 7${CEND}. Upgrade Memcached
  123. \t${CMSG} 8${CEND}. Upgrade phpMyAdmin
  124. \t${CMSG} 9${CEND}. Upgrade OneinStack latest
  125. \t${CMSG}10${CEND}. Upgrade acme.sh latest
  126. \t${CMSG} q${CEND}. Exit
  127. "
  128. echo
  129. read -e -p "Please input the correct option: " Upgrade_flag
  130. if [[ ! "${Upgrade_flag}" =~ ^[1-9,q]$|^10$ ]]; then
  131. echo "${CWARNING}input error! Please only input 1~10 and q${CEND}"
  132. else
  133. case "${Upgrade_flag}" in
  134. 1)
  135. [ -e "${nginx_install_dir}/sbin/nginx" ] && Upgrade_Nginx
  136. [ -e "${tengine_install_dir}/sbin/nginx" ] && Upgrade_Tengine
  137. [ -e "${openresty_install_dir}/nginx/sbin/nginx" ] && Upgrade_OpenResty
  138. ;;
  139. 2)
  140. Upgrade_Apache
  141. ;;
  142. 3)
  143. Upgrade_Tomcat
  144. ;;
  145. 4)
  146. Upgrade_DB
  147. ;;
  148. 5)
  149. Upgrade_PHP
  150. ;;
  151. 6)
  152. Upgrade_Redis
  153. ;;
  154. 7)
  155. Upgrade_Memcached
  156. ;;
  157. 8)
  158. Upgrade_phpMyAdmin
  159. ;;
  160. 9)
  161. Upgrade_OneinStack
  162. ;;
  163. 10)
  164. [ -e ~/.acme.sh/acme.sh ] && { ~/.acme.sh/acme.sh --force --upgrade; ~/.acme.sh/acme.sh --version; }
  165. ;;
  166. q)
  167. exit
  168. ;;
  169. esac
  170. fi
  171. done
  172. }
  173. if [ ${ARG_NUM} == 0 ]; then
  174. Menu
  175. else
  176. [ "${nginx_flag}" == 'y' ] && Upgrade_Nginx
  177. [ "${tengine_flag}" == 'y' ] && Upgrade_Tengine
  178. [ "${openresty_flag}" == 'y' ] && Upgrade_OpenResty
  179. [ "${apache_flag}" == 'y' ] && Upgrade_Apache
  180. [ "${tomcat_flag}" == 'y' ] && Upgrade_Tomcat
  181. [ "${db_flag}" == 'y' ] && Upgrade_DB
  182. [ "${php_flag}" == 'y' ] && Upgrade_PHP
  183. [ "${redis_flag}" == 'y' ] && Upgrade_Redis
  184. [ "${memcached_flag}" == 'y' ] && Upgrade_Memcached
  185. [ "${phpmyadmin_flag}" == 'y' ] && Upgrade_phpMyAdmin
  186. [ "${NEW_oneinstack_ver}" == 'latest' ] && Upgrade_OneinStack
  187. [ "${NEW_acme_ver}" == 'latest' ] && [ -e ~/.acme.sh/acme.sh ] && { ~/.acme.sh/acme.sh --force --upgrade; ~/.acme.sh/acme.sh --version; }
  188. fi