vst-install.sh 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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.7'
  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. mysql -e "DELETE FROM mysql.user WHERE User=''"
  464. mysql -e "DROP DATABASE test"
  465. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  466. mysql -e "FLUSH PRIVILEGES"
  467. # Bind configuration
  468. wget $CHOST/$VERSION/named.conf -O /etc/named.conf
  469. chown root:named /etc/named.conf
  470. chmod 640 /etc/named.conf
  471. chkconfig named on
  472. service named start
  473. if [ "$?" -ne 0 ]; then
  474. echo "Error: named start failed"
  475. exit
  476. fi
  477. # Exim
  478. wget $CHOST/$VERSION/exim.conf -O /etc/exim/exim.conf
  479. if [ "$srv_type" = 'micro' ] || [ "$srv_type" = 'small' ]; then
  480. sed -i "s/^SPAMASSASSIN/#SPAMASSASSIN/g" /etc/exim/exim.conf
  481. sed -i "s/^CLAMD/#CLAMD/g" /etc/exim/exim.conf
  482. fi
  483. wget $CHOST/$VERSION/dnsbl.conf -O /etc/exim/dnsbl.conf
  484. wget $CHOST/$VERSION/spam-blocks.conf -O /etc/exim/spam-blocks.conf
  485. touch /etc/exim/white-blocks.conf
  486. rm -rf /etc/exim/domains
  487. mkdir -p /etc/exim/domains
  488. chmod 640 /etc/exim/exim.conf
  489. gpasswd -a exim mail
  490. if [ -e /etc/init.d/sendmail ]; then
  491. chkconfig sendmail off
  492. service sendmail stop
  493. fi
  494. if [ -e /etc/init.d/postfix ]; then
  495. chkconfig postfix off
  496. service postfix stop
  497. fi
  498. rm -f /etc/alternatives/mta
  499. ln -s /usr/sbin/sendmail.exim /etc/alternatives/mta
  500. chkconfig exim on
  501. service exim start
  502. if [ "$?" -ne 0 ]; then
  503. echo "Error: exim start failed"
  504. exit
  505. fi
  506. # Dovecot configuration
  507. if [ "$release" -eq '5' ]; then
  508. wget $CHOST/$VERSION/dovecot.conf -O /etc/dovecot.conf
  509. else
  510. wget $CHOST/$VERSION/dovecot.tar.gz -O /etc/dovecot.tar.gz
  511. cd /etc/
  512. rm -rf dovecot
  513. tar -xzf dovecot.tar.gz
  514. rm -f dovecot.tar.gz
  515. chown -R root:root /etc/dovecot
  516. fi
  517. gpasswd -a dovecot mail
  518. chkconfig dovecot on
  519. service dovecot start
  520. if [ "$?" -ne 0 ]; then
  521. echo "Error: dovecot start failed"
  522. exit
  523. fi
  524. # ClamAV configuration
  525. if [ "$srv_type" = 'medium' ] || [ "$srv_type" = 'large' ]; then
  526. wget $CHOST/$VERSION/clamd.conf -O /etc/clamd.conf
  527. wget $CHOST/$VERSION/freshclam.conf -O /etc/freshclam.conf
  528. gpasswd -a clam exim
  529. gpasswd -a clam mail
  530. /usr/bin/freshclam
  531. chkconfig clamd on
  532. service clamd start
  533. if [ "$?" -ne 0 ]; then
  534. echo "Error: clamd start failed"
  535. exit
  536. fi
  537. fi
  538. # SpamAssassin configuration
  539. if [ "$srv_type" = 'medium' ] || [ "$srv_type" = 'large' ]; then
  540. chkconfig spamassassin on
  541. service spamassassin start
  542. if [ "$?" -ne 0 ]; then
  543. echo "Error: spamassassin start failed"
  544. exit
  545. fi
  546. fi
  547. # php configuration
  548. sed -i 's/short_open_tag = Off/short_open_tag = On/g' /etc/php.ini
  549. sed -i "s/;date.timezone =/date.timezone = UTC/g" /etc/php.ini
  550. # phpMyAdmin configuration
  551. wget $CHOST/$VERSION/httpd-pma.conf -O /etc/httpd/conf.d/phpMyAdmin.conf
  552. wget $CHOST/$VERSION/pma.conf -O /etc/phpMyAdmin/config.inc.php
  553. sed -i "s/%blowfish_secret%/$(gen_pass)/g" /etc/phpMyAdmin/config.inc.php
  554. # Roundcube configuration
  555. wget $CHOST/$VERSION/httpd-webmail.conf -O /etc/httpd/conf.d/roundcubemail.conf
  556. wget $CHOST/$VERSION/roundcube-main.conf -O /etc/roundcubemail/main.inc.php
  557. wget $CHOST/$VERSION/roundcube-db.conf -O /etc/roundcubemail/db.inc.php
  558. wget $CHOST/$VERSION/roundcube-driver.php -O \
  559. /usr/share/roundcubemail/plugins/password/drivers/vesta.php
  560. wget $CHOST/$VERSION/roundcube-pw.conf -O \
  561. /usr/share/roundcubemail/plugins/password/config.inc.php
  562. r="$(gen_pass)"
  563. mysql -e "CREATE DATABASE roundcube"
  564. mysql -e "GRANT ALL ON roundcube.* TO roundcube@localhost IDENTIFIED BY '$r'"
  565. sed -i "s/%password%/$r/g" /etc/roundcubemail/db.inc.php
  566. mysql roundcube < /usr/share/doc/roundcubemail-*/SQL/mysql.initial.sql
  567. # Vesta configuration
  568. echo "export VESTA='/usr/local/vesta'" > /etc/profile.d/vesta.sh
  569. chmod 755 /etc/profile.d/vesta.sh
  570. source /etc/profile.d/vesta.sh
  571. echo 'PATH=$PATH:/usr/local/vesta/bin' >> /root/.bash_profile
  572. echo 'export PATH' >> /root/.bash_profile
  573. source /root/.bash_profile
  574. wget $CHOST/$VERSION/vesta.log -O /etc/logrotate.d/vesta
  575. # Directory tree
  576. mkdir -p $VESTA/conf
  577. mkdir -p $VESTA/log
  578. mkdir -p $VESTA/ssl
  579. mkdir -p $VESTA/data
  580. mkdir -p $VESTA/data/ips
  581. mkdir -p $VESTA/data/queue
  582. mkdir -p $VESTA/data/users
  583. touch $VESTA/data/queue/backup.pipe
  584. touch $VESTA/data/queue/disk.pipe
  585. touch $VESTA/data/queue/webstats.pipe
  586. touch $VESTA/data/queue/restart.pipe
  587. touch $VESTA/data/queue/traffic.pipe
  588. chmod 750 $VESTA/conf
  589. chmod 750 $VESTA/data/users
  590. chmod 750 $VESTA/data/ips
  591. chmod -R 750 $VESTA/data/queue
  592. ln -s /usr/local/vesta/log /var/log/vesta
  593. touch /var/log/vesta/system.log
  594. touch /var/log/vesta/nginx-error.log
  595. touch /var/log/vesta/auth.log
  596. chmod 660 /var/log/vesta/*
  597. adduser backup
  598. ln -s /home/backup /backup
  599. chmod a+x /backup
  600. # vesta.conf
  601. wget $RHOST/$REPO/vesta.conf -O $VESTA/conf/vesta.conf
  602. if [ "$srv_type" = 'micro' ] || [ "$srv_type" = 'small' ]; then
  603. sed -i "s/clamav//g" $VESTA/conf/vesta.conf
  604. sed -i "s/spamassassin//g" $VESTA/conf/vesta.conf
  605. fi
  606. # Templates
  607. cd /usr/local/vesta/data
  608. wget $CHOST/$VERSION/packages.tar.gz -O packages.tar.gz
  609. tar -xzf packages.tar.gz
  610. rm -f packages.tar.gz
  611. cd /usr/local/vesta/data
  612. wget $CHOST/$VERSION/templates.tar.gz -O templates.tar.gz
  613. tar -xzf templates.tar.gz
  614. rm -f templates.tar.gz
  615. chmod -R 755 /usr/local/vesta/data/templates
  616. cp templates/web/skel/public_html/index.html /var/www/html/
  617. sed -i 's/%domain%/It worked!/g' /var/www/html/index.html
  618. if [ "$srv_type" = 'micro' ]; then
  619. rm -f /usr/local/vesta/data/templates/web/apache_phpfcgid.*
  620. fi
  621. # Default SSL keys
  622. cd /usr/local/vesta/ssl
  623. wget $CHOST/$VERSION/certificate.crt -O certificate.crt
  624. wget $CHOST/$VERSION/certificate.key -O certificate.key
  625. # Adding admin user
  626. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  627. chattr -i /home/admin/conf > /dev/null 2>&1
  628. userdel -f admin
  629. mv -f /home/admin $vst_backups/home/
  630. rm -f /tmp/sess_*
  631. fi
  632. vpass=$(gen_pass)
  633. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  634. if [ $? -ne 0 ]; then
  635. echo "Error: can't create admin user"
  636. exit 1
  637. fi
  638. $VESTA/bin/v-change-user-shell admin bash
  639. $VESTA/bin/v-change-user-language admin en
  640. # Configure mysql host
  641. $VESTA/bin/v-add-database-server mysql localhost root $mpass
  642. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  643. # Configuring system ips
  644. $VESTA/bin/v-update-sys-ip
  645. # Get main ip
  646. main_ip=$(ifconfig |grep 'inet addr:' |grep -v 127.0.0.1 |head -n1 | \
  647. cut -f2 -d: | cut -f1 -d ' ')
  648. # Get remote ip
  649. vst_ip=$(wget vestacp.com/what-is-my-ip/ -O - 2>/dev/null)
  650. if [ ! -z "$vst_ip" ] && [ "$vst_ip" != "$main_ip" ]; then
  651. # Set NAT association
  652. $VESTA/bin/v-change-sys-ip-nat $main_ip $vst_ip
  653. # Assign passive ip address
  654. echo "pasv_address=$vst_ip" >> /etc/vsftpd/vsftpd.conf
  655. service vsftpd restart
  656. fi
  657. if [ -z "$vst_ip" ]; then
  658. vst_ip=$main_ip
  659. fi
  660. # Add default web domain
  661. $VESTA/bin/v-add-web-domain admin default.domain $vst_ip
  662. # Add default dns domain
  663. $VESTA/bin/v-add-dns-domain admin default.domain $vst_ip
  664. # Add default mail domain
  665. $VESTA/bin/v-add-mail-domain admin default.domain
  666. # Configuring crond
  667. command='sudo /usr/local/vesta/bin/v-update-sys-queue disk'
  668. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  669. command='sudo /usr/local/vesta/bin/v-update-sys-queue traffic'
  670. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  671. command='sudo /usr/local/vesta/bin/v-update-sys-queue webstats'
  672. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  673. command='sudo /usr/local/vesta/bin/v-update-sys-queue backup'
  674. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  675. command='sudo /usr/local/vesta/bin/v-backup-users'
  676. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  677. command='sudo /usr/local/vesta/bin/v-update-user-stats'
  678. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  679. command='sudo /usr/local/vesta/bin/v-update-sys-rrd'
  680. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  681. # Build inititall rrd images
  682. $VESTA/bin/v-update-sys-rrd
  683. # Start system service
  684. chkconfig vesta on
  685. service vesta start
  686. if [ "$?" -ne 0 ]; then
  687. echo "Error: vesta start failed"
  688. exit
  689. fi
  690. # Send notification to vestacp.com
  691. wget vestacp.com/notify/?$REPO -O /dev/null
  692. # Send notification to admin email
  693. echo -e "Congratulations, you have just successfully installed \
  694. the Vesta Control Panel
  695. You can login in Vesta with following credentials:
  696. username: admin
  697. password: $vpass
  698. https://$vst_ip:8083
  699. We hope that you enjoy your installation of Vesta. Please \
  700. feel free to contact us anytime if you have any questions.
  701. Thank you.
  702. --
  703. Sincerely yours
  704. vestacp.com team
  705. " > $tmpfile
  706. send_mail="$VESTA/web/inc/mail-wrapper.php"
  707. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  708. rm -f $tmpfile
  709. # Congrats
  710. echo '======================================================='
  711. echo
  712. echo
  713. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  714. echo ' _| _| _| _| _| _| _| '
  715. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  716. echo ' _| _| _| _| _| _| _| '
  717. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  718. echo
  719. echo
  720. echo '-------------------------------'
  721. echo " https://$vst_ip:8083"
  722. echo ' username: admin'
  723. echo " password: $vpass"
  724. echo '-------------------------------'
  725. echo
  726. echo
  727. echo 'Congratulations,'
  728. echo 'you have successfully installed Vesta Control Panel.'
  729. echo
  730. echo
  731. # Tricky way to get new PATH variable
  732. cd
  733. bash
  734. # EOF