addons.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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.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. phpExtensionDir=$(${php_install_dir}/bin/php-config --extension-dir)
  44. PHP_detail_version=$(${php_install_dir}/bin/php -r 'echo PHP_VERSION;')
  45. PHP_main_version=${PHP_detail_version%.*}
  46. case "${PHP_main_version}" in
  47. "5.3")
  48. PHP_version=1
  49. ;;
  50. "5.4")
  51. PHP_version=2
  52. ;;
  53. "5.5")
  54. PHP_version=3
  55. ;;
  56. "5.6")
  57. PHP_version=4
  58. ;;
  59. "7.0" | "7.1")
  60. PHP_version=5
  61. ;;
  62. *)
  63. echo "${CFAILURE}Your PHP version ${PHP_main_version} is not supported! ${CEND}"
  64. kill -9 $$
  65. ;;
  66. esac
  67. else
  68. echo "${CFAILURE}Couldn't find phpize! ${CEND}"
  69. kill -9 $$
  70. fi
  71. # Check PHP Extensions
  72. Check_PHP_Extension() {
  73. [ -e "${php_install_dir}/etc/php.d/ext-${PHP_extension}.ini" ] && { echo "${CWARNING}PHP ${PHP_extension} module already installed! ${CEND}"; exit 1; }
  74. }
  75. # restart PHP
  76. Restart_PHP() {
  77. [ -e "${apache_install_dir}/conf/httpd.conf" ] && /etc/init.d/httpd restart || /etc/init.d/php-fpm restart
  78. }
  79. # Check succ
  80. Check_succ() {
  81. [ -f "${phpExtensionDir}/${PHP_extension}.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP ${PHP_extension} module installed successfully! ${CEND}"; }
  82. }
  83. # Uninstall succ
  84. Uninstall_succ() {
  85. [ -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}"; }
  86. }
  87. Install_letsencrypt() {
  88. if [ "${CentOS_RHEL_version}" == '7' ]; then
  89. [ ! -e /etc/yum.repos.d/epel.repo ] && cat > /etc/yum.repos.d/epel.repo << EOF
  90. [epel]
  91. name=Extra Packages for Enterprise Linux 7 - \$basearch
  92. #baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch
  93. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
  94. failovermethod=priority
  95. enabled=1
  96. gpgcheck=0
  97. EOF
  98. elif [ "${CentOS_RHEL_version}" == '6' ]; then
  99. [ ! -e /etc/yum.repos.d/epel.repo ] && cat > /etc/yum.repos.d/epel.repo << EOF
  100. [epel]
  101. name=Extra Packages for Enterprise Linux 6 - \$basearch
  102. #baseurl=http://download.fedoraproject.org/pub/epel/6/\$basearch
  103. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=\$basearch
  104. failovermethod=priority
  105. enabled=1
  106. gpgcheck=0
  107. EOF
  108. fi
  109. pushd ${oneinstack_dir}/src
  110. src_url=https://dl.eff.org/certbot-auto && Download_src
  111. /bin/mv certbot-auto /usr/local/bin/
  112. chmod +x /usr/local/bin/certbot-auto
  113. certbot-auto -n
  114. popd
  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 "${CSUCCESS}Let's Encrypt client install failed, Please try 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. case "${PHP_cache}" in
  173. 1)
  174. PHP_extension=opcache
  175. ;;
  176. 2)
  177. PHP_extension=xcache
  178. ;;
  179. 3)
  180. PHP_extension=apcu
  181. ;;
  182. 4)
  183. PHP_extension=eaccelerator
  184. ;;
  185. esac
  186. break
  187. fi
  188. done
  189. if [ "${ACTION}" = '1' ]; then
  190. Check_PHP_Extension
  191. if [ -e ${php_install_dir}/etc/php.d/ext-ZendGuardLoader.ini ]; then
  192. echo; echo "${CWARNING}You have to install ZendGuardLoader, You need to uninstall it before install ${PHP_extension}! ${CEND}"; echo; exit 1
  193. else
  194. case "${PHP_cache}" in
  195. 1)
  196. pushd ${oneinstack_dir}/src
  197. if [[ "${PHP_main_version}" =~ ^5.[3-4]$ ]]; then
  198. src_url=https://pecl.php.net/get/zendopcache-${zendopcache_version}.tgz && Download_src
  199. Install_ZendOPcache
  200. else
  201. src_url=http://www.php.net/distributions/php-${PHP_detail_version}.tar.gz && Download_src
  202. Install_ZendOPcache
  203. fi
  204. popd
  205. Check_succ
  206. ;;
  207. 2)
  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. ;;
  220. 3)
  221. if [[ "${PHP_main_version}" =~ ^5.[3-6]$|^7.[0-1]$ ]]; then
  222. checkDownload
  223. Install_APCU
  224. Check_succ
  225. else
  226. echo "${CWARNING}Your php does not support APCU! ${CEND}"; exit 1
  227. fi
  228. ;;
  229. 4)
  230. if [[ "${PHP_main_version}" =~ ^5.[3-4]$ ]]; then
  231. checkDownload
  232. Install_eAccelerator
  233. Check_succ
  234. else
  235. echo "${CWARNING}Your php does not support eAccelerator! ${CEND}"; exit 1
  236. fi
  237. ;;
  238. esac
  239. fi
  240. else
  241. Uninstall_succ
  242. fi
  243. ;;
  244. 2)
  245. ACTION_FUN
  246. while :; do echo
  247. echo "Please select ZendGuardLoader/ionCube:"
  248. echo -e "\t${CMSG}1${CEND}. ZendGuardLoader"
  249. echo -e "\t${CMSG}2${CEND}. ionCube Loader"
  250. read -p "Please input a number:(Default 1 press Enter) " Loader
  251. [ -z "${Loader}" ] && Loader=1
  252. if [[ ! "${Loader}" =~ ^[1,2]$ ]]; then
  253. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  254. else
  255. [ "${Loader}" = '1' ] && PHP_extension=ZendGuardLoader
  256. [ "${Loader}" = '2' ] && PHP_extension=0ioncube
  257. break
  258. fi
  259. done
  260. if [ "${ACTION}" = '1' ]; then
  261. Check_PHP_Extension
  262. if [ "${Loader}" = '1' ]; then
  263. if [[ "${PHP_main_version}" =~ ^5.[3-6]$ ]] || [ "${armPlatform}" != 'y' ]; then
  264. if [ -e ${php_install_dir}/etc/php.d/ext-opcache.ini ]; then
  265. echo; echo "${CWARNING}You have to install OpCache, You need to uninstall it before install ZendGuardLoader! ${CEND}"; echo; exit 1
  266. else
  267. ZendGuardLoader_yn='y' && checkDownload
  268. Install_ZendGuardLoader
  269. Check_succ
  270. fi
  271. else
  272. echo; echo "${CWARNING}Your php ${PHP_detail_version} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  273. fi
  274. elif [ "${Loader}" = '2' ]; then
  275. if [[ "${PHP_main_version}" =~ ^5.[3-6]$|^7.0$ ]] || [ "${TARGET_ARCH}" != "arm64" ]; then
  276. ionCube_yn='y' && checkDownload
  277. Install_ionCube
  278. Restart_PHP; echo "${CSUCCESS}PHP ioncube module installed successfully! ${CEND}";
  279. else
  280. echo; echo "${CWARNING}Your php ${PHP_detail_version} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  281. fi
  282. fi
  283. else
  284. Uninstall_succ
  285. fi
  286. ;;
  287. 3)
  288. ACTION_FUN
  289. while :; do echo
  290. echo "Please select ImageMagick/GraphicsMagick:"
  291. echo -e "\t${CMSG}1${CEND}. ImageMagick"
  292. echo -e "\t${CMSG}2${CEND}. GraphicsMagick"
  293. read -p "Please input a number:(Default 1 press Enter) " Magick
  294. [ -z "${Magick}" ] && Magick=1
  295. if [[ ! "${Magick}" =~ ^[1,2]$ ]]; then
  296. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  297. else
  298. [ "${Magick}" = '1' ] && PHP_extension=imagick
  299. [ "${Magick}" = '2' ] && PHP_extension=gmagick
  300. break
  301. fi
  302. done
  303. if [ "${ACTION}" = '1' ]; then
  304. Check_PHP_Extension
  305. Magick_yn=y && checkDownload
  306. if [ "${Magick}" = '1' ]; then
  307. [ ! -d "/usr/local/imagemagick" ] && Install_ImageMagick
  308. Install_php-imagick
  309. Check_succ
  310. elif [ "${Magick}" = '2' ]; then
  311. [ ! -d "/usr/local/graphicsmagick" ] && Install_GraphicsMagick
  312. Install_php-gmagick
  313. Check_succ
  314. fi
  315. else
  316. Uninstall_succ
  317. [ -d "/usr/local/imagemagick" ] && rm -rf /usr/local/imagemagick
  318. [ -d "/usr/local/graphicsmagick" ] && rm -rf /usr/local/graphicsmagick
  319. fi
  320. ;;
  321. 4)
  322. ACTION_FUN
  323. PHP_extension=fileinfo
  324. if [ "${ACTION}" = '1' ]; then
  325. Check_PHP_Extension
  326. pushd ${oneinstack_dir}/src
  327. src_url=http://www.php.net/distributions/php-${PHP_detail_version}.tar.gz && Download_src
  328. tar xzf php-${PHP_detail_version}.tar.gz
  329. popd
  330. pushd php-${PHP_detail_version}/ext/fileinfo
  331. ${php_install_dir}/bin/phpize
  332. ./configure --with-php-config=${php_install_dir}/bin/php-config
  333. make -j ${THREAD} && make install
  334. popd
  335. echo "extension=fileinfo.so" > ${php_install_dir}/etc/php.d/ext-fileinfo.ini
  336. Check_succ
  337. else
  338. Uninstall_succ
  339. fi
  340. ;;
  341. 5)
  342. ACTION_FUN
  343. while :; do echo
  344. echo "Please select memcache/memcached PHP Extension:"
  345. echo -e "\t${CMSG}1${CEND}. memcache PHP Extension"
  346. echo -e "\t${CMSG}2${CEND}. memcached PHP Extension"
  347. echo -e "\t${CMSG}3${CEND}. memcache/memcached PHP Extension"
  348. read -p "Please input a number:(Default 1 press Enter) " Memcache
  349. [ -z "${Memcache}" ] && Memcache=1
  350. if [[ ! "${Memcache}" =~ ^[1-3]$ ]]; then
  351. echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
  352. else
  353. [ "${Memcache}" = '1' ] && PHP_extension=memcache
  354. [ "${Memcache}" = '2' ] && PHP_extension=memcached
  355. break
  356. fi
  357. done
  358. if [ "${ACTION}" = '1' ]; then
  359. memcached_yn=y && checkDownload
  360. case "${Memcache}" in
  361. 1)
  362. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  363. Check_PHP_Extension
  364. Install_php-memcache
  365. Check_succ
  366. ;;
  367. 2)
  368. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  369. Check_PHP_Extension
  370. Install_php-memcached
  371. Check_succ
  372. ;;
  373. 3)
  374. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  375. PHP_extension=memcache && Check_PHP_Extension
  376. Install_php-memcache
  377. PHP_extension=memcached && Check_PHP_Extension
  378. Install_php-memcached
  379. [ -f "${phpExtensionDir}/memcache.so" -a "${phpExtensionDir}/memcached.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP memcache/memcached module installed successfully! ${CEND}"; }
  380. ;;
  381. esac
  382. else
  383. PHP_extension=memcache && Uninstall_succ
  384. PHP_extension=memcached && Uninstall_succ
  385. [ -e "${memcached_install_dir}" ] && { service memcached stop > /dev/null 2>&1; rm -rf ${memcached_install_dir} /etc/init.d/memcached /usr/bin/memcached; }
  386. fi
  387. ;;
  388. 6)
  389. ACTION_FUN
  390. PHP_extension=redis
  391. redis_yn=y && checkDownload
  392. if [ "${ACTION}" = '1' ]; then
  393. [ ! -d "${redis_install_dir}" ] && Install_redis-server
  394. Check_PHP_Extension
  395. Install_php-redis
  396. else
  397. Uninstall_succ
  398. [ -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-*; }
  399. fi
  400. ;;
  401. 7)
  402. ACTION_FUN
  403. if [ "${ACTION}" = '1' ]; then
  404. Install_letsencrypt
  405. else
  406. Uninstall_letsencrypt
  407. fi
  408. ;;
  409. q)
  410. exit
  411. ;;
  412. esac
  413. fi
  414. done