vst-install.sh 23 KB

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