addons.sh 16 KB

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