addons.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ 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 5+ Debian 6+ and Ubuntu 12+ #
  15. # Install/Uninstall PHP Extensions #
  16. # For more information please visit https://oneinstack.com #
  17. #######################################################################
  18. "
  19. # get pwd
  20. sed -i "s@^oneinstack_dir.*@oneinstack_dir=`pwd`@" ./options.conf
  21. . ./versions.txt
  22. . ./options.conf
  23. . ./include/color.sh
  24. . ./include/memory.sh
  25. . ./include/check_os.sh
  26. . ./include/download.sh
  27. . ./include/get_char.sh
  28. . ./include/zendopcache.sh
  29. . ./include/xcache.sh
  30. . ./include/apcu.sh
  31. . ./include/eaccelerator-0.9.sh
  32. . ./include/eaccelerator-1.0-dev.sh
  33. . ./include/ZendGuardLoader.sh
  34. . ./include/ioncube.sh
  35. . ./include/ImageMagick.sh
  36. . ./include/GraphicsMagick.sh
  37. . ./include/memcached.sh
  38. . ./include/redis.sh
  39. # Check if user is root
  40. [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  41. # Check PHP
  42. if [ -e "$php_install_dir/bin/phpize" ];then
  43. PHP_version_detail=`$php_install_dir/bin/php -r 'echo PHP_VERSION;'`
  44. PHP_version=`echo $PHP_version_detail | awk -F. '{print $1"."$2}'`
  45. fi
  46. # Check PHP Extensions
  47. Check_PHP_Extension() {
  48. [ -e "$php_install_dir/etc/php.d/ext-${PHP_extension}.ini" ] && { echo "${CWARNING}PHP $PHP_extension module already installed! ${CEND}"; exit 1; }
  49. }
  50. # restart PHP
  51. Restart_PHP() {
  52. [ -e "$apache_install_dir/conf/httpd.conf" ] && /etc/init.d/httpd restart || /etc/init.d/php-fpm restart
  53. }
  54. # Check succ
  55. Check_succ() {
  56. [ -f "`$php_install_dir/bin/php-config --extension-dir`/${PHP_extension}.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP $PHP_extension module install successfully! ${CEND}"; }
  57. }
  58. # Uninstall succ
  59. Uninstall_succ() {
  60. [ -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}"; }
  61. }
  62. # PHP 5.5,5,6,7.0 install opcache
  63. Install_opcache() {
  64. $php_install_dir/bin/phpize
  65. ./configure --with-php-config=$php_install_dir/bin/php-config
  66. make -j ${THREAD} && make install
  67. cat > $php_install_dir/etc/php.d/ext-opcache.ini << EOF
  68. [opcache]
  69. zend_extension=opcache.so
  70. opcache.enable=1
  71. opcache.memory_consumption=$Memory_limit
  72. opcache.interned_strings_buffer=8
  73. opcache.max_accelerated_files=4000
  74. opcache.revalidate_freq=60
  75. opcache.save_comments=0
  76. opcache.fast_shutdown=1
  77. opcache.enable_cli=1
  78. ;opcache.optimization_level=0
  79. EOF
  80. }
  81. Install_letsencrypt() {
  82. if [ "$CentOS_RHEL_version" == '7' ];then
  83. [ ! -e /etc/yum.repos.d/epel.repo ] && cat > /etc/yum.repos.d/epel.repo << EOF
  84. [epel]
  85. name=Extra Packages for Enterprise Linux 7 - \$basearch
  86. #baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch
  87. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
  88. failovermethod=priority
  89. enabled=1
  90. gpgcheck=0
  91. EOF
  92. elif [ "$CentOS_RHEL_version" == '6' ];then
  93. [ ! -e /etc/yum.repos.d/epel.repo ] && cat > /etc/yum.repos.d/epel.repo << EOF
  94. [epel]
  95. name=Extra Packages for Enterprise Linux 6 - \$basearch
  96. #baseurl=http://download.fedoraproject.org/pub/epel/6/\$basearch
  97. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=\$basearch
  98. failovermethod=priority
  99. enabled=1
  100. gpgcheck=0
  101. EOF
  102. fi
  103. cd $oneinstack_dir/src
  104. src_url=https://dl.eff.org/certbot-auto && Download_src
  105. /bin/mv certbot-auto /usr/local/bin/
  106. chmod +x /usr/local/bin/certbot-auto
  107. certbot-auto -n --help all
  108. certbot-auto -h | grep '\-\-standalone' > /dev/null && echo; echo "${CSUCCESS}Let's Encrypt client install successfully! ${CEND}"
  109. }
  110. Uninstall_letsencrypt() {
  111. rm -rf /usr/local/bin/cerbot-auto /etc/letsencrypt /var/log/letsencrypt
  112. [ "$OS" == 'CentOS' ] && Cron_file=/var/spool/cron/root || Cron_file=/var/spool/cron/crontabs/root
  113. sed -i '/certbot-auto/d' $Cron_file
  114. echo; echo "${CMSG}Let's Encrypt client uninstall completed${CEND}";
  115. }
  116. ACTION_FUN() {
  117. while :; do
  118. echo
  119. echo 'Please select an action:'
  120. echo -e "\t${CMSG}1${CEND}. install"
  121. echo -e "\t${CMSG}2${CEND}. uninstall"
  122. read -p "Please input a number:(Default 1 press Enter) " ACTION
  123. [ -z "$ACTION" ] && ACTION=1
  124. if [[ ! $ACTION =~ ^[1,2]$ ]];then
  125. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  126. else
  127. break
  128. fi
  129. done
  130. }
  131. while :;do
  132. printf "
  133. What Are You Doing?
  134. \t${CMSG}1${CEND}. Install/Uninstall PHP opcode cache
  135. \t${CMSG}2${CEND}. Install/Uninstall ZendGuardLoader/ionCube PHP Extension
  136. \t${CMSG}3${CEND}. Install/Uninstall ImageMagick/GraphicsMagick PHP Extension
  137. \t${CMSG}4${CEND}. Install/Uninstall fileinfo PHP Extension
  138. \t${CMSG}5${CEND}. Install/Uninstall memcached/memcache
  139. \t${CMSG}6${CEND}. Install/Uninstall Redis
  140. \t${CMSG}7${CEND}. Install/Uninstall Let's Encrypt client
  141. \t${CMSG}q${CEND}. Exit
  142. "
  143. read -p "Please input the correct option: " Number
  144. if [[ ! $Number =~ ^[1-7,q]$ ]];then
  145. echo "${CFAILURE}input error! Please only input 1 ~ 7 and q${CEND}"
  146. else
  147. case "$Number" in
  148. 1)
  149. ACTION_FUN
  150. while :; do echo
  151. echo 'Please select a opcode cache of the PHP:'
  152. echo -e "\t${CMSG}1${CEND}. Zend OPcache"
  153. echo -e "\t${CMSG}2${CEND}. XCache"
  154. echo -e "\t${CMSG}3${CEND}. APCU"
  155. echo -e "\t${CMSG}4${CEND}. eAccelerator"
  156. read -p "Please input a number:(Default 1 press Enter) " PHP_cache
  157. [ -z "$PHP_cache" ] && PHP_cache=1
  158. if [[ ! $PHP_cache =~ ^[1-4]$ ]];then
  159. echo "${CWARNING}input error! Please only input number 1,2,3,4${CEND}"
  160. else
  161. [ $PHP_cache = 1 ] && PHP_extension=opcache
  162. [ $PHP_cache = 2 ] && PHP_extension=xcache
  163. [ $PHP_cache = 3 ] && PHP_extension=apcu
  164. [ $PHP_cache = 4 ] && PHP_extension=eaccelerator
  165. break
  166. fi
  167. done
  168. if [ $ACTION = 1 ];then
  169. Check_PHP_Extension
  170. if [ -e $php_install_dir/etc/php.d/ext-ZendGuardLoader.ini ];then
  171. echo; echo "${CWARNING}You have to install ZendGuardLoader, You need to uninstall it before install $PHP_extension! ${CEND}"; echo; exit 1
  172. else
  173. if [ $PHP_cache = 1 ];then
  174. cd $oneinstack_dir/src
  175. if [[ $PHP_version =~ ^5.[3-4]$ ]];then
  176. Install_ZendOPcache
  177. elif [ "$PHP_version" == '5.5' ];then
  178. src_url=http://www.php.net/distributions/php-$php_5_version.tar.gz && Download_src
  179. tar xzf php-$php_5_version.tar.gz
  180. cd php-$php_5_version/ext/opcache
  181. Install_opcache
  182. elif [ "$PHP_version" == '5.6' ];then
  183. src_url=http://www.php.net/distributions/php-$php_6_version.tar.gz && Download_src
  184. tar xzf php-$php_6_version.tar.gz
  185. cd php-$php_6_version/ext/opcache
  186. Install_opcache
  187. elif [ "$PHP_version" == '7.0' ];then
  188. src_url=http://www.php.net/distributions/php-$php_7_version.tar.gz && Download_src
  189. tar xzf php-$php_7_version.tar.gz
  190. cd php-$php_7_version/ext/opcache
  191. Install_opcache
  192. fi
  193. Check_succ
  194. elif [ $PHP_cache = 2 ];then
  195. if [[ $PHP_version =~ ^5.[3-6]$ ]];then
  196. while :; do
  197. read -p "Please input xcache admin password: " xcache_admin_pass
  198. (( ${#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}"
  199. done
  200. Install_XCache
  201. Check_succ
  202. else
  203. echo "${CWARNING}Your php does not support XCache! ${CEND}"; exit 1
  204. fi
  205. elif [ $PHP_cache = 3 ];then
  206. if [[ $PHP_version =~ ^5.[3-5]$ ]];then
  207. Install_APCU
  208. Check_succ
  209. else
  210. echo "${CWARNING}Your php does not support APCU! ${CEND}"; exit 1
  211. fi
  212. elif [ $PHP_cache = 4 ];then
  213. if [ "$PHP_version" == '5.3' ];then
  214. Install_eAccelerator-0-9
  215. Check_succ
  216. elif [ "$PHP_version" == '5.4' ];then
  217. Install_eAccelerator-1-0-dev
  218. Check_succ
  219. else
  220. echo "${CWARNING}Your php does not support eAccelerator! ${CEND}"; exit 1
  221. fi
  222. fi
  223. fi
  224. else
  225. Uninstall_succ
  226. fi
  227. ;;
  228. 2)
  229. ACTION_FUN
  230. while :; do echo
  231. echo 'Please select ZendGuardLoader/ionCube:'
  232. echo -e "\t${CMSG}1${CEND}. ZendGuardLoader"
  233. echo -e "\t${CMSG}2${CEND}. ionCube Loader"
  234. read -p "Please input a number:(Default 1 press Enter) " Loader
  235. [ -z "$Loader" ] && Loader=1
  236. if [[ ! $Loader =~ ^[1,2]$ ]];then
  237. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  238. else
  239. [ $Loader = 1 ] && PHP_extension=ZendGuardLoader
  240. [ $Loader = 2 ] && PHP_extension=ioncube
  241. break
  242. fi
  243. done
  244. if [ $ACTION = 1 ];then
  245. Check_PHP_Extension
  246. if [[ $PHP_version =~ ^5.[3-6]$ ]];then
  247. if [ $Loader = 1 ];then
  248. if [ -e $php_install_dir/etc/php.d/ext-opcache.ini ];then
  249. echo; echo "${CWARNING}You have to install OpCache, You need to uninstall it before install ZendGuardLoader! ${CEND}"; echo; exit 1
  250. else
  251. Install_ZendGuardLoader
  252. Check_succ
  253. fi
  254. elif [ $Loader = 2 ];then
  255. Install_ionCube
  256. Restart_PHP; echo "${CSUCCESS}PHP $PHP_extension module install successfully! ${CEND}";
  257. fi
  258. else
  259. echo; echo "${CWARNING}Your php does not support $PHP_extension! ${CEND}";
  260. fi
  261. else
  262. Uninstall_succ
  263. fi
  264. ;;
  265. 3)
  266. ACTION_FUN
  267. while :; do echo
  268. echo 'Please select ImageMagick/GraphicsMagick:'
  269. echo -e "\t${CMSG}1${CEND}. ImageMagick"
  270. echo -e "\t${CMSG}2${CEND}. GraphicsMagick"
  271. read -p "Please input a number:(Default 1 press Enter) " Magick
  272. [ -z "$Magick" ] && Magick=1
  273. if [[ ! $Magick =~ ^[1,2]$ ]];then
  274. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  275. else
  276. [ $Magick = 1 ] && PHP_extension=imagick
  277. [ $Magick = 2 ] && PHP_extension=gmagick
  278. break
  279. fi
  280. done
  281. if [ $ACTION = 1 ];then
  282. Check_PHP_Extension
  283. if [ $Magick = 1 ];then
  284. [ ! -d "/usr/local/imagemagick" ] && Install_ImageMagick
  285. Install_php-imagick
  286. Check_succ
  287. elif [ $Magick = 2 ];then
  288. [ ! -d "/usr/local/graphicsmagick" ] && Install_GraphicsMagick
  289. Install_php-gmagick
  290. Check_succ
  291. fi
  292. else
  293. Uninstall_succ
  294. [ -d "/usr/local/imagemagick" ] && rm -rf /usr/local/imagemagick
  295. [ -d "/usr/local/graphicsmagick" ] && rm -rf /usr/local/graphicsmagick
  296. fi
  297. ;;
  298. 4)
  299. ACTION_FUN
  300. PHP_extension=fileinfo
  301. if [ $ACTION = 1 ];then
  302. Check_PHP_Extension
  303. cd $oneinstack_dir/src
  304. src_url=http://www.php.net/distributions/php-$PHP_version_detail.tar.gz && Download_src
  305. tar xzf php-$PHP_version_detail.tar.gz
  306. cd php-$PHP_version_detail/ext/fileinfo
  307. $php_install_dir/bin/phpize
  308. ./configure --with-php-config=$php_install_dir/bin/php-config
  309. make -j ${THREAD} && make install
  310. echo 'extension=fileinfo.so' > $php_install_dir/etc/php.d/ext-fileinfo.ini
  311. Check_succ
  312. else
  313. Uninstall_succ
  314. fi
  315. ;;
  316. 5)
  317. ACTION_FUN
  318. while :; do echo
  319. echo 'Please select memcache/memcached PHP Extension:'
  320. echo -e "\t${CMSG}1${CEND}. memcache PHP Extension"
  321. echo -e "\t${CMSG}2${CEND}. memcached PHP Extension"
  322. echo -e "\t${CMSG}3${CEND}. memcache/memcached PHP Extension"
  323. read -p "Please input a number:(Default 1 press Enter) " Memcache
  324. [ -z "$Memcache" ] && Memcache=1
  325. if [[ ! $Memcache =~ ^[1-3]$ ]];then
  326. echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
  327. else
  328. [ $Memcache = 1 ] && PHP_extension=memcache
  329. [ $Memcache = 2 ] && PHP_extension=memcached
  330. break
  331. fi
  332. done
  333. if [ $ACTION = 1 ];then
  334. if [ $Memcache = 1 ];then
  335. [ ! -d "$memcached_install_dir/include/memcached" ] && Install_memcached
  336. Check_PHP_Extension
  337. Install_php-memcache
  338. Check_succ
  339. elif [ $Memcache = 2 ];then
  340. [ ! -d "$memcached_install_dir/include/memcached" ] && Install_memcached
  341. Check_PHP_Extension
  342. Install_php-memcached
  343. Check_succ
  344. elif [ $Memcache = 3 ];then
  345. [ ! -d "$memcached_install_dir/include/memcached" ] && Install_memcached
  346. PHP_extension=memcache && Check_PHP_Extension
  347. Install_php-memcache
  348. PHP_extension=memcached && Check_PHP_Extension
  349. Install_php-memcached
  350. [ -f "`$php_install_dir/bin/php-config --extension-dir`/memcache.so" -a "`$php_install_dir/bin/php-config --extension-dir`/memcached.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP memcache/memcached module install successfully! ${CEND}"; }
  351. fi
  352. else
  353. PHP_extension=memcache && Uninstall_succ
  354. PHP_extension=memcached && Uninstall_succ
  355. [ -e "$memcached_install_dir" ] && { service memcached stop > /dev/null 2>&1; rm -rf $memcached_install_dir /etc/init.d/memcached /usr/bin/memcached; }
  356. fi
  357. ;;
  358. 6)
  359. ACTION_FUN
  360. PHP_extension=redis
  361. if [ $ACTION = 1 ];then
  362. [ ! -d "$redis_install_dir" ] && Install_redis-server
  363. Check_PHP_Extension
  364. Install_php-redis
  365. else
  366. Uninstall_succ
  367. [ -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-*; }
  368. fi
  369. ;;
  370. 7)
  371. ACTION_FUN
  372. if [ $ACTION = 1 ];then
  373. Install_letsencrypt
  374. else
  375. Uninstall_letsencrypt
  376. fi
  377. ;;
  378. q)
  379. exit
  380. ;;
  381. esac
  382. fi
  383. done