vst-install.sh 24 KB

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