addons.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. ACTION_FUN
  206. while :; do echo
  207. echo "Please select a opcode cache of the PHP:"
  208. echo -e "\t${CMSG}1${CEND}. Zend OPcache"
  209. echo -e "\t${CMSG}2${CEND}. XCache"
  210. echo -e "\t${CMSG}3${CEND}. APCU"
  211. echo -e "\t${CMSG}4${CEND}. eAccelerator"
  212. read -p "Please input a number:(Default 1 press Enter) " PHP_cache
  213. [ -z "${PHP_cache}" ] && PHP_cache=1
  214. if [[ ! "${PHP_cache}" =~ ^[1-4]$ ]]; then
  215. echo "${CWARNING}input error! Please only input number 1~4${CEND}"
  216. else
  217. case "${PHP_cache}" in
  218. 1)
  219. PHP_extension=opcache
  220. ;;
  221. 2)
  222. PHP_extension=xcache
  223. ;;
  224. 3)
  225. PHP_extension=apcu
  226. ;;
  227. 4)
  228. PHP_extension=eaccelerator
  229. ;;
  230. esac
  231. break
  232. fi
  233. done
  234. if [ "${ACTION}" = '1' ]; then
  235. Check_PHP_Extension
  236. if [ -e ${php_install_dir}/etc/php.d/ext-ZendGuardLoader.ini ]; then
  237. echo; echo "${CWARNING}You have to install ZendGuardLoader, You need to uninstall it before install ${PHP_extension}! ${CEND}"; echo; exit 1
  238. else
  239. case "${PHP_cache}" in
  240. 1)
  241. pushd ${oneinstack_dir}/src
  242. if [[ "${PHP_main_version}" =~ ^5.[3-4]$ ]]; then
  243. src_url=https://pecl.php.net/get/zendopcache-${zendopcache_version}.tgz && Download_src
  244. Install_ZendOPcache
  245. else
  246. src_url=http://www.php.net/distributions/php-${PHP_detail_version}.tar.gz && Download_src
  247. Install_ZendOPcache
  248. fi
  249. popd
  250. Check_succ
  251. ;;
  252. 2)
  253. if [[ ${PHP_main_version} =~ ^5.[3-6]$ ]]; then
  254. while :; do
  255. read -p "Please input xcache admin password: " xcache_admin_pass
  256. (( ${#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}"
  257. done
  258. checkDownload
  259. Install_XCache
  260. Check_succ
  261. else
  262. echo "${CWARNING}Your php does not support XCache! ${CEND}"; exit 1
  263. fi
  264. ;;
  265. 3)
  266. if [[ "${PHP_main_version}" =~ ^5.[3-6]$|^7.[0-1]$ ]]; then
  267. checkDownload
  268. Install_APCU
  269. Check_succ
  270. else
  271. echo "${CWARNING}Your php does not support APCU! ${CEND}"; exit 1
  272. fi
  273. ;;
  274. 4)
  275. if [[ "${PHP_main_version}" =~ ^5.[3-4]$ ]]; then
  276. checkDownload
  277. Install_eAccelerator
  278. Check_succ
  279. else
  280. echo "${CWARNING}Your php does not support eAccelerator! ${CEND}"; exit 1
  281. fi
  282. ;;
  283. esac
  284. fi
  285. else
  286. Uninstall_succ
  287. fi
  288. ;;
  289. 2)
  290. ACTION_FUN
  291. while :; do echo
  292. echo "Please select ZendGuardLoader/ionCube:"
  293. echo -e "\t${CMSG}1${CEND}. ZendGuardLoader"
  294. echo -e "\t${CMSG}2${CEND}. ionCube Loader"
  295. read -p "Please input a number:(Default 1 press Enter) " Loader
  296. [ -z "${Loader}" ] && Loader=1
  297. if [[ ! "${Loader}" =~ ^[1,2]$ ]]; then
  298. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  299. else
  300. [ "${Loader}" = '1' ] && PHP_extension=ZendGuardLoader
  301. [ "${Loader}" = '2' ] && PHP_extension=0ioncube
  302. break
  303. fi
  304. done
  305. if [ "${ACTION}" = '1' ]; then
  306. Check_PHP_Extension
  307. if [ "${Loader}" = '1' ]; then
  308. if [[ "${PHP_main_version}" =~ ^5.[3-6]$ ]] || [ "${armPlatform}" != 'y' ]; then
  309. if [ -e ${php_install_dir}/etc/php.d/ext-opcache.ini ]; then
  310. echo; echo "${CWARNING}You have to install OpCache, You need to uninstall it before install ZendGuardLoader! ${CEND}"; echo; exit 1
  311. else
  312. ZendGuardLoader_yn='y' && checkDownload
  313. Install_ZendGuardLoader
  314. Check_succ
  315. fi
  316. else
  317. echo; echo "${CWARNING}Your php ${PHP_detail_version} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  318. fi
  319. elif [ "${Loader}" = '2' ]; then
  320. if [[ "${PHP_main_version}" =~ ^5.[3-6]$|^7.[0-2]$ ]] || [ "${TARGET_ARCH}" != "arm64" ]; then
  321. ionCube_yn='y' && checkDownload
  322. Install_ionCube
  323. Restart_PHP; echo "${CSUCCESS}PHP ioncube module installed successfully! ${CEND}";
  324. else
  325. echo; echo "${CWARNING}Your php ${PHP_detail_version} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  326. fi
  327. fi
  328. else
  329. Uninstall_succ
  330. fi
  331. ;;
  332. 3)
  333. ACTION_FUN
  334. while :; do echo
  335. echo "Please select ImageMagick/GraphicsMagick:"
  336. echo -e "\t${CMSG}1${CEND}. ImageMagick"
  337. echo -e "\t${CMSG}2${CEND}. GraphicsMagick"
  338. read -p "Please input a number:(Default 1 press Enter) " Magick
  339. [ -z "${Magick}" ] && Magick=1
  340. if [[ ! "${Magick}" =~ ^[1,2]$ ]]; then
  341. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  342. else
  343. [ "${Magick}" = '1' ] && PHP_extension=imagick
  344. [ "${Magick}" = '2' ] && PHP_extension=gmagick
  345. break
  346. fi
  347. done
  348. if [ "${ACTION}" = '1' ]; then
  349. Check_PHP_Extension
  350. Magick_yn=y && checkDownload
  351. if [ "${Magick}" = '1' ]; then
  352. [ ! -d "/usr/local/imagemagick" ] && Install_ImageMagick
  353. Install_php-imagick
  354. Check_succ
  355. elif [ "${Magick}" = '2' ]; then
  356. [ ! -d "/usr/local/graphicsmagick" ] && Install_GraphicsMagick
  357. Install_php-gmagick
  358. Check_succ
  359. fi
  360. else
  361. Uninstall_succ
  362. [ -d "/usr/local/imagemagick" ] && rm -rf /usr/local/imagemagick
  363. [ -d "/usr/local/graphicsmagick" ] && rm -rf /usr/local/graphicsmagick
  364. fi
  365. ;;
  366. 4)
  367. ACTION_FUN
  368. PHP_extension=fileinfo
  369. if [ "${ACTION}" = '1' ]; then
  370. Check_PHP_Extension
  371. pushd ${oneinstack_dir}/src
  372. src_url=http://www.php.net/distributions/php-${PHP_detail_version}.tar.gz && Download_src
  373. tar xzf php-${PHP_detail_version}.tar.gz
  374. pushd php-${PHP_detail_version}/ext/fileinfo
  375. ${php_install_dir}/bin/phpize
  376. ./configure --with-php-config=${php_install_dir}/bin/php-config
  377. make -j ${THREAD} && make install
  378. popd;popd
  379. rm -rf php-${PHP_detail_version}
  380. echo "extension=fileinfo.so" > ${php_install_dir}/etc/php.d/ext-fileinfo.ini
  381. Check_succ
  382. else
  383. Uninstall_succ
  384. fi
  385. ;;
  386. 5)
  387. ACTION_FUN
  388. while :; do echo
  389. echo "Please select memcache/memcached PHP Extension:"
  390. echo -e "\t${CMSG}1${CEND}. memcache PHP Extension"
  391. echo -e "\t${CMSG}2${CEND}. memcached PHP Extension"
  392. echo -e "\t${CMSG}3${CEND}. memcache/memcached PHP Extension"
  393. read -p "Please input a number:(Default 1 press Enter) " Memcache
  394. [ -z "${Memcache}" ] && Memcache=1
  395. if [[ ! "${Memcache}" =~ ^[1-3]$ ]]; then
  396. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  397. else
  398. [ "${Memcache}" = '1' ] && PHP_extension=memcache
  399. [ "${Memcache}" = '2' ] && PHP_extension=memcached
  400. break
  401. fi
  402. done
  403. if [ "${ACTION}" = '1' ]; then
  404. memcached_yn=y && checkDownload
  405. case "${Memcache}" in
  406. 1)
  407. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  408. Check_PHP_Extension
  409. Install_php-memcache
  410. Check_succ
  411. ;;
  412. 2)
  413. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  414. Check_PHP_Extension
  415. Install_php-memcached
  416. Check_succ
  417. ;;
  418. 3)
  419. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  420. PHP_extension=memcache && Check_PHP_Extension
  421. Install_php-memcache
  422. PHP_extension=memcached && Check_PHP_Extension
  423. Install_php-memcached
  424. [ -f "${phpExtensionDir}/memcache.so" -a "${phpExtensionDir}/memcached.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP memcache/memcached module installed successfully! ${CEND}"; }
  425. ;;
  426. esac
  427. else
  428. PHP_extension=memcache && Uninstall_succ
  429. PHP_extension=memcached && Uninstall_succ
  430. [ -e "${memcached_install_dir}" ] && { service memcached stop > /dev/null 2>&1; rm -rf ${memcached_install_dir} /etc/init.d/memcached /usr/bin/memcached; }
  431. fi
  432. ;;
  433. 6)
  434. ACTION_FUN
  435. PHP_extension=redis
  436. redis_yn=y && checkDownload
  437. if [ "${ACTION}" = '1' ]; then
  438. [ ! -d "${redis_install_dir}" ] && Install_redis-server
  439. Check_PHP_Extension
  440. Install_php-redis
  441. else
  442. Uninstall_succ
  443. [ -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-*; }
  444. fi
  445. ;;
  446. 7)
  447. ACTION_FUN
  448. if [ "${ACTION}" = '1' ]; then
  449. Install_letsencrypt
  450. else
  451. Uninstall_letsencrypt
  452. fi
  453. ;;
  454. 8)
  455. ACTION_FUN
  456. PHP_extension=swoole
  457. if [ "${ACTION}" = '1' ]; then
  458. Check_PHP_Extension
  459. pushd ${oneinstack_dir}/src
  460. src_url=http://mirrors.linuxeye.com/oneinstack/src/swoole-${swoole_version}.tgz && Download_src
  461. tar xzf swoole-${swoole_version}.tgz
  462. pushd swoole-${swoole_version}
  463. ${php_install_dir}/bin/phpize
  464. ./configure --with-php-config=${php_install_dir}/bin/php-config
  465. make -j ${THREAD} && make install
  466. popd
  467. rm -rf swoole-${swoole_version}
  468. popd
  469. echo 'extension=swoole.so' > ${php_install_dir}/etc/php.d/ext-swoole.ini
  470. Check_succ
  471. else
  472. Uninstall_succ
  473. fi
  474. ;;
  475. 9)
  476. [[ ! "${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; }
  477. ACTION_FUN
  478. PHP_extension=xdebug
  479. if [ "${ACTION}" = '1' ]; then
  480. Check_PHP_Extension
  481. pushd ${oneinstack_dir}/src
  482. src_url=http://mirrors.linuxeye.com/oneinstack/src/xdebug-${xdebug_version}.tgz && Download_src
  483. src_url=http://mirrors.linuxeye.com/oneinstack/src/webgrind-master.zip && Download_src
  484. tar xzf xdebug-${xdebug_version}.tgz
  485. unzip -q webgrind-master.zip
  486. /bin/mv webgrind-master ${wwwroot_dir}/default/webgrind
  487. pushd xdebug-${xdebug_version}
  488. ${php_install_dir}/bin/phpize
  489. ./configure --with-php-config=${php_install_dir}/bin/php-config
  490. make -j ${THREAD} && make install
  491. popd
  492. rm -rf xdebug-${xdebug_version}
  493. popd
  494. [ ! -e /tmp/xdebug ] && { mkdir /tmp/xdebug; chown ${run_user}.${run_user} /tmp/xdebug; }
  495. [ ! -e /tmp/webgrind ] && { mkdir /tmp/webgrind; chown ${run_user}.${run_user} /tmp/webgrind; }
  496. chown -R ${run_user}.${run_user} ${wwwroot_dir}/default/webgrind
  497. sed -i 's@static $storageDir.*@static $storageDir = "/tmp/webgrind";@' ${wwwroot_dir}/default/webgrind/config.php
  498. sed -i 's@static $profilerDir.*@static $profilerDir = "/tmp/xdebug";@' ${wwwroot_dir}/default/webgrind/config.php
  499. cat > ${php_install_dir}/etc/php.d/ext-xdebug.ini << EOF
  500. [xdebug]
  501. zend_extension=xdebug.so
  502. xdebug.trace_output_dir=/tmp/xdebug
  503. xdebug.profiler_output_dir = /tmp/xdebug
  504. xdebug.profiler_enable = On
  505. xdebug.profiler_enable_trigger = 1
  506. EOF
  507. Check_succ
  508. echo; echo "Webgrind URL: ${CMSG}http://{Public IP}/webgrind ${CEND}"
  509. else
  510. rm -rf /tmp/{xdebug,webgrind} ${wwwroot_dir}/default/webgrind
  511. Uninstall_succ
  512. fi
  513. ;;
  514. 10)
  515. ACTION_FUN
  516. if [ "${ACTION}" = '1' ]; then
  517. [ -e "/usr/local/bin/composer" ] && { echo "${CWARNING}PHP Composer already installed! ${CEND}"; exit 1; }
  518. if [ "$IPADDR_COUNTRY"x == "CN"x ]; then
  519. wget -c https://dl.laravel-china.org/composer.phar -O /usr/local/bin/composer > /dev/null 2>&1
  520. ${php_install_dir}/bin/php /usr/local/bin/composer config -g repo.packagist composer https://packagist.phpcomposer.com
  521. else
  522. wget -c https://getcomposer.org/composer.phar -O /usr/local/bin/composer > /dev/null 2>&1
  523. fi
  524. chmod +x /usr/local/bin/composer
  525. if [ -e "/usr/local/bin/composer" ]; then
  526. echo; echo "${CSUCCESS}Composer installed successfully! ${CEND}"
  527. else
  528. echo; echo "${CFAILURE}Composer install failed, Please try again! ${CEND}"
  529. fi
  530. else
  531. rm -rf /usr/local/bin/composer
  532. echo; echo "${CMSG}composer uninstall completed${CEND}";
  533. fi
  534. ;;
  535. 11)
  536. ACTION_FUN
  537. if [ "${ACTION}" = '1' ]; then
  538. Install_fail2ban
  539. else
  540. Uninstall_fail2ban
  541. fi
  542. ;;
  543. q)
  544. exit
  545. ;;
  546. esac
  547. fi
  548. done