vst-install-debian.sh 45 KB

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