vst-install-amazon.sh 45 KB

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