vst-install-rhel.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. #!/bin/bash
  2. # Vesta RHEL/CentOS installer v.03
  3. #----------------------------------------------------------#
  4. # Variables&Functions #
  5. #----------------------------------------------------------#
  6. export PATH=$PATH:/sbin
  7. RHOST='r.vestacp.com'
  8. CHOST='c.vestacp.com'
  9. REPO='cmmnt'
  10. VERSION='0.9.8/rhel'
  11. YUM_REPO='/etc/yum.repos.d/vesta.repo'
  12. software="nginx httpd mod_ssl mod_ruid2 mod_extract_forwarded mod_fcgid
  13. php php-bcmath php-cli php-common php-gd php-imap php-mbstring php-mcrypt
  14. php-mysql php-pdo php-soap php-tidy php-xml php-xmlrpc php-pecl-apc
  15. phpMyAdmin awstats webalizer vsftpd mysql mysql-server exim dovecot clamd
  16. spamassassin curl roundcubemail bind bind-utils bind-libs mc screen ftp
  17. libpng libjpeg libmcrypt mhash zip unzip openssl flex rssh libxml2
  18. ImageMagick sqlite pcre sudo bc jwhois mailx lsof tar telnet rsync
  19. rrdtool GeoIP freetype ntp openssh-clients vesta vesta-nginx vesta-php"
  20. help() {
  21. echo "usage: $0 [OPTIONS]
  22. -d, --disable-remi Disable remi
  23. -e, --email Define email address
  24. -h, --help Print this help and exit
  25. -f, --force Force installation
  26. -n, --noupdate Do not run yum update command"
  27. exit 1
  28. }
  29. # Password generator
  30. gen_pass() {
  31. MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  32. LENGTH=10
  33. while [ ${n:=1} -le $LENGTH ]; do
  34. PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  35. let n+=1
  36. done
  37. echo "$PASS"
  38. }
  39. #----------------------------------------------------------#
  40. # Verifications #
  41. #----------------------------------------------------------#
  42. # Translating argument to --gnu-long-options
  43. for arg; do
  44. delim=""
  45. case "$arg" in
  46. --help) args="${args}-h " ;;
  47. --disable-remi) args="${args}-d " ;;
  48. --force) args="${args}-f " ;;
  49. --email) args="${args}-e " ;;
  50. --noupdate) args="${args}-n " ;;
  51. *) [[ "${arg:0:1}" == "-" ]] || delim="\""
  52. args="${args}${delim}${arg}${delim} ";;
  53. esac
  54. done
  55. eval set -- "$args"
  56. # Getopt
  57. while getopts "dhfne:" Option; do
  58. case $Option in
  59. d) disable_remi='yes' ;; # Disable remi repo
  60. h) help ;; # Help
  61. e) email=$OPTARG ;; # Set email
  62. f) force='yes' ;; # Force install
  63. n) noupdate='yes' ;; # Disable yum update
  64. *) help ;; # Default
  65. esac
  66. done
  67. # Am I root?
  68. if [ "x$(id -u)" != 'x0' ]; then
  69. echo 'Error: this script can only be executed by root'
  70. exit 1
  71. fi
  72. # Check supported version
  73. if [ ! -e '/etc/redhat-release' ]; then
  74. echo 'Error: sorry, we currently support RHEL and CentOS only'
  75. exit 1
  76. fi
  77. # Check supported OS
  78. arch=$(uname -i)
  79. os=$(cut -f 1 -d ' ' /etc/redhat-release)
  80. release=$(grep -o "[0-9]" /etc/redhat-release |head -n1)
  81. codename="${os}_$release"
  82. if [ $os != 'CentOS' ] && [ $os != 'Red' ]; then
  83. echo 'Error: sorry, we currently support RHEL and CentOS only'
  84. fi
  85. # Check admin user account
  86. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" != 'yes' ]; then
  87. echo "Error: user admin exists"
  88. echo
  89. echo 'Please remove admin user account before proceeding.'
  90. echo 'If you want to do it automatically run installer with -f option:'
  91. echo "Example: bash $0 --force"
  92. exit 1
  93. fi
  94. # Check admin user account
  95. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" != 'yes' ]; then
  96. echo "Error: user admin exists"
  97. echo
  98. echo 'Please remove admin user account before proceeding.'
  99. echo 'If you want to do it automatically run installer with -f option:'
  100. echo "Example: bash $0 --force"
  101. exit 1
  102. fi
  103. # Check wget
  104. if [ ! -e '/usr/bin/wget' ]; then
  105. yum -y install wget
  106. if [ $? -ne 0 ]; then
  107. echo "Error: can't install wget"
  108. exit 1
  109. fi
  110. fi
  111. # Check repo availability
  112. wget -q "$CHOST/$VERSION/vesta.conf" -O /dev/null
  113. if [ $? -ne 0 ]; then
  114. echo "Error: no access to $REPO repository"
  115. exit 1
  116. fi
  117. # Check installed packages
  118. tmpfile=$(mktemp -p /tmp)
  119. rpm -qa > $tmpfile
  120. for pkg in exim bind-9 mysql-server httpd nginx vesta; do
  121. if [ ! -z "$(grep $pkg $tmpfile)" ]; then
  122. conflicts="$pkg $conflicts"
  123. fi
  124. done
  125. rm -f $tmpfile
  126. if [ ! -z "$conflicts" ] && [ -z "$force" ]; then
  127. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  128. echo
  129. echo 'Following packages are already installed:'
  130. echo "$conflicts"
  131. echo
  132. echo 'It is highly recommended to remove them before proceeding.'
  133. echo 'If you want to force installation run this script with -f option:'
  134. echo "Example: bash $0 --force"
  135. echo
  136. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  137. echo
  138. exit 1
  139. fi
  140. # Check server type
  141. memory=$(grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9])
  142. if [ "$memory" -lt '350000' ] && [ -z "$force" ]; then
  143. echo "Error: not enough memory to install Vesta Control Panel."
  144. echo -e "\nMinimum RAM required: 350Mb"
  145. echo 'If you want to force installation run this script with -f option:'
  146. echo "Example: bash $0 --force"
  147. exit 1
  148. fi
  149. srv_type='micro'
  150. if [ "$memory" -gt '1000000' ]; then
  151. srv_type='small'
  152. fi
  153. if [ "$memory" -gt '3000000' ]; then
  154. srv_type='medium'
  155. fi
  156. if [ "$memory" -gt '7000000' ]; then
  157. srv_type='large'
  158. fi
  159. # Are you sure ?
  160. if [ -z $email ]; then
  161. clear
  162. echo
  163. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  164. echo ' _| _| _| _| _| _| _| '
  165. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  166. echo ' _| _| _| _| _| _| _| '
  167. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  168. echo
  169. echo ' Vesta Control Panel'
  170. echo
  171. echo
  172. echo 'Following software will be installed on your system:'
  173. echo ' - Nginx frontend web server'
  174. echo ' - Apache application web server'
  175. echo ' - Bind DNS server'
  176. echo ' - Exim mail server'
  177. echo ' - Dovecot IMAP and POP3 server'
  178. if [ "$srv_type" = 'medium' ] || [ "$srv_type" = 'large' ]; then
  179. echo ' - Clam mail antivirus'
  180. echo ' - SpamAssassin antispam'
  181. fi
  182. echo ' - MySQL database server'
  183. echo ' - Vsftpd FTP server'
  184. echo
  185. echo ' * SELinux and Iptables will be disabled'
  186. echo
  187. read -p 'Do you want to proceed? [y/n]): ' answer
  188. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  189. echo 'Goodbye'
  190. exit 1
  191. fi
  192. # Check email
  193. read -p 'Please enter valid email address: ' email
  194. fi
  195. # Validate email
  196. local_part=$(echo $email | cut -s -f1 -d\@)
  197. remote_host=$(echo $email | cut -s -f2 -d\@)
  198. mx_failed=1
  199. if [ ! -z "$remote_host" ] && [ ! -z "$local_part" ]; then
  200. /usr/bin/host -t mx "$remote_host" > /dev/null 2>&1
  201. mx_failed="$?"
  202. fi
  203. if [ "$mx_failed" -eq 1 ]; then
  204. echo "Error: email $email is not valid"
  205. exit 1
  206. fi
  207. # Check for ipv6 on loopback interface
  208. check_lo_ipv6=$(/sbin/ifconfig lo| grep 'inet6 addr')
  209. check_rc_ipv6=$(grep 'scope global dev lo' /etc/rc.local)
  210. if [ ! -z "$check_lo_ipv6)" ] && [ -z "$check_rc_ipv6" ]; then
  211. ip addr add ::2/128 scope global dev lo
  212. echo "# Vesta: Workraround for openssl validation func" >> /etc/rc.local
  213. echo "ip addr add ::2/128 scope global dev lo" >> /etc/rc.local
  214. chmod a+x /etc/rc.local
  215. fi
  216. #----------------------------------------------------------#
  217. # Install repository #
  218. #----------------------------------------------------------#
  219. # Let's start
  220. echo -e "\n\n\n\nInstallation will take about 15 minutes ...\n"
  221. sleep 5
  222. # Update system
  223. if [ -z "$noupdate" ]; then
  224. yum -y update
  225. if [ $? -ne 0 ]; then
  226. echo 'Error: yum update failed'
  227. exit 1
  228. fi
  229. fi
  230. # Install EPEL repo
  231. if [ ! -e '/etc/yum.repos.d/epel.repo' ]; then
  232. if [ "$release" -eq '5' ]; then
  233. epel="5/$arch/epel-release-5-4.noarch.rpm"
  234. fi
  235. if [ "$release" -eq '6' ]; then
  236. epel="6/$arch/epel-release-6-8.noarch.rpm"
  237. fi
  238. rpm -ivh http://dl.fedoraproject.org/pub/epel/$epel
  239. if [ $? -ne 0 ]; then
  240. echo "Error: can't install EPEL repository"
  241. exit 1
  242. fi
  243. fi
  244. # Install remi repo
  245. if [ ! -e '/etc/yum.repos.d/remi.repo' ]; then
  246. if [ "$release" -eq '5' ]; then
  247. remi="remi-release-5.rpm"
  248. fi
  249. if [ "$release" -eq '6' ]; then
  250. remi="remi-release-6.rpm"
  251. fi
  252. rpm -ivh http://rpms.famillecollet.com/enterprise/$remi
  253. if [ $? -ne 0 ]; then
  254. echo "Error: can't install remi repository"
  255. exit 1
  256. fi
  257. fi
  258. # Install nginx repo
  259. if [ ! -e '/etc/yum.repos.d/nginx.repo' ]; then
  260. echo "[nginx]" > /etc/yum.repos.d/nginx.repo
  261. echo "name=nginx repo" >> /etc/yum.repos.d/nginx.repo
  262. echo "baseurl=http://nginx.org/packages/centos/$release/\$basearch/" \
  263. >> /etc/yum.repos.d/nginx.repo
  264. echo "gpgcheck=0" >> /etc/yum.repos.d/nginx.repo
  265. echo "enabled=1" >> /etc/yum.repos.d/nginx.repo
  266. fi
  267. # Install vesta repo
  268. echo "[vesta]" > $YUM_REPO
  269. echo "name=Vesta - $REPO" >> $YUM_REPO
  270. echo "baseurl=http://$RHOST/$REPO/$release/\$basearch/" >> $YUM_REPO
  271. echo "enabled=1" >> $YUM_REPO
  272. echo "gpgcheck=1" >> $YUM_REPO
  273. echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA" >> $YUM_REPO
  274. wget $CHOST/GPG.txt -O /etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA
  275. #----------------------------------------------------------#
  276. # Backups #
  277. #----------------------------------------------------------#
  278. # Prepare backup tree
  279. vst_backups="/root/vst_install_backups/$(date +%s)"
  280. mkdir -p $vst_backups/nginx
  281. mkdir -p $vst_backups/httpd
  282. mkdir -p $vst_backups/mysql
  283. mkdir -p $vst_backups/exim
  284. mkdir -p $vst_backups/dovecot
  285. mkdir -p $vst_backups/clamd
  286. mkdir -p $vst_backups/spamassassin
  287. mkdir -p $vst_backups/vsftpd
  288. mkdir -p $vst_backups/named
  289. mkdir -p $vst_backups/vesta/admin
  290. mkdir -p $vst_backups/home
  291. # Backup sudoers
  292. if [ -e '/etc/sudoers' ]; then
  293. cp /etc/sudoers $vst_backups/
  294. fi
  295. # Backup nginx
  296. service nginx stop > /dev/null 2>&1
  297. if [ -e '/etc/nginx/nginx.conf' ]; then
  298. cp -r /etc/nginx/* $vst_backups/nginx/
  299. fi
  300. # Backup httpd
  301. service httpd stop > /dev/null 2>&1
  302. if [ -e '/etc/httpd/conf/httpd.conf' ]; then
  303. cp -r /etc/httpd/* $vst_backups/httpd/
  304. fi
  305. # Backup bind
  306. service named stop > /dev/null 2>&1
  307. if [ -e '/etc/named.conf' ]; then
  308. cp /etc/named.conf $vst_backups/named/
  309. fi
  310. # Backup vsftpd
  311. service vsftpd stop > /dev/null 2>&1
  312. if [ -e '/etc/vsftpd/vsftpd.conf' ]; then
  313. cp /etc/vsftpd/vsftpd.conf $vst_backups/vsftpd/
  314. fi
  315. # Backup exim
  316. service exim stop > /dev/null 2>&1
  317. if [ -e '/etc/exim/exim.conf' ]; then
  318. cp -r /etc/exim/* $vst_backups/exim/
  319. fi
  320. # Backup clamav
  321. service clamd stop > /dev/null 2>&1
  322. if [ -e '/etc/clamd.conf' ]; then
  323. cp /etc/clamd.conf $vst_backups/clamd/
  324. fi
  325. # Backup SpamAssassin
  326. service spamassassin stop > /dev/null 2>&1
  327. if [ -e '/etc/mail/spamassassin' ]; then
  328. cp -r /etc/mail/spamassassin/* $vst_backups/spamassassin/
  329. fi
  330. # Backup dovecot
  331. service dovecot stop > /dev/null 2>&1
  332. if [ -e '/etc/dovecot.conf' ]; then
  333. cp /etc/dovecot.conf $vst_backups/dovecot/
  334. fi
  335. if [ -e '/etc/dovecot' ]; then
  336. cp -r /etc/dovecot/* $vst_backups/dovecot/
  337. fi
  338. # Backup MySQL stuff
  339. service mysqld stop > /dev/null 2>&1
  340. if [ -e '/var/lib/mysql' ]; then
  341. mv /var/lib/mysql $vst_backups/mysql/mysql_datadir
  342. fi
  343. if [ -e '/etc/my.cnf' ]; then
  344. cp /etc/my.cnf $vst_backups/mysql/
  345. fi
  346. if [ -e '/root/.my.cnf' ]; then
  347. mv /root/.my.cnf $vst_backups/mysql/
  348. fi
  349. # Backup vesta
  350. service vesta stop > /dev/null 2>&1
  351. if [ -e '/usr/local/vesta/data' ]; then
  352. mv /usr/local/vesta/data $vst_backups/vesta/
  353. fi
  354. if [ -e '/usr/local/vesta/conf' ]; then
  355. mv /usr/local/vesta/conf $vst_backups/vesta/
  356. fi
  357. if [ -e '/home/admin/conf/' ]; then
  358. mv /home/admin/conf/ $vst_backups/vesta/admin
  359. fi
  360. #----------------------------------------------------------#
  361. # Install packages #
  362. #----------------------------------------------------------#
  363. # Exclude heavy packages
  364. if [ "$srv_type" = 'micro' ]; then
  365. software=$(echo "$software" | sed -e 's/mod_fcgid//')
  366. software=$(echo "$software" | sed -e 's/clamd//')
  367. software=$(echo "$software" | sed -e 's/spamassassin//')
  368. fi
  369. if [ "$srv_type" = 'small' ]; then
  370. software=$(echo "$software" | sed -e 's/clamd//')
  371. software=$(echo "$software" | sed -e 's/spamassassin//')
  372. fi
  373. # Install Vesta packages
  374. if [ -z "$disable_remi" ]; then
  375. yum -y --disablerepo=* --enablerepo="base,updates,nginx,epel,vesta,remi" \
  376. install $software
  377. else
  378. yum -y --disablerepo=* --enablerepo="base,updates,nginx,epel,vesta" \
  379. install $software
  380. fi
  381. if [ $? -ne 0 ]; then
  382. echo 'Error: yum install failed'
  383. exit 1
  384. fi
  385. #----------------------------------------------------------#
  386. # Configure system #
  387. #----------------------------------------------------------#
  388. # Set writable permission on tmp directory
  389. chmod 777 /tmp
  390. # Disabling SELinux
  391. if [ -e '/etc/sysconfig/selinux' ]; then
  392. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  393. setenforce 0
  394. fi
  395. if [ -e '/etc/selinux/config' ]; then
  396. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  397. setenforce 0
  398. fi
  399. # Disabling iptables
  400. chkconfig iptables off
  401. service iptables stop
  402. # Disabling webalizer routine
  403. rm -f /etc/cron.daily/00webalizer
  404. # Set directory color
  405. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  406. # Sudo configuration
  407. wget $CHOST/$VERSION/sudoers.conf -O /etc/sudoers
  408. chmod 0440 /etc/sudoers
  409. # NTP Synchronization
  410. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  411. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  412. chmod 775 /etc/cron.daily/ntpdate
  413. ntpdate -s pool.ntp.org
  414. # Setup rssh
  415. if [ -z "$(grep /usr/bin/rssh /etc/shells)" ]; then
  416. echo /usr/bin/rssh >> /etc/shells
  417. fi
  418. sed -i 's/#allowscp/allowscp/' /etc/rssh.conf
  419. sed -i 's/#allowsftp/allowsftp/' /etc/rssh.conf
  420. sed -i 's/#allowrsync/allowrsync/' /etc/rssh.conf
  421. chmod 755 /usr/bin/rssh
  422. # Nginx configuration
  423. rm -f /etc/nginx/conf.d/*.conf
  424. wget $CHOST/$VERSION/nginx.conf -O /etc/nginx/nginx.conf
  425. wget $CHOST/$VERSION/nginx-status.conf -O /etc/nginx/conf.d/status.conf
  426. touch /etc/nginx/conf.d/vesta.conf
  427. chkconfig nginx on
  428. service nginx start
  429. if [ "$?" -ne 0 ]; then
  430. echo "Error: nginx start failed"
  431. exit 1
  432. fi
  433. # Apache configuration
  434. wget $CHOST/$VERSION/httpd.conf -O /etc/httpd/conf/httpd.conf
  435. wget $CHOST/$VERSION/httpd-status.conf -O /etc/httpd/conf.d/status.conf
  436. wget $CHOST/$VERSION/httpd-ssl.conf -O /etc/httpd/conf.d/ssl.conf
  437. wget $CHOST/$VERSION/httpd.log -O /etc/logrotate.d/httpd
  438. echo "MEFaccept 127.0.0.1" >> /etc/httpd/conf.d/mod_extract_forwarded.conf
  439. rm -f /etc/httpd/conf.d/proxy_ajp.conf
  440. echo > /etc/httpd/conf.d/proxy_ajp.conf
  441. rm -f /etc/httpd/conf.d/vesta.conf
  442. echo > /etc/httpd/conf.d/vesta.conf
  443. touch /var/log/httpd/access_log
  444. touch /var/log/httpd/error_log
  445. touch /var/log/httpd/suexec.log
  446. mkdir -p /var/log/httpd/domains
  447. chmod a+x /var/log/httpd
  448. chmod 640 /var/log/httpd/access_log
  449. chmod 640 /var/log/httpd/error_log
  450. chmod 640 /var/log/httpd/suexec.log
  451. chmod 751 /var/log/httpd/domains
  452. chkconfig httpd on
  453. service httpd start
  454. if [ "$?" -ne 0 ]; then
  455. echo "Error: httpd start failed"
  456. exit 1
  457. fi
  458. # Vsftpd configuration
  459. wget $CHOST/$VERSION/vsftpd.conf -O /etc/vsftpd/vsftpd.conf
  460. chkconfig vsftpd on
  461. service vsftpd start
  462. if [ "$?" -ne 0 ]; then
  463. echo "Error: vsftpd start failed"
  464. exit 1
  465. fi
  466. # MySQL configuration
  467. mpass=$(gen_pass)
  468. if [ "$srv_type" = 'micro' ]; then
  469. wget $CHOST/$VERSION/mysql-512.cnf -O /etc/my.cnf
  470. else
  471. wget $CHOST/$VERSION/mysql.cnf -O /etc/my.cnf
  472. fi
  473. chkconfig mysqld on
  474. service mysqld start
  475. if [ "$?" -ne 0 ]; then
  476. # Fix for aio on OpenVZ
  477. if [ -e "/proc/user_beancounters" ]; then
  478. sed -i "s/#innodb_use_native_aio/innodb_use_native_aio/g" /etc/my.cnf
  479. fi
  480. service mysqld start
  481. if [ "$?" -ne 0 ]; then
  482. echo "Error: mysqld start failed"
  483. exit 1
  484. fi
  485. fi
  486. mysqladmin -u root password $mpass
  487. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  488. chmod 600 /root/.my.cnf
  489. mysql -e "DELETE FROM mysql.user WHERE User=''"
  490. mysql -e "DROP DATABASE test"
  491. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  492. mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
  493. mysql -e "FLUSH PRIVILEGES"
  494. # Bind configuration
  495. wget $CHOST/$VERSION/named.conf -O /etc/named.conf
  496. chown root:named /etc/named.conf
  497. chmod 640 /etc/named.conf
  498. chkconfig named on
  499. service named start
  500. if [ "$?" -ne 0 ]; then
  501. echo "Error: named start failed"
  502. exit 1
  503. fi
  504. # Exim
  505. wget $CHOST/$VERSION/exim.conf -O /etc/exim/exim.conf
  506. if [ "$srv_type" = 'micro' ] || [ "$srv_type" = 'small' ]; then
  507. sed -i "s/^SPAMASSASSIN/#SPAMASSASSIN/g" /etc/exim/exim.conf
  508. sed -i "s/^CLAMD/#CLAMD/g" /etc/exim/exim.conf
  509. fi
  510. wget $CHOST/$VERSION/dnsbl.conf -O /etc/exim/dnsbl.conf
  511. wget $CHOST/$VERSION/spam-blocks.conf -O /etc/exim/spam-blocks.conf
  512. touch /etc/exim/white-blocks.conf
  513. rm -rf /etc/exim/domains
  514. mkdir -p /etc/exim/domains
  515. chmod 640 /etc/exim/exim.conf
  516. gpasswd -a exim mail
  517. if [ -e /etc/init.d/sendmail ]; then
  518. chkconfig sendmail off
  519. service sendmail stop
  520. fi
  521. if [ -e /etc/init.d/postfix ]; then
  522. chkconfig postfix off
  523. service postfix stop
  524. fi
  525. rm -f /etc/alternatives/mta
  526. ln -s /usr/sbin/sendmail.exim /etc/alternatives/mta
  527. chkconfig exim on
  528. service exim start
  529. if [ "$?" -ne 0 ]; then
  530. echo "Error: exim start failed"
  531. exit 1
  532. fi
  533. # Dovecot configuration
  534. if [ "$release" -eq '5' ]; then
  535. wget $CHOST/$VERSION/dovecot.conf -O /etc/dovecot.conf
  536. else
  537. wget $CHOST/$VERSION/dovecot.tar.gz -O /etc/dovecot.tar.gz
  538. cd /etc/
  539. rm -rf dovecot
  540. tar -xzf dovecot.tar.gz
  541. rm -f dovecot.tar.gz
  542. chown -R root:root /etc/dovecot
  543. fi
  544. gpasswd -a dovecot mail
  545. chkconfig dovecot on
  546. service dovecot start
  547. if [ "$?" -ne 0 ]; then
  548. echo "Error: dovecot start failed"
  549. exit 1
  550. fi
  551. # ClamAV configuration
  552. if [ "$srv_type" = 'medium' ] || [ "$srv_type" = 'large' ]; then
  553. wget $CHOST/$VERSION/clamd.conf -O /etc/clamd.conf
  554. wget $CHOST/$VERSION/freshclam.conf -O /etc/freshclam.conf
  555. gpasswd -a clam exim
  556. gpasswd -a clam mail
  557. /usr/bin/freshclam
  558. chkconfig clamd on
  559. service clamd start
  560. if [ "$?" -ne 0 ]; then
  561. echo "Error: clamd start failed"
  562. exit 1
  563. fi
  564. fi
  565. # SpamAssassin configuration
  566. if [ "$srv_type" = 'medium' ] || [ "$srv_type" = 'large' ]; then
  567. chkconfig spamassassin on
  568. service spamassassin start
  569. if [ "$?" -ne 0 ]; then
  570. echo "Error: spamassassin start failed"
  571. exit 1
  572. fi
  573. fi
  574. # php configuration
  575. sed -i 's/short_open_tag = Off/short_open_tag = On/g' /etc/php.ini
  576. sed -i "s/;date.timezone =/date.timezone = UTC/g" /etc/php.ini
  577. # phpMyAdmin configuration
  578. wget $CHOST/$VERSION/httpd-pma.conf -O /etc/httpd/conf.d/phpMyAdmin.conf
  579. wget $CHOST/$VERSION/pma.conf -O /etc/phpMyAdmin/config.inc.php
  580. sed -i "s/%blowfish_secret%/$(gen_pass)/g" /etc/phpMyAdmin/config.inc.php
  581. # Roundcube configuration
  582. wget $CHOST/$VERSION/httpd-webmail.conf -O /etc/httpd/conf.d/roundcubemail.conf
  583. wget $CHOST/$VERSION/roundcube-main.conf -O /etc/roundcubemail/main.inc.php
  584. wget $CHOST/$VERSION/roundcube-db.conf -O /etc/roundcubemail/db.inc.php
  585. wget $CHOST/$VERSION/roundcube-driver.php -O \
  586. /usr/share/roundcubemail/plugins/password/drivers/vesta.php
  587. wget $CHOST/$VERSION/roundcube-pw.conf -O \
  588. /usr/share/roundcubemail/plugins/password/config.inc.php
  589. r="$(gen_pass)"
  590. mysql -e "CREATE DATABASE roundcube"
  591. mysql -e "GRANT ALL ON roundcube.* TO roundcube@localhost IDENTIFIED BY '$r'"
  592. sed -i "s/%password%/$r/g" /etc/roundcubemail/db.inc.php
  593. mysql roundcube < /usr/share/doc/roundcubemail-*/SQL/mysql.initial.sql
  594. # Vesta configuration
  595. echo "export VESTA='/usr/local/vesta'" > /etc/profile.d/vesta.sh
  596. chmod 755 /etc/profile.d/vesta.sh
  597. source /etc/profile.d/vesta.sh
  598. echo 'PATH=$PATH:/usr/local/vesta/bin' >> /root/.bash_profile
  599. echo 'export PATH' >> /root/.bash_profile
  600. source /root/.bash_profile
  601. wget $CHOST/$VERSION/vesta.log -O /etc/logrotate.d/vesta
  602. # Directory tree
  603. mkdir -p $VESTA/conf
  604. mkdir -p $VESTA/log
  605. mkdir -p $VESTA/ssl
  606. mkdir -p $VESTA/data
  607. mkdir -p $VESTA/data/ips
  608. mkdir -p $VESTA/data/queue
  609. mkdir -p $VESTA/data/users
  610. touch $VESTA/data/queue/backup.pipe
  611. touch $VESTA/data/queue/disk.pipe
  612. touch $VESTA/data/queue/webstats.pipe
  613. touch $VESTA/data/queue/restart.pipe
  614. touch $VESTA/data/queue/traffic.pipe
  615. chmod 750 $VESTA/conf
  616. chmod 750 $VESTA/data/users
  617. chmod 750 $VESTA/data/ips
  618. chmod -R 750 $VESTA/data/queue
  619. ln -s /usr/local/vesta/log /var/log/vesta
  620. touch /var/log/vesta/system.log
  621. touch /var/log/vesta/nginx-error.log
  622. touch /var/log/vesta/auth.log
  623. chmod 660 /var/log/vesta/*
  624. adduser backup
  625. ln -s /home/backup /backup
  626. chmod a+x /backup
  627. # vesta.conf
  628. wget $CHOST/$VERSION/vesta.conf -O $VESTA/conf/vesta.conf
  629. if [ "$srv_type" = 'micro' ] || [ "$srv_type" = 'small' ]; then
  630. sed -i "s/clamav//g" $VESTA/conf/vesta.conf
  631. sed -i "s/spamassassin//g" $VESTA/conf/vesta.conf
  632. fi
  633. # Templates
  634. cd /usr/local/vesta/data
  635. wget $CHOST/$VERSION/packages.tar.gz -O packages.tar.gz
  636. tar -xzf packages.tar.gz
  637. rm -f packages.tar.gz
  638. cd /usr/local/vesta/data
  639. wget $CHOST/$VERSION/templates.tar.gz -O templates.tar.gz
  640. tar -xzf templates.tar.gz
  641. rm -f templates.tar.gz
  642. chmod -R 755 /usr/local/vesta/data/templates
  643. cp templates/web/skel/public_html/index.html /var/www/html/
  644. sed -i 's/%domain%/It worked!/g' /var/www/html/index.html
  645. if [ "$srv_type" = 'micro' ]; then
  646. rm -f /usr/local/vesta/data/templates/web/httpd/phpfcgid.*
  647. fi
  648. # Default SSL keys
  649. cd /usr/local/vesta/ssl
  650. wget $CHOST/$VERSION/certificate.crt -O certificate.crt
  651. wget $CHOST/$VERSION/certificate.key -O certificate.key
  652. # Adding admin user
  653. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  654. chattr -i /home/admin/conf > /dev/null 2>&1
  655. userdel -f admin
  656. chattr -i /home/admin/conf
  657. mv -f /home/admin $vst_backups/home/
  658. rm -f /tmp/sess_*
  659. fi
  660. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  661. groupdel admin > /dev/null 2>&1
  662. fi
  663. vpass=$(gen_pass)
  664. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  665. if [ $? -ne 0 ]; then
  666. echo "Error: can't create admin user"
  667. exit 1
  668. fi
  669. $VESTA/bin/v-change-user-shell admin bash
  670. $VESTA/bin/v-change-user-language admin en
  671. # Configure mysql host
  672. $VESTA/bin/v-add-database-host mysql localhost root $mpass
  673. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  674. # Configuring system ips
  675. $VESTA/bin/v-update-sys-ip
  676. # Get main ip
  677. main_ip=$(ifconfig |grep 'inet addr:' |grep -v 127.0.0.1 |head -n1 | \
  678. cut -f2 -d: | cut -f1 -d ' ')
  679. # Get remote ip
  680. vst_ip=$(wget vestacp.com/what-is-my-ip/ -O - 2>/dev/null)
  681. if [ ! -z "$vst_ip" ] && [ "$vst_ip" != "$main_ip" ]; then
  682. # Set NAT association
  683. $VESTA/bin/v-change-sys-ip-nat $main_ip $vst_ip
  684. fi
  685. if [ -z "$vst_ip" ]; then
  686. vst_ip=$main_ip
  687. fi
  688. # Add default web domain
  689. $VESTA/bin/v-add-web-domain admin default.domain $vst_ip
  690. # Add default dns domain
  691. $VESTA/bin/v-add-dns-domain admin default.domain $vst_ip
  692. # Add default mail domain
  693. $VESTA/bin/v-add-mail-domain admin default.domain
  694. # Configuring crond
  695. command='sudo /usr/local/vesta/bin/v-update-sys-queue disk'
  696. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  697. command='sudo /usr/local/vesta/bin/v-update-sys-queue traffic'
  698. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  699. command='sudo /usr/local/vesta/bin/v-update-sys-queue webstats'
  700. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  701. command='sudo /usr/local/vesta/bin/v-update-sys-queue backup'
  702. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  703. command='sudo /usr/local/vesta/bin/v-backup-users'
  704. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  705. command='sudo /usr/local/vesta/bin/v-update-user-stats'
  706. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  707. command='sudo /usr/local/vesta/bin/v-update-sys-rrd'
  708. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  709. # Build inititall rrd images
  710. $VESTA/bin/v-update-sys-rrd
  711. # Start system service
  712. chkconfig vesta on
  713. service vesta start
  714. if [ "$?" -ne 0 ]; then
  715. echo "Error: vesta start failed"
  716. exit 1
  717. fi
  718. # Send notification to vestacp.com
  719. wget vestacp.com/notify/?$codename -O /dev/null
  720. # Send notification to admin email
  721. echo -e "Congratulations, you have just successfully installed \
  722. the Vesta Control Panel
  723. You can login in Vesta with following credentials:
  724. username: admin
  725. password: $vpass
  726. https://$vst_ip:8083
  727. We hope that you enjoy your installation of Vesta. Please \
  728. feel free to contact us anytime if you have any questions.
  729. Thank you.
  730. --
  731. Sincerely yours
  732. vestacp.com team
  733. " > $tmpfile
  734. send_mail="$VESTA/web/inc/mail-wrapper.php"
  735. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  736. rm -f $tmpfile
  737. # Congrats
  738. echo '======================================================='
  739. echo
  740. echo
  741. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  742. echo ' _| _| _| _| _| _| _| '
  743. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  744. echo ' _| _| _| _| _| _| _| '
  745. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  746. echo
  747. echo
  748. echo '-------------------------------'
  749. echo " https://$vst_ip:8083"
  750. echo ' username: admin'
  751. echo " password: $vpass"
  752. echo '-------------------------------'
  753. echo
  754. echo
  755. echo 'Congratulations,'
  756. echo 'you have successfully installed Vesta Control Panel.'
  757. echo
  758. echo
  759. # Tricky way to get new PATH variable
  760. cd
  761. bash
  762. # EOF