vst-install.sh 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. <<<<<<< HEAD
  2. #!/bin/bash
  3. # Vesta installer
  4. # Define Variables
  5. RHOST='r.vestacp.com'
  6. CHOST='c.vestacp.com'
  7. REPO='cmmnt'
  8. VERSION='0.9.7'
  9. YUM_REPO='/etc/yum.repos.d/vesta.repo'
  10. arch=$(uname -i)
  11. tools="screen mc libpng libjpeg curl curl libmcrypt libmcrypt mhash mhash
  12. freetype openssl flex libxml2 ImageMagick sqlite sqlite pcre pcre sudo bc
  13. mailx lsof ntp tar whois telnet rsync"
  14. rpms="nginx httpd mod_ssl mod_ruid2 mod_extract_forwarded mod_fcgid ftp
  15. webalizer awstats mysql mysql-server php php-bcmath php-cli php-common
  16. php-gd php-imap php-mbstring php-mcrypt php-mysql php-pdo php-soap php-tidy
  17. php-xml php-xmlrpc phpMyAdmin exim dovecot clamd spamassassin roundcubemail
  18. bind bind-utils bind-libs vsftpd rrdtool GeoIP vesta vesta-nginx vesta-php"
  19. # Am I root?
  20. if [ "x$(id -u)" != 'x0' ]; then
  21. echo 'Error: this script can only be executed by root'
  22. exit 1
  23. fi
  24. # Check supported version
  25. if [ ! -e '/etc/redhat-release' ]; then
  26. echo 'Error: sorry, we currently support RHEL and CentOS only'
  27. exit 1
  28. fi
  29. os=$(cut -f 1 -d ' ' /etc/redhat-release)
  30. if [ $os != 'CentOS' ] && [ $os != 'Red' ]; then
  31. echo 'Error: sorry, we currently support RHEL and CentOS only'
  32. fi
  33. release=$(grep -o "[0-9]" /etc/redhat-release |head -n1)
  34. help() {
  35. echo "usage: $0 [OPTIONS]
  36. -e, --email Define email address
  37. -h, --help Print this help and exit
  38. -f, --force Force installation"
  39. exit 1
  40. }
  41. # Translating argument to --gnu-long-options
  42. for arg; do
  43. delim=""
  44. case "$arg" in
  45. --help) args="${args}-h " ;;
  46. --force) args="${args}-f " ;;
  47. --email) args="${args}-e " ;;
  48. *) [[ "${arg:0:1}" == "-" ]] || delim="\""
  49. args="${args}${delim}${arg}${delim} ";;
  50. esac
  51. done
  52. eval set -- "$args"
  53. # Getopt
  54. while getopts "hfe:" Option; do
  55. case $Option in
  56. h) help ;; # Help
  57. e) email=$OPTARG ;; # Contact email
  58. f) force=yes ;; # Force install
  59. *) help ;; # Default
  60. esac
  61. done
  62. # Are you sure ?
  63. if [ -z $email ]; then
  64. echo
  65. echo
  66. echo
  67. echo
  68. echo
  69. echo ' ***********************************************************'
  70. echo
  71. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  72. echo ' _| _| _| _| _| _| _| '
  73. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  74. echo ' _| _| _| _| _| _| _| '
  75. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  76. echo
  77. echo
  78. echo
  79. echo
  80. echo
  81. echo
  82. echo
  83. echo
  84. echo ' ***********************************************************'
  85. echo
  86. echo
  87. read -n 1 -p 'Do you want to install Vesta Control Panel? [y/n]): ' answer
  88. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  89. echo 'Goodbye'
  90. exit 1
  91. fi
  92. echo
  93. # Check email
  94. read -p 'Please enter valid email address: ' email
  95. fi
  96. # Validate email
  97. local_part=$(echo $email | cut -s -f1 -d\@)
  98. remote_host=$(echo $email | cut -s -f2 -d\@)
  99. mx_failed=1
  100. if [ ! -z "$remote_host" ] && [ ! -z "$local_part" ]; then
  101. /usr/bin/host -t mx "$remote_host" &> /dev/null
  102. mx_failed="$?"
  103. fi
  104. if [ "$mx_failed" -eq 1 ]; then
  105. echo "Error: email $email is not valid"
  106. exit 1
  107. fi
  108. echo
  109. echo
  110. echo
  111. echo
  112. echo 'Installation will take about 15 minutes ...'
  113. echo
  114. sleep 2
  115. # Check wget
  116. if [ ! -e '/usr/bin/wget' ]; then
  117. yum -y install wget
  118. if [ $? -ne 0 ]; then
  119. echo "Error: can't install wget"
  120. exit 1
  121. fi
  122. fi
  123. # Check repo availability
  124. wget "$RHOST/$REPO/vesta.conf" -O /dev/null
  125. if [ $? -ne 0 ]; then
  126. echo "Error: no access to $REPO repository"
  127. exit 1
  128. fi
  129. # Check installed packages
  130. tmpfile=$(mktemp -p /tmp)
  131. rpm -qa > $tmpfile
  132. for rpm in $rpms; do
  133. if [ ! -z "$(grep ^$rpm. $tmpfile)" ]; then
  134. conflicts="$rpm $conflicts"
  135. fi
  136. done
  137. rm -f $tmpfile
  138. if [ ! -z "$conflicts" ] && [ -z "$force" ]; then
  139. echo
  140. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  141. echo
  142. echo 'Following rpm packages aleady installed:'
  143. echo "$conflicts"
  144. echo
  145. echo 'It is highly recommended to remove them before proceeding.'
  146. echo
  147. echo 'If you want to force installation run this script with -f option:'
  148. echo "Example: bash $0 --force"
  149. echo
  150. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  151. echo
  152. exit 1
  153. fi
  154. # Password generator
  155. gen_pass() {
  156. MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  157. LENGTH=10
  158. while [ ${n:=1} -le $LENGTH ]; do
  159. PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  160. let n+=1
  161. done
  162. echo "$PASS"
  163. }
  164. # Update system
  165. yum -y update
  166. if [ $? -ne 0 ]; then
  167. echo 'Error: yum update failed'
  168. exit 1
  169. fi
  170. # Install additional packages
  171. yum -y install $tools
  172. if [ $? -ne 0 ]; then
  173. echo 'Error: yum install failed'
  174. exit 1
  175. fi
  176. # Install EPEL repo
  177. if [ ! -e '/etc/yum.repos.d/epel.repo' ]; then
  178. if [ "$release" -eq '5' ]; then
  179. epel="5/$arch/epel-release-5-4.noarch.rpm"
  180. fi
  181. if [ "$release" -eq '6' ]; then
  182. epel="6/$arch/epel-release-6-8.noarch.rpm"
  183. fi
  184. rpm -ivh http://dl.fedoraproject.org/pub/epel/$epel
  185. if [ $? -ne 0 ]; then
  186. echo "Error: can't install EPEL repository"
  187. exit 1
  188. fi
  189. fi
  190. # Install remi repo
  191. if [ ! -e '/etc/yum.repos.d/remi.repo' ]; then
  192. if [ "$release" -eq '5' ]; then
  193. remi="remi-release-5.rpm"
  194. fi
  195. if [ "$release" -eq '6' ]; then
  196. remi="remi-release-6.rpm"
  197. fi
  198. rpm -ivh http://rpms.famillecollet.com/enterprise/$remi
  199. if [ $? -ne 0 ]; then
  200. echo "Error: can't install remi repository"
  201. exit 1
  202. fi
  203. fi
  204. # Install vesta repo
  205. echo "[vesta]
  206. name=Vesta - $REPO
  207. baseurl=http://$RHOST/$REPO/$release/\$basearch/
  208. enabled=1
  209. gpgcheck=1
  210. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA" > $YUM_REPO
  211. wget $CHOST/GPG.txt -O /etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA
  212. # Checking if old MySQL stuff exists
  213. if [ -e '/var/lib/mysql' ]; then
  214. mv -f /var/lib/mysql /var/lib/mysql_old
  215. fi
  216. if [ -e '/etc/my.cnf' ]; then
  217. mv -f /etc/my.cnf /etc/my.cnf_old
  218. fi
  219. if [ -e '/root/.my.cnf' ]; then
  220. mv -f /root/.my.cnf
  221. fi
  222. # Vesta packages
  223. yum -y --enablerepo=remi install $rpms
  224. if [ $? -ne 0 ]; then
  225. echo 'Error: yum install failed'
  226. exit 1
  227. fi
  228. # Configuring run levels
  229. chkconfig iptables off
  230. if [ -e /etc/init.d/sendmail ]; then
  231. chkconfig sendmail off
  232. fi
  233. if [ -e /etc/init.d/postfix ]; then
  234. chkconfig postfix off
  235. fi
  236. chkconfig vesta on
  237. chkconfig httpd on
  238. chkconfig nginx on
  239. chkconfig mysqld on
  240. chkconfig vsftpd on
  241. chkconfig named on
  242. chkconfig exim on
  243. chkconfig clamd on
  244. chkconfig spamassassin on
  245. chkconfig dovecot on
  246. # Make dirs more visible
  247. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  248. # Vesta does not support SELINUX for now
  249. if [ -e '/etc/sysconfig/selinux' ]; then
  250. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  251. setenforce 0
  252. fi
  253. if [ -e '/etc/selinux/config' ]; then
  254. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  255. setenforce 0
  256. fi
  257. # Vesta use own webalizer routine
  258. rm -f /etc/cron.daily/00webalizer
  259. # NTP Synchronization
  260. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  261. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  262. chmod 775 /etc/cron.daily/ntpdate
  263. ntpdate -s pool.ntp.org
  264. # Vesta Environment
  265. echo "export VESTA='/usr/local/vesta'" > /etc/profile.d/vesta.sh
  266. chmod 755 /etc/profile.d/vesta.sh
  267. source /etc/profile.d/vesta.sh
  268. echo 'PATH=$PATH:/usr/local/vesta/bin' >> /root/.bash_profile
  269. echo 'export PATH' >> /root/.bash_profile
  270. source /root/.bash_profile
  271. mkdir -p $VESTA/conf
  272. mkdir -p $VESTA/log
  273. mkdir -p $VESTA/data
  274. mkdir -p $VESTA/ssl
  275. chmod 770 $VESTA/conf
  276. # Make backup directory
  277. vst_backups="/root/vst_install_backups/$(date +%s)"
  278. mkdir -p $vst_backups
  279. mkdir -p $vst_backups/nginx
  280. mkdir -p $vst_backups/httpd
  281. mkdir -p $vst_backups/mysql
  282. mkdir -p $vst_backups/exim
  283. mkdir -p $vst_backups/dovecot
  284. mkdir -p $vst_backups/clamd
  285. mkdir -p $vst_backups/vsftpd
  286. mkdir -p $vst_backups/named
  287. wget $RHOST/$REPO/vesta.conf -O $VESTA/conf/vesta.conf
  288. if [ -e '/etc/sudoers' ]; then
  289. mv /etc/sudoers $vst_backups/
  290. fi
  291. wget $CHOST/$VERSION/sudoers.conf -O /etc/sudoers
  292. chmod 0440 /etc/sudoers
  293. wget $CHOST/$VERSION/vesta.log -O /etc/logrotate.d/vesta
  294. sed -i "s/umask 022/umask 002/g" /etc/profile
  295. # Create backup directory
  296. adduser backup
  297. ln -s /home/backup /backup
  298. chmod a+x /backup
  299. # Configuring data templates
  300. cd /usr/local/vesta/data
  301. mkdir ips
  302. mkdir queue
  303. mkdir users
  304. touch queue/backup.pipe
  305. touch queue/disk.pipe
  306. touch queue/webstats.pipe
  307. touch queue/restart.pipe
  308. touch queue/traffic.pipe
  309. chmod 750 users
  310. chmod 750 ips
  311. chmod -R 750 queue
  312. wget $CHOST/$VERSION/packages.tar.gz -O packages.tar.gz
  313. tar -xzf packages.tar.gz
  314. rm -f packages.tar.gz
  315. cd /usr/local/vesta/data
  316. wget $CHOST/$VERSION/templates.tar.gz -O templates.tar.gz
  317. tar -xzf templates.tar.gz
  318. rm -f templates.tar.gz
  319. chmod -R 755 /usr/local/vesta/data/templates
  320. cp templates/web/skel/public_html/index.html /var/www/html/
  321. sed -i 's/%domain%/It worked!/g' /var/www/html/index.html
  322. # Configuring ssl keys
  323. cd /usr/local/vesta/ssl
  324. wget $CHOST/$VERSION/certificate.crt -O certificate.crt
  325. wget $CHOST/$VERSION/certificate.key -O certificate.key
  326. # Adding admin user
  327. vpass=$(gen_pass)
  328. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  329. if [ $? -ne 0 ]; then
  330. echo "Error: can't create admin user"
  331. exit 1
  332. fi
  333. # Set shell
  334. $VESTA/bin/v-change-user-shell admin bash
  335. # Apache
  336. if [ -e '/etc/httpd/conf/httpd.conf' ]; then
  337. mv /etc/httpd/conf/httpd.conf $vst_backups/httpd/
  338. fi
  339. if [ -e '/etc/httpd/conf.d/ssl.conf' ]; then
  340. mv /etc/httpd/conf.d/ssl.conf $vst_backups/httpd/
  341. fi
  342. if [ -e '/etc/httpd/conf.d/proxy_ajp.conf' ]; then
  343. mv /etc/httpd/conf.d/proxy_ajp.conf $vst_backups/httpd/
  344. fi
  345. wget $CHOST/$VERSION/httpd.conf -O /etc/httpd/conf/httpd.conf
  346. wget $CHOST/$VERSION/httpd-status.conf -O /etc/httpd/conf.d/status.conf
  347. wget $CHOST/$VERSION/httpd-ssl.conf -O /etc/httpd/conf.d/ssl.conf
  348. wget $CHOST/$VERSION/httpd.log -O /etc/logrotate.d/httpd
  349. echo "MEFaccept 127.0.0.1" >> /etc/httpd/conf.d/mod_extract_forwarded.conf
  350. echo > /etc/httpd/conf.d/proxy_ajp.conf
  351. echo > /etc/httpd/conf.d/vesta.conf
  352. touch /var/log/httpd/access_log
  353. touch /var/log/httpd/error_log
  354. touch /var/log/httpd/suexec.log
  355. mkdir -p /var/log/httpd/domains
  356. chmod a+x /var/log/httpd
  357. chmod 640 /var/log/httpd/access_log
  358. chmod 640 /var/log/httpd/error_log
  359. chmod 640 /var/log/httpd/suexec.log
  360. chmod 751 /var/log/httpd/domains
  361. # Nginx
  362. if [ -e '/etc/nginx/nginx.conf' ]; then
  363. mv /etc/nginx/nginx.conf $vst_backups/nginx/
  364. fi
  365. if [ -f '/etc/nginx/conf.d/default.conf' ]; then
  366. mv /etc/nginx/conf.d/default.conf $vst_backups/nginx/
  367. fi
  368. if [ -e '/etc/nginx/conf.d/example_ssl.conf' ]; then
  369. mv /etc/nginx/conf.d/example_ssl.conf $vst_backups/nginx/
  370. fi
  371. wget $CHOST/$VERSION/nginx.conf -O /etc/nginx/nginx.conf
  372. wget $CHOST/$VERSION/nginx-status.conf -O /etc/nginx/conf.d/status.conf
  373. touch /etc/nginx/conf.d/vesta_ip.conf
  374. touch /etc/nginx/conf.d/vesta_users.conf
  375. # VsFTP
  376. if [ -e '/etc/vsftpd/vsftpd.conf' ]; then
  377. mv /etc/vsftpd/vsftpd.conf $vst_backups/vsftpd/
  378. fi
  379. wget $CHOST/$VERSION/vsftpd.conf -O /etc/vsftpd/vsftpd.conf
  380. # MySQL
  381. if [ -e '/etc/my.cnf' ]; then
  382. mv /etc/my.cnf $vst_backups/mysql/
  383. fi
  384. if [ -e '/root/.my.cnf' ]; then
  385. mv /root/.my.cnf $vst_backups/mysql/
  386. fi
  387. mpass=$(gen_pass)
  388. server_memory="$(grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9])"
  389. if [ "$server_memory" -gt '1000000' ]; then
  390. wget $CHOST/$VERSION/mysql.cnf -O /etc/my.cnf
  391. else
  392. wget $CHOST/$VERSION/mysql-512.cnf -O /etc/my.cnf
  393. fi
  394. service mysqld start
  395. mysqladmin -u root password $mpass
  396. echo -e "[client]\npassword='$mpass'\n" >/root/.my.cnf
  397. $VESTA/bin/v-add-database-server mysql localhost 3306 root $mpass
  398. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  399. # Bind
  400. if [ -e '/etc/named.conf' ]; then
  401. mv /etc/named.conf $vst_backups/named/
  402. fi
  403. wget $CHOST/$VERSION/named.conf -O /etc/named.conf
  404. chown root:named /etc/named.conf
  405. chmod 640 /etc/named.conf
  406. # Exim
  407. if [ -e '/etc/exim/exim.conf' ]; then
  408. mv /etc/exim/exim.conf $vst_backups/exim/
  409. fi
  410. if [ -e '/etc/clamd.conf' ]; then
  411. mv /etc/clamd.conf $vst_backups/clamd/
  412. fi
  413. wget $CHOST/$VERSION/exim.conf -O /etc/exim/exim.conf
  414. wget $CHOST/$VERSION/dnsbl.conf -O /etc/exim/dnsbl.conf
  415. wget $CHOST/$VERSION/spam-blocks.conf -O /etc/exim/spam-blocks.conf
  416. wget $CHOST/$VERSION/clamd.conf -O /etc/clamd.conf
  417. mkdir /etc/exim/domains
  418. chmod 640 /etc/exim/exim.conf
  419. gpasswd -a clam exim
  420. gpasswd -a exim mail
  421. gpasswd -a clam mail
  422. gpasswd -a dovecot mail
  423. /usr/bin/freshclam
  424. # Dovecot config
  425. if [ "$release" -eq '5' ]; then
  426. if -e [ '/etc/dovecot.conf' ]; then
  427. mv /etc/dovecot.conf $vst_backups/dovecot/
  428. fi
  429. wget $CHOST/$VERSION/dovecot.conf -O /etc/dovecot.conf
  430. else
  431. if [ -e '/etc/dovecot' ]; then
  432. mv /etc/dovecot/* $vst_backups/dovecot/
  433. fi
  434. wget $CHOST/$VERSION/dovecot.tar.gz -O /etc/dovecot.tar.gz
  435. cd /etc/
  436. tar -xzf dovecot.tar.gz
  437. rm -f dovecot.tar.gz
  438. fi
  439. # PMA
  440. wget $CHOST/$VERSION/httpd-pma.conf -O /etc/httpd/conf.d/phpMyAdmin.conf
  441. wget $CHOST/$VERSION/pma.conf -O /etc/phpMyAdmin/config.inc.php
  442. sed -i "s/%blowfish_secret%/$(gen_pass)/g" /etc/phpMyAdmin/config.inc.php
  443. # Roundcube setup
  444. wget $CHOST/$VERSION/httpd-webmail.conf -O /etc/httpd/conf.d/roundcubemail.conf
  445. wget $CHOST/$VERSION/roundcube-main.conf -O /etc/roundcubemail/main.inc.php
  446. wget $CHOST/$VERSION/roundcube-db.conf -O /etc/roundcubemail/db.inc.php
  447. r="$(gen_pass)"
  448. mysql -e "CREATE DATABASE roundcube"
  449. mysql -e "GRANT ALL ON roundcube.* TO roundcube@localhost IDENTIFIED BY '$r'"
  450. sed -i "s/%password%/$r/g" /etc/roundcubemail/db.inc.php
  451. mysql roundcube < /usr/share/doc/roundcubemail-*/SQL/mysql.initial.sql
  452. # Configuring ip
  453. $VESTA/bin/v-update-sys-ip
  454. # Get main ip
  455. main_ip=$(ifconfig |grep 'inet addr:' |grep -v 127.0.0.1 |head -n1 |\
  456. cut -f2 -d: | cut -f1 -d ' ')
  457. # Add default web domain on main ip
  458. $VESTA/bin/v-add-web-domain admin default.domain $main_ip
  459. # Add default dns domain on main ip
  460. $VESTA/bin/v-add-dns-domain admin default.domain $main_ip
  461. # Add default mail domain
  462. $VESTA/bin/v-add-mail-domain admin default.domain
  463. # Configuring crond
  464. command='sudo /usr/local/vesta/bin/v-update-sys-queue disk'
  465. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  466. command='sudo /usr/local/vesta/bin/v-update-sys-queue traffic'
  467. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  468. command='sudo /usr/local/vesta/bin/v-update-sys-queue webstats'
  469. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  470. command='sudo /usr/local/vesta/bin/v-update-sys-queue backup'
  471. $VESTA/bin/v-add-cron-job 'admin' '*/30' '*' '*' '*' '*' "$command"
  472. command='sudo /usr/local/vesta/bin/v-backup-users'
  473. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  474. command='sudo /usr/local/vesta/bin/v-update-user-stats'
  475. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '01' '*' '*' "$command"
  476. command='sudo /usr/local/vesta/bin/v-update-sys-rrd'
  477. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  478. # Creating symlink
  479. ln -s /usr/local/vesta/log /var/log/vesta
  480. # Stop unused services
  481. services='iptables sendmail postfix'
  482. for srv in $services; do
  483. service $srv status > /dev/null
  484. if [ $? -eq 0 ]; then
  485. service $srv stop
  486. fi
  487. done
  488. # Start system service
  489. services='vesta httpd nginx vsftpd exim dovecot clamd spamassassin named crond'
  490. for srv in $services; do
  491. service $srv status > /dev/null
  492. if [ $? -gt 0 ]; then
  493. service $srv start
  494. else
  495. service $srv restart
  496. fi
  497. done
  498. # Change sendmail client
  499. rm -f /etc/alternatives/mta
  500. ln -s /usr/sbin/sendmail.exim /etc/alternatives/mta
  501. # Build inititall rrd images
  502. $VESTA/bin/v-update-sys-rrd
  503. # Send notification to vestacp.com
  504. wget vestacp.com/notify/?$REPO -O /dev/null
  505. # Get server ip
  506. vst_ip=$(wget vestacp.com/what-is-my-ip/ -O - 2>/dev/null)
  507. if [ ! -z "$vst_ip" ] && [ "$vst_ip" != "$main_ip" ]; then
  508. # Assign passive ip address
  509. echo "pasv_address=$vst_ip" >> /etc/vsftpd/vsftpd.conf
  510. fi
  511. if [ -z "$vst_ip" ]; then
  512. vst_ip=$main_ip
  513. fi
  514. # Send email
  515. echo -e "Congratulations, you have just successfully installed \
  516. the Vesta Control Panel
  517. You can login in Vesta with following credentials:
  518. username: admin
  519. password: $vpass
  520. https://$vst_ip:8083
  521. We hope that you enjoy your installation of Vesta. Please \
  522. feel free to contact us anytime if you have any questions.
  523. Thank you.
  524. --
  525. Sincerely yours
  526. vestacp.com team
  527. " > $tmpfile
  528. cat $tmpfile | mail -s "Vesta Control Panel" $email
  529. rm -f $tmpfile
  530. # Congrats
  531. echo
  532. echo
  533. echo ' ***********************************************************'
  534. echo
  535. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  536. echo ' _| _| _| _| _| _| _| '
  537. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  538. echo ' _| _| _| _| _| _| _| '
  539. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  540. echo
  541. echo ' Congratulations, you have just successfully installed'
  542. echo ' the Vesta Control Panel!'
  543. echo
  544. echo ' Now you can login in Vesta with following credentials:'
  545. echo ' username: admin'
  546. echo " password: $vpass"
  547. echo " https://$vst_ip:8083/"
  548. echo
  549. echo
  550. echo ' Thank you for using our product.'
  551. echo
  552. echo ' ***********************************************************'
  553. echo
  554. echo
  555. # Tricky way to get new PATH variable
  556. cd
  557. bash
  558. # EOF
  559. =======
  560. #!/bin/bash
  561. # Vesta installer
  562. # Define Variables
  563. RHOST='r.vestacp.com'
  564. CHOST='c.vestacp.com'
  565. REPO='cmmnt'
  566. VERSION='0.9.7'
  567. YUM_REPO='/etc/yum.repos.d/vesta.repo'
  568. arch=$(uname -i)
  569. tools="screen mc libpng libjpeg curl libmcrypt mhash zip unzip freetype ntp
  570. openssl flex libxml2 ImageMagick sqlite pcre sudo bc jwhois mailx lsof
  571. tar telnet rsync"
  572. rpms="nginx httpd mod_ssl mod_ruid2 mod_extract_forwarded mod_fcgid ftp
  573. webalizer awstats mysql mysql-server php php-bcmath php-cli php-common
  574. php-gd php-imap php-mbstring php-mcrypt php-mysql php-pdo php-soap php-tidy
  575. php-xml php-xmlrpc phpMyAdmin exim dovecot clamd spamassassin roundcubemail
  576. bind bind-utils bind-libs vsftpd rrdtool GeoIP vesta vesta-nginx vesta-php"
  577. # Am I root?
  578. if [ "x$(id -u)" != 'x0' ]; then
  579. echo 'Error: this script can only be executed by root'
  580. exit 1
  581. fi
  582. # Check supported version
  583. if [ ! -e '/etc/redhat-release' ]; then
  584. echo 'Error: sorry, we currently support RHEL and CentOS only'
  585. exit 1
  586. fi
  587. os=$(cut -f 1 -d ' ' /etc/redhat-release)
  588. if [ $os != 'CentOS' ] && [ $os != 'Red' ]; then
  589. echo 'Error: sorry, we currently support RHEL and CentOS only'
  590. fi
  591. release=$(grep -o "[0-9]" /etc/redhat-release |head -n1)
  592. help() {
  593. echo "usage: $0 [OPTIONS]
  594. -d, --disable-remi Disable remi
  595. -e, --email Define email address
  596. -h, --help Print this help and exit
  597. -f, --force Force installation"
  598. exit 1
  599. }
  600. # Translating argument to --gnu-long-options
  601. for arg; do
  602. delim=""
  603. case "$arg" in
  604. --help) args="${args}-h " ;;
  605. --disable-remi) args="${args}-d " ;;
  606. --force) args="${args}-f " ;;
  607. --email) args="${args}-e " ;;
  608. *) [[ "${arg:0:1}" == "-" ]] || delim="\""
  609. args="${args}${delim}${arg}${delim} ";;
  610. esac
  611. done
  612. eval set -- "$args"
  613. # Getopt
  614. while getopts "dhfe:" Option; do
  615. case $Option in
  616. d) disable_remi='yes' ;; # Disable remi repo
  617. h) help ;; # Help
  618. e) email=$OPTARG ;; # Contact email
  619. f) force=yes ;; # Force install
  620. *) help ;; # Default
  621. esac
  622. done
  623. # Are you sure ?
  624. if [ -z $email ]; then
  625. echo
  626. echo
  627. echo
  628. echo
  629. echo
  630. echo ' ***********************************************************'
  631. echo
  632. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  633. echo ' _| _| _| _| _| _| _| '
  634. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  635. echo ' _| _| _| _| _| _| _| '
  636. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  637. echo
  638. echo
  639. echo
  640. echo
  641. echo
  642. echo
  643. echo
  644. echo
  645. echo ' ***********************************************************'
  646. echo
  647. echo
  648. read -n 1 -p 'Do you want to install Vesta Control Panel? [y/n]): ' answer
  649. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  650. echo 'Goodbye'
  651. exit 1
  652. fi
  653. echo
  654. # Check email
  655. read -p 'Please enter valid email address: ' email
  656. fi
  657. # Validate email
  658. local_part=$(echo $email | cut -s -f1 -d\@)
  659. remote_host=$(echo $email | cut -s -f2 -d\@)
  660. mx_failed=1
  661. if [ ! -z "$remote_host" ] && [ ! -z "$local_part" ]; then
  662. /usr/bin/host -t mx "$remote_host" &> /dev/null
  663. mx_failed="$?"
  664. fi
  665. if [ "$mx_failed" -eq 1 ]; then
  666. echo "Error: email $email is not valid"
  667. exit 1
  668. fi
  669. echo
  670. echo
  671. echo
  672. echo
  673. echo 'Installation will take about 15 minutes ...'
  674. echo
  675. sleep 2
  676. # Check wget
  677. if [ ! -e '/usr/bin/wget' ]; then
  678. yum -y install wget
  679. if [ $? -ne 0 ]; then
  680. echo "Error: can't install wget"
  681. exit 1
  682. fi
  683. fi
  684. # Check repo availability
  685. wget "$RHOST/$REPO/vesta.conf" -O /dev/null
  686. if [ $? -ne 0 ]; then
  687. echo "Error: no access to $REPO repository"
  688. exit 1
  689. fi
  690. # Check installed packages
  691. tmpfile=$(mktemp -p /tmp)
  692. rpm -qa > $tmpfile
  693. for rpm in $rpms; do
  694. if [ ! -z "$(grep ^$rpm. $tmpfile)" ]; then
  695. conflicts="$rpm $conflicts"
  696. fi
  697. done
  698. rm -f $tmpfile
  699. if [ ! -z "$conflicts" ] && [ -z "$force" ]; then
  700. echo
  701. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  702. echo
  703. echo 'Following rpm packages aleady installed:'
  704. echo "$conflicts"
  705. echo
  706. echo 'It is highly recommended to remove them before proceeding.'
  707. echo
  708. echo 'If you want to force installation run this script with -f option:'
  709. echo "Example: bash $0 --force"
  710. echo
  711. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  712. echo
  713. exit 1
  714. fi
  715. # Password generator
  716. gen_pass() {
  717. MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  718. LENGTH=10
  719. while [ ${n:=1} -le $LENGTH ]; do
  720. PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  721. let n+=1
  722. done
  723. echo "$PASS"
  724. }
  725. # Update system
  726. yum -y update
  727. if [ $? -ne 0 ]; then
  728. echo 'Error: yum update failed'
  729. exit 1
  730. fi
  731. # Install additional packages
  732. yum -y install $tools
  733. if [ $? -ne 0 ]; then
  734. echo 'Error: yum install failed'
  735. exit 1
  736. fi
  737. # Install EPEL repo
  738. if [ ! -e '/etc/yum.repos.d/epel.repo' ]; then
  739. if [ "$release" -eq '5' ]; then
  740. epel="5/$arch/epel-release-5-4.noarch.rpm"
  741. fi
  742. if [ "$release" -eq '6' ]; then
  743. epel="6/$arch/epel-release-6-8.noarch.rpm"
  744. fi
  745. rpm -ivh http://dl.fedoraproject.org/pub/epel/$epel
  746. if [ $? -ne 0 ]; then
  747. echo "Error: can't install EPEL repository"
  748. exit 1
  749. fi
  750. fi
  751. # Install remi repo
  752. if [ ! -e '/etc/yum.repos.d/remi.repo' ]; then
  753. if [ "$release" -eq '5' ]; then
  754. remi="remi-release-5.rpm"
  755. fi
  756. if [ "$release" -eq '6' ]; then
  757. remi="remi-release-6.rpm"
  758. fi
  759. rpm -ivh http://rpms.famillecollet.com/enterprise/$remi
  760. if [ $? -ne 0 ]; then
  761. echo "Error: can't install remi repository"
  762. exit 1
  763. fi
  764. fi
  765. # Install vesta repo
  766. echo "[vesta]
  767. name=Vesta - $REPO
  768. baseurl=http://$RHOST/$REPO/$release/\$basearch/
  769. enabled=1
  770. gpgcheck=1
  771. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA" > $YUM_REPO
  772. wget $CHOST/GPG.txt -O /etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA
  773. # Checking if old MySQL stuff exists
  774. if [ -e '/var/lib/mysql' ]; then
  775. mv -f /var/lib/mysql /var/lib/mysql_old
  776. fi
  777. if [ -e '/etc/my.cnf' ]; then
  778. mv -f /etc/my.cnf /etc/my.cnf_old
  779. fi
  780. if [ -e '/root/.my.cnf' ]; then
  781. mv -f /root/.my.cnf
  782. fi
  783. # Install Vesta packages
  784. if [ -z "$disable_remi" ]; then
  785. yum -y --enablerepo=remi install $rpms
  786. else
  787. yum -y install $rpms
  788. fi
  789. if [ $? -ne 0 ]; then
  790. echo 'Error: yum install failed'
  791. exit 1
  792. fi
  793. # Configuring run levels
  794. chkconfig iptables off
  795. if [ -e /etc/init.d/sendmail ]; then
  796. chkconfig sendmail off
  797. fi
  798. if [ -e /etc/init.d/postfix ]; then
  799. chkconfig postfix off
  800. fi
  801. chkconfig vesta on
  802. chkconfig httpd on
  803. chkconfig nginx on
  804. chkconfig mysqld on
  805. chkconfig vsftpd on
  806. chkconfig named on
  807. chkconfig exim on
  808. chkconfig clamd on
  809. chkconfig spamassassin on
  810. chkconfig dovecot on
  811. # Make dirs more visible
  812. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  813. # Vesta does not support SELINUX for now
  814. if [ -e '/etc/sysconfig/selinux' ]; then
  815. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  816. setenforce 0
  817. fi
  818. if [ -e '/etc/selinux/config' ]; then
  819. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  820. setenforce 0
  821. fi
  822. # Vesta use own webalizer routine
  823. rm -f /etc/cron.daily/00webalizer
  824. # NTP Synchronization
  825. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  826. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  827. chmod 775 /etc/cron.daily/ntpdate
  828. ntpdate -s pool.ntp.org
  829. # Vesta Environment
  830. echo "export VESTA='/usr/local/vesta'" > /etc/profile.d/vesta.sh
  831. chmod 755 /etc/profile.d/vesta.sh
  832. source /etc/profile.d/vesta.sh
  833. echo 'PATH=$PATH:/usr/local/vesta/bin' >> /root/.bash_profile
  834. echo 'export PATH' >> /root/.bash_profile
  835. source /root/.bash_profile
  836. mkdir -p $VESTA/conf
  837. mkdir -p $VESTA/log
  838. mkdir -p $VESTA/data
  839. mkdir -p $VESTA/ssl
  840. chmod 770 $VESTA/conf
  841. # Make backup directory
  842. vst_backups="/root/vst_install_backups/$(date +%s)"
  843. mkdir -p $vst_backups
  844. mkdir -p $vst_backups/nginx
  845. mkdir -p $vst_backups/httpd
  846. mkdir -p $vst_backups/mysql
  847. mkdir -p $vst_backups/exim
  848. mkdir -p $vst_backups/dovecot
  849. mkdir -p $vst_backups/clamd
  850. mkdir -p $vst_backups/vsftpd
  851. mkdir -p $vst_backups/named
  852. wget $RHOST/$REPO/vesta.conf -O $VESTA/conf/vesta.conf
  853. if [ -e '/etc/sudoers' ]; then
  854. mv /etc/sudoers $vst_backups/
  855. fi
  856. wget $CHOST/$VERSION/sudoers.conf -O /etc/sudoers
  857. chmod 0440 /etc/sudoers
  858. wget $CHOST/$VERSION/vesta.log -O /etc/logrotate.d/vesta
  859. sed -i "s/umask 022/umask 002/g" /etc/profile
  860. # Create backup directory
  861. adduser backup
  862. ln -s /home/backup /backup
  863. chmod a+x /backup
  864. # Configuring data templates
  865. cd /usr/local/vesta/data
  866. mkdir ips
  867. mkdir queue
  868. mkdir users
  869. touch queue/backup.pipe
  870. touch queue/disk.pipe
  871. touch queue/webstats.pipe
  872. touch queue/restart.pipe
  873. touch queue/traffic.pipe
  874. chmod 750 users
  875. chmod 750 ips
  876. chmod -R 750 queue
  877. wget $CHOST/$VERSION/packages.tar.gz -O packages.tar.gz
  878. tar -xzf packages.tar.gz
  879. rm -f packages.tar.gz
  880. cd /usr/local/vesta/data
  881. wget $CHOST/$VERSION/templates.tar.gz -O templates.tar.gz
  882. tar -xzf templates.tar.gz
  883. rm -f templates.tar.gz
  884. chmod -R 755 /usr/local/vesta/data/templates
  885. cp templates/web/skel/public_html/index.html /var/www/html/
  886. sed -i 's/%domain%/It worked!/g' /var/www/html/index.html
  887. # Configuring ssl keys
  888. cd /usr/local/vesta/ssl
  889. wget $CHOST/$VERSION/certificate.crt -O certificate.crt
  890. wget $CHOST/$VERSION/certificate.key -O certificate.key
  891. # Adding admin user
  892. vpass=$(gen_pass)
  893. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  894. if [ $? -ne 0 ]; then
  895. echo "Error: can't create admin user"
  896. exit 1
  897. fi
  898. # Set shell
  899. $VESTA/bin/v-change-user-shell admin bash
  900. # Apache
  901. if [ -e '/etc/httpd/conf/httpd.conf' ]; then
  902. mv /etc/httpd/conf/httpd.conf $vst_backups/httpd/
  903. fi
  904. if [ -e '/etc/httpd/conf.d/ssl.conf' ]; then
  905. mv /etc/httpd/conf.d/ssl.conf $vst_backups/httpd/
  906. fi
  907. if [ -e '/etc/httpd/conf.d/proxy_ajp.conf' ]; then
  908. mv /etc/httpd/conf.d/proxy_ajp.conf $vst_backups/httpd/
  909. fi
  910. wget $CHOST/$VERSION/httpd.conf -O /etc/httpd/conf/httpd.conf
  911. wget $CHOST/$VERSION/httpd-status.conf -O /etc/httpd/conf.d/status.conf
  912. wget $CHOST/$VERSION/httpd-ssl.conf -O /etc/httpd/conf.d/ssl.conf
  913. wget $CHOST/$VERSION/httpd.log -O /etc/logrotate.d/httpd
  914. echo "MEFaccept 127.0.0.1" >> /etc/httpd/conf.d/mod_extract_forwarded.conf
  915. echo > /etc/httpd/conf.d/proxy_ajp.conf
  916. echo > /etc/httpd/conf.d/vesta.conf
  917. touch /var/log/httpd/access_log
  918. touch /var/log/httpd/error_log
  919. touch /var/log/httpd/suexec.log
  920. mkdir -p /var/log/httpd/domains
  921. chmod a+x /var/log/httpd
  922. chmod 640 /var/log/httpd/access_log
  923. chmod 640 /var/log/httpd/error_log
  924. chmod 640 /var/log/httpd/suexec.log
  925. chmod 751 /var/log/httpd/domains
  926. # Nginx
  927. if [ -e '/etc/nginx/nginx.conf' ]; then
  928. mv /etc/nginx/nginx.conf $vst_backups/nginx/
  929. fi
  930. if [ -f '/etc/nginx/conf.d/default.conf' ]; then
  931. mv /etc/nginx/conf.d/default.conf $vst_backups/nginx/
  932. fi
  933. if [ -e '/etc/nginx/conf.d/example_ssl.conf' ]; then
  934. mv /etc/nginx/conf.d/example_ssl.conf $vst_backups/nginx/
  935. fi
  936. wget $CHOST/$VERSION/nginx.conf -O /etc/nginx/nginx.conf
  937. wget $CHOST/$VERSION/nginx-status.conf -O /etc/nginx/conf.d/status.conf
  938. touch /etc/nginx/conf.d/vesta_ip.conf
  939. touch /etc/nginx/conf.d/vesta_users.conf
  940. # VsFTP
  941. if [ -e '/etc/vsftpd/vsftpd.conf' ]; then
  942. mv /etc/vsftpd/vsftpd.conf $vst_backups/vsftpd/
  943. fi
  944. wget $CHOST/$VERSION/vsftpd.conf -O /etc/vsftpd/vsftpd.conf
  945. # MySQL
  946. if [ -e '/etc/my.cnf' ]; then
  947. mv /etc/my.cnf $vst_backups/mysql/
  948. fi
  949. if [ -e '/root/.my.cnf' ]; then
  950. mv /root/.my.cnf $vst_backups/mysql/
  951. fi
  952. mpass=$(gen_pass)
  953. server_memory="$(grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9])"
  954. if [ "$server_memory" -gt '1000000' ]; then
  955. wget $CHOST/$VERSION/mysql.cnf -O /etc/my.cnf
  956. else
  957. wget $CHOST/$VERSION/mysql-512.cnf -O /etc/my.cnf
  958. fi
  959. service mysqld start
  960. mysqladmin -u root password $mpass
  961. echo -e "[client]\npassword='$mpass'\n" >/root/.my.cnf
  962. $VESTA/bin/v-add-database-server mysql localhost 3306 root $mpass
  963. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  964. # Bind
  965. if [ -e '/etc/named.conf' ]; then
  966. mv /etc/named.conf $vst_backups/named/
  967. fi
  968. wget $CHOST/$VERSION/named.conf -O /etc/named.conf
  969. chown root:named /etc/named.conf
  970. chmod 640 /etc/named.conf
  971. # Exim
  972. if [ -e '/etc/exim/exim.conf' ]; then
  973. mv /etc/exim/exim.conf $vst_backups/exim/
  974. fi
  975. if [ -e '/etc/clamd.conf' ]; then
  976. mv /etc/clamd.conf $vst_backups/clamd/
  977. fi
  978. wget $CHOST/$VERSION/exim.conf -O /etc/exim/exim.conf
  979. wget $CHOST/$VERSION/dnsbl.conf -O /etc/exim/dnsbl.conf
  980. wget $CHOST/$VERSION/spam-blocks.conf -O /etc/exim/spam-blocks.conf
  981. wget $CHOST/$VERSION/clamd.conf -O /etc/clamd.conf
  982. mkdir /etc/exim/domains
  983. chmod 640 /etc/exim/exim.conf
  984. gpasswd -a clam exim
  985. gpasswd -a exim mail
  986. gpasswd -a clam mail
  987. gpasswd -a dovecot mail
  988. /usr/bin/freshclam
  989. # Dovecot config
  990. if [ "$release" -eq '5' ]; then
  991. if -e [ '/etc/dovecot.conf' ]; then
  992. mv /etc/dovecot.conf $vst_backups/dovecot/
  993. fi
  994. wget $CHOST/$VERSION/dovecot.conf -O /etc/dovecot.conf
  995. else
  996. if [ -e '/etc/dovecot' ]; then
  997. mv /etc/dovecot/* $vst_backups/dovecot/
  998. fi
  999. wget $CHOST/$VERSION/dovecot.tar.gz -O /etc/dovecot.tar.gz
  1000. cd /etc/
  1001. tar -xzf dovecot.tar.gz
  1002. rm -f dovecot.tar.gz
  1003. fi
  1004. # PMA
  1005. wget $CHOST/$VERSION/httpd-pma.conf -O /etc/httpd/conf.d/phpMyAdmin.conf
  1006. wget $CHOST/$VERSION/pma.conf -O /etc/phpMyAdmin/config.inc.php
  1007. sed -i "s/%blowfish_secret%/$(gen_pass)/g" /etc/phpMyAdmin/config.inc.php
  1008. # Roundcube setup
  1009. wget $CHOST/$VERSION/httpd-webmail.conf -O /etc/httpd/conf.d/roundcubemail.conf
  1010. wget $CHOST/$VERSION/roundcube-main.conf -O /etc/roundcubemail/main.inc.php
  1011. wget $CHOST/$VERSION/roundcube-db.conf -O /etc/roundcubemail/db.inc.php
  1012. wget $CHOST/$VERSION/roundcube-driver.php -O /usr/share/roundcubemail/plugins/password/vesta.php
  1013. wget $CHOST/$VERSION/roundcube-pw.conf -O /usr/share/roundcubemail/plugins/password/config.inc.php
  1014. r="$(gen_pass)"
  1015. mysql -e "CREATE DATABASE roundcube"
  1016. mysql -e "GRANT ALL ON roundcube.* TO roundcube@localhost IDENTIFIED BY '$r'"
  1017. sed -i "s/%password%/$r/g" /etc/roundcubemail/db.inc.php
  1018. mysql roundcube < /usr/share/doc/roundcubemail-*/SQL/mysql.initial.sql
  1019. # Configuring ip
  1020. $VESTA/bin/v-update-sys-ip
  1021. # Get main ip
  1022. main_ip=$(ifconfig |grep 'inet addr:' |grep -v 127.0.0.1 |head -n1 |\
  1023. cut -f2 -d: | cut -f1 -d ' ')
  1024. # Add default web domain on main ip
  1025. $VESTA/bin/v-add-web-domain admin default.domain $main_ip
  1026. # Add default dns domain on main ip
  1027. $VESTA/bin/v-add-dns-domain admin default.domain $main_ip
  1028. # Add default mail domain
  1029. $VESTA/bin/v-add-mail-domain admin default.domain
  1030. # Configuring crond
  1031. command='sudo /usr/local/vesta/bin/v-update-sys-queue disk'
  1032. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1033. command='sudo /usr/local/vesta/bin/v-update-sys-queue traffic'
  1034. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1035. command='sudo /usr/local/vesta/bin/v-update-sys-queue webstats'
  1036. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1037. command='sudo /usr/local/vesta/bin/v-update-sys-queue backup'
  1038. $VESTA/bin/v-add-cron-job 'admin' '*/30' '*' '*' '*' '*' "$command"
  1039. command='sudo /usr/local/vesta/bin/v-backup-users'
  1040. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1041. command='sudo /usr/local/vesta/bin/v-update-user-stats'
  1042. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '01' '*' '*' "$command"
  1043. command='sudo /usr/local/vesta/bin/v-update-sys-rrd'
  1044. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1045. # Creating symlink
  1046. ln -s /usr/local/vesta/log /var/log/vesta
  1047. # Stop unused services
  1048. services='iptables sendmail postfix'
  1049. for srv in $services; do
  1050. service $srv status > /dev/null
  1051. if [ $? -eq 0 ]; then
  1052. service $srv stop
  1053. fi
  1054. done
  1055. # Start system service
  1056. services='vesta httpd nginx vsftpd exim dovecot clamd spamassassin named crond'
  1057. for srv in $services; do
  1058. service $srv status > /dev/null
  1059. if [ $? -gt 0 ]; then
  1060. service $srv start
  1061. else
  1062. service $srv restart
  1063. fi
  1064. done
  1065. # Change sendmail client
  1066. rm -f /etc/alternatives/mta
  1067. ln -s /usr/sbin/sendmail.exim /etc/alternatives/mta
  1068. # Build inititall rrd images
  1069. $VESTA/bin/v-update-sys-rrd
  1070. # Send notification to vestacp.com
  1071. wget vestacp.com/notify/?$REPO -O /dev/null
  1072. # Get server ip
  1073. vst_ip=$(wget vestacp.com/what-is-my-ip/ -O - 2>/dev/null)
  1074. if [ ! -z "$vst_ip" ] && [ "$vst_ip" != "$main_ip" ]; then
  1075. # Assign passive ip address
  1076. echo "pasv_address=$vst_ip" >> /etc/vsftpd/vsftpd.conf
  1077. fi
  1078. if [ -z "$vst_ip" ]; then
  1079. vst_ip=$main_ip
  1080. fi
  1081. # Send email
  1082. echo -e "Congratulations, you have just successfully installed \
  1083. the Vesta Control Panel
  1084. You can login in Vesta with following credentials:
  1085. username: admin
  1086. password: $vpass
  1087. https://$vst_ip:8083
  1088. We hope that you enjoy your installation of Vesta. Please \
  1089. feel free to contact us anytime if you have any questions.
  1090. Thank you.
  1091. --
  1092. Sincerely yours
  1093. vestacp.com team
  1094. " > $tmpfile
  1095. cat $tmpfile | mail -s "Vesta Control Panel" $email
  1096. rm -f $tmpfile
  1097. # Congrats
  1098. echo
  1099. echo
  1100. echo ' ***********************************************************'
  1101. echo
  1102. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  1103. echo ' _| _| _| _| _| _| _| '
  1104. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  1105. echo ' _| _| _| _| _| _| _| '
  1106. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  1107. echo
  1108. echo ' Congratulations, you have just successfully installed'
  1109. echo ' the Vesta Control Panel!'
  1110. echo
  1111. echo ' Now you can login in Vesta with following credentials:'
  1112. echo ' username: admin'
  1113. echo " password: $vpass"
  1114. echo " https://$vst_ip:8083/"
  1115. echo
  1116. echo
  1117. echo ' Thank you for using our product.'
  1118. echo
  1119. echo ' ***********************************************************'
  1120. echo
  1121. echo
  1122. # Tricky way to get new PATH variable
  1123. cd
  1124. bash
  1125. # EOF
  1126. >>>>>>> 994c40901078e48fe939536f7b366e29c2e44a1d