addons.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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 --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. echo; echo "${CMSG}Let's Encrypt client uninstall completed${CEND}";
  113. }
  114. ACTION_FUN() {
  115. while :; do
  116. echo
  117. echo 'Please select an action:'
  118. echo -e "\t${CMSG}1${CEND}. install"
  119. echo -e "\t${CMSG}2${CEND}. uninstall"
  120. read -p "Please input a number:(Default 1 press Enter) " ACTION
  121. [ -z "$ACTION" ] && ACTION=1
  122. if [[ ! $ACTION =~ ^[1,2]$ ]];then
  123. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  124. else
  125. break
  126. fi
  127. done
  128. }
  129. while :;do
  130. printf "
  131. What Are You Doing?
  132. \t${CMSG}1${CEND}. Install/Uninstall PHP opcode cache
  133. \t${CMSG}2${CEND}. Install/Uninstall ZendGuardLoader/ionCube PHP Extension
  134. \t${CMSG}3${CEND}. Install/Uninstall ImageMagick/GraphicsMagick PHP Extension
  135. \t${CMSG}4${CEND}. Install/Uninstall fileinfo PHP Extension
  136. \t${CMSG}5${CEND}. Install/Uninstall memcached/memcache
  137. \t${CMSG}6${CEND}. Install/Uninstall Redis
  138. \t${CMSG}7${CEND}. Install/Uninstall Let's Encrypt client
  139. \t${CMSG}q${CEND}. Exit
  140. "
  141. read -p "Please input the correct option: " Number
  142. if [[ ! $Number =~ ^[1-7,q]$ ]];then
  143. echo "${CFAILURE}input error! Please only input 1 ~ 7 and q${CEND}"
  144. else
  145. case "$Number" in
  146. 1)
  147. ACTION_FUN
  148. while :; do echo
  149. echo 'Please select a opcode cache of the PHP:'
  150. echo -e "\t${CMSG}1${CEND}. Zend OPcache"
  151. echo -e "\t${CMSG}2${CEND}. XCache"
  152. echo -e "\t${CMSG}3${CEND}. APCU"
  153. echo -e "\t${CMSG}4${CEND}. eAccelerator"
  154. read -p "Please input a number:(Default 1 press Enter) " PHP_cache
  155. [ -z "$PHP_cache" ] && PHP_cache=1
  156. if [[ ! $PHP_cache =~ ^[1-4]$ ]];then
  157. echo "${CWARNING}input error! Please only input number 1,2,3,4${CEND}"
  158. else
  159. [ $PHP_cache = 1 ] && PHP_extension=opcache
  160. [ $PHP_cache = 2 ] && PHP_extension=xcache
  161. [ $PHP_cache = 3 ] && PHP_extension=apcu
  162. [ $PHP_cache = 4 ] && PHP_extension=eaccelerator
  163. break
  164. fi
  165. done
  166. if [ $ACTION = 1 ];then
  167. Check_PHP_Extension
  168. if [ -e $php_install_dir/etc/php.d/ext-ZendGuardLoader.ini ];then
  169. echo; echo "${CWARNING}You have to install ZendGuardLoader, You need to uninstall it before install $PHP_extension! ${CEND}"; echo; exit 1
  170. else
  171. if [ $PHP_cache = 1 ];then
  172. cd $oneinstack_dir/src
  173. if [[ $PHP_version =~ ^5.[3-4]$ ]];then
  174. Install_ZendOPcache
  175. elif [ "$PHP_version" == '5.5' ];then
  176. src_url=http://www.php.net/distributions/php-$php_5_version.tar.gz && Download_src
  177. tar xzf php-$php_5_version.tar.gz
  178. cd php-$php_5_version/ext/opcache
  179. Install_opcache
  180. elif [ "$PHP_version" == '5.6' ];then
  181. src_url=http://www.php.net/distributions/php-$php_6_version.tar.gz && Download_src
  182. tar xzf php-$php_6_version.tar.gz
  183. cd php-$php_6_version/ext/opcache
  184. Install_opcache
  185. elif [ "$PHP_version" == '7.0' ];then
  186. src_url=http://www.php.net/distributions/php-$php_7_version.tar.gz && Download_src
  187. tar xzf php-$php_7_version.tar.gz
  188. cd php-$php_7_version/ext/opcache
  189. Install_opcache
  190. fi
  191. Check_succ
  192. elif [ $PHP_cache = 2 ];then
  193. if [[ $PHP_version =~ ^5.[3-6]$ ]];then
  194. while :; do
  195. read -p "Please input xcache admin password: " xcache_admin_pass
  196. (( ${#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}"
  197. done
  198. Install_XCache
  199. Check_succ
  200. else
  201. echo "${CWARNING}Your php does not support XCache! ${CEND}"; exit 1
  202. fi
  203. elif [ $PHP_cache = 3 ];then
  204. if [[ $PHP_version =~ ^5.[3-5]$ ]];then
  205. Install_APCU
  206. Check_succ
  207. else
  208. echo "${CWARNING}Your php does not support APCU! ${CEND}"; exit 1
  209. fi
  210. elif [ $PHP_cache = 4 ];then
  211. if [ "$PHP_version" == '5.3' ];then
  212. Install_eAccelerator-0-9
  213. Check_succ
  214. elif [ "$PHP_version" == '5.4' ];then
  215. Install_eAccelerator-1-0-dev
  216. Check_succ
  217. else
  218. echo "${CWARNING}Your php does not support eAccelerator! ${CEND}"; exit 1
  219. fi
  220. fi
  221. fi
  222. else
  223. Uninstall_succ
  224. fi
  225. ;;
  226. 2)
  227. ACTION_FUN
  228. while :; do echo
  229. echo 'Please select ZendGuardLoader/ionCube:'
  230. echo -e "\t${CMSG}1${CEND}. ZendGuardLoader"
  231. echo -e "\t${CMSG}2${CEND}. ionCube Loader"
  232. read -p "Please input a number:(Default 1 press Enter) " Loader
  233. [ -z "$Loader" ] && Loader=1
  234. if [[ ! $Loader =~ ^[1,2]$ ]];then
  235. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  236. else
  237. [ $Loader = 1 ] && PHP_extension=ZendGuardLoader
  238. [ $Loader = 2 ] && PHP_extension=ioncube
  239. break
  240. fi
  241. done
  242. if [ $ACTION = 1 ];then
  243. Check_PHP_Extension
  244. if [[ $PHP_version =~ ^5.[3-6]$ ]];then
  245. if [ $Loader = 1 ];then
  246. if [ -e $php_install_dir/etc/php.d/ext-opcache.ini ];then
  247. echo; echo "${CWARNING}You have to install OpCache, You need to uninstall it before install ZendGuardLoader! ${CEND}"; echo; exit 1
  248. else
  249. Install_ZendGuardLoader
  250. Check_succ
  251. fi
  252. elif [ $Loader = 2 ];then
  253. Install_ionCube
  254. Restart_PHP; echo "${CSUCCESS}PHP $PHP_extension module install successfully! ${CEND}";
  255. fi
  256. else
  257. echo; echo "${CWARNING}Your php does not support $PHP_extension! ${CEND}";
  258. fi
  259. else
  260. Uninstall_succ
  261. fi
  262. ;;
  263. 3)
  264. ACTION_FUN
  265. while :; do echo
  266. echo 'Please select ImageMagick/GraphicsMagick:'
  267. echo -e "\t${CMSG}1${CEND}. ImageMagick"
  268. echo -e "\t${CMSG}2${CEND}. GraphicsMagick"
  269. read -p "Please input a number:(Default 1 press Enter) " Magick
  270. [ -z "$Magick" ] && Magick=1
  271. if [[ ! $Magick =~ ^[1,2]$ ]];then
  272. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  273. else
  274. [ $Magick = 1 ] && PHP_extension=imagick
  275. [ $Magick = 2 ] && PHP_extension=gmagick
  276. break
  277. fi
  278. done
  279. if [ $ACTION = 1 ];then
  280. Check_PHP_Extension
  281. if [ $Magick = 1 ];then
  282. [ ! -d "/usr/local/imagemagick" ] && Install_ImageMagick
  283. Install_php-imagick
  284. Check_succ
  285. elif [ $Magick = 2 ];then
  286. [ ! -d "/usr/local/graphicsmagick" ] && Install_GraphicsMagick
  287. Install_php-gmagick
  288. Check_succ
  289. fi
  290. else
  291. Uninstall_succ
  292. [ -d "/usr/local/imagemagick" ] && rm -rf /usr/local/imagemagick
  293. [ -d "/usr/local/graphicsmagick" ] && rm -rf /usr/local/graphicsmagick
  294. fi
  295. ;;
  296. 4)
  297. ACTION_FUN
  298. PHP_extension=fileinfo
  299. if [ $ACTION = 1 ];then
  300. Check_PHP_Extension
  301. cd $oneinstack_dir/src
  302. src_url=http://www.php.net/distributions/php-$PHP_version_detail.tar.gz && Download_src
  303. tar xzf php-$PHP_version_detail.tar.gz
  304. cd php-$PHP_version_detail/ext/fileinfo
  305. $php_install_dir/bin/phpize
  306. ./configure --with-php-config=$php_install_dir/bin/php-config
  307. make -j ${THREAD} && make install
  308. echo 'extension=fileinfo.so' > $php_install_dir/etc/php.d/ext-fileinfo.ini
  309. Check_succ
  310. else
  311. Uninstall_succ
  312. fi
  313. ;;
  314. 5)
  315. ACTION_FUN
  316. while :; do echo
  317. echo 'Please select memcache/memcached PHP Extension:'
  318. echo -e "\t${CMSG}1${CEND}. memcache PHP Extension"
  319. echo -e "\t${CMSG}2${CEND}. memcached PHP Extension"
  320. echo -e "\t${CMSG}3${CEND}. memcache/memcached PHP Extension"
  321. read -p "Please input a number:(Default 1 press Enter) " Memcache
  322. [ -z "$Memcache" ] && Memcache=1
  323. if [[ ! $Memcache =~ ^[1-3]$ ]];then
  324. echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
  325. else
  326. [ $Memcache = 1 ] && PHP_extension=memcache
  327. [ $Memcache = 2 ] && PHP_extension=memcached
  328. break
  329. fi
  330. done
  331. if [ $ACTION = 1 ];then
  332. if [ $Memcache = 1 ];then
  333. [ ! -d "$memcached_install_dir/include/memcached" ] && Install_memcached
  334. Check_PHP_Extension
  335. Install_php-memcache
  336. Check_succ
  337. elif [ $Memcache = 2 ];then
  338. [ ! -d "$memcached_install_dir/include/memcached" ] && Install_memcached
  339. Check_PHP_Extension
  340. Install_php-memcached
  341. Check_succ
  342. elif [ $Memcache = 3 ];then
  343. [ ! -d "$memcached_install_dir/include/memcached" ] && Install_memcached
  344. PHP_extension=memcache && Check_PHP_Extension
  345. Install_php-memcache
  346. PHP_extension=memcached && Check_PHP_Extension
  347. Install_php-memcached
  348. [ -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}"; }
  349. fi
  350. else
  351. PHP_extension=memcache && Uninstall_succ
  352. PHP_extension=memcached && Uninstall_succ
  353. [ -e "$memcached_install_dir" ] && { service memcached stop > /dev/null 2>&1; rm -rf $memcached_install_dir /etc/init.d/memcached /usr/bin/memcached; }
  354. fi
  355. ;;
  356. 6)
  357. ACTION_FUN
  358. PHP_extension=redis
  359. if [ $ACTION = 1 ];then
  360. [ ! -d "$redis_install_dir" ] && Install_redis-server
  361. Check_PHP_Extension
  362. Install_php-redis
  363. else
  364. Uninstall_succ
  365. [ -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-*; }
  366. fi
  367. ;;
  368. 7)
  369. ACTION_FUN
  370. if [ $ACTION = 1 ];then
  371. Install_letsencrypt
  372. else
  373. Uninstall_letsencrypt
  374. fi
  375. ;;
  376. q)
  377. exit
  378. ;;
  379. esac
  380. fi
  381. done