vst-install-debian.sh 48 KB

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