vst-install-debian.sh 45 KB

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