addons.sh 24 KB

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