vst-install-debian.sh 27 KB

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