vst-install-debian.sh 46 KB

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