addons.sh 22 KB

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