vst-install-ubuntu.sh 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. #!/bin/bash
  2. # Vesta Ubuntu installer v.04
  3. #----------------------------------------------------------#
  4. # Variables&Functions #
  5. #----------------------------------------------------------#
  6. export PATH=$PATH:/sbin
  7. export DEBIAN_FRONTEND=noninteractive
  8. RHOST='apt.vestacp.com'
  9. CHOST='c.vestacp.com'
  10. VERSION='0.9.8/ubuntu'
  11. software="nginx apache2 apache2-utils apache2-suexec-custom bsdutils e2fsprogs
  12. libapache2-mod-ruid2 libapache2-mod-rpaf libapache2-mod-fcgid bind9 idn
  13. mysql-server mysql-common mysql-client php5-common php5-cgi php5-mysql
  14. php5-curl libapache2-mod-php5 vsftpd mc exim4 exim4-daemon-heavy
  15. clamav-daemon flex dovecot-imapd dovecot-pop3d phpMyAdmin awstats e2fslibs
  16. webalizer jwhois rssh git spamassassin roundcube roundcube-mysql quota
  17. roundcube-plugins apparmor-utils sudo bc ftp lsof ntpdate rrdtool
  18. fail2ban dnsutils vesta vesta-nginx vesta-php"
  19. help() {
  20. echo "usage: $0 [OPTIONS]
  21. -h, --help Print this help and exit
  22. -f, --force Force installation
  23. -i, --disable-iptables Disable iptables support
  24. -b, --disable-fail2ban Disable fail2ban protection
  25. -n, --noupdate Do not run apt-get upgrade command
  26. -s, --hostname Set server hostname
  27. -e, --email Set email address
  28. -p, --password Set admin password instead of generating it
  29. -m, --mysql-password Set MySQL password instead of generating it
  30. -q, --quota Enable File System Quota"
  31. exit 1
  32. }
  33. # Password generator
  34. gen_pass() {
  35. MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  36. LENGTH=10
  37. while [ ${n:=1} -le $LENGTH ]; do
  38. PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  39. let n+=1
  40. done
  41. echo "$PASS"
  42. }
  43. #----------------------------------------------------------#
  44. # Verifications #
  45. #----------------------------------------------------------#
  46. # Translating argument to --gnu-long-options
  47. for arg; do
  48. delim=""
  49. case "$arg" in
  50. --help) args="${args}-h " ;;
  51. --force) args="${args}-f " ;;
  52. --disable-fail2ban) args="${args}-b " ;;
  53. --disable-iptables) args="${args}-i " ;;
  54. --noupdate) args="${args}-n " ;;
  55. --hostname) args="${args}-s " ;;
  56. --email) args="${args}-e " ;;
  57. --password) args="${args}-p " ;;
  58. --mysql-password) args="${args}-m " ;;
  59. --quota) args="${args}-q " ;;
  60. *) [[ "${arg:0:1}" == "-" ]] || delim="\""
  61. args="${args}${delim}${arg}${delim} ";;
  62. esac
  63. done
  64. eval set -- "$args"
  65. # Getopt
  66. while getopts "hfibdnqe:m:p:s:" Option; do
  67. case $Option in
  68. h) help ;; # Help
  69. f) force='yes' ;; # Force install
  70. i) disable_iptables='yes' ;; # Disable iptables
  71. b) disable_fail2ban='yes' ;; # Disable fail2ban
  72. n) noupdate='yes' ;; # Disable apt-get upgrade
  73. s) servername=$OPTARG ;; # Server hostname
  74. e) email=$OPTARG ;; # Set email
  75. p) vpass=$OPTARG ;; # Admin password
  76. m) mpass=$OPTARG ;; # MySQL pasword
  77. q) quota='yes' ;; # Enable quota
  78. *) help ;; # Default
  79. esac
  80. done
  81. # Am I root?
  82. if [ "x$(id -u)" != 'x0' ]; then
  83. echo 'Error: this script can only be executed by root'
  84. exit 1
  85. fi
  86. # Check supported version
  87. if [ -e '/etc/redhat-release' ]; then
  88. echo 'Error: sorry, this installer works only on Ubuntu'
  89. exit 1
  90. fi
  91. # Check supported OS
  92. if [ "$(arch)" != 'x86_64' ]; then
  93. arch='i386'
  94. else
  95. arch="amd64"
  96. fi
  97. os=$(head -n 1 /etc/issue | cut -f 1 -d ' ')
  98. release=$(head -n 1 /etc/issue | cut -f 2 -d ' ' )
  99. codename=$(lsb_release -cs | egrep "precise|quantal|raring|saucy|trusty")
  100. if [ -z "$codename" ]; then
  101. echo "Error: Ubuntu $(lsb_release -r|awk '{print $2}') is not supported"
  102. exit 1
  103. fi
  104. # Check admin user account
  105. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" != 'yes' ]; then
  106. echo "Error: user admin exists"
  107. echo
  108. echo 'Please remove admin user account before proceeding.'
  109. echo 'If you want to do it automatically run installer with -f option:'
  110. echo "Example: bash $0 --force"
  111. exit 1
  112. fi
  113. # Check admin group
  114. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" != 'yes' ]; then
  115. echo "Error: group admin exists"
  116. echo
  117. echo 'Please remove admin group before proceeding.'
  118. echo 'If you want to do it automatically run installer with -f option:'
  119. echo "Example: bash $0 --force"
  120. exit 1
  121. fi
  122. # Check wget
  123. if [ ! -e '/usr/bin/wget' ]; then
  124. apt-get -y install wget
  125. if [ $? -ne 0 ]; then
  126. echo "Error: can't install wget"
  127. exit 1
  128. fi
  129. fi
  130. # Check repo availability
  131. wget -q "$CHOST/$VERSION/vesta.conf" -O /dev/null
  132. if [ $? -ne 0 ]; then
  133. echo "Error: no access to repository"
  134. exit 1
  135. fi
  136. # Check installed packages
  137. tmpfile=$(mktemp -p /tmp)
  138. dpkg --get-selections > $tmpfile
  139. for pkg in exim4 mysql-server apache2 nginx vesta; do
  140. if [ ! -z "$(grep $pkg $tmpfile)" ]; then
  141. conflicts="$pkg $conflicts"
  142. fi
  143. done
  144. rm -f $tmpfile
  145. if [ ! -z "$conflicts" ] && [ -z "$force" ]; then
  146. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  147. echo
  148. echo 'Following packages are already installed:'
  149. echo "$conflicts"
  150. echo
  151. echo 'It is highly recommended to remove them before proceeding.'
  152. echo 'If you want to force installation run this script with -f option:'
  153. echo "Example: bash $0 --force"
  154. echo
  155. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  156. echo
  157. exit 1
  158. fi
  159. # Check server type
  160. memory=$(grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9])
  161. if [ "$memory" -lt '350000' ] && [ -z "$force" ]; then
  162. echo "Error: not enough memory to install Vesta Control Panel."
  163. echo -e "\nMinimum RAM required: 350Mb"
  164. echo 'If you want to force installation run this script with -f option:'
  165. echo "Example: bash $0 --force"
  166. exit 1
  167. fi
  168. srv_type='micro'
  169. if [ "$memory" -gt '1000000' ]; then
  170. srv_type='small'
  171. fi
  172. if [ "$memory" -gt '3000000' ]; then
  173. srv_type='medium'
  174. fi
  175. if [ "$memory" -gt '7000000' ]; then
  176. srv_type='large'
  177. fi
  178. # Are you sure ?
  179. if [ -z $email ]; then
  180. clear
  181. echo
  182. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  183. echo ' _| _| _| _| _| _| _| '
  184. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  185. echo ' _| _| _| _| _| _| _| '
  186. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  187. echo
  188. echo ' Vesta Control Panel'
  189. echo
  190. echo
  191. echo 'Following software will be installed on your system:'
  192. echo ' - Nginx frontend web server'
  193. echo ' - Apache application web server'
  194. echo ' - Bind DNS server'
  195. echo ' - Exim mail server'
  196. echo ' - Dovecot IMAP and POP3 server'
  197. if [ "$srv_type" = 'medium' ] || [ "$srv_type" = 'large' ]; then
  198. echo ' - Clam mail antivirus'
  199. echo ' - SpamAssassin antispam'
  200. fi
  201. echo ' - MySQL database server'
  202. echo ' - Vsftpd FTP server'
  203. echo
  204. echo
  205. read -p 'Do you want to proceed? [y/n]): ' answer
  206. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  207. echo 'Goodbye'
  208. exit 1
  209. fi
  210. # Check email
  211. read -p 'Please enter valid email address: ' email
  212. # Define server hostname
  213. if [ -z "$servername" ]; then
  214. read -p "Please enter hostname [$(hostname)]: " servername
  215. fi
  216. fi
  217. # Validate email
  218. local_part=$(echo $email | cut -s -f1 -d\@)
  219. remote_host=$(echo $email | cut -s -f2 -d\@)
  220. mx_failed=1
  221. if [ ! -z "$remote_host" ] && [ ! -z "$local_part" ]; then
  222. /usr/bin/host -t mx "$remote_host" > /dev/null 2>&1
  223. mx_failed="$?"
  224. fi
  225. if [ "$mx_failed" -eq 1 ]; then
  226. echo "Error: email $email is not valid"
  227. exit 1
  228. fi
  229. #----------------------------------------------------------#
  230. # Install repository #
  231. #----------------------------------------------------------#
  232. # Let's start
  233. echo -e "\n\n\n\nInstallation will take about 15 minutes ...\n"
  234. sleep 5
  235. # Update system
  236. if [ -z "$noupdate" ]; then
  237. apt-get -y upgrade
  238. if [ $? -ne 0 ]; then
  239. echo 'Error: apt-get upgrade failed'
  240. exit 1
  241. fi
  242. fi
  243. # Install nginx repo
  244. apt=/etc/apt/sources.list.d
  245. echo "deb http://nginx.org/packages/ubuntu/ $codename nginx" > $apt/nginx.list
  246. wget http://nginx.org/keys/nginx_signing.key -O /tmp/nginx_signing.key
  247. apt-key add /tmp/nginx_signing.key
  248. # Install vesta repo
  249. echo "deb http://$RHOST/$codename/ $codename vesta" > $apt/vesta.list
  250. wget $CHOST/deb_signing.key -O deb_signing.key
  251. apt-key add deb_signing.key
  252. #----------------------------------------------------------#
  253. # Backups #
  254. #----------------------------------------------------------#
  255. # Prepare backup tree
  256. vst_backups="/root/vst_install_backups/$(date +%s)"
  257. mkdir -p $vst_backups/nginx
  258. mkdir -p $vst_backups/apache2
  259. mkdir -p $vst_backups/mysql
  260. mkdir -p $vst_backups/exim4
  261. mkdir -p $vst_backups/dovecot
  262. mkdir -p $vst_backups/clamav
  263. mkdir -p $vst_backups/spamassassin
  264. mkdir -p $vst_backups/vsftpd
  265. mkdir -p $vst_backups/bind
  266. mkdir -p $vst_backups/vesta
  267. mkdir -p $vst_backups/home
  268. # Backup nginx
  269. service nginx stop > /dev/null 2>&1
  270. if [ -e '/etc/nginx/nginx.conf' ]; then
  271. cp -r /etc/nginx/* $vst_backups/nginx/
  272. fi
  273. # Backup apache2
  274. service apache2 stop > /dev/null 2>&1
  275. if [ -e '/etc/apache2/apache2.conf' ]; then
  276. cp -r /etc/apache2/* $vst_backups/apache2/
  277. fi
  278. # Backup bind9
  279. service bind9 stop > /dev/null 2>&1
  280. if [ -e '/etc/bind/named.conf' ]; then
  281. cp -r /etc/bind/* $vst_backups/bind/
  282. fi
  283. # Backup vsftpd
  284. service vsftpd stop > /dev/null 2>&1
  285. if [ -e '/etc/vsftpd.conf' ]; then
  286. cp /etc/vsftpd.conf $vst_backups/vsftpd/
  287. fi
  288. # Backup exim4
  289. service exim4 stop > /dev/null 2>&1
  290. if [ -e '/etc/exim4/exim4.conf.template' ]; then
  291. cp -r /etc/exim4/* $vst_backups/exim4/
  292. fi
  293. # Backup clamav
  294. service clamav-daemon stop > /dev/null 2>&1
  295. if [ -e '/etc/clamav/clamd.conf' ]; then
  296. cp -r /etc/clamav/* $vst_backups/clamav/
  297. fi
  298. # Backup SpamAssassin
  299. service spamassassin stop > /dev/null 2>&1
  300. if [ -e '/etc/spamassassin/local.cf' ]; then
  301. cp -r /etc/spamassassin/* $vst_backups/spamassassin/
  302. fi
  303. # Backup dovecot
  304. service dovecot stop > /dev/null 2>&1
  305. if [ -e '/etc/dovecot.conf' ]; then
  306. cp /etc/dovecot.conf $vst_backups/dovecot/
  307. fi
  308. if [ -e '/etc/dovecot' ]; then
  309. cp -r /etc/dovecot/* $vst_backups/dovecot/
  310. fi
  311. # Backup MySQL stuff
  312. service mysql stop > /dev/null 2>&1
  313. if [ -e '/var/lib/mysql' ]; then
  314. mv /var/lib/mysql $vst_backups/mysql/mysql_datadir
  315. fi
  316. if [ -e '/etc/mysql/my.cnf' ]; then
  317. cp -r /etc/mysql/* $vst_backups/mysql/
  318. fi
  319. if [ -e '/root/.my.cnf' ]; then
  320. mv /root/.my.cnf $vst_backups/mysql/
  321. fi
  322. # Backup vesta
  323. service vesta stop > /dev/null 2>&1
  324. if [ -e '/usr/local/vesta' ]; then
  325. cp -r /usr/local/vesta/* $vst_backups/vesta/
  326. apt-get -y remove vesta*
  327. apt-get -y purge vesta*
  328. rm -rf /usr/local/vesta
  329. fi
  330. #----------------------------------------------------------#
  331. # Install packages #
  332. #----------------------------------------------------------#
  333. # Exclude heavy packages
  334. if [ "$srv_type" = 'micro' ]; then
  335. software=$(echo "$software" | sed -e 's/libapache2-mod-fcgid//')
  336. software=$(echo "$software" | sed -e 's/clamav-daemon//')
  337. software=$(echo "$software" | sed -e 's/spamassassin//')
  338. fi
  339. if [ "$srv_type" = 'small' ]; then
  340. software=$(echo "$software" | sed -e 's/clamav-daemon//')
  341. software=$(echo "$software" | sed -e 's/spamassassin//')
  342. fi
  343. # Exclude fail2ban
  344. if [ "$disable_fail2ban" = 'yes' ]; then
  345. software=$(echo "$software" | sed -e 's/fail2ban//')
  346. fi
  347. # Update system packages
  348. apt-get update
  349. # Disable daemon autostart
  350. # For more details /usr/share/doc/sysv-rc/README.policy-rc.d.gz
  351. echo -e '#!/bin/sh \nexit 101' > /usr/sbin/policy-rc.d
  352. chmod a+x /usr/sbin/policy-rc.d
  353. # Install Vesta packages
  354. apt-get -y install $software
  355. if [ $? -ne 0 ]; then
  356. echo 'Error: apt-get install failed'
  357. exit 1
  358. fi
  359. # Restore policy
  360. rm -f /usr/sbin/policy-rc.d
  361. #----------------------------------------------------------#
  362. # Configure system #
  363. #----------------------------------------------------------#
  364. # Set writable permission on tmp directory
  365. chmod 777 /tmp
  366. # Vesta configuration
  367. echo "export VESTA='/usr/local/vesta'" > /etc/profile.d/vesta.sh
  368. chmod 755 /etc/profile.d/vesta.sh
  369. source /etc/profile.d/vesta.sh
  370. echo 'PATH=$PATH:/usr/local/vesta/bin' >> /root/.bash_profile
  371. echo 'export PATH' >> /root/.bash_profile
  372. source /root/.bash_profile
  373. wget $CHOST/$VERSION/vesta.log -O /etc/logrotate.d/vesta
  374. # Directory tree
  375. mkdir -p $VESTA/conf
  376. mkdir -p $VESTA/log
  377. mkdir -p $VESTA/ssl
  378. mkdir -p $VESTA/data
  379. mkdir -p $VESTA/data/ips
  380. mkdir -p $VESTA/data/queue
  381. mkdir -p $VESTA/data/users
  382. mkdir -p $VESTA/data/firewall
  383. touch $VESTA/data/queue/backup.pipe
  384. touch $VESTA/data/queue/disk.pipe
  385. touch $VESTA/data/queue/webstats.pipe
  386. touch $VESTA/data/queue/restart.pipe
  387. touch $VESTA/data/queue/traffic.pipe
  388. chmod 750 $VESTA/conf
  389. chmod 750 $VESTA/data/users
  390. chmod 750 $VESTA/data/ips
  391. chmod -R 750 $VESTA/data/queue
  392. ln -s /usr/local/vesta/log /var/log/vesta
  393. touch /var/log/vesta/system.log
  394. touch /var/log/vesta/nginx-error.log
  395. touch /var/log/vesta/auth.log
  396. chmod 660 /var/log/vesta/*
  397. adduser backup > /dev/null 2>&1
  398. mkdir -p /home/backup
  399. chown backup:backup /home/backup
  400. ln -s /home/backup /backup
  401. chmod a+x /backup
  402. # vesta.conf
  403. wget $CHOST/$VERSION/vesta.conf -O $VESTA/conf/vesta.conf
  404. if [ "$srv_type" = 'micro' ] || [ "$srv_type" = 'small' ]; then
  405. sed -i "s/clamav-daemon//g" $VESTA/conf/vesta.conf
  406. sed -i "s/spamassassin//g" $VESTA/conf/vesta.conf
  407. fi
  408. # Set server hostname
  409. if [ -z "$servername" ]; then
  410. servername=$(hostname)
  411. fi
  412. /usr/local/vesta/bin/v-change-sys-hostname $servername 2>/dev/null
  413. # Templates, packages
  414. cd /usr/local/vesta/data
  415. wget $CHOST/$VERSION/packages.tar.gz -O packages.tar.gz
  416. tar -xzf packages.tar.gz
  417. rm -f packages.tar.gz
  418. cd /usr/local/vesta/data
  419. wget $CHOST/$VERSION/templates.tar.gz -O templates.tar.gz
  420. tar -xzf templates.tar.gz
  421. rm -f templates.tar.gz
  422. if [ "$codename" = 'saucy' ] || [ "$codename" = 'trusty' ]; then
  423. sed -i "s/Include /IncludeOptional /g" \
  424. $VESTA/data/templates/web/apache2/*tpl
  425. fi
  426. chmod -R 755 /usr/local/vesta/data/templates
  427. cp templates/web/skel/public_html/index.html /var/www/
  428. sed -i 's/%domain%/It worked!/g' /var/www/index.html
  429. if [ "$srv_type" = 'micro' ]; then
  430. rm -f /usr/local/vesta/data/templates/web/apache2/phpfcgid.*
  431. fi
  432. # Removing CGI templates
  433. if [ "$codename" = 'trusty' ]; then
  434. rm -f /usr/local/vesta/data/templates/web/apache2/phpcgi.*
  435. fi
  436. # Generating SSL certificate
  437. $VESTA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  438. 'San Francisco' 'Vesta Control Panel' 'IT' > /tmp/vst.pem
  439. # Parsing merged certificate file
  440. crt_end=$(grep -n "END CERTIFICATE-" /tmp/vst.pem |cut -f 1 -d:)
  441. key_start=$(grep -n "BEGIN RSA" /tmp/vst.pem |cut -f 1 -d:)
  442. key_end=$(grep -n "END RSA" /tmp/vst.pem |cut -f 1 -d:)
  443. # Adding SSL certificate
  444. cd /usr/local/vesta/ssl
  445. sed -n "1,${crt_end}p" /tmp/vst.pem > certificate.crt
  446. sed -n "$key_start,${key_end}p" /tmp/vst.pem > certificate.key
  447. chown root:mail /usr/local/vesta/ssl/*
  448. chmod 660 /usr/local/vesta/ssl/*
  449. rm /tmp/vst.pem
  450. # Enable SSH password auth
  451. sed -i "s/rdAuthentication no/rdAuthentication yes/g" /etc/ssh/sshd_config
  452. service ssh restart
  453. # AppArmor
  454. aa-complain /usr/sbin/named
  455. # Disable awstats cron
  456. rm -f /etc/cron.d/awstats
  457. # Set directory color
  458. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  459. # Register /sbin/nologin
  460. echo "/sbin/nologin" >> /etc/shells
  461. # Sudo configuration
  462. wget $CHOST/$VERSION/sudoers.vestacp.conf -O /etc/sudoers.d/vestacp
  463. wget $CHOST/$VERSION/sudoers.admin.conf -O /etc/sudoers.d/admin
  464. chmod 440 /etc/sudoers.d/vestacp
  465. chmod 440 /etc/sudoers.d/admin
  466. echo 'Defaults:admin !syslog' >>/etc/sudoers.d/admin
  467. # NTP Synchronization
  468. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  469. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  470. chmod 775 /etc/cron.daily/ntpdate
  471. ntpdate -s pool.ntp.org
  472. # Setup rssh
  473. if [ -z "$(grep /usr/bin/rssh /etc/shells)" ]; then
  474. echo /usr/bin/rssh >> /etc/shells
  475. fi
  476. sed -i 's/#allowscp/allowscp/' /etc/rssh.conf
  477. sed -i 's/#allowsftp/allowsftp/' /etc/rssh.conf
  478. sed -i 's/#allowrsync/allowrsync/' /etc/rssh.conf
  479. chmod 755 /usr/bin/rssh
  480. # Nginx configuration
  481. rm -f /etc/nginx/conf.d/*.conf
  482. wget $CHOST/$VERSION/nginx.conf -O /etc/nginx/nginx.conf
  483. wget $CHOST/$VERSION/nginx-status.conf -O /etc/nginx/conf.d/status.conf
  484. touch /etc/nginx/conf.d/vesta.conf
  485. update-rc.d nginx defaults
  486. service nginx stop > /dev/null 2>&1
  487. service nginx start
  488. if [ "$?" -ne 0 ]; then
  489. echo "Error: nginx start failed"
  490. exit 1
  491. fi
  492. # Apache configuration
  493. wget $CHOST/$VERSION/apache2.conf -O /etc/apache2/apache2.conf
  494. if [ "$codename" = 'saucy' ] || [ "$codename" = 'trusty' ]; then
  495. sed -i "/^LockFile /d" /etc/apache2/apache2.conf
  496. fi
  497. wget $CHOST/$VERSION/apache2-status.conf \
  498. -O /etc/apache2/mods-enabled/status.conf
  499. wget $CHOST/$VERSION/apache2.log -O /etc/logrotate.d/apache2
  500. echo "# Powered by vesta" > /etc/apache2/sites-available/default
  501. echo "# Powered by vesta" > /etc/apache2/sites-available/default-ssl
  502. echo "# Powered by vesta" > /etc/apache2/ports.conf
  503. mkdir -p /etc/apache2/conf.d
  504. rm -f /etc/apache2/conf.d/vesta.conf
  505. echo > /etc/apache2/conf.d/vesta.conf
  506. touch /var/log/apache2/access.log
  507. touch /var/log/apache2/error.log
  508. mkdir -p /var/log/apache2/domains
  509. chmod a+x /var/log/apache2
  510. chmod 640 /var/log/apache2/access.log
  511. chmod 640 /var/log/apache2/error.log
  512. chmod 751 /var/log/apache2/domains
  513. a2enmod rewrite
  514. a2enmod ssl
  515. a2enmod suexec
  516. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  517. update-rc.d apache2 defaults
  518. service apache2 stop > /dev/null 2>&1
  519. service apache2 start
  520. if [ "$?" -ne 0 ]; then
  521. echo "Error: apache2 start failed"
  522. exit 1
  523. fi
  524. # Vsftpd configuration
  525. wget $CHOST/$VERSION/vsftpd.conf -O /etc/vsftpd.conf
  526. update-rc.d vsftpd defaults
  527. service vsftpd stop > /dev/null 2>&1
  528. service vsftpd start
  529. if [ "$?" -ne 0 ]; then
  530. echo "Error: vsftpd start failed"
  531. exit 1
  532. fi
  533. # Generating MySQL password if it wasn't set
  534. if [ -z "$mpass" ]; then
  535. mpass=$(gen_pass)
  536. fi
  537. # MySQL configuration
  538. wget $CHOST/$VERSION/my.cnf -O /etc/mysql/my.cnf
  539. mysql_install_db
  540. if [ "$release" != '14.04' ]; then
  541. update-rc.d mysql defaults
  542. fi
  543. service mysql stop > /dev/null 2>&1
  544. service mysql start
  545. if [ "$?" -ne 0 ]; then
  546. echo "Error: mysql start failed"
  547. exit 1
  548. fi
  549. mysqladmin -u root password $mpass
  550. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  551. chmod 600 /root/.my.cnf
  552. mysql -e "DELETE FROM mysql.user WHERE User=''"
  553. mysql -e "DROP DATABASE test" > /dev/null 2>&1
  554. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  555. mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
  556. mysql -e "FLUSH PRIVILEGES"
  557. # Bind configuration
  558. wget $CHOST/$VERSION/named.conf -O /etc/bind/named.conf
  559. sed -i "s%listen-on%//listen%" /etc/bind/named.conf.options
  560. chown root:bind /etc/bind/named.conf
  561. chmod 640 /etc/bind/named.conf
  562. update-rc.d bind9 defaults
  563. service bind9 stop > /dev/null 2>&1
  564. service bind9 start
  565. if [ "$?" -ne 0 ]; then
  566. echo "Error: bind9 start failed"
  567. exit 1
  568. fi
  569. # Exim
  570. wget $CHOST/$VERSION/exim4.conf.template -O /etc/exim4/exim4.conf.template
  571. if [ "$srv_type" != 'micro' ] && [ "$srv_type" != 'small' ]; then
  572. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  573. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  574. fi
  575. wget $CHOST/$VERSION/dnsbl.conf -O /etc/exim4/dnsbl.conf
  576. wget $CHOST/$VERSION/spam-blocks.conf -O /etc/exim4/spam-blocks.conf
  577. touch /etc/exim4/white-blocks.conf
  578. rm -rf /etc/exim4/domains
  579. mkdir -p /etc/exim4/domains
  580. chmod 640 /etc/exim4/exim4.conf.template
  581. gpasswd -a Debian-exim mail
  582. if [ -e /etc/init.d/sendmail ]; then
  583. update-rc.d -f sendmail remove
  584. service sendmail stop
  585. fi
  586. if [ -e /etc/init.d/postfix ]; then
  587. update-rc.d -f postfix remove
  588. service postfix stop
  589. fi
  590. rm -f /etc/alternatives/mta
  591. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  592. update-rc.d exim4 defaults
  593. service exim4 stop > /dev/null 2>&1
  594. service exim4 start
  595. if [ "$?" -ne 0 ]; then
  596. echo "Error: exim start failed"
  597. exit
  598. fi
  599. # Dovecot configuration
  600. wget $CHOST/$VERSION/dovecot.conf -O /etc/dovecot/dovecot.conf
  601. cd /etc/dovecot/
  602. wget $CHOST/$VERSION/dovecot-conf.d.tar.gz
  603. rm -rf conf.d *.ext README
  604. tar -xzf dovecot-conf.d.tar.gz
  605. rm -f dovecot-conf.d.tar.gz
  606. chown -R root:root /etc/dovecot
  607. gpasswd -a dovecot mail
  608. update-rc.d dovecot defaults
  609. service dovecot stop > /dev/null 2>&1
  610. service dovecot start
  611. if [ "$?" -ne 0 ]; then
  612. echo "Error: dovecot start failed"
  613. exit 1
  614. fi
  615. # ClamAV configuration
  616. if [ "$srv_type" = 'medium' ] || [ "$srv_type" = 'large' ]; then
  617. wget $CHOST/$VERSION/clamd.conf -O /etc/clamav/clamd.conf
  618. gpasswd -a clamav mail
  619. gpasswd -a clamav Debian-exim
  620. /usr/bin/freshclam
  621. update-rc.d clamav-daemon defaults
  622. service clamav-daemon stop > /dev/null 2>&1
  623. service clamav-daemon start
  624. if [ "$?" -ne 0 ]; then
  625. echo "Error: clamav start failed"
  626. exit 1
  627. fi
  628. fi
  629. # SpamAssassin configuration
  630. if [ "$srv_type" = 'medium' ] || [ "$srv_type" = 'large' ]; then
  631. update-rc.d spamassassin defaults
  632. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  633. service spamassassin stop > /dev/null 2>&1
  634. service spamassassin start
  635. if [ "$?" -ne 0 ]; then
  636. echo "Error: spamassassin start failed"
  637. exit 1
  638. fi
  639. fi
  640. # Fail2ban configuration
  641. if [ -z "$disable_fail2ban" ]; then
  642. cd /etc
  643. wget $CHOST/$VERSION/fail2ban.tar.gz -O fail2ban.tar.gz
  644. tar -xzf fail2ban.tar.gz
  645. rm -f fail2ban.tar.gz
  646. chkconfig fail2ban on
  647. service fail2ban start
  648. else
  649. sed -i "s/fail2ban//" $VESTA/conf/vestac.conf
  650. fi
  651. # php configuration
  652. sed -i "s/;date.timezone =/date.timezone = UTC/g" /etc/php5/apache2/php.ini
  653. sed -i "s/;date.timezone =/date.timezone = UTC/g" /etc/php5/cli/php.ini
  654. if [ "$codename" = 'saucy' ] || [ "$codename" = 'trusty' ]; then
  655. ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available
  656. php5enmod mcrypt
  657. service apache2 restart
  658. fi
  659. # phpMyAdmin configuration
  660. wget $CHOST/$VERSION/apache2-pma.conf -O /etc/phpmyadmin/apache.conf
  661. wget $CHOST/$VERSION/pma.conf -O /etc/phpmyadmin/config.inc.php
  662. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  663. mv -f /etc/phpmyadmin/config-db.php /etc/phpmyadmin/config-db.php_
  664. chmod 777 /var/lib/phpmyadmin/tmp
  665. # Roundcube configuration
  666. wget $CHOST/$VERSION/apache2-webmail.conf -O /etc/roundcube/apache.conf
  667. wget $CHOST/$VERSION/roundcube-main.conf -O /etc/roundcube/main.inc.php
  668. wget $CHOST/$VERSION/roundcube-db.conf -O /etc/roundcube/db.inc.php
  669. wget $CHOST/$VERSION/roundcube-driver.php -O \
  670. /usr/share/roundcube/plugins/password/drivers/vesta.php
  671. wget $CHOST/$VERSION/roundcube-pw.conf -O \
  672. /etc/roundcube/plugins/password/config.inc.php
  673. r="$(gen_pass)"
  674. mysql -e "DROP DATABASE roundcube" > /dev/null 2>&1
  675. mysql -e "CREATE DATABASE roundcube"
  676. mysql -e "GRANT ALL ON roundcube.* TO roundcube@localhost IDENTIFIED BY '$r'"
  677. sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
  678. mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  679. if [ "$codename" = 'saucy' ] || [ "$codename" = 'trusty' ]; then
  680. wget $CHOST/$VERSION/roundcube-driver-new.php -O \
  681. /usr/share/roundcube/plugins/password/drivers/vesta.php
  682. ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/
  683. service apache2 restart
  684. fi
  685. mkdir -p /var/log/roundcube/error
  686. chmod -R 777 /var/log/roundcube
  687. # Deleting old admin user account if exists
  688. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  689. chattr -i /home/admin/conf > /dev/null 2>&1
  690. userdel -f admin
  691. chattr -i /home/admin/conf
  692. mv -f /home/admin $vst_backups/home/
  693. rm -f /tmp/sess_*
  694. fi
  695. if [ ! -z "$(grep ^admin: /etc/group)" ]; then
  696. groupdel admin > /dev/null 2>&1
  697. fi
  698. # Generating admin password if it wasn't set
  699. if [ -z "$vpass" ]; then
  700. vpass=$(gen_pass)
  701. fi
  702. # Adding admin account
  703. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  704. if [ $? -ne 0 ]; then
  705. echo "Error: can't create admin user"
  706. exit 1
  707. fi
  708. $VESTA/bin/v-change-user-shell admin bash
  709. $VESTA/bin/v-change-user-language admin en
  710. # Configure mysql host
  711. $VESTA/bin/v-add-database-host mysql localhost root $mpass
  712. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  713. # Configuring system ips
  714. $VESTA/bin/v-update-sys-ip
  715. # Firewall configuartion
  716. cd $VESTA/data
  717. wget $CHOST/$VERSION/firewall.tar.gz -O firewall.tar.gz
  718. tar -xzf firewall.tar.gz
  719. rm -f firewall.tar.gz
  720. if [ "$disable_iptables" = 'yes' ]; then
  721. sed -i "s/iptables//" $VESTA/conf/vesta.conf
  722. else
  723. /usr/local/vesta/bin/v-update-firewall
  724. fi
  725. # Get main ip
  726. main_ip=$(ifconfig |grep 'inet addr:' |grep -v 127.0.0.1 |head -n1 | \
  727. cut -f2 -d: | cut -f1 -d ' ')
  728. # Get remote ip
  729. vst_ip=$(wget vestacp.com/what-is-my-ip/ -O - 2>/dev/null)
  730. if [ ! -z "$vst_ip" ] && [ "$vst_ip" != "$main_ip" ]; then
  731. # Set NAT association
  732. $VESTA/bin/v-change-sys-ip-nat $main_ip $vst_ip
  733. fi
  734. if [ -z "$vst_ip" ]; then
  735. vst_ip=$main_ip
  736. fi
  737. # Add default web domain
  738. $VESTA/bin/v-add-web-domain admin default.domain $vst_ip
  739. # Add default dns domain
  740. $VESTA/bin/v-add-dns-domain admin default.domain $vst_ip
  741. # Add default mail domain
  742. $VESTA/bin/v-add-mail-domain admin default.domain
  743. # Configuring cron jobs
  744. command='sudo /usr/local/vesta/bin/v-update-sys-queue disk'
  745. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  746. command='sudo /usr/local/vesta/bin/v-update-sys-queue traffic'
  747. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  748. command='sudo /usr/local/vesta/bin/v-update-sys-queue webstats'
  749. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  750. command='sudo /usr/local/vesta/bin/v-update-sys-queue backup'
  751. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  752. command='sudo /usr/local/vesta/bin/v-backup-users'
  753. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  754. command='sudo /usr/local/vesta/bin/v-update-user-stats'
  755. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  756. command='sudo /usr/local/vesta/bin/v-update-sys-rrd'
  757. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  758. # Building inititall rrd images
  759. $VESTA/bin/v-update-sys-rrd
  760. # Enable file system quota
  761. if [ "$quota" = 'yes' ]; then
  762. $VESTA/bin/v-add-sys-quota
  763. fi
  764. # Start system service
  765. update-rc.d vesta defaults
  766. service vesta stop > /dev/null 2>&1
  767. service vesta start
  768. if [ "$?" -ne 0 ]; then
  769. echo "Error: vesta start failed"
  770. exit 1
  771. fi
  772. # Send notification to vestacp.com
  773. wget vestacp.com/notify/?$codename -O /dev/null
  774. # Send notification to admin email
  775. echo -e "Congratulations, you have just successfully installed \
  776. the Vesta Control Panel
  777. You can login in Vesta with following credentials:
  778. username: admin
  779. password: $vpass
  780. https://$vst_ip:8083
  781. We hope that you enjoy your installation of Vesta. Please \
  782. feel free to contact us anytime if you have any questions.
  783. Thank you.
  784. --
  785. Sincerely yours
  786. vestacp.com team
  787. " > $tmpfile
  788. send_mail="$VESTA/web/inc/mail-wrapper.php"
  789. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  790. rm -f $tmpfile
  791. # Congrats
  792. echo '======================================================='
  793. echo
  794. echo
  795. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  796. echo ' _| _| _| _| _| _| _| '
  797. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  798. echo ' _| _| _| _| _| _| _| '
  799. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  800. echo
  801. echo
  802. echo '-------------------------------'
  803. echo " https://$vst_ip:8083"
  804. echo ' username: admin'
  805. echo " password: $vpass"
  806. echo '-------------------------------'
  807. echo
  808. echo
  809. echo 'Congratulations,'
  810. echo 'you have successfully installed Vesta Control Panel.'
  811. echo
  812. echo
  813. # Tricky way to get new PATH variable
  814. cd
  815. bash
  816. #EOF