install.sh 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 6+ Debian 7+ 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 6+ Debian 7+ and Ubuntu 12+ #
  15. # For more information please visit https://oneinstack.com #
  16. #######################################################################
  17. "
  18. # Check if user is root
  19. [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  20. oneinstack_dir=$(dirname "`readlink -f $0`")
  21. pushd ${oneinstack_dir} > /dev/null
  22. . ./versions.txt
  23. . ./options.conf
  24. . ./include/color.sh
  25. . ./include/check_os.sh
  26. . ./include/check_dir.sh
  27. . ./include/download.sh
  28. . ./include/get_char.sh
  29. mkdir -p ${wwwroot_dir}/default ${wwwlogs_dir}
  30. [ -d /data ] && chmod 755 /data
  31. # Use default SSH port 22. If you use another SSH port on your server
  32. if [ -e "/etc/ssh/sshd_config" ]; then
  33. [ -z "`grep ^Port /etc/ssh/sshd_config`" ] && now_ssh_port=22 || now_ssh_port=`grep ^Port /etc/ssh/sshd_config | awk '{print $2}'`
  34. while :; do echo
  35. read -p "Please input SSH port(Default: ${now_ssh_port}): " ssh_port
  36. [ -z "${ssh_port}" ] && ssh_port=${now_ssh_port}
  37. if [ ${ssh_port} -eq 22 >/dev/null 2>&1 -o ${ssh_port} -gt 1024 >/dev/null 2>&1 -a ${ssh_port} -lt 65535 >/dev/null 2>&1 ]; then
  38. break
  39. else
  40. echo "${CWARNING}input error! Input range: 22,1025~65534${CEND}"
  41. fi
  42. done
  43. if [ -z "`grep ^Port /etc/ssh/sshd_config`" -a "${ssh_port}" != '22' ]; then
  44. sed -i "s@^#Port.*@&\nPort ${ssh_port}@" /etc/ssh/sshd_config
  45. elif [ -n "`grep ^Port /etc/ssh/sshd_config`" ]; then
  46. sed -i "s@^Port.*@Port ${ssh_port}@" /etc/ssh/sshd_config
  47. fi
  48. fi
  49. # check iptables
  50. while :; do echo
  51. read -p "Do you want to enable iptables? [y/n]: " iptables_yn
  52. if [[ ! ${iptables_yn} =~ ^[y,n]$ ]]; then
  53. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  54. else
  55. break
  56. fi
  57. done
  58. # check Web server
  59. while :; do echo
  60. read -p "Do you want to install Web server? [y/n]: " web_yn
  61. if [[ ! ${web_yn} =~ ^[y,n]$ ]]; then
  62. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  63. else
  64. if [ "${web_yn}" == 'y' ]; then
  65. # Nginx/Tegine/OpenResty
  66. while :; do echo
  67. echo 'Please select Nginx server:'
  68. echo -e "\t${CMSG}1${CEND}. Install Nginx"
  69. echo -e "\t${CMSG}2${CEND}. Install Tengine"
  70. echo -e "\t${CMSG}3${CEND}. Install OpenResty"
  71. echo -e "\t${CMSG}4${CEND}. Do not install"
  72. read -p "Please input a number:(Default 1 press Enter) " nginx_option
  73. [ -z "${nginx_option}" ] && nginx_option=1
  74. if [[ ! ${nginx_option} =~ ^[1-4]$ ]]; then
  75. echo "${CWARNING}input error! Please only input number 1~4${CEND}"
  76. else
  77. [ "${nginx_option}" != '4' -a -e "$nginx_install_dir/sbin/nginx" ] && { echo "${CWARNING}Nginx already installed! ${CEND}"; nginx_option=Other; }
  78. [ "${nginx_option}" != '4' -a -e "$tengine_install_dir/sbin/nginx" ] && { echo "${CWARNING}Tengine already installed! ${CEND}"; nginx_option=Other; }
  79. [ "${nginx_option}" != '4' -a -e "$openresty_install_dir/nginx/sbin/nginx" ] && { echo "${CWARNING}OpenResty already installed! ${CEND}"; nginx_option=Other; }
  80. break
  81. fi
  82. done
  83. # Apache
  84. while :; do echo
  85. echo 'Please select Apache server:'
  86. echo -e "\t${CMSG}1${CEND}. Install Apache-2.4"
  87. echo -e "\t${CMSG}2${CEND}. Install Apache-2.2"
  88. echo -e "\t${CMSG}3${CEND}. Do not install"
  89. read -p "Please input a number:(Default 3 press Enter) " apache_option
  90. [ -z "${apache_option}" ] && apache_option=3
  91. if [[ ! ${apache_option} =~ ^[1-3]$ ]]; then
  92. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  93. else
  94. [ "${apache_option}" != '3' -a -e "$apache_install_dir/conf/httpd.conf" ] && { echo "${CWARNING}Aapche already installed! ${CEND}"; apache_option=Other; }
  95. break
  96. fi
  97. done
  98. # Tomcat
  99. while :; do echo
  100. echo 'Please select tomcat server:'
  101. echo -e "\t${CMSG}1${CEND}. Install Tomcat-8"
  102. echo -e "\t${CMSG}2${CEND}. Install Tomcat-7"
  103. echo -e "\t${CMSG}3${CEND}. Install Tomcat-6"
  104. echo -e "\t${CMSG}4${CEND}. Do not install"
  105. read -p "Please input a number:(Default 4 press Enter) " tomcat_option
  106. [ -z "${tomcat_option}" ] && tomcat_option=4
  107. if [[ ! ${tomcat_option} =~ ^[1-4]$ ]]; then
  108. echo "${CWARNING}input error! Please only input number 1~4${CEND}"
  109. else
  110. [ "${tomcat_option}" != '4' -a -e "$tomcat_install_dir/conf/server.xml" ] && { echo "${CWARNING}Tomcat already installed! ${CEND}" ; tomcat_option=Other; }
  111. if [ "${tomcat_option}" == '1' ]; then
  112. while :; do echo
  113. echo 'Please select JDK version:'
  114. echo -e "\t${CMSG}1${CEND}. Install JDK-1.8"
  115. echo -e "\t${CMSG}2${CEND}. Install JDK-1.7"
  116. read -p "Please input a number:(Default 2 press Enter) " jdk_option
  117. [ -z "${jdk_option}" ] && jdk_option=2
  118. if [[ ! ${jdk_option} =~ ^[1-2]$ ]]; then
  119. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  120. else
  121. break
  122. fi
  123. done
  124. elif [ "${tomcat_option}" == '2' ]; then
  125. while :; do echo
  126. echo 'Please select JDK version:'
  127. echo -e "\t${CMSG}1${CEND}. Install JDK-1.8"
  128. echo -e "\t${CMSG}2${CEND}. Install JDK-1.7"
  129. echo -e "\t${CMSG}3${CEND}. Install JDK-1.6"
  130. read -p "Please input a number:(Default 2 press Enter) " jdk_option
  131. [ -z "${jdk_option}" ] && jdk_option=2
  132. if [[ ! ${jdk_option} =~ ^[1-3]$ ]]; then
  133. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  134. else
  135. break
  136. fi
  137. done
  138. elif [ "${tomcat_option}" == '3' ]; then
  139. while :; do echo
  140. echo 'Please select JDK version:'
  141. echo -e "\t${CMSG}2${CEND}. Install JDK-1.7"
  142. echo -e "\t${CMSG}3${CEND}. Install JDK-1.6"
  143. read -p "Please input a number:(Default 2 press Enter) " jdk_option
  144. [ -z "${jdk_option}" ] && jdk_option=2
  145. if [[ ! ${jdk_option} =~ ^[2-3]$ ]]; then
  146. echo "${CWARNING}input error! Please only input number 2~3${CEND}"
  147. else
  148. break
  149. fi
  150. done
  151. fi
  152. break
  153. fi
  154. done
  155. fi
  156. break
  157. fi
  158. done
  159. # choice database
  160. while :; do echo
  161. read -p "Do you want to install Database? [y/n]: " db_yn
  162. if [[ ! ${db_yn} =~ ^[y,n]$ ]]; then
  163. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  164. else
  165. if [ "${db_yn}" == 'y' ]; then
  166. while :; do echo
  167. echo 'Please select a version of the Database:'
  168. echo -e "\t${CMSG} 1${CEND}. Install MySQL-5.7"
  169. echo -e "\t${CMSG} 2${CEND}. Install MySQL-5.6"
  170. echo -e "\t${CMSG} 3${CEND}. Install MySQL-5.5"
  171. echo -e "\t${CMSG} 4${CEND}. Install MariaDB-10.2"
  172. echo -e "\t${CMSG} 5${CEND}. Install MariaDB-10.1"
  173. echo -e "\t${CMSG} 6${CEND}. Install MariaDB-10.0"
  174. echo -e "\t${CMSG} 7${CEND}. Install MariaDB-5.5"
  175. echo -e "\t${CMSG} 8${CEND}. Install Percona-5.7"
  176. echo -e "\t${CMSG} 9${CEND}. Install Percona-5.6"
  177. echo -e "\t${CMSG}10${CEND}. Install Percona-5.5"
  178. echo -e "\t${CMSG}11${CEND}. Install AliSQL-5.6"
  179. echo -e "\t${CMSG}12${CEND}. Install PostgreSQL"
  180. echo -e "\t${CMSG}13${CEND}. Install MongoDB"
  181. read -p "Please input a number:(Default 2 press Enter) " db_option
  182. [ -z "${db_option}" ] && db_option=2
  183. [ "${db_option}" == '13' -a "$OS_BIT" == '32' ] && { echo "${CWARNING}By not supporting 32-bit! ${CEND}"; continue; }
  184. if [ ${db_option} -ge 1 >/dev/null 2>&1 -a ${db_option} -le 13 >/dev/null 2>&1 ]; then
  185. if [ "${db_option}" == '12' ]; then
  186. [ -e "${pgsql_install_dir}/bin/psql" ] && { echo "${CWARNING}PostgreSQL already installed! ${CEND}"; db_yn=Other; break; }
  187. elif [ "${db_option}" == '13' ]; then
  188. [ -e "${mongo_install_dir}/bin/mongo" ] && { echo "${CWARNING}MongoDB already installed! ${CEND}"; db_yn=Other; break; }
  189. else
  190. [ -d "${db_install_dir}/support-files" ] && { echo "${CWARNING}MySQL already installed! ${CEND}"; db_yn=Other; break; }
  191. fi
  192. while :; do
  193. if [ "${db_option}" == '12' ]; then
  194. read -p "Please input the postgres password of database: " dbrootpwd
  195. else
  196. read -p "Please input the root password of database: " dbrootpwd
  197. fi
  198. [ -n "`echo $dbrootpwd | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and & ${CEND}"; continue; }
  199. if (( ${#dbrootpwd} >= 5 )); then
  200. if [ "${db_option}" == '12' ]; then
  201. sed -i "s+^dbpostgrespwd.*+dbpostgrespwd='$dbrootpwd'+" ./options.conf
  202. dbpostgrespwd="$dbrootpwd"
  203. elif [ "${db_option}" == '13' ]; then
  204. sed -i "s+^dbmongopwd.*+dbmongopwd='$dbrootpwd'+" ./options.conf
  205. dbmongopwd="$dbrootpwd"
  206. else
  207. sed -i "s+^dbrootpwd.*+dbrootpwd='$dbrootpwd'+" ./options.conf
  208. fi
  209. break
  210. else
  211. echo "${CWARNING}password least 5 characters! ${CEND}"
  212. fi
  213. done
  214. # choose install methods
  215. if [ ${db_option} -ge 1 >/dev/null 2>&1 -a ${db_option} -le 10 >/dev/null 2>&1 ]; then
  216. while :; do echo
  217. echo "Please choose installation of the database:"
  218. echo -e "\t${CMSG}1${CEND}. Install database from binary package."
  219. echo -e "\t${CMSG}2${CEND}. Install database from source package."
  220. read -p "Please input a number:(Default 1 press Enter) " dbinstallmethod
  221. [ -z "${dbinstallmethod}" ] && dbinstallmethod=1
  222. if [[ ! ${dbinstallmethod} =~ ^[1-2]$ ]]; then
  223. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  224. else
  225. break
  226. fi
  227. done
  228. fi
  229. break
  230. else
  231. echo "${CWARNING}input error! Please only input number 1~13${CEND}"
  232. fi
  233. done
  234. fi
  235. break
  236. fi
  237. done
  238. # check PHP
  239. while :; do echo
  240. read -p "Do you want to install PHP? [y/n]: " php_yn
  241. if [[ ! ${php_yn} =~ ^[y,n]$ ]]; then
  242. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  243. else
  244. if [ "${php_yn}" == 'y' ]; then
  245. [ -e "${php_install_dir}/bin/phpize" ] && { echo "${CWARNING}PHP already installed! ${CEND}"; php_yn=Other; break; }
  246. while :; do echo
  247. echo 'Please select a version of the PHP:'
  248. echo -e "\t${CMSG}1${CEND}. Install php-5.3"
  249. echo -e "\t${CMSG}2${CEND}. Install php-5.4"
  250. echo -e "\t${CMSG}3${CEND}. Install php-5.5"
  251. echo -e "\t${CMSG}4${CEND}. Install php-5.6"
  252. echo -e "\t${CMSG}5${CEND}. Install php-7.0"
  253. echo -e "\t${CMSG}6${CEND}. Install php-7.1"
  254. echo -e "\t${CMSG}7${CEND}. Install php-7.2"
  255. read -p "Please input a number:(Default 5 press Enter) " php_option
  256. [ -z "${php_option}" ] && php_option=5
  257. if [[ ! ${php_option} =~ ^[1-7]$ ]]; then
  258. echo "${CWARNING}input error! Please only input number 1~7${CEND}"
  259. else
  260. while :; do echo
  261. read -p "Do you want to install opcode cache of the PHP? [y/n]: " phpcache_yn
  262. if [[ ! ${phpcache_yn} =~ ^[y,n]$ ]]; then
  263. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  264. else
  265. if [ "${phpcache_yn}" == 'y' ]; then
  266. if [ ${php_option} == 1 ]; then
  267. while :; do
  268. echo 'Please select a opcode cache of the PHP:'
  269. echo -e "\t${CMSG}1${CEND}. Install Zend OPcache"
  270. echo -e "\t${CMSG}2${CEND}. Install XCache"
  271. echo -e "\t${CMSG}3${CEND}. Install APCU"
  272. echo -e "\t${CMSG}4${CEND}. Install eAccelerator-0.9"
  273. read -p "Please input a number:(Default 1 press Enter) " phpcache_option
  274. [ -z "${phpcache_option}" ] && phpcache_option=1
  275. if [[ ! ${phpcache_option} =~ ^[1-4]$ ]]; then
  276. echo "${CWARNING}input error! Please only input number 1~4${CEND}"
  277. else
  278. break
  279. fi
  280. done
  281. fi
  282. if [ ${php_option} == 2 ]; then
  283. while :; do
  284. echo 'Please select a opcode cache of the PHP:'
  285. echo -e "\t${CMSG}1${CEND}. Install Zend OPcache"
  286. echo -e "\t${CMSG}2${CEND}. Install XCache"
  287. echo -e "\t${CMSG}3${CEND}. Install APCU"
  288. echo -e "\t${CMSG}4${CEND}. Install eAccelerator-1.0-dev"
  289. read -p "Please input a number:(Default 1 press Enter) " phpcache_option
  290. [ -z "${phpcache_option}" ] && phpcache_option=1
  291. if [[ ! ${phpcache_option} =~ ^[1-4]$ ]]; then
  292. echo "${CWARNING}input error! Please only input number 1~4${CEND}"
  293. else
  294. break
  295. fi
  296. done
  297. fi
  298. if [ ${php_option} == 3 ]; then
  299. while :; do
  300. echo 'Please select a opcode cache of the PHP:'
  301. echo -e "\t${CMSG}1${CEND}. Install Zend OPcache"
  302. echo -e "\t${CMSG}2${CEND}. Install XCache"
  303. echo -e "\t${CMSG}3${CEND}. Install APCU"
  304. read -p "Please input a number:(Default 1 press Enter) " phpcache_option
  305. [ -z "${phpcache_option}" ] && phpcache_option=1
  306. if [[ ! ${phpcache_option} =~ ^[1-3]$ ]]; then
  307. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  308. else
  309. break
  310. fi
  311. done
  312. fi
  313. if [ ${php_option} == 4 ]; then
  314. while :; do
  315. echo 'Please select a opcode cache of the PHP:'
  316. echo -e "\t${CMSG}1${CEND}. Install Zend OPcache"
  317. echo -e "\t${CMSG}2${CEND}. Install XCache"
  318. echo -e "\t${CMSG}3${CEND}. Install APCU"
  319. read -p "Please input a number:(Default 1 press Enter) " phpcache_option
  320. [ -z "${phpcache_option}" ] && phpcache_option=1
  321. if [[ ! ${phpcache_option} =~ ^[1-3]$ ]]; then
  322. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  323. else
  324. break
  325. fi
  326. done
  327. fi
  328. if [[ ${php_option} =~ ^[5-6]$ ]]; then
  329. while :; do
  330. echo 'Please select a opcode cache of the PHP:'
  331. echo -e "\t${CMSG}1${CEND}. Install Zend OPcache"
  332. echo -e "\t${CMSG}3${CEND}. Install APCU"
  333. read -p "Please input a number:(Default 1 press Enter) " phpcache_option
  334. [ -z "${phpcache_option}" ] && phpcache_option=1
  335. if [[ ! ${phpcache_option} =~ ^[1,3]$ ]]; then
  336. echo "${CWARNING}input error! Please only input number 1,3${CEND}"
  337. else
  338. break
  339. fi
  340. done
  341. fi
  342. [ ${php_option} == 7 ] && phpcache_option=1
  343. fi
  344. break
  345. fi
  346. done
  347. if [ "${phpcache_option}" == '2' ]; then
  348. while :; do
  349. read -p "Please input xcache admin password: " xcache_admin_pass
  350. (( ${#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}"
  351. done
  352. fi
  353. if [[ ${php_option} =~ ^[1-4]$ ]] && [ "${phpcache_option}" != '1' -a "${armplatform}" != "y" ]; then
  354. while :; do echo
  355. read -p "Do you want to install ZendGuardLoader? [y/n]: " zendguardloader_yn
  356. if [[ ! ${zendguardloader_yn} =~ ^[y,n]$ ]]; then
  357. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  358. else
  359. break
  360. fi
  361. done
  362. fi
  363. # ionCube
  364. if [ "${TARGET_ARCH}" != "arm64" ]; then
  365. while :; do echo
  366. read -p "Do you want to install ionCube? [y/n]: " ioncube_yn
  367. if [[ ! ${ioncube_yn} =~ ^[y,n]$ ]]; then
  368. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  369. else
  370. break
  371. fi
  372. done
  373. fi
  374. # ImageMagick or GraphicsMagick
  375. while :; do echo
  376. read -p "Do you want to install ImageMagick or GraphicsMagick? [y/n]: " magick_yn
  377. if [[ ! ${magick_yn} =~ ^[y,n]$ ]]; then
  378. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  379. else
  380. break
  381. fi
  382. done
  383. if [ "${magick_yn}" == 'y' ]; then
  384. while :; do
  385. echo 'Please select ImageMagick or GraphicsMagick:'
  386. echo -e "\t${CMSG}1${CEND}. Install ImageMagick"
  387. echo -e "\t${CMSG}2${CEND}. Install GraphicsMagick"
  388. read -p "Please input a number:(Default 1 press Enter) " magick_option
  389. [ -z "${magick_option}" ] && magick_option=1
  390. if [[ ! ${magick_option} =~ ^[1-2]$ ]]; then
  391. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  392. else
  393. break
  394. fi
  395. done
  396. fi
  397. break
  398. fi
  399. done
  400. fi
  401. break
  402. fi
  403. done
  404. # check Pureftpd
  405. while :; do echo
  406. read -p "Do you want to install Pure-FTPd? [y/n]: " ftp_yn
  407. if [[ ! ${ftp_yn} =~ ^[y,n]$ ]]; then
  408. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  409. else
  410. [ "${ftp_yn}" == 'y' -a -e "${pureftpd_install_dir}/sbin/pure-ftpwho" ] && { echo "${CWARNING}Pure-FTPd already installed! ${CEND}"; ftp_yn=Other; }
  411. break
  412. fi
  413. done
  414. # check phpMyAdmin
  415. if [[ ${php_option} =~ ^[1-7]$ ]] || [ -e "${php_install_dir}/bin/phpize" ]; then
  416. while :; do echo
  417. read -p "Do you want to install phpMyAdmin? [y/n]: " phpmyadmin_yn
  418. if [[ ! ${phpmyadmin_yn} =~ ^[y,n]$ ]]; then
  419. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  420. else
  421. [ "${phpmyadmin_yn}" == 'y' -a -d "${wwwroot_dir}/default/phpMyAdmin" ] && { echo "${CWARNING}phpMyAdmin already installed! ${CEND}"; phpmyadmin_yn=Other; }
  422. break
  423. fi
  424. done
  425. fi
  426. # check redis
  427. while :; do echo
  428. read -p "Do you want to install redis? [y/n]: " redis_yn
  429. if [[ ! ${redis_yn} =~ ^[y,n]$ ]]; then
  430. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  431. else
  432. break
  433. fi
  434. done
  435. # check memcached
  436. while :; do echo
  437. read -p "Do you want to install memcached? [y/n]: " memcached_yn
  438. if [[ ! ${memcached_yn} =~ ^[y,n]$ ]]; then
  439. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  440. else
  441. break
  442. fi
  443. done
  444. while :; do echo
  445. read -p "Do you want to install HHVM? [y/n]: " hhvm_yn
  446. if [[ ! ${hhvm_yn} =~ ^[y,n]$ ]]; then
  447. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  448. else
  449. if [ "${hhvm_yn}" == 'y' ]; then
  450. [ -e "/usr/bin/hhvm" ] && { echo "${CWARNING}HHVM already installed! ${CEND}"; hhvm_yn=Other; break; }
  451. if [ "$OS" == 'CentOS' -a "$OS_BIT" == '64' ] && [ -n "`grep -E ' 7\.| 6\.[5-9]' /etc/redhat-release`" ]; then
  452. break
  453. else
  454. echo
  455. echo "${CWARNING}HHVM only support CentOS6.5+ 64bit, CentOS7 64bit! ${CEND}"
  456. echo "Press Ctrl+c to cancel or Press any key to continue..."
  457. char=`get_char`
  458. hhvm_yn=Other
  459. fi
  460. fi
  461. break
  462. fi
  463. done
  464. # get the IP information
  465. IPADDR=`./include/get_ipaddr.py`
  466. PUBLIC_IPADDR=`./include/get_public_ipaddr.py`
  467. IPADDR_COUNTRY_ISP=`./include/get_ipaddr_state.py $PUBLIC_IPADDR`
  468. IPADDR_COUNTRY=`echo $IPADDR_COUNTRY_ISP | awk '{print $1}'`
  469. # Check download source packages
  470. . ./include/check_download.sh
  471. downloadDepsSrc=1
  472. checkDownload 2>&1 | tee -a ${oneinstack_dir}/install.log
  473. # del openssl for jcloud
  474. [ -e "/usr/local/bin/openssl" ] && rm -rf /usr/local/bin/openssl
  475. [ -e "/usr/local/include/openssl" ] && rm -rf /usr/local/include/openssl
  476. # Check binary dependencies packages
  477. . ./include/check_sw.sh
  478. case "${OS}" in
  479. "CentOS")
  480. installDepsCentOS 2>&1 | tee ${oneinstack_dir}/install.log
  481. ;;
  482. "Debian")
  483. installDepsDebian 2>&1 | tee ${oneinstack_dir}/install.log
  484. ;;
  485. "Ubuntu")
  486. installDepsUbuntu 2>&1 | tee ${oneinstack_dir}/install.log
  487. ;;
  488. esac
  489. # init
  490. startTime=`date +%s`
  491. . ./include/memory.sh
  492. case "${OS}" in
  493. "CentOS")
  494. . include/init_CentOS.sh 2>&1 | tee -a ${oneinstack_dir}/install.log
  495. [ -n "$(gcc --version | head -n1 | grep '4\.1\.')" ] && export CC="gcc44" CXX="g++44"
  496. ;;
  497. "Debian")
  498. . include/init_Debian.sh 2>&1 | tee -a ${oneinstack_dir}/install.log
  499. ;;
  500. "Ubuntu")
  501. . include/init_Ubuntu.sh 2>&1 | tee -a ${oneinstack_dir}/install.log
  502. ;;
  503. esac
  504. # Install dependencies from source package
  505. installDepsBySrc 2>&1 | tee -a ${oneinstack_dir}/install.log
  506. # Jemalloc
  507. if [[ ${nginx_option} =~ ^[1-3]$ ]] || [ "${db_yn}" == 'y' ]; then
  508. . include/jemalloc.sh
  509. Install_Jemalloc | tee -a ${oneinstack_dir}/install.log
  510. fi
  511. # openSSL
  512. . ./include/openssl.sh
  513. if [[ ${tomcat_option} =~ ^[1-3]$ ]] || [[ ${apache_option} =~ ^[1-2]$ ]] || [[ ${php_option} =~ ^[1-7]$ ]]; then
  514. Install_openSSL102 | tee -a ${oneinstack_dir}/install.log
  515. fi
  516. # Database
  517. case "${db_option}" in
  518. 1)
  519. if [ "${dbinstallmethod}" == "2" ]; then
  520. . include/boost.sh
  521. installBoost 2>&1 | tee -a ${oneinstack_dir}/install.log
  522. fi
  523. . include/mysql-5.7.sh
  524. Install_MySQL57 2>&1 | tee -a ${oneinstack_dir}/install.log
  525. ;;
  526. 2)
  527. . include/mysql-5.6.sh
  528. Install_MySQL56 2>&1 | tee -a ${oneinstack_dir}/install.log
  529. ;;
  530. 3)
  531. . include/mysql-5.5.sh
  532. Install_MySQL55 2>&1 | tee -a ${oneinstack_dir}/install.log
  533. ;;
  534. 4)
  535. if [ "${dbinstallmethod}" == "2" ]; then
  536. . include/boost.sh
  537. installBoost 2>&1 | tee -a ${oneinstack_dir}/install.log
  538. fi
  539. . include/mariadb-10.2.sh
  540. Install_MariaDB102 2>&1 | tee -a ${oneinstack_dir}/install.log
  541. ;;
  542. 5)
  543. if [ "${dbinstallmethod}" == "2" ]; then
  544. . include/boost.sh
  545. installBoost 2>&1 | tee -a ${oneinstack_dir}/install.log
  546. fi
  547. . include/mariadb-10.1.sh
  548. Install_MariaDB101 2>&1 | tee -a ${oneinstack_dir}/install.log
  549. ;;
  550. 6)
  551. . include/mariadb-10.0.sh
  552. Install_MariaDB100 2>&1 | tee -a ${oneinstack_dir}/install.log
  553. ;;
  554. 7)
  555. . include/mariadb-5.5.sh
  556. Install_MariaDB55 2>&1 | tee -a ${oneinstack_dir}/install.log
  557. ;;
  558. 8)
  559. if [ "${dbinstallmethod}" == "2" ]; then
  560. . include/boost.sh
  561. installBoost 2>&1 | tee -a ${oneinstack_dir}/install.log
  562. fi
  563. . include/percona-5.7.sh
  564. Install_Percona57 2>&1 | tee -a ${oneinstack_dir}/install.log
  565. ;;
  566. 9)
  567. . include/percona-5.6.sh
  568. Install_Percona56 2>&1 | tee -a ${oneinstack_dir}/install.log
  569. ;;
  570. 10)
  571. . include/percona-5.5.sh
  572. Install_Percona55 2>&1 | tee -a ${oneinstack_dir}/install.log
  573. ;;
  574. 11)
  575. . include/alisql-5.6.sh
  576. Install_AliSQL56 2>&1 | tee -a ${oneinstack_dir}/install.log
  577. ;;
  578. 12)
  579. . include/postgresql.sh
  580. Install_PostgreSQL 2>&1 | tee -a ${oneinstack_dir}/install.log
  581. ;;
  582. 13)
  583. . include/mongodb.sh
  584. Install_MongoDB 2>&1 | tee -a ${oneinstack_dir}/install.log
  585. ;;
  586. esac
  587. # Apache
  588. if [ "${apache_option}" == '1' ]; then
  589. . include/apache-2.4.sh
  590. Install_Apache24 2>&1 | tee -a ${oneinstack_dir}/install.log
  591. elif [ "${apache_option}" == '2' ]; then
  592. . include/apache-2.2.sh
  593. Install_Apache22 2>&1 | tee -a ${oneinstack_dir}/install.log
  594. fi
  595. # PHP
  596. case "${php_option}" in
  597. 1)
  598. . include/php-5.3.sh
  599. Install_PHP53 2>&1 | tee -a ${oneinstack_dir}/install.log
  600. ;;
  601. 2)
  602. . include/php-5.4.sh
  603. Install_PHP54 2>&1 | tee -a ${oneinstack_dir}/install.log
  604. ;;
  605. 3)
  606. . include/php-5.5.sh
  607. Install_PHP55 2>&1 | tee -a ${oneinstack_dir}/install.log
  608. ;;
  609. 4)
  610. . include/php-5.6.sh
  611. Install_PHP56 2>&1 | tee -a ${oneinstack_dir}/install.log
  612. ;;
  613. 5)
  614. . include/php-7.0.sh
  615. Install_PHP70 2>&1 | tee -a ${oneinstack_dir}/install.log
  616. ;;
  617. 6)
  618. . include/php-7.1.sh
  619. Install_PHP71 2>&1 | tee -a ${oneinstack_dir}/install.log
  620. ;;
  621. 7)
  622. . include/php-7.2.sh
  623. Install_PHP72 2>&1 | tee -a ${oneinstack_dir}/install.log
  624. ;;
  625. esac
  626. # pecl_pgsql
  627. if [ "${db_option}" == '12' -a -e "${php_install_dir}/bin/phpize" ]; then
  628. . include/pecl_pgsql.sh
  629. Install_pecl-pgsql 2>&1 | tee -a ${oneinstack_dir}/install.log
  630. fi
  631. # pecl_mongodb
  632. if [ "${db_option}" == '13' -a -e "${php_install_dir}/bin/phpize" ]; then
  633. . include/pecl_mongodb.sh
  634. Install_pecl-mongodb 2>&1 | tee -a ${oneinstack_dir}/install.log
  635. fi
  636. # ImageMagick or GraphicsMagick
  637. if [ "${magick_option}" == '1' ]; then
  638. . include/ImageMagick.sh
  639. [ ! -d "/usr/local/imagemagick" ] && Install_ImageMagick 2>&1 | tee -a ${oneinstack_dir}/install.log
  640. [ ! -e "`${php_install_dir}/bin/php-config --extension-dir`/imagick.so" ] && Install_php-imagick 2>&1 | tee -a ${oneinstack_dir}/install.log
  641. elif [ "${magick_option}" == '2' ]; then
  642. . include/GraphicsMagick.sh
  643. [ ! -d "/usr/local/graphicsmagick" ] && Install_GraphicsMagick 2>&1 | tee -a ${oneinstack_dir}/install.log
  644. [ ! -e "`${php_install_dir}/bin/php-config --extension-dir`/gmagick.so" ] && Install_php-gmagick 2>&1 | tee -a ${oneinstack_dir}/install.log
  645. fi
  646. # ionCube
  647. if [ "${ioncube_yn}" == 'y' ]; then
  648. . include/ioncube.sh
  649. Install_ionCube 2>&1 | tee -a ${oneinstack_dir}/install.log
  650. fi
  651. # PHP opcode cache
  652. case "${phpcache_option}" in
  653. 1)
  654. if [[ "${php_option}" =~ ^[1,2]$ ]]; then
  655. . include/zendopcache.sh
  656. Install_ZendOPcache 2>&1 | tee -a ${oneinstack_dir}/install.log
  657. fi
  658. ;;
  659. 2)
  660. . include/xcache.sh
  661. Install_XCache 2>&1 | tee -a ${oneinstack_dir}/install.log
  662. ;;
  663. 3)
  664. . include/apcu.sh
  665. Install_APCU 2>&1 | tee -a ${oneinstack_dir}/install.log
  666. ;;
  667. 4)
  668. if [[ "${php_option}" =~ ^[1,2]$ ]]; then
  669. . include/eaccelerator.sh
  670. Install_eAccelerator 2>&1 | tee -a ${oneinstack_dir}/install.log
  671. fi
  672. ;;
  673. esac
  674. # ZendGuardLoader (php <= 5.6)
  675. if [ "${zendguardloader_yn}" == 'y' ]; then
  676. . include/ZendGuardLoader.sh
  677. Install_ZendGuardLoader 2>&1 | tee -a ${oneinstack_dir}/install.log
  678. fi
  679. # Web server
  680. case "${nginx_option}" in
  681. 1)
  682. . include/nginx.sh
  683. Install_Nginx 2>&1 | tee -a ${oneinstack_dir}/install.log
  684. ;;
  685. 2)
  686. . include/tengine.sh
  687. Install_Tengine 2>&1 | tee -a ${oneinstack_dir}/install.log
  688. ;;
  689. 3)
  690. . include/openresty.sh
  691. Install_OpenResty 2>&1 | tee -a ${oneinstack_dir}/install.log
  692. ;;
  693. esac
  694. # JDK
  695. case "${jdk_option}" in
  696. 1)
  697. . include/jdk-1.8.sh
  698. Install-JDK18 2>&1 | tee -a ${oneinstack_dir}/install.log
  699. ;;
  700. 2)
  701. . include/jdk-1.7.sh
  702. Install-JDK17 2>&1 | tee -a ${oneinstack_dir}/install.log
  703. ;;
  704. 3)
  705. . include/jdk-1.6.sh
  706. Install-JDK16 2>&1 | tee -a ${oneinstack_dir}/install.log
  707. ;;
  708. esac
  709. case "${tomcat_option}" in
  710. 1)
  711. . include/tomcat-8.sh
  712. Install_Tomcat8 2>&1 | tee -a ${oneinstack_dir}/install.log
  713. ;;
  714. 2)
  715. . include/tomcat-7.sh
  716. Install_Tomcat7 2>&1 | tee -a ${oneinstack_dir}/install.log
  717. ;;
  718. 3)
  719. . include/tomcat-6.sh
  720. Install_Tomcat6 2>&1 | tee -a ${oneinstack_dir}/install.log
  721. ;;
  722. esac
  723. # Pure-FTPd
  724. if [ "${ftp_yn}" == 'y' ]; then
  725. . include/pureftpd.sh
  726. Install_PureFTPd 2>&1 | tee -a ${oneinstack_dir}/install.log
  727. fi
  728. # phpMyAdmin
  729. if [ "${phpmyadmin_yn}" == 'y' ]; then
  730. . include/phpmyadmin.sh
  731. Install_phpMyAdmin 2>&1 | tee -a ${oneinstack_dir}/install.log
  732. fi
  733. # redis
  734. if [ "${redis_yn}" == 'y' ]; then
  735. . include/redis.sh
  736. [ ! -d "${redis_install_dir}" ] && Install_redis-server 2>&1 | tee -a ${oneinstack_dir}/install.log
  737. [ -e "${php_install_dir}/bin/phpize" ] && [ ! -e "$(${php_install_dir}/bin/php-config --extension-dir)/redis.so" ] && Install_php-redis 2>&1 | tee -a ${oneinstack_dir}/install.log
  738. fi
  739. # memcached
  740. if [ "${memcached_yn}" == 'y' ]; then
  741. . include/memcached.sh
  742. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached 2>&1 | tee -a ${oneinstack_dir}/install.log
  743. [ -e "${php_install_dir}/bin/phpize" ] && [ ! -e "$(${php_install_dir}/bin/php-config --extension-dir)/memcache.so" ] && Install_php-memcache 2>&1 | tee -a ${oneinstack_dir}/install.log
  744. [ -e "${php_install_dir}/bin/phpize" ] && [ ! -e "$(${php_install_dir}/bin/php-config --extension-dir)/memcached.so" ] && Install_php-memcached 2>&1 | tee -a ${oneinstack_dir}/install.log
  745. fi
  746. # index example
  747. if [ ! -e "${wwwroot_dir}/default/index.html" -a "${web_yn}" == 'y' ]; then
  748. . include/demo.sh
  749. DEMO 2>&1 | tee -a ${oneinstack_dir}/install.log
  750. fi
  751. # get web_install_dir and db_install_dir
  752. . include/check_dir.sh
  753. # HHVM
  754. if [ "${hhvm_yn}" == 'y' ]; then
  755. . include/hhvm_CentOS.sh
  756. Install_hhvm_CentOS 2>&1 | tee -a ${oneinstack_dir}/install.log
  757. fi
  758. # Starting DB
  759. [ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}
  760. [ -d "${db_install_dir}/support-files" -a -z "$(ps -ef | grep -v grep | grep mysql)" ] && /etc/init.d/mysqld start
  761. endTime=`date +%s`
  762. ((installTime=($endTime-$startTime)/60))
  763. echo "####################Congratulations########################"
  764. echo "Total OneinStack Install Time: ${CQUESTION}${installTime}${CEND} minutes"
  765. [ "${web_yn}" == 'y' -a "${nginx_option}" != '4' -a "${apache_option}" == '3' ] && echo -e "\n$(printf "%-32s" "Nginx install dir":)${CMSG}${web_install_dir}${CEND}"
  766. [ "${web_yn}" == 'y' -a "${nginx_option}" != '4' -a "${apache_option}" != '3' ] && echo -e "\n$(printf "%-32s" "Nginx install dir":)${CMSG}${web_install_dir}${CEND}\n$(printf "%-32s" "Apache install dir":)${CMSG}${apache_install_dir}${CEND}"
  767. [ "${web_yn}" == 'y' -a "${nginx_option}" == '4' -a "${apache_option}" != '3' ] && echo -e "\n$(printf "%-32s" "Apache install dir":)${CMSG}${apache_install_dir}${CEND}"
  768. [[ "${tomcat_option}" =~ ^[1,2]$ ]] && echo -e "\n$(printf "%-32s" "Tomcat install dir":)${CMSG}${tomcat_install_dir}${CEND}"
  769. [[ "${db_option}" =~ ^[1-9]$|^1[0-1]$ ]] && echo -e "\n$(printf "%-32s" "Database install dir:")${CMSG}${db_install_dir}${CEND}"
  770. [[ "${db_option}" =~ ^[1-9]$|^1[0-1]$ ]] && echo "$(printf "%-32s" "Database data dir:")${CMSG}${db_data_dir}${CEND}"
  771. [[ "${db_option}" =~ ^[1-9]$|^1[0-1]$ ]] && echo "$(printf "%-32s" "Database user:")${CMSG}root${CEND}"
  772. [[ "${db_option}" =~ ^[1-9]$|^1[0-1]$ ]] && echo "$(printf "%-32s" "Database password:")${CMSG}${dbrootpwd}${CEND}"
  773. [ "${db_option}" == '12' ] && echo -e "\n$(printf "%-32s" "PostgreSQL install dir:")${CMSG}${pgsql_install_dir}${CEND}"
  774. [ "${db_option}" == '12' ] && echo "$(printf "%-32s" "PostgreSQL data dir:")${CMSG}${pgsql_data_dir}${CEND}"
  775. [ "${db_option}" == '12' ] && echo "$(printf "%-32s" "PostgreSQL user:")${CMSG}postgres${CEND}"
  776. [ "${db_option}" == '12' ] && echo "$(printf "%-32s" "postgres password:")${CMSG}${dbpostgrespwd}${CEND}"
  777. [ "${db_option}" == '13' ] && echo -e "\n$(printf "%-32s" "MongoDB install dir:")${CMSG}${mongo_install_dir}${CEND}"
  778. [ "${db_option}" == '13' ] && echo "$(printf "%-32s" "MongoDB data dir:")${CMSG}${mongo_data_dir}${CEND}"
  779. [ "${db_option}" == '13' ] && echo "$(printf "%-32s" "MongoDB user:")${CMSG}root${CEND}"
  780. [ "${db_option}" == '13' ] && echo "$(printf "%-32s" "MongoDB password:")${CMSG}${dbmongopwd}${CEND}"
  781. [ "${php_yn}" == 'y' ] && echo -e "\n$(printf "%-32s" "PHP install dir:")${CMSG}${php_install_dir}${CEND}"
  782. [ "${phpcache_option}" == '1' ] && echo "$(printf "%-32s" "Opcache Control Panel URL:")${CMSG}http://${IPADDR}/ocp.php${CEND}"
  783. [ "${phpcache_option}" == '2' ] && echo "$(printf "%-32s" "xcache Control Panel URL:")${CMSG}http://${IPADDR}/xcache${CEND}"
  784. [ "${phpcache_option}" == '2' ] && echo "$(printf "%-32s" "xcache user:")${CMSG}admin${CEND}"
  785. [ "${phpcache_option}" == '2' ] && echo "$(printf "%-32s" "xcache password:")${CMSG}${xcache_admin_pass}${CEND}"
  786. [ "${phpcache_option}" == '3' ] && echo "$(printf "%-32s" "APC Control Panel URL:")${CMSG}http://${IPADDR}/apc.php${CEND}"
  787. [ "${phpcache_option}" == '4' ] && echo "$(printf "%-32s" "eAccelerator Control Panel URL:")${CMSG}http://${IPADDR}/control.php${CEND}"
  788. [ "${phpcache_option}" == '4' ] && echo "$(printf "%-32s" "eAccelerator user:")${CMSG}admin${CEND}"
  789. [ "${phpcache_option}" == '4' ] && echo "$(printf "%-32s" "eAccelerator password:")${CMSG}eAccelerator${CEND}"
  790. [ "${ftp_yn}" == 'y' ] && echo -e "\n$(printf "%-32s" "Pure-FTPd install dir:")${CMSG}${pureftpd_install_dir}${CEND}"
  791. [ "${ftp_yn}" == 'y' ] && echo "$(printf "%-32s" "Create FTP virtual script:")${CMSG}./pureftpd_vhost.sh${CEND}"
  792. [ "${phpmyadmin_yn}" == 'y' ] && echo -e "\n$(printf "%-32s" "phpMyAdmin dir:")${CMSG}${wwwroot_dir}/default/phpMyAdmin${CEND}"
  793. [ "${phpmyadmin_yn}" == 'y' ] && echo "$(printf "%-32s" "phpMyAdmin Control Panel URL:")${CMSG}http://${IPADDR}/phpMyAdmin${CEND}"
  794. [ "${redis_yn}" == 'y' ] && echo -e "\n$(printf "%-32s" "redis install dir:")${CMSG}${redis_install_dir}${CEND}"
  795. [ "${memcached_yn}" == 'y' ] && echo -e "\n$(printf "%-32s" "memcached install dir:")${CMSG}${memcached_install_dir}${CEND}"
  796. [ "${web_yn}" == 'y' ] && echo -e "\n$(printf "%-32s" "Index URL:")${CMSG}http://${IPADDR}/${CEND}"
  797. while :; do echo
  798. echo "${CMSG}Please restart the server and see if the services start up fine.${CEND}"
  799. read -p "Do you want to restart OS ? [y/n]: " restart_yn
  800. if [[ ! "${restart_yn}" =~ ^[y,n]$ ]]; then
  801. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  802. else
  803. break
  804. fi
  805. done
  806. [ "${restart_yn}" == 'y' ] && reboot