addons.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/lj2007331/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 6+ Debian 7+ and Ubuntu 12+ #
  15. # Install/Uninstall Extensions #
  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. # get the IP information
  24. PUBLIC_IPADDR=$(./include/get_public_ipaddr.py)
  25. IPADDR_COUNTRY=$(./include/get_ipaddr_state.py $PUBLIC_IPADDR)
  26. . ./versions.txt
  27. . ./options.conf
  28. . ./include/color.sh
  29. . ./include/memory.sh
  30. . ./include/check_os.sh
  31. . ./include/check_download.sh
  32. . ./include/download.sh
  33. . ./include/get_char.sh
  34. . ./include/zendopcache.sh
  35. . ./include/xcache.sh
  36. . ./include/apcu.sh
  37. . ./include/eaccelerator.sh
  38. . ./include/ZendGuardLoader.sh
  39. . ./include/ioncube.sh
  40. . ./include/sourceguardian.sh
  41. . ./include/ImageMagick.sh
  42. . ./include/GraphicsMagick.sh
  43. . ./include/memcached.sh
  44. . ./include/redis.sh
  45. . ./include/python.sh
  46. . ./include/ngx_lua_waf.sh
  47. # Check PHP
  48. if [ -e "${php_install_dir}/bin/phpize" ]; then
  49. phpExtensionDir=$(${php_install_dir}/bin/php-config --extension-dir)
  50. PHP_detail_ver=$(${php_install_dir}/bin/php -r 'echo PHP_VERSION;')
  51. PHP_main_ver=${PHP_detail_ver%.*}
  52. fi
  53. # Check PHP Extensions
  54. Check_PHP_Extension() {
  55. [ ! -e "${php_install_dir}/bin/phpize" ] && { echo "${CWARNING}PHP was not exist! ${CEND}"; exit 1; }
  56. [ -e "`ls ${php_install_dir}/etc/php.d/0?-${PHP_extension}.ini 2> /dev/null`" ] && { echo "${CWARNING}PHP ${PHP_extension} module already installed! ${CEND}"; exit 1; }
  57. }
  58. # restart PHP
  59. Restart_PHP() {
  60. [ -e "${apache_install_dir}/conf/httpd.conf" ] && /etc/init.d/httpd restart || /etc/init.d/php-fpm restart
  61. }
  62. # Check succ
  63. Check_succ() {
  64. [ -f "${phpExtensionDir}/${PHP_extension}.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP ${PHP_extension} module installed successfully! ${CEND}"; }
  65. }
  66. # Uninstall succ
  67. Uninstall_succ() {
  68. [ -e "`ls ${php_install_dir}/etc/php.d/0?-${PHP_extension}.ini 2> /dev/null`" ] && { rm -rf ${php_install_dir}/etc/php.d/0?-${PHP_extension}.ini; Restart_PHP; echo; echo "${CMSG}PHP ${PHP_extension} module uninstall completed${CEND}"; } || { echo; echo "${CWARNING}${PHP_extension} module does not exist! ${CEND}"; }
  69. }
  70. Install_fail2ban() {
  71. [ ! -e "${python_install_dir}/bin/python" ] && Install_Python
  72. pushd ${oneinstack_dir}/src > /dev/null
  73. src_url=http://mirrors.linuxeye.com/oneinstack/src/fail2ban-${fail2ban_ver}.tar.gz && Download_src
  74. tar xzf fail2ban-${fail2ban_ver}.tar.gz
  75. pushd fail2ban-${fail2ban_ver}
  76. sed -i 's@for i in xrange(50)@for i in range(50)@' fail2ban/__init__.py
  77. ${python_install_dir}/bin/python setup.py install
  78. if [ "${PM}" == 'yum' ]; then
  79. LOGPATH=/var/log/secure
  80. /bin/cp files/redhat-initd /etc/init.d/fail2ban
  81. sed -i "s@^FAIL2BAN=.*@FAIL2BAN=${python_install_dir}/bin/fail2ban-client@" /etc/init.d/fail2ban
  82. sed -i 's@Starting fail2ban.*@&\n [ ! -e "/var/run/fail2ban" ] \&\& mkdir /var/run/fail2ban@' /etc/init.d/fail2ban
  83. chmod +x /etc/init.d/fail2ban
  84. chkconfig --add fail2ban
  85. chkconfig fail2ban on
  86. fi
  87. if [ "${PM}" == 'apt' ]; then
  88. LOGPATH=/var/log/auth.log
  89. /bin/cp files/debian-initd /etc/init.d/fail2ban
  90. sed -i 's@2 3 4 5@3 4 5@' /etc/init.d/fail2ban
  91. sed -i "s@^DAEMON=.*@DAEMON=${python_install_dir}/bin/\$NAME-client@" /etc/init.d/fail2ban
  92. chmod +x /etc/init.d/fail2ban
  93. update-rc.d fail2ban defaults
  94. fi
  95. [ -z "`grep ^Port /etc/ssh/sshd_config`" ] && now_ssh_port=22 || now_ssh_port=`grep ^Port /etc/ssh/sshd_config | awk '{print $2}' | head -1`
  96. cat > /etc/fail2ban/jail.local << EOF
  97. [DEFAULT]
  98. ignoreip = 127.0.0.1/8
  99. bantime = 86400
  100. findtime = 600
  101. maxretry = 5
  102. [ssh-iptables]
  103. enabled = true
  104. filter = sshd
  105. action = iptables[name=SSH, port=$now_ssh_port, protocol=tcp]
  106. logpath = $LOGPATH
  107. EOF
  108. cat > /etc/logrotate.d/fail2ban << EOF
  109. /var/log/fail2ban.log {
  110. missingok
  111. notifempty
  112. postrotate
  113. ${python_install_dir}/bin/fail2ban-client flushlogs >/dev/null || true
  114. endscript
  115. }
  116. EOF
  117. sed -i 's@^iptables = iptables.*@iptables = iptables@' /etc/fail2ban/action.d/iptables-common.conf
  118. kill -9 `ps -ef | grep fail2ban | grep -v grep | awk '{print $2}'` > /dev/null 2>&1
  119. /etc/init.d/fail2ban start
  120. popd
  121. if [ -e "${python_install_dir}/bin/fail2ban-python" ]; then
  122. echo; echo "${CSUCCESS}fail2ban installed successfully! ${CEND}"
  123. else
  124. echo; echo "${CFAILURE}fail2ban install failed, Please try again! ${CEND}"
  125. fi
  126. popd
  127. }
  128. Uninstall_fail2ban() {
  129. /etc/init.d/fail2ban stop
  130. ${python_install_dir}/bin/pip uninstall -y fail2ban > /dev/null 2>&1
  131. rm -rf /etc/init.d/fail2ban /etc/fail2ban /etc/logrotate.d/fail2ban /var/log/fail2ban.* /var/run/fail2ban
  132. echo; echo "${CMSG}fail2ban uninstall completed${CEND}";
  133. }
  134. ACTION_FUN() {
  135. while :; do
  136. echo
  137. echo "Please select an action:"
  138. echo -e "\t${CMSG}1${CEND}. install"
  139. echo -e "\t${CMSG}2${CEND}. uninstall"
  140. read -e -p "Please input a number:(Default 1 press Enter) " ACTION
  141. [ -z "${ACTION}" ] && ACTION=1
  142. if [[ ! "${ACTION}" =~ ^[1,2]$ ]]; then
  143. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  144. else
  145. break
  146. fi
  147. done
  148. }
  149. while :;do
  150. printf "
  151. What Are You Doing?
  152. \t${CMSG} 1${CEND}. Install/Uninstall PHP opcode cache
  153. \t${CMSG} 2${CEND}. Install/Uninstall ZendGuardLoader/ionCube/SourceGuardian PHP Extension
  154. \t${CMSG} 3${CEND}. Install/Uninstall ImageMagick/GraphicsMagick PHP Extension
  155. \t${CMSG} 4${CEND}. Install/Uninstall fileinfo/imap/phalcon PHP Extension
  156. \t${CMSG} 5${CEND}. Install/Uninstall memcached/memcache
  157. \t${CMSG} 6${CEND}. Install/Uninstall Redis
  158. \t${CMSG} 7${CEND}. Install/Uninstall swoole PHP Extension
  159. \t${CMSG} 8${CEND}. Install/Uninstall xdebug PHP Extension
  160. \t${CMSG} 9${CEND}. Install/Uninstall PHP Composer
  161. \t${CMSG}10${CEND}. Install/Uninstall fail2ban
  162. \t${CMSG}11${CEND}. Install/Uninstall ngx_lua_waf
  163. \t${CMSG} q${CEND}. Exit
  164. "
  165. read -e -p "Please input the correct option: " Number
  166. if [[ ! "${Number}" =~ ^[1-9,q]$|^1[0-1]$ ]]; then
  167. echo "${CFAILURE}input error! Please only input 1~11 and q${CEND}"
  168. else
  169. case "${Number}" in
  170. 1)
  171. ACTION_FUN
  172. while :; do echo
  173. echo "Please select a opcode cache of the PHP:"
  174. echo -e "\t${CMSG}1${CEND}. Zend OPcache"
  175. echo -e "\t${CMSG}2${CEND}. XCache"
  176. echo -e "\t${CMSG}3${CEND}. APCU"
  177. echo -e "\t${CMSG}4${CEND}. eAccelerator"
  178. read -e -p "Please input a number:(Default 1 press Enter) " phpcache_option
  179. [ -z "${phpcache_option}" ] && phpcache_option=1
  180. if [[ ! "${phpcache_option}" =~ ^[1-4]$ ]]; then
  181. echo "${CWARNING}input error! Please only input number 1~4${CEND}"
  182. else
  183. case "${phpcache_option}" in
  184. 1)
  185. PHP_extension=opcache
  186. ;;
  187. 2)
  188. PHP_extension=xcache
  189. ;;
  190. 3)
  191. PHP_extension=apcu
  192. ;;
  193. 4)
  194. PHP_extension=eaccelerator
  195. ;;
  196. esac
  197. break
  198. fi
  199. done
  200. if [ "${ACTION}" = '1' ]; then
  201. Check_PHP_Extension
  202. case "${phpcache_option}" in
  203. 1)
  204. pushd ${oneinstack_dir}/src > /dev/null
  205. if [[ "${PHP_main_ver}" =~ ^5.[3-4]$ ]]; then
  206. src_url=https://pecl.php.net/get/zendopcache-${zendopcache_ver}.tgz && Download_src
  207. Install_ZendOPcache
  208. else
  209. src_url=http://www.php.net/distributions/php-${PHP_detail_ver}.tar.gz && Download_src
  210. Install_ZendOPcache
  211. fi
  212. popd
  213. Check_succ
  214. ;;
  215. 2)
  216. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$ ]]; then
  217. while :; do
  218. read -e -p "Please input xcache admin password: " xcachepwd
  219. (( ${#xcachepwd} >= 5 )) && { xcachepwd_md5=$(echo -n "${xcachepwd}" | md5sum | awk '{print $1}') ; break ; } || echo "${CFAILURE}xcache admin password least 5 characters! ${CEND}"
  220. done
  221. checkDownload
  222. Install_XCache
  223. Check_succ
  224. else
  225. echo "${CWARNING}Your php does not support XCache! ${CEND}"; exit 1
  226. fi
  227. ;;
  228. 3)
  229. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$|^7.[0-2]$ ]]; then
  230. checkDownload
  231. Install_APCU
  232. Check_succ
  233. else
  234. echo "${CWARNING}Your php does not support APCU! ${CEND}"; exit 1
  235. fi
  236. ;;
  237. 4)
  238. if [[ "${PHP_main_ver}" =~ ^5.[3-4]$ ]]; then
  239. checkDownload
  240. Install_eAccelerator
  241. Check_succ
  242. else
  243. echo "${CWARNING}Your php does not support eAccelerator! ${CEND}"; exit 1
  244. fi
  245. ;;
  246. esac
  247. else
  248. Uninstall_succ
  249. fi
  250. ;;
  251. 2)
  252. ACTION_FUN
  253. while :; do echo
  254. echo "Please select ZendGuardLoader/ionCube/SourceGuardian:"
  255. echo -e "\t${CMSG}1${CEND}. ZendGuardLoader"
  256. echo -e "\t${CMSG}2${CEND}. ionCube Loader"
  257. echo -e "\t${CMSG}3${CEND}. SourceGuardian"
  258. read -e -p "Please input a number:(Default 1 press Enter) " Loader
  259. [ -z "${Loader}" ] && Loader=1
  260. if [[ ! "${Loader}" =~ ^[1-3]$ ]]; then
  261. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  262. else
  263. [ "${Loader}" = '1' ] && PHP_extension=ZendGuardLoader
  264. [ "${Loader}" = '2' ] && PHP_extension=ioncube
  265. [ "${Loader}" = '3' ] && PHP_extension=sourceguardian
  266. break
  267. fi
  268. done
  269. if [ "${ACTION}" = '1' ]; then
  270. Check_PHP_Extension
  271. if [ "${Loader}" = '1' ]; then
  272. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$ ]] && [ "${armplatform}" != 'y' ]; then
  273. zendguardloader_yn='y' && checkDownload
  274. Install_ZendGuardLoader
  275. Check_succ
  276. else
  277. echo; echo "${CWARNING}Your php ${PHP_detail_ver} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  278. fi
  279. elif [ "${Loader}" = '2' ]; then
  280. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$|^7.[0-2]$ ]] || [ "${TARGET_ARCH}" != "arm64" ]; then
  281. ioncube_yn='y' && checkDownload
  282. Install_ionCube
  283. Restart_PHP; echo "${CSUCCESS}PHP ioncube module installed successfully! ${CEND}";
  284. else
  285. echo; echo "${CWARNING}Your php ${PHP_detail_ver} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  286. fi
  287. elif [ "${Loader}" = '3' ]; then
  288. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$|^7.[0-2]$ ]] || [ "${TARGET_ARCH}" != "armv8" ]; then
  289. sourceguardian_yn='y' && checkDownload
  290. Install_SourceGuardian
  291. Restart_PHP; echo "${CSUCCESS}PHP SourceGuardian module installed successfully! ${CEND}";
  292. else
  293. echo; echo "${CWARNING}Your php ${PHP_detail_ver} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  294. fi
  295. fi
  296. else
  297. Uninstall_succ
  298. fi
  299. ;;
  300. 3)
  301. ACTION_FUN
  302. while :; do echo
  303. echo "Please select ImageMagick/GraphicsMagick:"
  304. echo -e "\t${CMSG}1${CEND}. ImageMagick"
  305. echo -e "\t${CMSG}2${CEND}. GraphicsMagick"
  306. read -e -p "Please input a number:(Default 1 press Enter) " magick_option
  307. [ -z "${magick_option}" ] && magick_option=1
  308. if [[ ! "${magick_option}" =~ ^[1,2]$ ]]; then
  309. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  310. else
  311. [ "${magick_option}" = '1' ] && PHP_extension=imagick
  312. [ "${magick_option}" = '2' ] && PHP_extension=gmagick
  313. break
  314. fi
  315. done
  316. if [ "${ACTION}" = '1' ]; then
  317. Check_PHP_Extension
  318. magick_yn=y && checkDownload
  319. if [ "${magick_option}" = '1' ]; then
  320. [ ! -d "${imagick_install_dir}" ] && Install_ImageMagick
  321. Install_php-imagick
  322. Check_succ
  323. elif [ "${magick_option}" = '2' ]; then
  324. [ ! -d "${gmagick_install_dir}" ] && Install_GraphicsMagick
  325. Install_php-gmagick
  326. Check_succ
  327. fi
  328. else
  329. Uninstall_succ
  330. [ -d "${imagick_install_dir}" ] && rm -rf ${imagick_install_dir}
  331. [ -d "${gmagick_install_dir}" ] && rm -rf ${gmagick_install_dir}
  332. fi
  333. ;;
  334. 4)
  335. ACTION_FUN
  336. while :; do echo
  337. echo "Please select fileinfo/imap/phalcon:"
  338. echo -e "\t${CMSG}1${CEND}. fileinfo"
  339. echo -e "\t${CMSG}2${CEND}. imap"
  340. echo -e "\t${CMSG}3${CEND}. phalcon"
  341. read -e -p "Please input a number:(Default 1 press Enter) " phpext_option
  342. [ -z "${phpext_option}" ] && phpext_option=1
  343. if [[ ! "${phpext_option}" =~ ^[1-3]$ ]]; then
  344. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  345. else
  346. if [ "${phpext_option}" = '1' ]; then
  347. PHP_extension=fileinfo
  348. elif [ "${phpext_option}" = '2' ]; then
  349. PHP_extension=imap
  350. IMAP_ARGS='--with-kerberos --with-imap --with-imap-ssl'
  351. if [ "${PM}" == 'yum' ]; then
  352. yum -y install libc-client-devel
  353. [ "${OS_BIT}" == '64' -a ! -e /usr/lib/libc-client.so ] && ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so
  354. else
  355. apt-get -y install libc-client2007e-dev
  356. fi
  357. elif [ "${phpext_option}" = '3' ]; then
  358. PHP_extension=phalcon
  359. fi
  360. break
  361. fi
  362. done
  363. if [ "${ACTION}" = '1' ]; then
  364. Check_PHP_Extension
  365. pushd ${oneinstack_dir}/src > /dev/null
  366. if [[ "${phpext_option}" =~ ^[1-2]$ ]]; then
  367. src_url=http://www.php.net/distributions/php-${PHP_detail_ver}.tar.gz && Download_src
  368. tar xzf php-${PHP_detail_ver}.tar.gz
  369. pushd php-${PHP_detail_ver}/ext/${PHP_extension}
  370. ${php_install_dir}/bin/phpize
  371. ./configure --with-php-config=${php_install_dir}/bin/php-config ${IMAP_ARGS}
  372. make -j ${THREAD} && make install
  373. popd
  374. rm -rf php-${PHP_detail_ver}
  375. elif [ "${phpext_option}" = '3' ]; then
  376. if [[ "${PHP_main_ver}" =~ ^5.[5-6]$|^7.[0-2]$ ]]; then
  377. src_url=http://mirrors.linuxeye.com/oneinstack/src/cphalcon-${phalcon_ver}.tar.gz && Download_src
  378. tar xzf cphalcon-${phalcon_ver}.tar.gz
  379. pushd cphalcon-${phalcon_ver}/build
  380. ./install --phpize ${php_install_dir}/bin/phpize --php-config ${php_install_dir}/bin/php-config --arch ${OS_BIT}bits
  381. popd
  382. rm -rf cphalcon-${phalcon_ver}
  383. else
  384. echo; echo "${CWARNING}Your php ${PHP_detail_ver} does not support ${PHP_extension}! ${CEND}";
  385. fi
  386. fi
  387. popd
  388. [ -f "${phpExtensionDir}/${PHP_extension}.so" ] && echo "extension=${PHP_extension}.so" > ${php_install_dir}/etc/php.d/04-${PHP_extension}.ini
  389. Check_succ
  390. else
  391. Uninstall_succ
  392. fi
  393. ;;
  394. 5)
  395. ACTION_FUN
  396. while :; do echo
  397. echo "Please select memcache/memcached PHP Extension:"
  398. echo -e "\t${CMSG}1${CEND}. memcache PHP Extension"
  399. echo -e "\t${CMSG}2${CEND}. memcached PHP Extension"
  400. echo -e "\t${CMSG}3${CEND}. memcache/memcached PHP Extension"
  401. read -e -p "Please input a number:(Default 1 press Enter) " Memcache
  402. [ -z "${Memcache}" ] && Memcache=1
  403. if [[ ! "${Memcache}" =~ ^[1-3]$ ]]; then
  404. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  405. else
  406. [ "${Memcache}" = '1' ] && PHP_extension=memcache
  407. [ "${Memcache}" = '2' ] && PHP_extension=memcached
  408. break
  409. fi
  410. done
  411. if [ "${ACTION}" = '1' ]; then
  412. memcached_yn=y && checkDownload
  413. case "${Memcache}" in
  414. 1)
  415. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  416. Check_PHP_Extension
  417. Install_php-memcache
  418. Check_succ
  419. ;;
  420. 2)
  421. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  422. Check_PHP_Extension
  423. Install_php-memcached
  424. Check_succ
  425. ;;
  426. 3)
  427. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  428. PHP_extension=memcache && Check_PHP_Extension
  429. Install_php-memcache
  430. PHP_extension=memcached && Check_PHP_Extension
  431. Install_php-memcached
  432. [ -f "${phpExtensionDir}/memcache.so" -a "${phpExtensionDir}/memcached.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP memcache/memcached module installed successfully! ${CEND}"; }
  433. ;;
  434. esac
  435. else
  436. PHP_extension=memcache && Uninstall_succ
  437. PHP_extension=memcached && Uninstall_succ
  438. [ -e "${memcached_install_dir}" ] && { service memcached stop > /dev/null 2>&1; rm -rf ${memcached_install_dir} /etc/init.d/memcached /usr/bin/memcached; }
  439. fi
  440. ;;
  441. 6)
  442. ACTION_FUN
  443. PHP_extension=redis
  444. redis_yn=y && checkDownload
  445. if [ "${ACTION}" = '1' ]; then
  446. [ ! -d "${redis_install_dir}" ] && Install_redis-server
  447. Check_PHP_Extension
  448. Install_php-redis
  449. else
  450. Uninstall_succ
  451. [ -e "${redis_install_dir}" ] && { service redis-server stop > /dev/null 2>&1; rm -rf ${redis_install_dir} /etc/init.d/redis-server /usr/local/bin/redis-*; }
  452. fi
  453. ;;
  454. 7)
  455. ACTION_FUN
  456. PHP_extension=swoole
  457. if [ "${ACTION}" = '1' ]; then
  458. Check_PHP_Extension
  459. pushd ${oneinstack_dir}/src > /dev/null
  460. if [[ "${PHP_main_ver}" =~ ^7\.[0-2]$ ]]; then
  461. src_url=https://pecl.php.net/get/swoole-${swoole_ver}.tgz && Download_src
  462. tar xzf swoole-${swoole_ver}.tgz
  463. pushd swoole-${swoole_ver}
  464. else
  465. src_url=https://pecl.php.net/get/swoole-1.10.5.tgz && Download_src
  466. tar xzf swoole-1.10.5.tgz
  467. pushd swoole-1.10.5
  468. fi
  469. ${php_install_dir}/bin/phpize
  470. ./configure --with-php-config=${php_install_dir}/bin/php-config --enable-openssl --with-openssl-dir=${openssl_install_dir}
  471. make -j ${THREAD} && make install
  472. popd
  473. rm -rf swoole-${swoole_ver}
  474. popd
  475. echo 'extension=swoole.so' > ${php_install_dir}/etc/php.d/06-swoole.ini
  476. Check_succ
  477. else
  478. Uninstall_succ
  479. fi
  480. ;;
  481. 8)
  482. ACTION_FUN
  483. PHP_extension=xdebug
  484. if [ "${ACTION}" = '1' ]; then
  485. Check_PHP_Extension
  486. pushd ${oneinstack_dir}/src > /dev/null
  487. if [[ "${PHP_main_ver}" =~ ^7\.[0-2]$ ]]; then
  488. src_url=https://pecl.php.net/get/xdebug-${xdebug_ver}.tgz && Download_src
  489. src_url=http://mirrors.linuxeye.com/oneinstack/src/webgrind-master.zip && Download_src
  490. tar xzf xdebug-${xdebug_ver}.tgz
  491. unzip -q webgrind-master.zip
  492. /bin/mv webgrind-master ${wwwroot_dir}/default/webgrind
  493. pushd xdebug-${xdebug_ver}
  494. elif [[ "${PHP_main_ver}" =~ ^5\.[5-6]$ ]]; then
  495. src_url=https://pecl.php.net/get/xdebug-2.5.5.tgz && Download_src
  496. src_url=http://mirrors.linuxeye.com/oneinstack/src/webgrind-master.zip && Download_src
  497. tar xzf xdebug-2.5.5.tgz
  498. unzip -q webgrind-master.zip
  499. /bin/mv webgrind-master ${wwwroot_dir}/default/webgrind
  500. pushd xdebug-2.5.5
  501. else
  502. echo "${CWARNING}Need a PHP version >= 5.5.0 and <= 7.2.0${CEND}"
  503. exit 1
  504. fi
  505. ${php_install_dir}/bin/phpize
  506. ./configure --with-php-config=${php_install_dir}/bin/php-config
  507. make -j ${THREAD} && make install
  508. popd
  509. rm -rf xdebug-${xdebug_ver}
  510. popd
  511. [ ! -e /tmp/xdebug ] && { mkdir /tmp/xdebug; chown ${run_user}.${run_user} /tmp/xdebug; }
  512. [ ! -e /tmp/webgrind ] && { mkdir /tmp/webgrind; chown ${run_user}.${run_user} /tmp/webgrind; }
  513. chown -R ${run_user}.${run_user} ${wwwroot_dir}/default/webgrind
  514. sed -i 's@static $storageDir.*@static $storageDir = "/tmp/webgrind";@' ${wwwroot_dir}/default/webgrind/config.php
  515. sed -i 's@static $profilerDir.*@static $profilerDir = "/tmp/xdebug";@' ${wwwroot_dir}/default/webgrind/config.php
  516. cat > ${php_install_dir}/etc/php.d/08-xdebug.ini << EOF
  517. [xdebug]
  518. zend_extension=xdebug.so
  519. xdebug.trace_output_dir=/tmp/xdebug
  520. xdebug.profiler_output_dir = /tmp/xdebug
  521. xdebug.profiler_enable = On
  522. xdebug.profiler_enable_trigger = 1
  523. EOF
  524. Check_succ
  525. echo; echo "Webgrind URL: ${CMSG}http://{Public IP}/webgrind ${CEND}"
  526. else
  527. rm -rf /tmp/{xdebug,webgrind} ${wwwroot_dir}/default/webgrind
  528. Uninstall_succ
  529. fi
  530. ;;
  531. 9)
  532. ACTION_FUN
  533. if [ "${ACTION}" = '1' ]; then
  534. [ -e "/usr/local/bin/composer" ] && { echo "${CWARNING}PHP Composer already installed! ${CEND}"; exit 1; }
  535. if [ "$IPADDR_COUNTRY"x == "CN"x ]; then
  536. wget -c https://dl.laravel-china.org/composer.phar -O /usr/local/bin/composer > /dev/null 2>&1
  537. ${php_install_dir}/bin/php /usr/local/bin/composer config -g repo.packagist composer https://packagist.phpcomposer.com
  538. else
  539. wget -c https://getcomposer.org/composer.phar -O /usr/local/bin/composer > /dev/null 2>&1
  540. fi
  541. chmod +x /usr/local/bin/composer
  542. if [ -e "/usr/local/bin/composer" ]; then
  543. echo; echo "${CSUCCESS}Composer installed successfully! ${CEND}"
  544. else
  545. echo; echo "${CFAILURE}Composer install failed, Please try again! ${CEND}"
  546. fi
  547. else
  548. rm -rf /usr/local/bin/composer
  549. echo; echo "${CMSG}composer uninstall completed${CEND}";
  550. fi
  551. ;;
  552. 10)
  553. ACTION_FUN
  554. if [ "${ACTION}" = '1' ]; then
  555. Install_fail2ban
  556. else
  557. Uninstall_fail2ban
  558. fi
  559. ;;
  560. 11)
  561. ACTION_FUN
  562. if [ "${ACTION}" = '1' ]; then
  563. [ -e "${nginx_install_dir}/sbin/nginx" ] && Nginx_lua_waf
  564. [ -e "${tengine_install_dir}/sbin/nginx" ] && Tengine_lua_waf
  565. enable_lua_waf
  566. else
  567. disable_lua_waf
  568. fi
  569. ;;
  570. q)
  571. exit
  572. ;;
  573. esac
  574. fi
  575. done