vst-install-debian.sh 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. #!/bin/bash
  2. # Vesta Debian installer v.05
  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='debian'
  11. VESTA='/usr/local/vesta'
  12. memory=$(grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9])
  13. arch=$(uname -i)
  14. os='debian'
  15. release=$(cat /etc/debian_version|grep -o [0-9]|head -n1)
  16. codename="$(cat /etc/os-release |grep VERSION= |cut -f 2 -d \(|cut -f 1 -d \))"
  17. vestacp="http://$CHOST/$VERSION/$release"
  18. if [ "$release" -eq 8 ]; then
  19. software="nginx apache2 apache2-utils apache2.2-common
  20. apache2-suexec-custom libapache2-mod-ruid2
  21. libapache2-mod-fcgid libapache2-mod-php5 php5 php5-common php5-cgi
  22. php5-mysql php5-curl php5-fpm php5-pgsql awstats webalizer vsftpd
  23. proftpd-basic bind9 exim4 exim4-daemon-heavy clamav-daemon
  24. spamassassin dovecot-imapd dovecot-pop3d roundcube-core
  25. roundcube-mysql roundcube-plugins mysql-server mysql-common
  26. mysql-client postgresql postgresql-contrib phppgadmin phpMyAdmin mc
  27. flex whois rssh git idn zip sudo bc ftp lsof ntpdate rrdtool quota
  28. e2fslibs bsdutils e2fsprogs curl imagemagick fail2ban dnsutils
  29. bsdmainutils cron vesta vesta-nginx vesta-php expect libmail-dkim-perl unrar-free"
  30. else
  31. software="nginx apache2 apache2-utils apache2.2-common
  32. apache2-suexec-custom libapache2-mod-ruid2
  33. libapache2-mod-fcgid libapache2-mod-php5 php5 php5-common php5-cgi
  34. php5-mysql php5-curl php5-fpm php5-pgsql awstats webalizer vsftpd
  35. proftpd-basic proftpd-mod-vroot bind9 exim4 exim4-daemon-heavy
  36. clamav-daemon spamassassin dovecot-imapd dovecot-pop3d roundcube-core
  37. roundcube-mysql roundcube-plugins mysql-server mysql-common
  38. mysql-client postgresql postgresql-contrib phppgadmin phpMyAdmin mc
  39. flex whois rssh git idn zip sudo bc ftp lsof ntpdate rrdtool quota
  40. e2fslibs bsdutils e2fsprogs curl imagemagick fail2ban dnsutils
  41. bsdmainutils cron vesta vesta-nginx vesta-php expect unrar-free"
  42. fi
  43. # Defining help function
  44. help() {
  45. echo "Usage: $0 [OPTIONS]
  46. -a, --apache Install Apache [yes|no] default: yes
  47. -n, --nginx Install Nginx [yes|no] default: yes
  48. -w, --phpfpm Install PHP-FPM [yes|no] default: no
  49. -v, --vsftpd Install Vsftpd [yes|no] default: yes
  50. -j, --proftpd Install ProFTPD [yes|no] default: no
  51. -k, --named Install Bind [yes|no] default: yes
  52. -m, --mysql Install MySQL [yes|no] default: yes
  53. -g, --postgresql Install PostgreSQL [yes|no] default: no
  54. -d, --mongodb Install MongoDB [yes|no] unsupported
  55. -x, --exim Install Exim [yes|no] default: yes
  56. -z, --dovecot Install Dovecot [yes|no] default: yes
  57. -c, --clamav Install ClamAV [yes|no] default: yes
  58. -t, --spamassassin Install SpamAssassin [yes|no] default: yes
  59. -i, --iptables Install Iptables [yes|no] default: yes
  60. -b, --fail2ban Install Fail2ban [yes|no] default: yes
  61. -q, --quota Filesystem Quota [yes|no] default: no
  62. -l, --lang Default language default: en
  63. -y, --interactive Interactive install [yes|no] default: yes
  64. -s, --hostname Set hostname
  65. -e, --email Set admin email
  66. -p, --password Set admin password
  67. -f, --force Force installation
  68. -h, --help Print this help
  69. Example: bash $0 -e demo@vestacp.com -p p4ssw0rd --apache no --phpfpm yes"
  70. exit 1
  71. }
  72. # Defining password-gen function
  73. gen_pass() {
  74. MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  75. LENGTH=10
  76. while [ ${n:=1} -le $LENGTH ]; do
  77. PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  78. let n+=1
  79. done
  80. echo "$PASS"
  81. }
  82. # Defning return code check function
  83. check_result() {
  84. if [ $1 -ne 0 ]; then
  85. echo "Error: $2"
  86. exit $1
  87. fi
  88. }
  89. # Defining function to set default value
  90. set_default_value() {
  91. eval variable=\$$1
  92. if [ -z "$variable" ]; then
  93. eval $1=$2
  94. fi
  95. if [ "$variable" != 'yes' ] && [ "$variable" != 'no' ]; then
  96. eval $1=$2
  97. fi
  98. }
  99. # Define function to set default language value
  100. set_default_lang() {
  101. if [ -z "$lang" ]; then
  102. eval lang=$1
  103. fi
  104. lang_list="
  105. ar cz el fa hu ja no pt se ua
  106. bs da en fi id ka pl ro tr vi
  107. cn de es fr it nl pt-BR ru tw
  108. bg ko sr th ur"
  109. if !(echo $lang_list |grep -w $lang 1>&2>/dev/null); then
  110. eval lang=$1
  111. fi
  112. }
  113. #----------------------------------------------------------#
  114. # Verifications #
  115. #----------------------------------------------------------#
  116. # Creating temporary file
  117. tmpfile=$(mktemp -p /tmp)
  118. # Translating argument to --gnu-long-options
  119. for arg; do
  120. delim=""
  121. case "$arg" in
  122. --apache) args="${args}-a " ;;
  123. --nginx) args="${args}-n " ;;
  124. --phpfpm) args="${args}-w " ;;
  125. --vsftpd) args="${args}-v " ;;
  126. --proftpd) args="${args}-j " ;;
  127. --named) args="${args}-k " ;;
  128. --mysql) args="${args}-m " ;;
  129. --postgresql) args="${args}-g " ;;
  130. --mongodb) args="${args}-d " ;;
  131. --exim) args="${args}-x " ;;
  132. --dovecot) args="${args}-z " ;;
  133. --clamav) args="${args}-c " ;;
  134. --spamassassin) args="${args}-t " ;;
  135. --iptables) args="${args}-i " ;;
  136. --fail2ban) args="${args}-b " ;;
  137. --remi) args="${args}-r " ;;
  138. --quota) args="${args}-q " ;;
  139. --lang) args="${args}-l " ;;
  140. --interactive) args="${args}-y " ;;
  141. --hostname) args="${args}-s " ;;
  142. --email) args="${args}-e " ;;
  143. --password) args="${args}-p " ;;
  144. --force) args="${args}-f " ;;
  145. --help) args="${args}-h " ;;
  146. *) [[ "${arg:0:1}" == "-" ]] || delim="\""
  147. args="${args}${delim}${arg}${delim} ";;
  148. esac
  149. done
  150. eval set -- "$args"
  151. # Parsing arguments
  152. while getopts "a:n:w:v:j:k:m:g:d:x:z:c:t:i:b:r:q:l:y:s:e:p:fh" Option; do
  153. case $Option in
  154. a) apache=$OPTARG ;; # Apache
  155. n) nginx=$OPTARG ;; # Nginx
  156. w) phpfpm=$OPTARG ;; # PHP-FPM
  157. v) vsftpd=$OPTARG ;; # Vsftpd
  158. j) proftpd=$OPTARG ;; # Proftpd
  159. k) named=$OPTARG ;; # Named
  160. m) mysql=$OPTARG ;; # MySQL
  161. g) postgresql=$OPTARG ;; # PostgreSQL
  162. d) mongodb=$OPTARG ;; # MongoDB (unsupported)
  163. x) exim=$OPTARG ;; # Exim
  164. z) dovecot=$OPTARG ;; # Dovecot
  165. c) clamd=$OPTARG ;; # ClamAV
  166. t) spamd=$OPTARG ;; # SpamAssassin
  167. i) iptables=$OPTARG ;; # Iptables
  168. b) fail2ban=$OPTARG ;; # Fail2ban
  169. r) remi=$OPTARG ;; # Remi repo
  170. q) quota=$OPTARG ;; # FS Quota
  171. l) lang=$OPTARG ;; # Language
  172. y) interactive=$OPTARG ;; # Interactive install
  173. s) servername=$OPTARG ;; # Hostname
  174. e) email=$OPTARG ;; # Admin email
  175. p) vpass=$OPTARG ;; # Admin password
  176. f) force='yes' ;; # Force install
  177. h) help ;; # Help
  178. *) help ;; # Print help (default)
  179. esac
  180. done
  181. # Defining default software stack
  182. set_default_value 'nginx' 'yes'
  183. set_default_value 'apache' 'yes'
  184. set_default_value 'phpfpm' 'no'
  185. set_default_value 'vsftpd' 'yes'
  186. set_default_value 'proftpd' 'no'
  187. set_default_value 'named' 'yes'
  188. set_default_value 'mysql' 'yes'
  189. set_default_value 'postgresql' 'no'
  190. set_default_value 'mongodb' 'no'
  191. set_default_value 'exim' 'yes'
  192. set_default_value 'dovecot' 'yes'
  193. if [ $memory -lt 1500000 ]; then
  194. set_default_value 'clamd' 'no'
  195. set_default_value 'spamd' 'no'
  196. else
  197. set_default_value 'clamd' 'yes'
  198. set_default_value 'spamd' 'yes'
  199. fi
  200. set_default_value 'iptables' 'yes'
  201. set_default_value 'fail2ban' 'yes'
  202. set_default_value 'quota' 'no'
  203. set_default_value 'interactive' 'yes'
  204. set_default_lang 'en'
  205. # Checking software conflicts
  206. if [ "$phpfpm" = 'yes' ]; then
  207. apache='no'
  208. nginx='yes'
  209. fi
  210. if [ "$proftpd" = 'yes' ]; then
  211. vsftpd='no'
  212. fi
  213. if [ "$exim" = 'no' ]; then
  214. clamd='no'
  215. spamd='no'
  216. dovecot='no'
  217. fi
  218. if [ "$iptables" = 'no' ]; then
  219. fail2ban='no'
  220. fi
  221. # Checking root permissions
  222. if [ "x$(id -u)" != 'x0' ]; then
  223. check_error 1 "Script can be run executed only by root"
  224. fi
  225. # Checking admin user account
  226. if [ ! -z "$(grep ^admin: /etc/passwd /etc/group)" ] && [ -z "$force" ]; then
  227. echo 'Please remove admin user account before proceeding.'
  228. echo 'If you want to do it automatically run installer with -f option:'
  229. echo -e "Example: bash $0 --force\n"
  230. check_result 1 "User admin exists"
  231. fi
  232. # Checking wget
  233. if [ ! -e '/usr/bin/wget' ]; then
  234. apt-get -y install wget
  235. check_result $? "Can't install wget"
  236. fi
  237. # Checking repository availability
  238. wget -q "$vestacp/deb_signing.key" -O /dev/null
  239. check_result $? "No access to Vesta repository"
  240. # Check installed packages
  241. tmpfile=$(mktemp -p /tmp)
  242. dpkg --get-selections > $tmpfile
  243. for pkg in exim4 mysql-server apache2 nginx vesta; do
  244. if [ ! -z "$(grep $pkg $tmpfile)" ]; then
  245. conflicts="$pkg $conflicts"
  246. fi
  247. done
  248. rm -f $tmpfile
  249. if [ ! -z "$conflicts" ] && [ -z "$force" ]; then
  250. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  251. echo
  252. echo 'Following packages are already installed:'
  253. echo "$conflicts"
  254. echo
  255. echo 'It is highly recommended to remove them before proceeding.'
  256. echo 'If you want to force installation run this script with -f option:'
  257. echo "Example: bash $0 --force"
  258. echo
  259. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  260. echo
  261. check_result 1 "Control Panel should be installed on clean server."
  262. fi
  263. #----------------------------------------------------------#
  264. # Brief Info #
  265. #----------------------------------------------------------#
  266. # Printing nice ascii aslogo
  267. clear
  268. echo
  269. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_|'
  270. echo ' _| _| _| _| _| _| _|'
  271. echo ' _| _| _|_|_| _|_| _| _|_|_|_|'
  272. echo ' _| _| _| _| _| _| _|'
  273. echo ' _| _|_|_|_| _|_|_| _| _| _|'
  274. echo
  275. echo ' Vesta Control Panel'
  276. echo -e "\n\n"
  277. echo 'Following software will be installed on your system:'
  278. # Web stack
  279. if [ "$nginx" = 'yes' ]; then
  280. echo ' - Nginx Web Server'
  281. fi
  282. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  283. echo ' - Apache Web Server'
  284. fi
  285. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  286. echo ' - Apache Web Server (as backend)'
  287. fi
  288. if [ "$phpfpm" = 'yes' ]; then
  289. echo ' - PHP-FPM Application Server'
  290. fi
  291. # DNS stack
  292. if [ "$named" = 'yes' ]; then
  293. echo ' - Bind DNS Server'
  294. fi
  295. # Mail Stack
  296. if [ "$exim" = 'yes' ]; then
  297. echo -n ' - Exim mail server'
  298. if [ "$clamd" = 'yes' ] || [ "$spamd" = 'yes' ] ; then
  299. echo -n ' + '
  300. if [ "$clamd" = 'yes' ]; then
  301. echo -n 'Antivirus '
  302. fi
  303. if [ "$spamd" = 'yes' ]; then
  304. echo -n 'Antispam'
  305. fi
  306. fi
  307. echo
  308. if [ "$dovecot" = 'yes' ]; then
  309. echo ' - Dovecot POP3/IMAP Server'
  310. fi
  311. fi
  312. # DB stack
  313. if [ "$mysql" = 'yes' ]; then
  314. echo ' - MySQL Database Server'
  315. fi
  316. if [ "$postgresql" = 'yes' ]; then
  317. echo ' - PostgreSQL Database Server'
  318. fi
  319. if [ "$mongodb" = 'yes' ]; then
  320. echo ' - MongoDB Database Server'
  321. fi
  322. # FTP stack
  323. if [ "$vsftpd" = 'yes' ]; then
  324. echo ' - Vsftpd FTP Server'
  325. fi
  326. if [ "$proftpd" = 'yes' ]; then
  327. echo ' - ProFTPD FTP Server'
  328. fi
  329. # Firewall stack
  330. if [ "$iptables" = 'yes' ]; then
  331. echo -n ' - Iptables Firewall'
  332. fi
  333. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  334. echo -n ' + Fail2Ban'
  335. fi
  336. echo -e "\n\n"
  337. # Asking for confirmation to proceed
  338. if [ "$interactive" = 'yes' ]; then
  339. read -p 'Would you like to continue [y/n]: ' answer
  340. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  341. echo 'Goodbye'
  342. exit 1
  343. fi
  344. # Asking for contact email
  345. if [ -z "$email" ]; then
  346. read -p 'Please enter admin email address: ' email
  347. fi
  348. # Asking to set FQDN hostname
  349. if [ -z "$servername" ]; then
  350. read -p "Please enter FQDN hostname [$(hostname)]: " servername
  351. fi
  352. fi
  353. # Generating admin password if it wasn't set
  354. if [ -z "$vpass" ]; then
  355. vpass=$(gen_pass)
  356. fi
  357. # Set hostname if it wasn't set
  358. if [ -z "$servername" ]; then
  359. servername=$(hostname -f)
  360. fi
  361. # Set FQDN if it wasn't set
  362. mask1='(([[:alnum:]](-?[[:alnum:]])*)\.)'
  363. mask2='*[[:alnum:]](-?[[:alnum:]])+\.[[:alnum:]]{2,}'
  364. if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
  365. if [ ! -z "$servername" ]; then
  366. servername="$servername.example.com"
  367. else
  368. servername="example.com"
  369. fi
  370. echo "127.0.0.1 $servername" >> /etc/hosts
  371. fi
  372. # Set email if it wasn't set
  373. if [ -z "$email" ]; then
  374. email="admin@$servername"
  375. fi
  376. # Defining backup directory
  377. vst_backups="/root/vst_install_backups/$(date +%s)"
  378. echo "Installation backup directory: $vst_backups"
  379. # Printing start message and sleeping for 5 seconds
  380. echo -e "\n\n\n\nInstallation will take about 15 minutes ...\n"
  381. sleep 5
  382. #----------------------------------------------------------#
  383. # Checking swap #
  384. #----------------------------------------------------------#
  385. # Checking swap on small instances
  386. if [ -z "$(swapon -s)" ] && [ $memory -lt 1000000 ]; then
  387. fallocate -l 1G /swapfile
  388. chmod 600 /swapfile
  389. mkswap /swapfile
  390. swapon /swapfile
  391. echo "/swapfile none swap sw 0 0" >> /etc/fstab
  392. fi
  393. #----------------------------------------------------------#
  394. # Install repository #
  395. #----------------------------------------------------------#
  396. # Updating system
  397. apt-get -y upgrade
  398. check_result $? 'apt-get upgrade failed'
  399. # Installing nginx repo
  400. apt=/etc/apt/sources.list.d
  401. echo "deb http://nginx.org/packages/debian/ $codename nginx" > $apt/nginx.list
  402. wget http://nginx.org/keys/nginx_signing.key -O /tmp/nginx_signing.key
  403. apt-key add /tmp/nginx_signing.key
  404. # Installing vesta repo
  405. echo "deb http://$RHOST/$codename/ $codename vesta" > $apt/vesta.list
  406. wget $CHOST/deb_signing.key -O deb_signing.key
  407. apt-key add deb_signing.key
  408. #----------------------------------------------------------#
  409. # Backup #
  410. #----------------------------------------------------------#
  411. # Creating backup directory tree
  412. mkdir -p $vst_backups
  413. cd $vst_backups
  414. mkdir nginx apache2 php5 php5-fpm vsftpd proftpd bind exim4 dovecot clamd
  415. mkdir spamassassin mysql postgresql mongodb vesta
  416. # Backing up Nginx configuration
  417. service nginx stop > /dev/null 2>&1
  418. cp -r /etc/nginx/* $vst_backups/nginx >/dev/null 2>&1
  419. # Backing up Apache configuration
  420. service apache2 stop > /dev/null 2>&1
  421. cp -r /etc/apache2/* $vst_backups/apache2 > /dev/null 2>&1
  422. rm -f /etc/apache2/conf.d/* > /dev/null 2>&1
  423. # Backing up PHP configuration
  424. cp /etc/php.ini $vst_backups/php > /dev/null 2>&1
  425. cp -r /etc/php.d $vst_backups/php > /dev/null 2>&1
  426. # Backing up PHP configuration
  427. service php5-fpm stop >/dev/null 2>&1
  428. cp /etc/php5/* $vst_backups/php5 > /dev/null 2>&1
  429. rm -f /etc/php5/fpm/pool.d/* >/dev/null 2>&1
  430. # Backing up Bind configuration
  431. service bind9 stop > /dev/null 2>&1
  432. cp -r /etc/bind/* $vst_backups/bind > /dev/null 2>&1
  433. # Backing up Vsftpd configuration
  434. service vsftpd stop > /dev/null 2>&1
  435. cp /etc/vsftpd.conf $vst_backups/vsftpd > /dev/null 2>&1
  436. # Backing up ProFTPD configuration
  437. service proftpd stop > /dev/null 2>&1
  438. cp /etc/proftpd.conf $vst_backups/proftpd >/dev/null 2>&1
  439. # Backing up Exim configuration
  440. service exim4 stop > /dev/null 2>&1
  441. cp -r /etc/exim4/* $vst_backups/exim4 > /dev/null 2>&1
  442. # Backing up ClamAV configuration
  443. service clamav-daemon stop > /dev/null 2>&1
  444. cp -r /etc/clamav/* $vst_backups/clamav > /dev/null 2>&1
  445. # Backing up SpamAssassin configuration
  446. service spamassassin stop > /dev/null 2>&1
  447. cp -r /etc/spamassassin/* $vst_backups/spamassassin > /dev/null 2>&1
  448. # Backing up Dovecot configuration
  449. service dovecot stop > /dev/null 2>&1
  450. cp /etc/dovecot.conf $vst_backups/dovecot > /dev/null 2>&1
  451. cp -r /etc/dovecot/* $vst_backups/dovecot > /dev/null 2>&1
  452. # Backing up MySQL/MariaDB configuration and data
  453. service mysql stop > /dev/null 2>&1
  454. killall -9 mysqld > /dev/null 2>&1
  455. mv /var/lib/mysql $vst_backups/mysql/mysql_datadir > /dev/null 2>&1
  456. cp -r /etc/mysql/* $vst_backups/mysql > /dev/null 2>&1
  457. mv -f /root/.my.cnf $vst_backups/mysql > /dev/null 2>&1
  458. # Backup vesta
  459. service vesta stop > /dev/null 2>&1
  460. cp -r $VESTA/* $vst_backups/vesta > /dev/null 2>&1
  461. apt-get -y remove vesta vesta-nginx vesta-php > /dev/null 2>&1
  462. apt-get -y purge vesta vesta-nginx vesta-php > /dev/null 2>&1
  463. rm -rf $VESTA > /dev/null 2>&1
  464. #----------------------------------------------------------#
  465. # Package Excludes #
  466. #----------------------------------------------------------#
  467. # Excluding packages
  468. if [ "$nginx" = 'no' ]; then
  469. software=$(echo "$software" | sed -e "s/^nginx//")
  470. fi
  471. if [ "$apache" = 'no' ]; then
  472. software=$(echo "$software" | sed -e "s/apache2 //")
  473. software=$(echo "$software" | sed -e "s/apache2-utils//")
  474. software=$(echo "$software" | sed -e "s/apache2-suexec-custom//")
  475. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  476. software=$(echo "$software" | sed -e "s/libapache2-mod-ruid2//")
  477. software=$(echo "$software" | sed -e "s/libapache2-mod-fcgid//")
  478. software=$(echo "$software" | sed -e "s/libapache2-mod-php5//")
  479. fi
  480. if [ "$phpfpm" = 'no' ]; then
  481. software=$(echo "$software" | sed -e "s/php5-fpm//")
  482. fi
  483. if [ "$vsftpd" = 'no' ]; then
  484. software=$(echo "$software" | sed -e "s/vsftpd//")
  485. fi
  486. if [ "$proftpd" = 'no' ]; then
  487. software=$(echo "$software" | sed -e "s/proftpd-basic//")
  488. software=$(echo "$software" | sed -e "s/proftpd-mod-vroot//")
  489. fi
  490. if [ "$named" = 'no' ]; then
  491. software=$(echo "$software" | sed -e "s/bind9//")
  492. fi
  493. if [ "$exim" = 'no' ]; then
  494. software=$(echo "$software" | sed -e "s/exim4 //")
  495. software=$(echo "$software" | sed -e "s/exim4-daemon-heavy//")
  496. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  497. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  498. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  499. software=$(echo "$software" | sed -e "s/spamassassin//")
  500. fi
  501. if [ "$clamd" = 'no' ]; then
  502. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  503. fi
  504. if [ "$spamd" = 'no' ]; then
  505. software=$(echo "$software" | sed -e "s/spamassassin//")
  506. software=$(echo "$software" | sed -e "s/libmail-dkim-perl//")
  507. fi
  508. if [ "$dovecot" = 'no' ]; then
  509. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  510. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  511. fi
  512. if [ "$mysql" = 'no' ]; then
  513. software=$(echo "$software" | sed -e 's/mysql-server//')
  514. software=$(echo "$software" | sed -e 's/mysql-client//')
  515. software=$(echo "$software" | sed -e 's/mysql-common//')
  516. software=$(echo "$software" | sed -e 's/php5-mysql//')
  517. software=$(echo "$software" | sed -e 's/phpMyAdmin//')
  518. fi
  519. if [ "$postgresql" = 'no' ]; then
  520. software=$(echo "$software" | sed -e 's/postgresql-contrib//')
  521. software=$(echo "$software" | sed -e 's/postgresql//')
  522. software=$(echo "$software" | sed -e 's/php5-pgsql//')
  523. software=$(echo "$software" | sed -e 's/phppgadmin//')
  524. fi
  525. if [ "$iptables" = 'no' ] || [ "$fail2ban" = 'no' ]; then
  526. software=$(echo "$software" | sed -e 's/fail2ban//')
  527. fi
  528. #----------------------------------------------------------#
  529. # Install packages #
  530. #----------------------------------------------------------#
  531. # Update system packages
  532. apt-get update
  533. # Disable daemon autostart /usr/share/doc/sysv-rc/README.policy-rc.d.gz
  534. echo -e '#!/bin/sh \nexit 101' > /usr/sbin/policy-rc.d
  535. chmod a+x /usr/sbin/policy-rc.d
  536. # Install apt packages
  537. apt-get -y install $software
  538. check_result $? "apt-get install failed"
  539. # Restore policy
  540. rm -f /usr/sbin/policy-rc.d
  541. #----------------------------------------------------------#
  542. # Configure system #
  543. #----------------------------------------------------------#
  544. # Enable SSH password auth
  545. sed -i "s/rdAuthentication no/rdAuthentication yes/g" /etc/ssh/sshd_config
  546. service ssh restart
  547. # Disable awstats cron
  548. rm -f /etc/cron.d/awstats
  549. # Set directory color
  550. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  551. # Register /sbin/nologin and /usr/sbin/nologin
  552. echo "/sbin/nologin" >> /etc/shells
  553. echo "/usr/sbin/nologin" >> /etc/shells
  554. # NTP Synchronization
  555. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  556. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  557. chmod 775 /etc/cron.daily/ntpdate
  558. ntpdate -s pool.ntp.org
  559. # Setup rssh
  560. if [ -z "$(grep /usr/bin/rssh /etc/shells)" ]; then
  561. echo /usr/bin/rssh >> /etc/shells
  562. fi
  563. sed -i 's/#allowscp/allowscp/' /etc/rssh.conf
  564. sed -i 's/#allowsftp/allowsftp/' /etc/rssh.conf
  565. sed -i 's/#allowrsync/allowrsync/' /etc/rssh.conf
  566. chmod 755 /usr/bin/rssh
  567. #----------------------------------------------------------#
  568. # Configure VESTA #
  569. #----------------------------------------------------------#
  570. # Downloading sudo configuration
  571. mkdir -p /etc/sudoers.d
  572. wget $vestacp/sudo/admin -O /etc/sudoers.d/admin
  573. chmod 440 /etc/sudoers.d/admin
  574. # Configuring system env
  575. echo "export VESTA='$VESTA'" > /etc/profile.d/vesta.sh
  576. chmod 755 /etc/profile.d/vesta.sh
  577. source /etc/profile.d/vesta.sh
  578. echo 'PATH=$PATH:'$VESTA'/bin' >> /root/.bash_profile
  579. echo 'export PATH' >> /root/.bash_profile
  580. source /root/.bash_profile
  581. # Configuring logrotate for vesta logs
  582. wget $vestacp/logrotate/vesta -O /etc/logrotate.d/vesta
  583. # Building directory tree and creating some blank files for vesta
  584. mkdir -p $VESTA/conf $VESTA/log $VESTA/ssl $VESTA/data/ips \
  585. $VESTA/data/queue $VESTA/data/users $VESTA/data/firewall \
  586. $VESTA/data/sessions
  587. touch $VESTA/data/queue/backup.pipe $VESTA/data/queue/disk.pipe \
  588. $VESTA/data/queue/webstats.pipe $VESTA/data/queue/restart.pipe \
  589. $VESTA/data/queue/traffic.pipe $VESTA/log/system.log \
  590. $VESTA/log/nginx-error.log $VESTA/log/auth.log
  591. chmod 750 $VESTA/conf $VESTA/data/users $VESTA/data/ips $VESTA/log
  592. chmod -R 750 $VESTA/data/queue
  593. chmod 660 $VESTA/log/*
  594. rm -f /var/log/vesta
  595. ln -s $VESTA/log /var/log/vesta
  596. chown admin:admin $VESTA/data/sessions
  597. chmod 770 $VESTA/data/sessions
  598. # Generating vesta configuration
  599. rm -f $VESTA/conf/vesta.conf 2>/dev/null
  600. touch $VESTA/conf/vesta.conf
  601. chmod 660 $VESTA/conf/vesta.conf
  602. # WEB stack
  603. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  604. echo "WEB_SYSTEM='apache2'" >> $VESTA/conf/vesta.conf
  605. echo "WEB_RGROUPS='www-data'" >> $VESTA/conf/vesta.conf
  606. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  607. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  608. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  609. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  610. fi
  611. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  612. echo "WEB_SYSTEM='apache2'" >> $VESTA/conf/vesta.conf
  613. echo "WEB_RGROUPS='www-data'" >> $VESTA/conf/vesta.conf
  614. echo "WEB_PORT='8080'" >> $VESTA/conf/vesta.conf
  615. echo "WEB_SSL_PORT='8443'" >> $VESTA/conf/vesta.conf
  616. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  617. echo "PROXY_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  618. echo "PROXY_PORT='80'" >> $VESTA/conf/vesta.conf
  619. echo "PROXY_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  620. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  621. fi
  622. if [ "$apache" = 'no' ] && [ "$nginx" = 'yes' ]; then
  623. echo "WEB_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  624. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  625. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  626. echo "WEB_SSL='openssl'" >> $VESTA/conf/vesta.conf
  627. if [ "$phpfpm" = 'yes' ]; then
  628. echo "WEB_BACKEND='php5-fpm'" >> $VESTA/conf/vesta.conf
  629. fi
  630. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  631. fi
  632. # FTP stack
  633. if [ "$vsftpd" = 'yes' ]; then
  634. echo "FTP_SYSTEM='vsftpd'" >> $VESTA/conf/vesta.conf
  635. fi
  636. if [ "$proftpd" = 'yes' ]; then
  637. echo "FTP_SYSTEM='proftpd'" >> $VESTA/conf/vesta.conf
  638. fi
  639. # DNS stack
  640. if [ "$named" = 'yes' ]; then
  641. echo "DNS_SYSTEM='bind9'" >> $VESTA/conf/vesta.conf
  642. fi
  643. # Mail stack
  644. if [ "$exim" = 'yes' ]; then
  645. echo "MAIL_SYSTEM='exim4'" >> $VESTA/conf/vesta.conf
  646. if [ "$clamd" = 'yes' ]; then
  647. echo "ANTIVIRUS_SYSTEM='clamav-daemon'" >> $VESTA/conf/vesta.conf
  648. fi
  649. if [ "$spamd" = 'yes' ]; then
  650. echo "ANTISPAM_SYSTEM='spamassassin'" >> $VESTA/conf/vesta.conf
  651. fi
  652. if [ "$dovecot" = 'yes' ]; then
  653. echo "IMAP_SYSTEM='dovecot'" >> $VESTA/conf/vesta.conf
  654. fi
  655. fi
  656. # CRON daemon
  657. echo "CRON_SYSTEM='cron'" >> $VESTA/conf/vesta.conf
  658. # Firewall stack
  659. if [ "$iptables" = 'yes' ]; then
  660. echo "FIREWALL_SYSTEM='iptables'" >> $VESTA/conf/vesta.conf
  661. fi
  662. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  663. echo "FIREWALL_EXTENSION='fail2ban'" >> $VESTA/conf/vesta.conf
  664. fi
  665. # Disk quota
  666. if [ "$quota" = 'yes' ]; then
  667. echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
  668. fi
  669. # Backups
  670. echo "BACKUP_SYSTEM='local'" >> $VESTA/conf/vesta.conf
  671. # Language
  672. echo "LANGUAGE='$lang'" >> $VESTA/conf/vesta.conf
  673. # Version
  674. echo "VERSION='0.9.8'" >> $VESTA/conf/vesta.conf
  675. # Downloading hosting packages
  676. cd $VESTA/data
  677. wget $vestacp/packages.tar.gz -O packages.tar.gz
  678. tar -xzf packages.tar.gz
  679. rm -f packages.tar.gz
  680. # Downloading templates
  681. wget $vestacp/templates.tar.gz -O templates.tar.gz
  682. tar -xzf templates.tar.gz
  683. rm -f templates.tar.gz
  684. # Copying index.html to default documentroot
  685. cp templates/web/skel/public_html/index.html /var/www/
  686. sed -i 's/%domain%/It worked!/g' /var/www/index.html
  687. # Downloading firewall rules
  688. wget $vestacp/firewall.tar.gz -O firewall.tar.gz
  689. tar -xzf firewall.tar.gz
  690. rm -f firewall.tar.gz
  691. # Configuring server hostname
  692. $VESTA/bin/v-change-sys-hostname $servername 2>/dev/null
  693. # Generating SSL certificate
  694. $VESTA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  695. 'San Francisco' 'Vesta Control Panel' 'IT' > /tmp/vst.pem
  696. # Parsing certificate file
  697. crt_end=$(grep -n "END CERTIFICATE-" /tmp/vst.pem |cut -f 1 -d:)
  698. key_start=$(grep -n "BEGIN RSA" /tmp/vst.pem |cut -f 1 -d:)
  699. key_end=$(grep -n "END RSA" /tmp/vst.pem |cut -f 1 -d:)
  700. # Adding SSL certificate
  701. cd $VESTA/ssl
  702. sed -n "1,${crt_end}p" /tmp/vst.pem > certificate.crt
  703. sed -n "$key_start,${key_end}p" /tmp/vst.pem > certificate.key
  704. chown root:mail $VESTA/ssl/*
  705. chmod 660 $VESTA/ssl/*
  706. rm /tmp/vst.pem
  707. #----------------------------------------------------------#
  708. # Configure Nginx #
  709. #----------------------------------------------------------#
  710. if [ "$nginx" = 'yes' ]; then
  711. rm -f /etc/nginx/conf.d/*.conf
  712. wget $vestacp/nginx/nginx.conf -O /etc/nginx/nginx.conf
  713. wget $vestacp/nginx/status.conf -O /etc/nginx/conf.d/status.conf
  714. wget $vestacp/nginx/phpmyadmin.inc -O /etc/nginx/conf.d/phpmyadmin.inc
  715. wget $vestacp/nginx/phppgadmin.inc -O /etc/nginx/conf.d/phppgadmin.inc
  716. wget $vestacp/nginx/webmail.inc -O /etc/nginx/conf.d/webmail.inc
  717. wget $vestacp/logrotate/nginx -O /etc/logrotate.d/nginx
  718. echo > /etc/nginx/conf.d/vesta.conf
  719. mkdir -p /var/log/nginx/domains
  720. update-rc.d nginx defaults
  721. service nginx start
  722. check_result $? "nginx start failed"
  723. fi
  724. #----------------------------------------------------------#
  725. # Configure Apache #
  726. #----------------------------------------------------------#
  727. if [ "$apache" = 'yes' ]; then
  728. wget $vestacp/apache2/apache2.conf -O /etc/apache2/apache2.conf
  729. wget $vestacp/apache2/status.conf -O /etc/apache2/mods-enabled/status.conf
  730. wget $vestacp/logrotate/apache2 -O /etc/logrotate.d/apache2
  731. a2enmod rewrite
  732. a2enmod suexec
  733. a2enmod ssl
  734. a2enmod actions
  735. a2enmod ruid2
  736. a2enmod headers
  737. mkdir -p /etc/apache2/conf.d
  738. echo > /etc/apache2/conf.d/vesta.conf
  739. echo "# Powered by vesta" > /etc/apache2/sites-available/default
  740. echo "# Powered by vesta" > /etc/apache2/sites-available/default-ssl
  741. echo "# Powered by vesta" > /etc/apache2/ports.conf
  742. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  743. touch /var/log/apache2/access.log /var/log/apache2/error.log
  744. mkdir -p /var/log/apache2/domains
  745. chmod a+x /var/log/apache2
  746. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  747. chmod 751 /var/log/apache2/domains
  748. update-rc.d apache2 defaults
  749. service apache2 start
  750. check_result $? "apache2 start failed"
  751. else
  752. update-rc.d apache2 disable >/dev/null 2>&1
  753. service apache2 stop >/dev/null 2>&1
  754. fi
  755. #----------------------------------------------------------#
  756. # Configure PHP-FPM #
  757. #----------------------------------------------------------#
  758. if [ "$phpfpm" = 'yes' ]; then
  759. wget $vestacp/php5-fpm/www.conf -O /etc/php5/fpm/pool.d/www.conf
  760. update-rc.d php5-fpm defaults
  761. service php5-fpm start
  762. check_result $? "php-fpm start failed"
  763. fi
  764. #----------------------------------------------------------#
  765. # Configure PHP #
  766. #----------------------------------------------------------#
  767. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  768. if [ -z "$ZONE" ]; then
  769. ZONE='UTC'
  770. fi
  771. for pconf in $(find /etc/php* -name php.ini); do
  772. sed -i "s/;date.timezone =/date.timezone = $ZONE/g" $pconf
  773. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  774. done
  775. #----------------------------------------------------------#
  776. # Configure VSFTPD #
  777. #----------------------------------------------------------#
  778. if [ "$vsftpd" = 'yes' ]; then
  779. wget $vestacp/vsftpd/vsftpd.conf -O /etc/vsftpd.conf
  780. update-rc.d vsftpd defaults
  781. service vsftpd start
  782. check_result $? "vsftpd start failed"
  783. # To be deleted after release 0.9.8-18
  784. echo "/sbin/nologin" >> /etc/shells
  785. fi
  786. #----------------------------------------------------------#
  787. # Configure ProFTPD #
  788. #----------------------------------------------------------#
  789. if [ "$proftpd" = 'yes' ]; then
  790. echo "127.0.0.1 $servername" >> /etc/hosts
  791. wget $vestacp/proftpd/proftpd.conf -O /etc/proftpd/proftpd.conf
  792. update-rc.d proftpd defaults
  793. service proftpd start
  794. check_result $? "proftpd start failed"
  795. fi
  796. #----------------------------------------------------------#
  797. # Configure MySQL/MariaDB #
  798. #----------------------------------------------------------#
  799. if [ "$mysql" = 'yes' ]; then
  800. mycnf="my-small.cnf"
  801. if [ $memory -gt 1200000 ]; then
  802. mycnf="my-medium.cnf"
  803. fi
  804. if [ $memory -gt 3900000 ]; then
  805. mycnf="my-large.cnf"
  806. fi
  807. # MySQL configuration
  808. wget $vestacp/mysql/$mycnf -O /etc/mysql/my.cnf
  809. mysql_install_db
  810. update-rc.d mysql defaults
  811. service mysql start
  812. check_result $? "mysql start failed"
  813. # Securing MySQL installation
  814. mysqladmin -u root password $vpass
  815. echo -e "[client]\npassword='$vpass'\n" > /root/.my.cnf
  816. chmod 600 /root/.my.cnf
  817. mysql -e "DELETE FROM mysql.user WHERE User=''"
  818. mysql -e "DROP DATABASE test" >/dev/null 2>&1
  819. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  820. mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
  821. mysql -e "FLUSH PRIVILEGES"
  822. # Configuring phpMyAdmin
  823. if [ "$apache" = 'yes' ]; then
  824. wget $vestacp/pma/apache.conf -O /etc/phpmyadmin/apache.conf
  825. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  826. fi
  827. wget $vestacp/pma/config.inc.php -O /etc/phpmyadmin/config.inc.php
  828. chmod 777 /var/lib/phpmyadmin/tmp
  829. fi
  830. #----------------------------------------------------------#
  831. # Configure PostgreSQL #
  832. #----------------------------------------------------------#
  833. if [ "$postgresql" = 'yes' ]; then
  834. wget $vestacp/postgresql/pg_hba.conf -O /etc/postgresql/*/main/pg_hba.conf
  835. service postgresql restart
  836. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$vpass'" 2>/dev/null
  837. # Configuring phpPgAdmin
  838. if [ "$apache" = 'yes' ]; then
  839. wget $vestacp/pga/phppgadmin.conf -O /etc/apache2/conf.d/phppgadmin.conf
  840. fi
  841. wget $vestacp/pga/config.inc.php -O /etc/phppgadmin/config.inc.php
  842. fi
  843. #----------------------------------------------------------#
  844. # Configure Bind #
  845. #----------------------------------------------------------#
  846. if [ "$named" = 'yes' ]; then
  847. wget $vestacp/bind/named.conf -O /etc/bind/named.conf
  848. sed -i "s%listen-on%//listen%" /etc/bind/named.conf.options
  849. chown root:bind /etc/bind/named.conf
  850. chmod 640 /etc/bind/named.conf
  851. aa-complain /usr/sbin/named 2>/dev/null
  852. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2>/dev/null
  853. service apparmor status >/dev/null 2>&1
  854. if [ $? -ne 0 ]; then
  855. service apparmor restart
  856. fi
  857. update-rc.d bind9 defaults
  858. service bind9 start
  859. check_result $? "bind9 start failed"
  860. fi
  861. #----------------------------------------------------------#
  862. # Configure Exim #
  863. #----------------------------------------------------------#
  864. if [ "$exim" = 'yes' ]; then
  865. gpasswd -a Debian-exim mail
  866. wget $vestacp/exim/exim4.conf.template -O /etc/exim4/exim4.conf.template
  867. wget $vestacp/exim/dnsbl.conf -O /etc/exim4/dnsbl.conf
  868. wget $vestacp/exim/spam-blocks.conf -O /etc/exim4/spam-blocks.conf
  869. touch /etc/exim4/white-blocks.conf
  870. if [ "$spamd" = 'yes' ]; then
  871. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  872. fi
  873. if [ "$clamd" = 'yes' ]; then
  874. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  875. fi
  876. chmod 640 /etc/exim4/exim4.conf.template
  877. rm -rf /etc/exim4/domains
  878. mkdir -p /etc/exim4/domains
  879. rm -f /etc/alternatives/mta
  880. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  881. update-rc.d -f sendmail remove > /dev/null 2>&1
  882. service sendmail stop > /dev/null 2>&1
  883. update-rc.d -f postfix remove > /dev/null 2>&1
  884. service postfix stop > /dev/null 2>&1
  885. update-rc.d exim4 defaults
  886. service exim4 start
  887. check_result $? "exim4 start failed"
  888. fi
  889. #----------------------------------------------------------#
  890. # Configure Dovecot #
  891. #----------------------------------------------------------#
  892. if [ "$dovecot" = 'yes' ]; then
  893. gpasswd -a dovecot mail
  894. wget $vestacp/dovecot.tar.gz -O /etc/dovecot.tar.gz
  895. wget $vestacp/logrotate/dovecot -O /etc/logrotate.d/dovecot
  896. cd /etc
  897. rm -rf dovecot dovecot.conf
  898. tar -xzf dovecot.tar.gz
  899. rm -f dovecot.tar.gz
  900. chown -R root:root /etc/dovecot*
  901. update-rc.d dovecot defaults
  902. service dovecot start
  903. check_result $? "dovecot start failed"
  904. fi
  905. #----------------------------------------------------------#
  906. # Configure ClamAV #
  907. #----------------------------------------------------------#
  908. if [ "$clamd" = 'yes' ]; then
  909. gpasswd -a clamav mail
  910. gpasswd -a clamav Debian-exim
  911. wget $vestacp/clamav/clamd.conf -O /etc/clamav/clamd.conf
  912. /usr/bin/freshclam
  913. update-rc.d clamav-daemon defaults
  914. if [ ! -d "/var/run/clamav" ]; then
  915. mkdir /var/run/clamav
  916. fi
  917. chown -R clamav:clamav /var/run/clamav
  918. if [ -f "/lib/systemd/system/clamav-daemon.service" ]; then
  919. file="/lib/systemd/system/clamav-daemon.service"
  920. if [ $( grep -ic "mkdir" $file ) -eq 0 ]; then
  921. sed -i "s/\[Service\]/\[Service\]\nExecStartPre = \/bin\/mkdir -p \/var\/run\/clamav\nExecStartPre = \/bin\/chown -R clamav:clamav \/var\/run\/clamav/g" $file
  922. fi
  923. fi
  924. service clamav-daemon start
  925. check_result $? "clamav-daeom start failed"
  926. fi
  927. #----------------------------------------------------------#
  928. # Configure SpamAssassin #
  929. #----------------------------------------------------------#
  930. if [ "$spamd" = 'yes' ]; then
  931. update-rc.d spamassassin defaults
  932. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  933. service spamassassin start
  934. check_result $? "spamassassin start failed"
  935. if [[ $(systemctl list-unit-files | grep spamassassin) =~ "disabled" ]]; then
  936. systemctl enable spamassassin
  937. fi
  938. fi
  939. #----------------------------------------------------------#
  940. # Configure RoundCube #
  941. #----------------------------------------------------------#
  942. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  943. if [ "$apache" = 'yes' ]; then
  944. wget $vestacp/roundcube/apache.conf -O /etc/roundcube/apache.conf
  945. ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/roundcube.conf
  946. fi
  947. wget $vestacp/roundcube/main.inc.php -O /etc/roundcube/main.inc.php
  948. wget $vestacp/roundcube/db.inc.php -O /etc/roundcube/db.inc.php
  949. chmod 640 /etc/roundcube/debian-db-roundcube.php
  950. chmod 640 /etc/roundcube/config.inc.php
  951. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  952. chown root:www-data /etc/roundcube/config.inc.php
  953. wget $vestacp/roundcube/vesta.php -O \
  954. /usr/share/roundcube/plugins/password/drivers/vesta.php
  955. wget $vestacp/roundcube/config.inc.php -O \
  956. /etc/roundcube/plugins/password/config.inc.php
  957. r="$(gen_pass)"
  958. mysql -e "CREATE DATABASE roundcube"
  959. mysql -e "GRANT ALL ON roundcube.* TO roundcube@localhost IDENTIFIED BY '$r'"
  960. sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
  961. sed -i "s/localhost/$servername/g" /etc/roundcube/plugins/password/config.inc.php
  962. mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  963. chmod a+r /etc/roundcube/main.inc.php
  964. if [ "$release" -eq 8 ]; then
  965. mv -f /etc/roundcube/main.inc.php /etc/roundcube/config.inc.php
  966. mv -f /etc/roundcube/db.inc.php /etc/roundcube/debian-db-roundcube.php
  967. chmod 640 /etc/roundcube/debian-db-roundcube.php
  968. chmod 640 /etc/roundcube/config.inc.php
  969. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  970. chown root:www-data /etc/roundcube/config.inc.php
  971. # RoundCube tinyMCE fix
  972. tinymceFixArchiveURL=$vestacp/roundcube/roundcube-tinymce.tar.gz
  973. tinymceParentFolder=/usr/share/roundcube/program/js
  974. tinymceFolder=$tinymceParentFolder/tinymce
  975. tinymceBadJS=$tinymceFolder/tiny_mce.js
  976. tinymceFixArchive=$tinymceParentFolder/roundcube-tinymce.tar.gz
  977. if [[ -L "$tinymceFolder" && -d "$tinymceFolder" ]]; then
  978. if [ -f "$tinymceBadJS" ]; then
  979. wget $tinymceFixArchiveURL -O $tinymceFixArchive
  980. if [[ -f "$tinymceFixArchive" && -s "$tinymceFixArchive" ]]; then
  981. rm $tinymceFolder
  982. tar -xzf $tinymceFixArchive -C $tinymceParentFolder
  983. rm $tinymceFixArchive
  984. chown -R root:root $tinymceFolder
  985. else
  986. echo "File roundcube-tinymce.tar.gz is not downloaded, RoundCube tinyMCE fix is not applied"
  987. rm $tinymceFixArchive
  988. fi
  989. fi
  990. fi
  991. fi
  992. fi
  993. #----------------------------------------------------------#
  994. # Configure Fail2Ban #
  995. #----------------------------------------------------------#
  996. if [ "$fail2ban" = 'yes' ]; then
  997. cd /etc
  998. wget $vestacp/fail2ban.tar.gz -O fail2ban.tar.gz
  999. tar -xzf fail2ban.tar.gz
  1000. rm -f fail2ban.tar.gz
  1001. if [ "$dovecot" = 'no' ]; then
  1002. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1003. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1004. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1005. fi
  1006. if [ "$exim" = 'no' ]; then
  1007. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1008. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1009. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1010. fi
  1011. update-rc.d fail2ban defaults
  1012. service fail2ban start
  1013. check_result $? "fail2ban start failed"
  1014. fi
  1015. #----------------------------------------------------------#
  1016. # Configure Admin User #
  1017. #----------------------------------------------------------#
  1018. # Deleting old admin user
  1019. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1020. chattr -i /home/admin/conf > /dev/null 2>&1
  1021. userdel -f admin >/dev/null 2>&1
  1022. chattr -i /home/admin/conf >/dev/null 2>&1
  1023. mv -f /home/admin $vst_backups/home/ >/dev/null 2>&1
  1024. rm -f /tmp/sess_* >/dev/null 2>&1
  1025. fi
  1026. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  1027. groupdel admin > /dev/null 2>&1
  1028. fi
  1029. # Adding vesta account
  1030. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  1031. check_result $? "can't create admin user"
  1032. $VESTA/bin/v-change-user-shell admin bash
  1033. $VESTA/bin/v-change-user-language admin $lang
  1034. # RoundCube permissions fix
  1035. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1036. if [ ! -d "/var/log/roundcube" ]; then
  1037. mkdir /var/log/roundcube
  1038. fi
  1039. chown admin:admin /var/log/roundcube
  1040. fi
  1041. # Configuring system ips
  1042. $VESTA/bin/v-update-sys-ip
  1043. # Get main ip
  1044. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1045. copy_of_ip=$ip
  1046. # Firewall configuration
  1047. if [ "$iptables" = 'yes' ]; then
  1048. $VESTA/bin/v-update-firewall
  1049. fi
  1050. # Get public ip
  1051. pub_ip=$(curl -s vestacp.com/what-is-my-ip/)
  1052. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1053. $VESTA/bin/v-change-sys-ip-nat $ip $pub_ip
  1054. ip=$pub_ip
  1055. fi
  1056. # Configuring libapache2-mod-remoteip
  1057. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  1058. copy_of_pub_ip=$pub_ip
  1059. echo "<IfModule mod_remoteip.c>" > /etc/apache2/mods-available/remoteip.conf
  1060. echo " RemoteIPHeader X-Real-IP" >> /etc/apache2/mods-available/remoteip.conf
  1061. if [ "$copy_of_ip" != "127.0.0.1" ] && [ "$copy_of_pub_ip" != "127.0.0.1" ]; then
  1062. echo " RemoteIPInternalProxy 127.0.0.1" >> /etc/apache2/mods-available/remoteip.conf
  1063. fi
  1064. if [ ! -z "$copy_of_ip" ] && [ "$copy_of_ip" != "$copy_of_pub_ip" ]; then
  1065. echo " RemoteIPInternalProxy $copy_of_ip" >> /etc/apache2/mods-available/remoteip.conf
  1066. fi
  1067. if [ ! -z "$copy_of_pub_ip" ]; then
  1068. echo " RemoteIPInternalProxy $copy_of_pub_ip" >> /etc/apache2/mods-available/remoteip.conf
  1069. fi
  1070. echo "</IfModule>" >> /etc/apache2/mods-available/remoteip.conf
  1071. sed -i "s/LogFormat \"%h/LogFormat \"%a/g" /etc/apache2/apache2.conf
  1072. a2enmod remoteip
  1073. service apache2 restart
  1074. fi
  1075. # Configuring mysql host
  1076. if [ "$mysql" = 'yes' ]; then
  1077. $VESTA/bin/v-add-database-host mysql localhost root $vpass
  1078. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  1079. fi
  1080. # Configuring pgsql host
  1081. if [ "$postgresql" = 'yes' ]; then
  1082. $VESTA/bin/v-add-database-host pgsql localhost postgres $vpass
  1083. $VESTA/bin/v-add-database admin db db $(gen_pass) pgsql
  1084. fi
  1085. # Adding default domain
  1086. $VESTA/bin/v-add-domain admin $servername
  1087. check_result $? "can't create $servername domain"
  1088. # Adding cron jobs
  1089. command="sudo $VESTA/bin/v-update-sys-queue disk"
  1090. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1091. command="sudo $VESTA/bin/v-update-sys-queue traffic"
  1092. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1093. command="sudo $VESTA/bin/v-update-sys-queue webstats"
  1094. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1095. command="sudo $VESTA/bin/v-update-sys-queue backup"
  1096. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1097. command="sudo $VESTA/bin/v-backup-users"
  1098. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1099. command="sudo $VESTA/bin/v-update-user-stats"
  1100. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1101. command="sudo $VESTA/bin/v-update-sys-rrd"
  1102. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1103. service cron restart
  1104. # Building inititall rrd images
  1105. $VESTA/bin/v-update-sys-rrd
  1106. # Enabling file system quota
  1107. if [ "$quota" = 'yes' ]; then
  1108. $VESTA/bin/v-add-sys-quota
  1109. fi
  1110. # Starting vesta service
  1111. update-rc.d vesta defaults
  1112. service vesta start
  1113. check_result $? "vesta start failed"
  1114. chown admin:admin $VESTA/data/sessions
  1115. # Adding notifications
  1116. $VESTA/upd/add_notifications.sh
  1117. # Adding cronjob for autoupdates
  1118. $VESTA/bin/v-add-cron-vesta-autoupdate
  1119. #----------------------------------------------------------#
  1120. # Vesta Access Info #
  1121. #----------------------------------------------------------#
  1122. # Sending install notification to vestacp.com
  1123. wget vestacp.com/notify/?$codename -O /dev/null -q
  1124. # Comparing hostname and ip
  1125. host_ip=$(host $servername| head -n 1 | awk '{print $NF}')
  1126. if [ "$host_ip" = "$ip" ]; then
  1127. ip="$servername"
  1128. fi
  1129. # Sending notification to admin email
  1130. echo -e "Congratulations, you have just successfully installed \
  1131. Vesta Control Panel
  1132. https://$ip:8083
  1133. username: admin
  1134. password: $vpass
  1135. We hope that you enjoy your installation of Vesta. Please \
  1136. feel free to contact us anytime if you have any questions.
  1137. Thank you.
  1138. --
  1139. Sincerely yours
  1140. vestacp.com team
  1141. " > $tmpfile
  1142. send_mail="$VESTA/web/inc/mail-wrapper.php"
  1143. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  1144. # Congrats
  1145. echo '======================================================='
  1146. echo
  1147. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  1148. echo ' _| _| _| _| _| _| _| '
  1149. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  1150. echo ' _| _| _| _| _| _| _| '
  1151. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  1152. echo
  1153. echo
  1154. cat $tmpfile
  1155. rm -f $tmpfile
  1156. # EOF