1
0

addons.sh 21 KB

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