addons.sh 24 KB

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