1
0

addons.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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/fail2ban.sh
  33. . ./include/ngx_lua_waf.sh
  34. # get the out ip country
  35. OUTIP_STATE=$(./include/ois.${ARCH} ip_state)
  36. # shellcheck disable=SC2154
  37. Show_Help() {
  38. echo
  39. echo "Usage: $0 command ...
  40. --help, -h Show this help message
  41. --install, -i Install
  42. --uninstall, -u Uninstall
  43. --composer Composer
  44. --fail2ban Fail2ban
  45. --ngx_lua_waf Ngx_lua_waf
  46. "
  47. }
  48. ARG_NUM=$#
  49. TEMP=`getopt -o hiu --long help,install,uninstall,composer,fail2ban,ngx_lua_waf -- "$@" 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. --)
  74. shift
  75. ;;
  76. *)
  77. echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
  78. ;;
  79. esac
  80. done
  81. ACTION_FUN() {
  82. while :; do
  83. echo
  84. echo "Please select an action:"
  85. echo -e "\t${CMSG}1${CEND}. install"
  86. echo -e "\t${CMSG}2${CEND}. uninstall"
  87. read -e -p "Please input a number:(Default 1 press Enter) " ACTION
  88. ACTION=${ACTION:-1}
  89. if [[ ! "${ACTION}" =~ ^[1,2]$ ]]; then
  90. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  91. else
  92. [ "${ACTION}" == '1' ] && install_flag=y
  93. [ "${ACTION}" == '2' ] && uninstall_flag=y
  94. break
  95. fi
  96. done
  97. }
  98. Menu() {
  99. while :;do
  100. printf "
  101. What Are You Doing?
  102. \t${CMSG}1${CEND}. Install/Uninstall PHP Composer
  103. \t${CMSG}2${CEND}. Install/Uninstall fail2ban
  104. \t${CMSG}3${CEND}. Install/Uninstall ngx_lua_waf
  105. \t${CMSG}q${CEND}. Exit
  106. "
  107. read -e -p "Please input the correct option: " Number
  108. if [[ ! "${Number}" =~ ^[1-3,q]$ ]]; then
  109. echo "${CFAILURE}input error! Please only input 1~3 and q${CEND}"
  110. else
  111. case "${Number}" in
  112. 1)
  113. ACTION_FUN
  114. if [ "${install_flag}" = 'y' ]; then
  115. Install_composer
  116. elif [ "${uninstall_flag}" = 'y' ]; then
  117. Uninstall_composer
  118. fi
  119. ;;
  120. 2)
  121. ACTION_FUN
  122. if [ "${install_flag}" = 'y' ]; then
  123. Install_fail2ban
  124. elif [ "${uninstall_flag}" = 'y' ]; then
  125. Uninstall_fail2ban
  126. fi
  127. ;;
  128. 3)
  129. ACTION_FUN
  130. if [ "${install_flag}" = 'y' ]; then
  131. # shellcheck disable=SC2154
  132. [ -e "${nginx_install_dir}/sbin/nginx" ] && Nginx_lua_waf
  133. # shellcheck disable=SC2154
  134. [ -e "${tengine_install_dir}/sbin/nginx" ] && Tengine_lua_waf
  135. enable_lua_waf
  136. elif [ "${uninstall_flag}" = 'y' ]; then
  137. disable_lua_waf
  138. fi
  139. ;;
  140. q)
  141. exit
  142. ;;
  143. esac
  144. fi
  145. done
  146. }
  147. if [ ${ARG_NUM} == 0 ]; then
  148. Menu
  149. else
  150. if [ "${composer_flag}" == 'y' ]; then
  151. if [ "${install_flag}" = 'y' ]; then
  152. Install_composer
  153. elif [ "${uninstall_flag}" = 'y' ]; then
  154. Uninstall_composer
  155. fi
  156. fi
  157. if [ "${fail2ban_flag}" == 'y' ]; then
  158. if [ "${install_flag}" = 'y' ]; then
  159. Install_fail2ban
  160. elif [ "${uninstall_flag}" = 'y' ]; then
  161. Uninstall_fail2ban
  162. fi
  163. fi
  164. if [ "${ngx_lua_waf_flag}" == 'y' ]; then
  165. if [ "${install_flag}" = 'y' ]; then
  166. [ -e "${nginx_install_dir}/sbin/nginx" ] && Nginx_lua_waf
  167. [ -e "${tengine_install_dir}/sbin/nginx" ] && Tengine_lua_waf
  168. enable_lua_waf
  169. elif [ "${uninstall_flag}" = 'y' ]; then
  170. disable_lua_waf
  171. fi
  172. fi
  173. fi