addons.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. # Install/Uninstall Extensions #
  16. # For more information please visit https://oneinstack.com #
  17. #######################################################################
  18. "
  19. # Check if user is root
  20. # shellcheck disable=SC2046
  21. [ $(id -u) != '0' ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  22. oneinstack_dir=$(dirname "`readlink -f $0`")
  23. # shellcheck disable=SC2164
  24. pushd ${oneinstack_dir} > /dev/null
  25. . ./versions.txt
  26. . ./options.conf
  27. . ./include/color.sh
  28. . ./include/check_os.sh
  29. . ./include/download.sh
  30. . ./include/get_char.sh
  31. . ./include/composer.sh
  32. . ./include/python.sh
  33. . ./include/fail2ban.sh
  34. . ./include/ngx_lua_waf.sh
  35. # shellcheck disable=SC2154
  36. Show_Help() {
  37. echo
  38. echo "Usage: $0 command ...
  39. --help, -h Show this help message
  40. --install, -i Install
  41. --uninstall, -u Uninstall
  42. --composer Composer
  43. --fail2ban Fail2ban
  44. --ngx_lua_waf Ngx_lua_waf
  45. --python Python (PATH: ${python_install_dir})
  46. "
  47. }
  48. ARG_NUM=$#
  49. TEMP=`getopt -o hiu --long help,install,uninstall,composer,fail2ban,ngx_lua_waf,python -- "$@" 2>/dev/null`
  50. [ $? != 0 ] && echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
  51. eval set -- "${TEMP}"
  52. while :; do
  53. [ -z "$1" ] && break;
  54. case "$1" in
  55. -h|--help)
  56. Show_Help; exit 0
  57. ;;
  58. -i|--install)
  59. install_flag=y; shift 1
  60. ;;
  61. -u|--uninstall)
  62. uninstall_flag=y; shift 1
  63. ;;
  64. --composer)
  65. composer_flag=y; shift 1
  66. ;;
  67. --fail2ban)
  68. fail2ban_flag=y; shift 1
  69. ;;
  70. --ngx_lua_waf)
  71. ngx_lua_waf_flag=y; shift 1
  72. ;;
  73. --python)
  74. python_flag=y; shift 1
  75. ;;
  76. --)
  77. shift
  78. ;;
  79. *)
  80. echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
  81. ;;
  82. esac
  83. done
  84. ACTION_FUN() {
  85. while :; do
  86. echo
  87. echo "Please select an action:"
  88. echo -e "\t${CMSG}1${CEND}. install"
  89. echo -e "\t${CMSG}2${CEND}. uninstall"
  90. read -e -p "Please input a number:(Default 1 press Enter) " ACTION
  91. ACTION=${ACTION:-1}
  92. if [[ ! "${ACTION}" =~ ^[1,2]$ ]]; then
  93. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  94. else
  95. [ "${ACTION}" == '1' ] && install_flag=y
  96. [ "${ACTION}" == '2' ] && uninstall_flag=y
  97. break
  98. fi
  99. done
  100. }
  101. Menu() {
  102. while :;do
  103. printf "
  104. What Are You Doing?
  105. \t${CMSG}1${CEND}. Install/Uninstall PHP Composer
  106. \t${CMSG}2${CEND}. Install/Uninstall fail2ban
  107. \t${CMSG}3${CEND}. Install/Uninstall ngx_lua_waf
  108. \t${CMSG}4${CEND}. Install/Uninstall Python3.6
  109. \t${CMSG}q${CEND}. Exit
  110. "
  111. read -e -p "Please input the correct option: " Number
  112. if [[ ! "${Number}" =~ ^[1-5,q]$ ]]; then
  113. echo "${CFAILURE}input error! Please only input 1~4 and q${CEND}"
  114. else
  115. case "${Number}" in
  116. 1)
  117. ACTION_FUN
  118. if [ "${install_flag}" = 'y' ]; then
  119. Install_composer
  120. elif [ "${uninstall_flag}" = 'y' ]; then
  121. Uninstall_composer
  122. fi
  123. ;;
  124. 2)
  125. ACTION_FUN
  126. if [ "${install_flag}" = 'y' ]; then
  127. Install_Python
  128. Install_fail2ban
  129. elif [ "${uninstall_flag}" = 'y' ]; then
  130. Uninstall_fail2ban
  131. fi
  132. ;;
  133. 3)
  134. ACTION_FUN
  135. if [ "${install_flag}" = 'y' ]; then
  136. # shellcheck disable=SC2154
  137. [ -e "${nginx_install_dir}/sbin/nginx" ] && Nginx_lua_waf
  138. # shellcheck disable=SC2154
  139. [ -e "${tengine_install_dir}/sbin/nginx" ] && Tengine_lua_waf
  140. enable_lua_waf
  141. elif [ "${uninstall_flag}" = 'y' ]; then
  142. disable_lua_waf
  143. fi
  144. ;;
  145. 4)
  146. ACTION_FUN
  147. if [ "${install_flag}" = 'y' ]; then
  148. Install_Python
  149. elif [ "${uninstall_flag}" = 'y' ]; then
  150. Uninstall_Python
  151. fi
  152. ;;
  153. 5)
  154. ACTION_FUN
  155. if [ "${install_flag}" = 'y' ]; then
  156. Install_Python
  157. Install_Panel
  158. elif [ "${uninstall_flag}" = 'y' ]; then
  159. Uninstall_Panel
  160. fi
  161. ;;
  162. q)
  163. exit
  164. ;;
  165. esac
  166. fi
  167. done
  168. }
  169. if [ ${ARG_NUM} == 0 ]; then
  170. Menu
  171. else
  172. if [ "${composer_flag}" == 'y' ]; then
  173. if [ "${install_flag}" = 'y' ]; then
  174. Install_composer
  175. elif [ "${uninstall_flag}" = 'y' ]; then
  176. Uninstall_composer
  177. fi
  178. fi
  179. if [ "${fail2ban_flag}" == 'y' ]; then
  180. if [ "${install_flag}" = 'y' ]; then
  181. Install_Python
  182. Install_fail2ban
  183. elif [ "${uninstall_flag}" = 'y' ]; then
  184. Uninstall_fail2ban
  185. fi
  186. fi
  187. if [ "${ngx_lua_waf_flag}" == 'y' ]; then
  188. if [ "${install_flag}" = 'y' ]; then
  189. [ -e "${nginx_install_dir}/sbin/nginx" ] && Nginx_lua_waf
  190. [ -e "${tengine_install_dir}/sbin/nginx" ] && Tengine_lua_waf
  191. enable_lua_waf
  192. elif [ "${uninstall_flag}" = 'y' ]; then
  193. disable_lua_waf
  194. fi
  195. fi
  196. if [ "${python_flag}" == 'y' ]; then
  197. if [ "${install_flag}" = 'y' ]; then
  198. Install_Python
  199. elif [ "${uninstall_flag}" = 'y' ]; then
  200. Uninstall_Python
  201. fi
  202. fi
  203. fi