vst-install.sh 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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 5
  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 nginx repo
  225. if [ ! -e '/etc/yum.repos.d/nginx.repo' ]; then
  226. echo "[nginx]" > /etc/yum.repos.d/nginx.repo
  227. echo "name=nginx repo" >> /etc/yum.repos.d/nginx.repo
  228. echo "baseurl=http://nginx.org/packages/centos/$release/\$basearch/" \
  229. >> /etc/yum.repos.d/nginx.repo
  230. echo "gpgcheck=0" >> /etc/yum.repos.d/nginx.repo
  231. echo "enabled=1" >> /etc/yum.repos.d/nginx.repo
  232. fi
  233. # Install vesta repo
  234. echo "[vesta]" > $YUM_REPO
  235. echo "name=Vesta - $REPO" >> $YUM_REPO
  236. echo "baseurl=http://$RHOST/$REPO/$release/\$basearch/" >> $YUM_REPO
  237. echo "enabled=1" >> $YUM_REPO
  238. echo "gpgcheck=1" >> $YUM_REPO
  239. echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA" >> $YUM_REPO
  240. wget $CHOST/GPG.txt -O /etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA
  241. #----------------------------------------------------------#
  242. # Backups #
  243. #----------------------------------------------------------#
  244. # Prepare backup tree
  245. vst_backups="/root/vst_install_backups/$(date +%s)"
  246. mkdir -p $vst_backups/nginx
  247. mkdir -p $vst_backups/httpd
  248. mkdir -p $vst_backups/mysql
  249. mkdir -p $vst_backups/exim
  250. mkdir -p $vst_backups/dovecot
  251. mkdir -p $vst_backups/clamd
  252. mkdir -p $vst_backups/vsftpd
  253. mkdir -p $vst_backups/named
  254. mkdir -p $vst_backups/vesta/admin
  255. # Backup sudoers
  256. if [ -e '/etc/sudoers' ]; then
  257. cp /etc/sudoers $vst_backups/
  258. fi
  259. # Backup nginx
  260. service nginx stop > /dev/null 2>&1
  261. if [ -e '/etc/nginx/nginx.conf' ]; then
  262. cp /etc/nginx/nginx.conf $vst_backups/nginx/
  263. fi
  264. if [ -f '/etc/nginx/conf.d/default.conf' ]; then
  265. cp /etc/nginx/conf.d/default.conf $vst_backups/nginx/
  266. fi
  267. if [ -e '/etc/nginx/conf.d/example_ssl.conf' ]; then
  268. cp /etc/nginx/conf.d/example_ssl.conf $vst_backups/nginx/
  269. fi
  270. if [ -e '/etc/nginx/conf.d/vesta_ip.conf' ]; then
  271. mv /etc/nginx/conf.d/vesta_ip.conf $vst_backups/nginx
  272. fi
  273. # Backup httpd
  274. service httpd stop > /dev/null 2>&1
  275. if [ -e '/etc/httpd/conf/httpd.conf' ]; then
  276. cp /etc/httpd/conf/httpd.conf $vst_backups/httpd/
  277. fi
  278. if [ -e '/etc/httpd/conf.d/ssl.conf' ]; then
  279. cp /etc/httpd/conf.d/ssl.conf $vst_backups/httpd/
  280. fi
  281. if [ -e '/etc/httpd/conf.d/proxy_ajp.conf' ]; then
  282. cp /etc/httpd/conf.d/proxy_ajp.conf $vst_backups/httpd/
  283. fi
  284. # Backup bind
  285. service named stop > /dev/null 2>&1
  286. if [ -e '/etc/named.conf' ]; then
  287. cp /etc/named.conf $vst_backups/named/
  288. fi
  289. # Backup vsftpd
  290. service vsftpd stop > /dev/null 2>&1
  291. if [ -e '/etc/vsftpd/vsftpd.conf' ]; then
  292. cp /etc/vsftpd/vsftpd.conf $vst_backups/vsftpd/
  293. fi
  294. # Backup exim
  295. service exim stop > /dev/null 2>&1
  296. if [ -e '/etc/exim/exim.conf' ]; then
  297. cp /etc/exim/exim.conf $vst_backups/exim/
  298. fi
  299. if [ -e '/etc/exim/domains' ]; then
  300. cp -r /etc/exim/domains $vst_backups/exim/
  301. fi
  302. # Backup clamav
  303. service clamd stop > /dev/null 2>&1
  304. if [ -e '/etc/clamd.conf' ]; then
  305. cp /etc/clamd.conf $vst_backups/clamd/
  306. fi
  307. # Backup SpamAssassin
  308. service spamassassin stop > /dev/null 2>&1
  309. if [ -e '/etc/mail/spamassassin' ]; then
  310. cp -r /etc/mail/spamassassin $vst_backups/
  311. fi
  312. # Backup dovecot
  313. service dovecot stop > /dev/null 2>&1
  314. if [ -e '/etc/dovecot.conf' ]; then
  315. cp /etc/dovecot.conf $vst_backups/dovecot/
  316. fi
  317. if [ -e '/etc/dovecot' ]; then
  318. cp -r /etc/dovecot $vst_backups/dovecot/
  319. fi
  320. # Backup MySQL stuff
  321. service mysqld stop > /dev/null 2>&1
  322. if [ -e '/var/lib/mysql' ]; then
  323. mv /var/lib/mysql $vst_backups/mysql/mysql_datadir
  324. fi
  325. if [ -e '/etc/my.cnf' ]; then
  326. cp /etc/my.cnf $vst_backups/mysql/
  327. fi
  328. if [ -e '/root/.my.cnf' ]; then
  329. mv /root/.my.cnf $vst_backups/mysql/
  330. fi
  331. # Backup vesta
  332. service vesta stop > /dev/null 2>&1
  333. if [ -e '/usr/local/vesta/data' ]; then
  334. mv /usr/local/vesta/data $vst_backups/vesta/
  335. fi
  336. if [ -e '/usr/local/vesta/conf' ]; then
  337. mv /usr/local/vesta/conf $vst_backups/vesta/
  338. fi
  339. if [ -e '/home/admin/conf/' ]; then
  340. mv /home/admin/conf/ $vst_backups/vesta/admin
  341. fi
  342. #----------------------------------------------------------#
  343. # Install packages #
  344. #----------------------------------------------------------#
  345. # Exclude heavy packages
  346. if [ "$srv_type" = 'micro' ]; then
  347. software=$(echo "$software" | sed -e 's/mod_fcgid//')
  348. software=$(echo "$software" | sed -e 's/clamd//')
  349. software=$(echo "$software" | sed -e 's/spamassassin//')
  350. fi
  351. if [ "$srv_type" = 'small' ]; then
  352. software=$(echo "$software" | sed -e 's/clamd//')
  353. software=$(echo "$software" | sed -e 's/spamassassin//')
  354. fi
  355. # Install Vesta packages
  356. if [ -z "$disable_remi" ]; then
  357. yum -y --enablerepo=remi install $software
  358. else
  359. yum -y install $software
  360. fi
  361. if [ $? -ne 0 ]; then
  362. echo 'Error: yum install failed'
  363. exit 1
  364. fi
  365. #----------------------------------------------------------#
  366. # Configure system #
  367. #----------------------------------------------------------#
  368. # Set writable permission on tmp directory
  369. chmod 777 /tmp
  370. # Disabling SELinux
  371. if [ -e '/etc/sysconfig/selinux' ]; then
  372. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  373. setenforce 0
  374. fi
  375. if [ -e '/etc/selinux/config' ]; then
  376. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  377. setenforce 0
  378. fi
  379. # Disabling iptables
  380. chkconfig iptables off
  381. service iptables stop
  382. # Disabling webalizer routine
  383. rm -f /etc/cron.daily/00webalizer
  384. # Set directory color
  385. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  386. # Sudo configuration
  387. wget $CHOST/$VERSION/sudoers.conf -O /etc/sudoers
  388. chmod 0440 /etc/sudoers
  389. # NTP Synchronization
  390. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  391. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  392. chmod 775 /etc/cron.daily/ntpdate
  393. ntpdate -s pool.ntp.org
  394. # Setup rssh
  395. if [ -z "$(grep /usr/bin/rssh /etc/shells)" ]; then
  396. echo /usr/bin/rssh >> /etc/shells
  397. fi
  398. sed -i 's/#allowscp/allowscp/' /etc/rssh.conf
  399. sed -i 's/#allowsftp/allowsftp/' /etc/rssh.conf
  400. sed -i 's/#allowrsync/allowrsync/' /etc/rssh.conf
  401. chmod 755 /usr/bin/rssh
  402. # Apache configuration
  403. wget $CHOST/$VERSION/httpd.conf -O /etc/httpd/conf/httpd.conf
  404. wget $CHOST/$VERSION/httpd-status.conf -O /etc/httpd/conf.d/status.conf
  405. wget $CHOST/$VERSION/httpd-ssl.conf -O /etc/httpd/conf.d/ssl.conf
  406. wget $CHOST/$VERSION/httpd.log -O /etc/logrotate.d/httpd
  407. echo "MEFaccept 127.0.0.1" >> /etc/httpd/conf.d/mod_extract_forwarded.conf
  408. rm -f /etc/httpd/conf.d/proxy_ajp.conf
  409. echo > /etc/httpd/conf.d/proxy_ajp.conf
  410. rm -f /etc/httpd/conf.d/vesta.conf
  411. echo > /etc/httpd/conf.d/vesta.conf
  412. touch /var/log/httpd/access_log
  413. touch /var/log/httpd/error_log
  414. touch /var/log/httpd/suexec.log
  415. mkdir -p /var/log/httpd/domains
  416. chmod a+x /var/log/httpd
  417. chmod 640 /var/log/httpd/access_log
  418. chmod 640 /var/log/httpd/error_log
  419. chmod 640 /var/log/httpd/suexec.log
  420. chmod 751 /var/log/httpd/domains
  421. chkconfig httpd on
  422. service httpd start
  423. if [ "$?" -ne 0 ]; then
  424. echo "Error: httpd start failed"
  425. exit
  426. fi
  427. # Nginx configuration
  428. wget $CHOST/$VERSION/nginx.conf -O /etc/nginx/nginx.conf
  429. wget $CHOST/$VERSION/nginx-status.conf -O /etc/nginx/conf.d/status.conf
  430. rm -f /etc/nginx/conf.d/vesta_ip.conf
  431. touch /etc/nginx/conf.d/vesta_ip.conf
  432. rm -f /etc/nginx/conf.d/vesta_users.conf
  433. touch /etc/nginx/conf.d/vesta_users.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. userdel -f admin
  628. fi
  629. vpass=$(gen_pass)
  630. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  631. if [ $? -ne 0 ]; then
  632. echo "Error: can't create admin user"
  633. exit 1
  634. fi
  635. $VESTA/bin/v-change-user-shell admin bash
  636. # Configure mysql host
  637. $VESTA/bin/v-add-database-server mysql localhost root $mpass
  638. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  639. # Configuring system ips
  640. $VESTA/bin/v-update-sys-ip
  641. # Get main ip
  642. main_ip=$(ifconfig |grep 'inet addr:' |grep -v 127.0.0.1 |head -n1 | \
  643. cut -f2 -d: | cut -f1 -d ' ')
  644. # Get remote ip
  645. vst_ip=$(wget vestacp.com/what-is-my-ip/ -O - 2>/dev/null)
  646. if [ ! -z "$vst_ip" ] && [ "$vst_ip" != "$main_ip" ]; then
  647. # Set NAT association
  648. $VESTA/bin/v-change-sys-ip-nat $main_ip $vst_ip
  649. # Assign passive ip address
  650. echo "pasv_address=$vst_ip" >> /etc/vsftpd/vsftpd.conf
  651. service vsftpd restart
  652. fi
  653. if [ -z "$vst_ip" ]; then
  654. vst_ip=$main_ip
  655. fi
  656. # Add default web domain
  657. $VESTA/bin/v-add-web-domain admin default.domain $vst_ip
  658. # Add default dns domain
  659. $VESTA/bin/v-add-dns-domain admin default.domain $vst_ip
  660. # Add default mail domain
  661. $VESTA/bin/v-add-mail-domain admin default.domain
  662. # Configuring crond
  663. command='sudo /usr/local/vesta/bin/v-update-sys-queue disk'
  664. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  665. command='sudo /usr/local/vesta/bin/v-update-sys-queue traffic'
  666. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  667. command='sudo /usr/local/vesta/bin/v-update-sys-queue webstats'
  668. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  669. command='sudo /usr/local/vesta/bin/v-update-sys-queue backup'
  670. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  671. command='sudo /usr/local/vesta/bin/v-backup-users'
  672. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  673. command='sudo /usr/local/vesta/bin/v-update-user-stats'
  674. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  675. command='sudo /usr/local/vesta/bin/v-update-sys-rrd'
  676. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  677. # Build inititall rrd images
  678. $VESTA/bin/v-update-sys-rrd
  679. # Start system service
  680. chkconfig vesta on
  681. service vesta start
  682. if [ "$?" -ne 0 ]; then
  683. echo "Error: vesta start failed"
  684. exit
  685. fi
  686. # Send notification to vestacp.com
  687. wget vestacp.com/notify/?$REPO -O /dev/null
  688. # Send notification to admin email
  689. echo -e "Congratulations, you have just successfully installed \
  690. the Vesta Control Panel
  691. You can login in Vesta with following credentials:
  692. username: admin
  693. password: $vpass
  694. https://$vst_ip:8083
  695. We hope that you enjoy your installation of Vesta. Please \
  696. feel free to contact us anytime if you have any questions.
  697. Thank you.
  698. --
  699. Sincerely yours
  700. vestacp.com team
  701. " > $tmpfile
  702. send_mail="$VESTA/web/inc/mail-wrapper.php"
  703. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  704. rm -f $tmpfile
  705. # Congrats
  706. echo '======================================================='
  707. echo
  708. echo
  709. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  710. echo ' _| _| _| _| _| _| _| '
  711. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  712. echo ' _| _| _| _| _| _| _| '
  713. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  714. echo
  715. echo
  716. echo '-------------------------------'
  717. echo " https://$vst_ip:8083"
  718. echo ' username: admin'
  719. echo " password: $vpass"
  720. echo '-------------------------------'
  721. echo
  722. echo
  723. echo 'Congratulations,'
  724. echo 'you have successfully installed Vesta Control Panel.'
  725. echo
  726. echo
  727. # Tricky way to get new PATH variable
  728. cd
  729. bash
  730. # EOF