addons.sh 21 KB

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