addons.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. if [ ! -e "/usr/bin/pip" ]; then
  111. src_url=http://mirrors.linuxeye.com/oneinstack/src/pip-9.0.1.tar.gz && Download_src
  112. tar xzf pip-9.0.1.tar.gz
  113. pushd pip-9.0.1
  114. python setup.py install
  115. popd
  116. rm -rf pip-9.0.1
  117. fi
  118. if [ ! -e "~/.pip/pip.conf" ] ;then
  119. # get the IP information
  120. PUBLIC_IPADDR=$(../include/get_public_ipaddr.py)
  121. IPADDR_COUNTRY=$(../include/get_ipaddr_state.py $PUBLIC_IPADDR | awk '{print $1}')
  122. [ "$IPADDR_COUNTRY"x != "CN"x ] && { mkdir ~/.pip; echo -e "[global]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple" > ~/.pip/pip.conf; }
  123. fi
  124. pip install certbot
  125. popd
  126. if [ -e "/usr/bin/certbot" ]; then
  127. echo; echo "${CSUCCESS}Let's Encrypt client installed successfully! ${CEND}"
  128. else
  129. echo; echo "${CFAILURE}Let's Encrypt client install failed, Please try again! ${CEND}"
  130. fi
  131. }
  132. Uninstall_letsencrypt() {
  133. pip uninstall certbot
  134. rm -rf /etc/letsencrypt /var/log/letsencrypt /var/lib/letsencrypt
  135. [ "${OS}" == "CentOS" ] && Cron_file=/var/spool/cron/root || Cron_file=/var/spool/cron/crontabs/root
  136. sed -i '/certbot/d' ${Cron_file}
  137. echo; echo "${CMSG}Let's Encrypt client uninstall completed${CEND}";
  138. }
  139. ACTION_FUN() {
  140. while :; do
  141. echo
  142. echo "Please select an action:"
  143. echo -e "\t${CMSG}1${CEND}. install"
  144. echo -e "\t${CMSG}2${CEND}. uninstall"
  145. read -p "Please input a number:(Default 1 press Enter) " ACTION
  146. [ -z "${ACTION}" ] && ACTION=1
  147. if [[ ! "${ACTION}" =~ ^[1,2]$ ]]; then
  148. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  149. else
  150. break
  151. fi
  152. done
  153. }
  154. while :;do
  155. printf "
  156. What Are You Doing?
  157. \t${CMSG}1${CEND}. Install/Uninstall PHP opcode cache
  158. \t${CMSG}2${CEND}. Install/Uninstall ZendGuardLoader/ionCube PHP Extension
  159. \t${CMSG}3${CEND}. Install/Uninstall ImageMagick/GraphicsMagick PHP Extension
  160. \t${CMSG}4${CEND}. Install/Uninstall fileinfo PHP Extension
  161. \t${CMSG}5${CEND}. Install/Uninstall memcached/memcache
  162. \t${CMSG}6${CEND}. Install/Uninstall Redis
  163. \t${CMSG}7${CEND}. Install/Uninstall Let's Encrypt client
  164. \t${CMSG}q${CEND}. Exit
  165. "
  166. read -p "Please input the correct option: " Number
  167. if [[ ! "${Number}" =~ ^[1-7,q]$ ]]; then
  168. echo "${CFAILURE}input error! Please only input 1 ~ 7 and q${CEND}"
  169. else
  170. case "${Number}" in
  171. 1)
  172. ACTION_FUN
  173. while :; do echo
  174. echo "Please select a opcode cache of the PHP:"
  175. echo -e "\t${CMSG}1${CEND}. Zend OPcache"
  176. echo -e "\t${CMSG}2${CEND}. XCache"
  177. echo -e "\t${CMSG}3${CEND}. APCU"
  178. echo -e "\t${CMSG}4${CEND}. eAccelerator"
  179. read -p "Please input a number:(Default 1 press Enter) " PHP_cache
  180. [ -z "${PHP_cache}" ] && PHP_cache=1
  181. if [[ ! "${PHP_cache}" =~ ^[1-4]$ ]]; then
  182. echo "${CWARNING}input error! Please only input number 1,2,3,4${CEND}"
  183. else
  184. case "${PHP_cache}" in
  185. 1)
  186. PHP_extension=opcache
  187. ;;
  188. 2)
  189. PHP_extension=xcache
  190. ;;
  191. 3)
  192. PHP_extension=apcu
  193. ;;
  194. 4)
  195. PHP_extension=eaccelerator
  196. ;;
  197. esac
  198. break
  199. fi
  200. done
  201. if [ "${ACTION}" = '1' ]; then
  202. Check_PHP_Extension
  203. if [ -e ${php_install_dir}/etc/php.d/ext-ZendGuardLoader.ini ]; then
  204. echo; echo "${CWARNING}You have to install ZendGuardLoader, You need to uninstall it before install ${PHP_extension}! ${CEND}"; echo; exit 1
  205. else
  206. case "${PHP_cache}" in
  207. 1)
  208. pushd ${oneinstack_dir}/src
  209. if [[ "${PHP_main_version}" =~ ^5.[3-4]$ ]]; then
  210. src_url=https://pecl.php.net/get/zendopcache-${zendopcache_version}.tgz && Download_src
  211. Install_ZendOPcache
  212. else
  213. src_url=http://www.php.net/distributions/php-${PHP_detail_version}.tar.gz && Download_src
  214. Install_ZendOPcache
  215. fi
  216. popd
  217. Check_succ
  218. ;;
  219. 2)
  220. if [[ ${PHP_main_version} =~ ^5.[3-6]$ ]]; then
  221. while :; do
  222. read -p "Please input xcache admin password: " xcache_admin_pass
  223. (( ${#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}"
  224. done
  225. checkDownload
  226. Install_XCache
  227. Check_succ
  228. else
  229. echo "${CWARNING}Your php does not support XCache! ${CEND}"; exit 1
  230. fi
  231. ;;
  232. 3)
  233. if [[ "${PHP_main_version}" =~ ^5.[3-6]$|^7.[0-1]$ ]]; then
  234. checkDownload
  235. Install_APCU
  236. Check_succ
  237. else
  238. echo "${CWARNING}Your php does not support APCU! ${CEND}"; exit 1
  239. fi
  240. ;;
  241. 4)
  242. if [[ "${PHP_main_version}" =~ ^5.[3-4]$ ]]; then
  243. checkDownload
  244. Install_eAccelerator
  245. Check_succ
  246. else
  247. echo "${CWARNING}Your php does not support eAccelerator! ${CEND}"; exit 1
  248. fi
  249. ;;
  250. esac
  251. fi
  252. else
  253. Uninstall_succ
  254. fi
  255. ;;
  256. 2)
  257. ACTION_FUN
  258. while :; do echo
  259. echo "Please select ZendGuardLoader/ionCube:"
  260. echo -e "\t${CMSG}1${CEND}. ZendGuardLoader"
  261. echo -e "\t${CMSG}2${CEND}. ionCube Loader"
  262. read -p "Please input a number:(Default 1 press Enter) " Loader
  263. [ -z "${Loader}" ] && Loader=1
  264. if [[ ! "${Loader}" =~ ^[1,2]$ ]]; then
  265. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  266. else
  267. [ "${Loader}" = '1' ] && PHP_extension=ZendGuardLoader
  268. [ "${Loader}" = '2' ] && PHP_extension=0ioncube
  269. break
  270. fi
  271. done
  272. if [ "${ACTION}" = '1' ]; then
  273. Check_PHP_Extension
  274. if [ "${Loader}" = '1' ]; then
  275. if [[ "${PHP_main_version}" =~ ^5.[3-6]$ ]] || [ "${armPlatform}" != 'y' ]; then
  276. if [ -e ${php_install_dir}/etc/php.d/ext-opcache.ini ]; then
  277. echo; echo "${CWARNING}You have to install OpCache, You need to uninstall it before install ZendGuardLoader! ${CEND}"; echo; exit 1
  278. else
  279. ZendGuardLoader_yn='y' && checkDownload
  280. Install_ZendGuardLoader
  281. Check_succ
  282. fi
  283. else
  284. echo; echo "${CWARNING}Your php ${PHP_detail_version} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  285. fi
  286. elif [ "${Loader}" = '2' ]; then
  287. if [[ "${PHP_main_version}" =~ ^5.[3-6]$|^7.0$ ]] || [ "${TARGET_ARCH}" != "arm64" ]; then
  288. ionCube_yn='y' && checkDownload
  289. Install_ionCube
  290. Restart_PHP; echo "${CSUCCESS}PHP ioncube module installed successfully! ${CEND}";
  291. else
  292. echo; echo "${CWARNING}Your php ${PHP_detail_version} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  293. fi
  294. fi
  295. else
  296. Uninstall_succ
  297. fi
  298. ;;
  299. 3)
  300. ACTION_FUN
  301. while :; do echo
  302. echo "Please select ImageMagick/GraphicsMagick:"
  303. echo -e "\t${CMSG}1${CEND}. ImageMagick"
  304. echo -e "\t${CMSG}2${CEND}. GraphicsMagick"
  305. read -p "Please input a number:(Default 1 press Enter) " Magick
  306. [ -z "${Magick}" ] && Magick=1
  307. if [[ ! "${Magick}" =~ ^[1,2]$ ]]; then
  308. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  309. else
  310. [ "${Magick}" = '1' ] && PHP_extension=imagick
  311. [ "${Magick}" = '2' ] && PHP_extension=gmagick
  312. break
  313. fi
  314. done
  315. if [ "${ACTION}" = '1' ]; then
  316. Check_PHP_Extension
  317. Magick_yn=y && checkDownload
  318. if [ "${Magick}" = '1' ]; then
  319. [ ! -d "/usr/local/imagemagick" ] && Install_ImageMagick
  320. Install_php-imagick
  321. Check_succ
  322. elif [ "${Magick}" = '2' ]; then
  323. [ ! -d "/usr/local/graphicsmagick" ] && Install_GraphicsMagick
  324. Install_php-gmagick
  325. Check_succ
  326. fi
  327. else
  328. Uninstall_succ
  329. [ -d "/usr/local/imagemagick" ] && rm -rf /usr/local/imagemagick
  330. [ -d "/usr/local/graphicsmagick" ] && rm -rf /usr/local/graphicsmagick
  331. fi
  332. ;;
  333. 4)
  334. ACTION_FUN
  335. PHP_extension=fileinfo
  336. if [ "${ACTION}" = '1' ]; then
  337. Check_PHP_Extension
  338. pushd ${oneinstack_dir}/src
  339. src_url=http://www.php.net/distributions/php-${PHP_detail_version}.tar.gz && Download_src
  340. tar xzf php-${PHP_detail_version}.tar.gz
  341. pushd php-${PHP_detail_version}/ext/fileinfo
  342. ${php_install_dir}/bin/phpize
  343. ./configure --with-php-config=${php_install_dir}/bin/php-config
  344. make -j ${THREAD} && make install
  345. popd;popd
  346. echo "extension=fileinfo.so" > ${php_install_dir}/etc/php.d/ext-fileinfo.ini
  347. Check_succ
  348. else
  349. Uninstall_succ
  350. fi
  351. ;;
  352. 5)
  353. ACTION_FUN
  354. while :; do echo
  355. echo "Please select memcache/memcached PHP Extension:"
  356. echo -e "\t${CMSG}1${CEND}. memcache PHP Extension"
  357. echo -e "\t${CMSG}2${CEND}. memcached PHP Extension"
  358. echo -e "\t${CMSG}3${CEND}. memcache/memcached PHP Extension"
  359. read -p "Please input a number:(Default 1 press Enter) " Memcache
  360. [ -z "${Memcache}" ] && Memcache=1
  361. if [[ ! "${Memcache}" =~ ^[1-3]$ ]]; then
  362. echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
  363. else
  364. [ "${Memcache}" = '1' ] && PHP_extension=memcache
  365. [ "${Memcache}" = '2' ] && PHP_extension=memcached
  366. break
  367. fi
  368. done
  369. if [ "${ACTION}" = '1' ]; then
  370. memcached_yn=y && checkDownload
  371. case "${Memcache}" in
  372. 1)
  373. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  374. Check_PHP_Extension
  375. Install_php-memcache
  376. Check_succ
  377. ;;
  378. 2)
  379. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  380. Check_PHP_Extension
  381. Install_php-memcached
  382. Check_succ
  383. ;;
  384. 3)
  385. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  386. PHP_extension=memcache && Check_PHP_Extension
  387. Install_php-memcache
  388. PHP_extension=memcached && Check_PHP_Extension
  389. Install_php-memcached
  390. [ -f "${phpExtensionDir}/memcache.so" -a "${phpExtensionDir}/memcached.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP memcache/memcached module installed successfully! ${CEND}"; }
  391. ;;
  392. esac
  393. else
  394. PHP_extension=memcache && Uninstall_succ
  395. PHP_extension=memcached && Uninstall_succ
  396. [ -e "${memcached_install_dir}" ] && { service memcached stop > /dev/null 2>&1; rm -rf ${memcached_install_dir} /etc/init.d/memcached /usr/bin/memcached; }
  397. fi
  398. ;;
  399. 6)
  400. ACTION_FUN
  401. PHP_extension=redis
  402. redis_yn=y && checkDownload
  403. if [ "${ACTION}" = '1' ]; then
  404. [ ! -d "${redis_install_dir}" ] && Install_redis-server
  405. Check_PHP_Extension
  406. Install_php-redis
  407. else
  408. Uninstall_succ
  409. [ -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-*; }
  410. fi
  411. ;;
  412. 7)
  413. ACTION_FUN
  414. if [ "${ACTION}" = '1' ]; then
  415. Install_letsencrypt
  416. else
  417. Uninstall_letsencrypt
  418. fi
  419. ;;
  420. q)
  421. exit
  422. ;;
  423. esac
  424. fi
  425. done