addons.sh 24 KB

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