addons.sh 17 KB

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