vst-install-amazon.sh 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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. # Defining software pack for all distros
  19. software="nginx httpd mod_ssl mod_ruid2 mod_fcgid mod_extract_forwarded
  20. php php-common php-cli php-bcmath php-gd php-imap php-mbstring php-mcrypt
  21. php-mysql php-pdo php-soap php-tidy php-xml php-xmlrpc php-fpm php-pgsql
  22. awstats webalizer vsftpd proftpd bind bind-utils bind-libs exim dovecot
  23. clamd spamassassin mysql mysql-server phpMyAdmin postgresql
  24. postgresql-server postgresql-contrib phpPgAdmin e2fsprogs openssh-clients
  25. ImageMagick curl mc screen ftp zip unzip flex sqlite pcre sudo bc jwhois
  26. mailx lsof tar telnet rrdtool net-tools ntp GeoIP freetype fail2ban
  27. which vesta vesta-nginx vesta-php vim-common expect vesta-ioncube
  28. vesta-softaculous"
  29. # Defining help function
  30. help() {
  31. echo "Usage: $0 [OPTIONS]
  32. -a, --apache Install Apache [yes|no] default: yes
  33. -n, --nginx Install Nginx [yes|no] default: yes
  34. -w, --phpfpm Install PHP-FPM [yes|no] default: no
  35. -v, --vsftpd Install Vsftpd [yes|no] default: yes
  36. -j, --proftpd Install ProFTPD [yes|no] default: no
  37. -k, --named Install Bind [yes|no] default: yes
  38. -m, --mysql Install MySQL [yes|no] default: yes
  39. -g, --postgresql Install PostgreSQL [yes|no] default: no
  40. -d, --mongodb Install MongoDB [yes|no] unsupported
  41. -x, --exim Install Exim [yes|no] default: yes
  42. -z, --dovecot Install Dovecot [yes|no] default: yes
  43. -c, --clamav Install ClamAV [yes|no] default: yes
  44. -t, --spamassassin Install SpamAssassin [yes|no] default: yes
  45. -i, --iptables Install Iptables [yes|no] default: yes
  46. -b, --fail2ban Install Fail2ban [yes|no] default: yes
  47. -r, --remi Install Remi repo [yes|no] default: yes
  48. -o, --softaculous Install Softaculous [yes|no] default: yes
  49. -q, --quota Filesystem Quota [yes|no] default: no
  50. -l, --lang Default language default: en
  51. -y, --interactive Interactive install [yes|no] default: yes
  52. -s, --hostname Set hostname
  53. -e, --email Set admin email
  54. -p, --password Set admin password
  55. -f, --force Force installation
  56. -h, --help Print this help
  57. Example: bash $0 -e demo@vestacp.com -p p4ssw0rd --apache no --phpfpm yes"
  58. exit 1
  59. }
  60. # Defining password-gen function
  61. gen_pass() {
  62. MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  63. LENGTH=10
  64. while [ ${n:=1} -le $LENGTH ]; do
  65. PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  66. let n+=1
  67. done
  68. echo "$PASS"
  69. }
  70. # Defining return code check function
  71. check_result() {
  72. if [ $1 -ne 0 ]; then
  73. echo "Error: $2"
  74. exit $1
  75. fi
  76. }
  77. # Defining function to set default value
  78. set_default_value() {
  79. eval variable=\$$1
  80. if [ -z "$variable" ]; then
  81. eval $1=$2
  82. fi
  83. if [ "$variable" != 'yes' ] && [ "$variable" != 'no' ]; then
  84. eval $1=$2
  85. fi
  86. }
  87. # Defining function to set default language value
  88. set_default_lang() {
  89. if [ -z "$lang" ]; then
  90. eval lang=$1
  91. fi
  92. lang_list="
  93. ar cz el fa hu ja no pt se ua
  94. bs da en fi id ka pl ro tr vi
  95. cn de es fr it nl pt-BR ru tw
  96. bg ko sr th ur"
  97. if !(echo $lang_list |grep -w $lang 1>&2>/dev/null); then
  98. eval lang=$1
  99. fi
  100. }
  101. #----------------------------------------------------------#
  102. # Verifications #
  103. #----------------------------------------------------------#
  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. --softaculous) args="${args}-o " ;;
  125. --quota) args="${args}-q " ;;
  126. --lang) args="${args}-l " ;;
  127. --interactive) args="${args}-y " ;;
  128. --hostname) args="${args}-s " ;;
  129. --email) args="${args}-e " ;;
  130. --password) args="${args}-p " ;;
  131. --force) args="${args}-f " ;;
  132. --help) args="${args}-h " ;;
  133. *) [[ "${arg:0:1}" == "-" ]] || delim="\""
  134. args="${args}${delim}${arg}${delim} ";;
  135. esac
  136. done
  137. eval set -- "$args"
  138. # Parsing arguments
  139. 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
  140. case $Option in
  141. a) apache=$OPTARG ;; # Apache
  142. n) nginx=$OPTARG ;; # Nginx
  143. w) phpfpm=$OPTARG ;; # PHP-FPM
  144. v) vsftpd=$OPTARG ;; # Vsftpd
  145. j) proftpd=$OPTARG ;; # Proftpd
  146. k) named=$OPTARG ;; # Named
  147. m) mysql=$OPTARG ;; # MySQL
  148. g) postgresql=$OPTARG ;; # PostgreSQL
  149. d) mongodb=$OPTARG ;; # MongoDB (unsupported)
  150. x) exim=$OPTARG ;; # Exim
  151. z) dovecot=$OPTARG ;; # Dovecot
  152. c) clamd=$OPTARG ;; # ClamAV
  153. t) spamd=$OPTARG ;; # SpamAssassin
  154. i) iptables=$OPTARG ;; # Iptables
  155. b) fail2ban=$OPTARG ;; # Fail2ban
  156. r) remi=$OPTARG ;; # Remi repo
  157. o) softaculous=$OPTARG ;; # Softaculous plugin
  158. q) quota=$OPTARG ;; # FS Quota
  159. l) lang=$OPTARG ;; # Language
  160. y) interactive=$OPTARG ;; # Interactive install
  161. s) servername=$OPTARG ;; # Hostname
  162. e) email=$OPTARG ;; # Admin email
  163. p) vpass=$OPTARG ;; # Admin password
  164. f) force='yes' ;; # Force install
  165. h) help ;; # Help
  166. *) help ;; # Print help (default)
  167. esac
  168. done
  169. # Defining default software stack
  170. set_default_value 'nginx' 'yes'
  171. set_default_value 'apache' 'yes'
  172. set_default_value 'phpfpm' 'no'
  173. set_default_value 'vsftpd' 'yes'
  174. set_default_value 'proftpd' 'no'
  175. set_default_value 'named' 'yes'
  176. set_default_value 'mysql' 'yes'
  177. set_default_value 'postgresql' 'no'
  178. set_default_value 'mongodb' 'no'
  179. set_default_value 'exim' 'yes'
  180. set_default_value 'dovecot' 'yes'
  181. if [ $memory -lt 1500000 ]; then
  182. set_default_value 'clamd' 'no'
  183. set_default_value 'spamd' 'no'
  184. else
  185. set_default_value 'clamd' 'yes'
  186. set_default_value 'spamd' 'yes'
  187. fi
  188. set_default_value 'iptables' 'yes'
  189. set_default_value 'fail2ban' 'yes'
  190. set_default_value 'remi' 'yes'
  191. set_default_value 'softaculous' 'yes'
  192. set_default_value 'quota' 'no'
  193. set_default_value 'interactive' 'yes'
  194. set_default_lang 'en'
  195. # Checking software conflicts
  196. if [ "$phpfpm" = 'yes' ]; then
  197. apache='no'
  198. nginx='yes'
  199. fi
  200. if [ "$proftpd" = 'yes' ]; then
  201. vsftpd='no'
  202. fi
  203. if [ "$exim" = 'no' ]; then
  204. clamd='no'
  205. spamd='no'
  206. dovecot='no'
  207. fi
  208. if [ "$iptables" = 'no' ]; then
  209. fail2ban='no'
  210. fi
  211. # Checking root permissions
  212. if [ "x$(id -u)" != 'x0' ]; then
  213. check_result 1 "Script can be run executed only by root"
  214. fi
  215. # Checking admin user account
  216. if [ ! -z "$(grep ^admin: /etc/passwd /etc/group)" ] && [ -z "$force" ]; then
  217. echo 'Please remove admin user account before proceeding.'
  218. echo 'If you want to do it automatically run installer with -f option:'
  219. echo -e "Example: bash $0 --force\n"
  220. check_result 1 "User admin exists"
  221. fi
  222. # Checking wget
  223. if [ ! -e '/usr/bin/wget' ]; then
  224. yum -y install wget
  225. check_result $? "Can't install wget"
  226. fi
  227. # Checking repository availability
  228. wget -q "c.vestacp.com/GPG.txt" -O /dev/null
  229. check_result $? "No access to Vesta repository"
  230. # Checking installed packages
  231. tmpfile=$(mktemp -p /tmp)
  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. rm -f $tmpfile
  239. if [ ! -z "$conflicts" ] && [ -z "$force" ]; then
  240. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  241. echo
  242. echo 'Following packages are already installed:'
  243. echo "$conflicts"
  244. echo
  245. echo 'It is highly recommended to remove them before proceeding.'
  246. echo 'If you want to force installation run this script with -f option:'
  247. echo "Example: bash $0 --force"
  248. echo
  249. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  250. echo
  251. check_result 1 "Control Panel should be installed on clean server."
  252. fi
  253. #----------------------------------------------------------#
  254. # Brief Info #
  255. #----------------------------------------------------------#
  256. # Printing nice ASCII logo
  257. clear
  258. echo
  259. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_|'
  260. echo ' _| _| _| _| _| _| _|'
  261. echo ' _| _| _|_|_| _|_| _| _|_|_|_|'
  262. echo ' _| _| _| _| _| _| _|'
  263. echo ' _| _|_|_|_| _|_|_| _| _| _|'
  264. echo
  265. echo ' Vesta Control Panel'
  266. echo -e "\n\n"
  267. echo 'The following software will be installed on your system:'
  268. # Web stack
  269. if [ "$nginx" = 'yes' ]; then
  270. echo ' - Nginx Web Server'
  271. fi
  272. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  273. echo ' - Apache Web Server'
  274. fi
  275. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  276. echo ' - Apache Web Server (as backend)'
  277. fi
  278. if [ "$phpfpm" = 'yes' ]; then
  279. echo ' - PHP-FPM Application Server'
  280. fi
  281. # DNS stack
  282. if [ "$named" = 'yes' ]; then
  283. echo ' - Bind DNS Server'
  284. fi
  285. # Mail stack
  286. if [ "$exim" = 'yes' ]; then
  287. echo -n ' - Exim Mail Server'
  288. if [ "$clamd" = 'yes' ] || [ "$spamd" = 'yes' ] ; then
  289. echo -n ' + '
  290. if [ "$clamd" = 'yes' ]; then
  291. echo -n 'ClamAV '
  292. fi
  293. if [ "$spamd" = 'yes' ]; then
  294. echo -n 'SpamAssassin'
  295. fi
  296. fi
  297. echo
  298. if [ "$dovecot" = 'yes' ]; then
  299. echo ' - Dovecot POP3/IMAP Server'
  300. fi
  301. fi
  302. # Database stack
  303. if [ "$mysql" = 'yes' ]; then
  304. if [ $release -ge 7 ]; then
  305. echo ' - MariaDB Database Server'
  306. else
  307. echo ' - MySQL Database Server'
  308. fi
  309. fi
  310. if [ "$postgresql" = 'yes' ]; then
  311. echo ' - PostgreSQL Database Server'
  312. fi
  313. if [ "$mongodb" = 'yes' ]; then
  314. echo ' - MongoDB Database Server'
  315. fi
  316. # FTP stack
  317. if [ "$vsftpd" = 'yes' ]; then
  318. echo ' - Vsftpd FTP Server'
  319. fi
  320. if [ "$proftpd" = 'yes' ]; then
  321. echo ' - ProFTPD FTP Server'
  322. fi
  323. # Softaculous
  324. if [ "$softaculous" = 'yes' ]; then
  325. echo ' - Softaculous Plugin'
  326. fi
  327. # Firewall stack
  328. if [ "$iptables" = 'yes' ]; then
  329. echo -n ' - Iptables Firewall'
  330. fi
  331. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  332. echo -n ' + Fail2Ban'
  333. fi
  334. echo -e "\n\n"
  335. # Asking for confirmation to proceed
  336. if [ "$interactive" = 'yes' ]; then
  337. read -p 'Would you like to continue [y/n]: ' answer
  338. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  339. echo 'Goodbye'
  340. exit 1
  341. fi
  342. # Asking for contact email
  343. if [ -z "$email" ]; then
  344. read -p 'Please enter admin email address: ' email
  345. fi
  346. # Asking to set FQDN hostname
  347. if [ -z "$servername" ]; then
  348. read -p "Please enter FQDN hostname [$(hostname)]: " servername
  349. fi
  350. fi
  351. # Generating admin password if it wasn't set
  352. if [ -z "$vpass" ]; then
  353. vpass=$(gen_pass)
  354. fi
  355. # Set hostname if it wasn't set
  356. if [ -z "$servername" ]; then
  357. servername=$(hostname -f)
  358. fi
  359. # Set FQDN if it wasn't set
  360. mask1='(([[:alnum:]](-?[[:alnum:]])*)\.)'
  361. mask2='*[[:alnum:]](-?[[:alnum:]])+\.[[:alnum:]]{2,}'
  362. if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
  363. if [ ! -z "$servername" ]; then
  364. servername="$servername.example.com"
  365. else
  366. servername="example.com"
  367. fi
  368. echo "127.0.0.1 $servername" >> /etc/hosts
  369. fi
  370. # Set email if it wasn't set
  371. if [ -z "$email" ]; then
  372. email="admin@$servername"
  373. fi
  374. # Defining backup directory
  375. vst_backups="/root/vst_install_backups/$(date +%s)"
  376. echo "Installation backup directory: $vst_backups"
  377. # Printing start message and sleeping for 5 seconds
  378. echo -e "\n\n\n\nInstallation will take about 15 minutes ...\n"
  379. sleep 5
  380. #----------------------------------------------------------#
  381. # Checking swap #
  382. #----------------------------------------------------------#
  383. # Checking swap on small instances
  384. if [ -z "$(swapon -s)" ] && [ $memory -lt 1000000 ]; then
  385. fallocate -l 1G /swapfile
  386. chmod 600 /swapfile
  387. mkswap /swapfile
  388. swapon /swapfile
  389. echo "/swapfile none swap sw 0 0" >> /etc/fstab
  390. fi
  391. #----------------------------------------------------------#
  392. # Install repositories #
  393. #----------------------------------------------------------#
  394. # Updating system
  395. yum -y update
  396. check_result $? 'yum update failed'
  397. # Enabling EPEL repository
  398. sed "1,10s/enabled=0/enabled=1/" -i /etc/yum.repos.d/epel.repo
  399. yum -y update
  400. check_result $? "Can't install EPEL repository"
  401. # Installing Nginx repository
  402. nrepo="/etc/yum.repos.d/nginx.repo"
  403. echo "[nginx]" > $nrepo
  404. echo "name=nginx repo" >> $nrepo
  405. echo "baseurl=http://nginx.org/packages/centos/$release/\$basearch/" >> $nrepo
  406. echo "gpgcheck=0" >> $nrepo
  407. echo "enabled=1" >> $nrepo
  408. # Installing Vesta repository
  409. vrepo='/etc/yum.repos.d/vesta.repo'
  410. echo "[vesta]" > $vrepo
  411. echo "name=Vesta - $REPO" >> $vrepo
  412. echo "baseurl=http://$RHOST/$REPO/$release/\$basearch/" >> $vrepo
  413. echo "enabled=1" >> $vrepo
  414. echo "gpgcheck=1" >> $vrepo
  415. echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA" >> $vrepo
  416. wget c.vestacp.com/GPG.txt -O /etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA
  417. #----------------------------------------------------------#
  418. # Backup #
  419. #----------------------------------------------------------#
  420. # Creating backup directory tree
  421. mkdir -p $vst_backups
  422. cd $vst_backups
  423. mkdir nginx httpd php php-fpm vsftpd proftpd named exim dovecot clamd \
  424. spamassassin mysql postgresql mongodb vesta
  425. # Backup Nginx configuration
  426. service nginx stop > /dev/null 2>&1
  427. cp -r /etc/nginx/* $vst_backups/nginx > /dev/null 2>&1
  428. # Backup Apache configuration
  429. service httpd stop > /dev/null 2>&1
  430. cp -r /etc/httpd/* $vst_backups/httpd > /dev/null 2>&1
  431. # Backup PHP-FPM configuration
  432. service php-fpm stop >/dev/null 2>&1
  433. cp /etc/php.ini $vst_backups/php > /dev/null 2>&1
  434. cp -r /etc/php.d $vst_backups/php > /dev/null 2>&1
  435. cp /etc/php-fpm.conf $vst_backups/php-fpm > /dev/null 2>&1
  436. mv -f /etc/php-fpm.d/* $vst_backups/php-fpm/ > /dev/null 2>&1
  437. # Backup Bind configuration
  438. yum remove bind-chroot > /dev/null 2>&1
  439. service named stop > /dev/null 2>&1
  440. cp /etc/named.conf $vst_backups/named >/dev/null 2>&1
  441. # Backup Vsftpd configuration
  442. service vsftpd stop > /dev/null 2>&1
  443. cp /etc/vsftpd/vsftpd.conf $vst_backups/vsftpd >/dev/null 2>&1
  444. # Backup ProFTPD configuration
  445. service proftpd stop > /dev/null 2>&1
  446. cp /etc/proftpd.conf $vst_backups/proftpd >/dev/null 2>&1
  447. # Backup Exim configuration
  448. service exim stop > /dev/null 2>&1
  449. cp -r /etc/exim/* $vst_backups/exim >/dev/null 2>&1
  450. # Backup ClamAV configuration
  451. service clamd stop > /dev/null 2>&1
  452. cp /etc/clamd.conf $vst_backups/clamd >/dev/null 2>&1
  453. cp -r /etc/clamd.d $vst_backups/clamd >/dev/null 2>&1
  454. # Backup SpamAssassin configuration
  455. service spamassassin stop > /dev/null 2>&1
  456. cp -r /etc/mail/spamassassin/* $vst_backups/spamassassin >/dev/null 2>&1
  457. # Backup Dovecot configuration
  458. service dovecot stop > /dev/null 2>&1
  459. cp /etc/dovecot.conf $vst_backups/dovecot > /dev/null 2>&1
  460. cp -r /etc/dovecot/* $vst_backups/dovecot > /dev/null 2>&1
  461. # Backup MySQL/MariaDB configuration and data
  462. service mysql stop > /dev/null 2>&1
  463. service mysqld stop > /dev/null 2>&1
  464. service mariadb stop > /dev/null 2>&1
  465. mv /var/lib/mysql $vst_backups/mysql/mysql_datadir >/dev/null 2>&1
  466. cp /etc/my.cnf $vst_backups/mysql > /dev/null 2>&1
  467. cp /etc/my.cnf.d $vst_backups/mysql > /dev/null 2>&1
  468. mv /root/.my.cnf $vst_backups/mysql > /dev/null 2>&1
  469. # Backup MySQL/MariaDB configuration and data
  470. service postgresql stop > /dev/null 2>&1
  471. mv /var/lib/pgsql/data $vst_backups/postgresql/ >/dev/null 2>&1
  472. # Backup Vesta
  473. service vesta stop > /dev/null 2>&1
  474. mv $VESTA/data/* $vst_backups/vesta > /dev/null 2>&1
  475. mv $VESTA/conf/* $vst_backups/vesta > /dev/null 2>&1
  476. #----------------------------------------------------------#
  477. # Package Excludes #
  478. #----------------------------------------------------------#
  479. # Excluding packages
  480. if [ "$nginx" = 'no' ]; then
  481. software=$(echo "$software" | sed -e "s/^nginx//")
  482. fi
  483. if [ "$apache" = 'no' ]; then
  484. software=$(echo "$software" | sed -e "s/httpd//")
  485. software=$(echo "$software" | sed -e "s/mod_ssl//")
  486. software=$(echo "$software" | sed -e "s/mod_fcgid//")
  487. software=$(echo "$software" | sed -e "s/mod_ruid2//")
  488. fi
  489. if [ "$phpfpm" = 'no' ]; then
  490. software=$(echo "$software" | sed -e "s/php-fpm//")
  491. fi
  492. if [ "$vsftpd" = 'no' ]; then
  493. software=$(echo "$software" | sed -e "s/vsftpd//")
  494. fi
  495. if [ "$proftpd" = 'no' ]; then
  496. software=$(echo "$software" | sed -e "s/proftpd//")
  497. fi
  498. if [ "$named" = 'no' ]; then
  499. software=$(echo "$software" | sed -e "s/bind //")
  500. fi
  501. if [ "$exim" = 'no' ]; then
  502. software=$(echo "$software" | sed -e "s/exim//")
  503. software=$(echo "$software" | sed -e "s/dovecot//")
  504. software=$(echo "$software" | sed -e "s/clamd//")
  505. software=$(echo "$software" | sed -e "s/clamav-server//")
  506. software=$(echo "$software" | sed -e "s/clamav-update//")
  507. software=$(echo "$software" | sed -e "s/spamassassin//")
  508. software=$(echo "$software" | sed -e "s/dovecot//")
  509. software=$(echo "$software" | sed -e "s/roundcubemail//")
  510. fi
  511. if [ "$clamd" = 'no' ]; then
  512. software=$(echo "$software" | sed -e "s/clamd//")
  513. software=$(echo "$software" | sed -e "s/clamav-server//")
  514. software=$(echo "$software" | sed -e "s/clamav-update//")
  515. fi
  516. if [ "$spamd" = 'no' ]; then
  517. software=$(echo "$software" | sed -e 's/spamassassin//')
  518. fi
  519. if [ "$dovecot" = 'no' ]; then
  520. software=$(echo "$software" | sed -e "s/dovecot//")
  521. fi
  522. if [ "$mysql" = 'no' ]; then
  523. software=$(echo "$software" | sed -e 's/mysql //')
  524. software=$(echo "$software" | sed -e 's/mysql-server//')
  525. software=$(echo "$software" | sed -e 's/mariadb //')
  526. software=$(echo "$software" | sed -e 's/mariadb-server//')
  527. software=$(echo "$software" | sed -e 's/php-mysql//')
  528. software=$(echo "$software" | sed -e 's/phpMyAdmin//')
  529. software=$(echo "$software" | sed -e 's/roundcubemail//')
  530. fi
  531. if [ "$postgresql" = 'no' ]; then
  532. software=$(echo "$software" | sed -e 's/postgresql //')
  533. software=$(echo "$software" | sed -e 's/postgresql-server//')
  534. software=$(echo "$software" | sed -e 's/postgresql-contrib//')
  535. software=$(echo "$software" | sed -e 's/php-pgsql//')
  536. software=$(echo "$software" | sed -e 's/phpPgAdmin//')
  537. fi
  538. if [ "$softaculous" = 'no' ]; then
  539. software=$(echo "$software" | sed -e 's/vesta-softaculous//')
  540. fi
  541. if [ "$iptables" = 'no' ] || [ "$fail2ban" = 'no' ]; then
  542. software=$(echo "$software" | sed -e 's/fail2ban//')
  543. fi
  544. #----------------------------------------------------------#
  545. # Install packages #
  546. #----------------------------------------------------------#
  547. # Installing rpm packages
  548. yum -y install $software
  549. check_result $? "yum install failed"
  550. # Installing roundcube
  551. if [ "$exim" != 'no' ]; then
  552. yum -y install --exclude=php-pear-Auth-SASL-0:1.0.4-1.2.amzn1.noarch \
  553. --exclude=php5\* --exclude=httpd24\* roundcubemail
  554. check_result $? "yum install failed"
  555. fi
  556. #----------------------------------------------------------#
  557. # Configure system #
  558. #----------------------------------------------------------#
  559. # Restarting rsyslog
  560. service rsyslog restart > /dev/null 2>&1
  561. # Checking ipv6 on loopback interface
  562. check_lo_ipv6=$(/sbin/ip addr | grep 'inet6')
  563. check_rc_ipv6=$(grep 'scope global dev lo' /etc/rc.local)
  564. if [ ! -z "$check_lo_ipv6)" ] && [ -z "$check_rc_ipv6" ]; then
  565. ip addr add ::2/128 scope global dev lo
  566. echo "# Vesta: Workraround for openssl validation func" >> /etc/rc.local
  567. echo "ip addr add ::2/128 scope global dev lo" >> /etc/rc.local
  568. chmod a+x /etc/rc.local
  569. fi
  570. # Disabling SELinux
  571. if [ -e '/etc/sysconfig/selinux' ]; then
  572. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  573. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  574. setenforce 0 2>/dev/null
  575. fi
  576. # Disabling iptables
  577. service iptables stop
  578. # Configuring NTP synchronization
  579. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  580. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  581. chmod 775 /etc/cron.daily/ntpdate
  582. ntpdate -s pool.ntp.org
  583. # Disabling webalizer routine
  584. rm -f /etc/cron.daily/00webalizer
  585. # Adding backup user
  586. adduser backup 2>/dev/null
  587. ln -sf /home/backup /backup
  588. chmod a+x /backup
  589. # Set directory color
  590. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  591. # Changing default systemd interval
  592. if [ "$release" -eq '7' ]; then
  593. # Hi Lennart
  594. echo "DefaultStartLimitInterval=1s" >> /etc/systemd/system.conf
  595. echo "DefaultStartLimitBurst=60" >> /etc/systemd/system.conf
  596. systemctl daemon-reexec
  597. fi
  598. #----------------------------------------------------------#
  599. # Configure VESTA #
  600. #----------------------------------------------------------#
  601. # Installing sudo configuration
  602. mkdir -p /etc/sudoers.d
  603. cp -f $vestacp/sudo/admin /etc/sudoers.d/
  604. chmod 440 /etc/sudoers.d/admin
  605. # Configuring system env
  606. echo "export VESTA='$VESTA'" > /etc/profile.d/vesta.sh
  607. chmod 755 /etc/profile.d/vesta.sh
  608. source /etc/profile.d/vesta.sh
  609. echo 'PATH=$PATH:'$VESTA'/bin' >> /root/.bash_profile
  610. echo 'export PATH' >> /root/.bash_profile
  611. source /root/.bash_profile
  612. # Configuring logrotate for vesta logs
  613. cp -f $vestacp/logrotate/vesta /etc/logrotate.d/
  614. # Building directory tree and creating some blank files for vesta
  615. mkdir -p $VESTA/conf $VESTA/log $VESTA/ssl $VESTA/data/ips \
  616. $VESTA/data/queue $VESTA/data/users $VESTA/data/firewall \
  617. $VESTA/data/sessions
  618. touch $VESTA/data/queue/backup.pipe $VESTA/data/queue/disk.pipe \
  619. $VESTA/data/queue/webstats.pipe $VESTA/data/queue/restart.pipe \
  620. $VESTA/data/queue/traffic.pipe $VESTA/log/system.log \
  621. $VESTA/log/nginx-error.log $VESTA/log/auth.log
  622. chmod 750 $VESTA/conf $VESTA/data/users $VESTA/data/ips $VESTA/log
  623. chmod -R 750 $VESTA/data/queue
  624. chmod 660 $VESTA/log/*
  625. rm -f /var/log/vesta
  626. ln -s $VESTA/log /var/log/vesta
  627. chmod 770 $VESTA/data/sessions
  628. # Generating vesta configuration
  629. rm -f $VESTA/conf/vesta.conf 2>/dev/null
  630. touch $VESTA/conf/vesta.conf
  631. chmod 660 $VESTA/conf/vesta.conf
  632. # Web stack
  633. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  634. echo "WEB_SYSTEM='httpd'" >> $VESTA/conf/vesta.conf
  635. echo "WEB_RGROUPS='apache'" >> $VESTA/conf/vesta.conf
  636. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  637. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  638. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  639. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  640. fi
  641. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  642. echo "WEB_SYSTEM='httpd'" >> $VESTA/conf/vesta.conf
  643. echo "WEB_RGROUPS='apache'" >> $VESTA/conf/vesta.conf
  644. echo "WEB_PORT='8080'" >> $VESTA/conf/vesta.conf
  645. echo "WEB_SSL_PORT='8443'" >> $VESTA/conf/vesta.conf
  646. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  647. echo "PROXY_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  648. echo "PROXY_PORT='80'" >> $VESTA/conf/vesta.conf
  649. echo "PROXY_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  650. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  651. fi
  652. if [ "$apache" = 'no' ] && [ "$nginx" = 'yes' ]; then
  653. echo "WEB_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  654. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  655. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  656. echo "WEB_SSL='openssl'" >> $VESTA/conf/vesta.conf
  657. if [ "$phpfpm" = 'yes' ]; then
  658. echo "WEB_BACKEND='php-fpm'" >> $VESTA/conf/vesta.conf
  659. fi
  660. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  661. fi
  662. # FTP stack
  663. if [ "$vsftpd" = 'yes' ]; then
  664. echo "FTP_SYSTEM='vsftpd'" >> $VESTA/conf/vesta.conf
  665. fi
  666. if [ "$proftpd" = 'yes' ]; then
  667. echo "FTP_SYSTEM='proftpd'" >> $VESTA/conf/vesta.conf
  668. fi
  669. # DNS stack
  670. if [ "$named" = 'yes' ]; then
  671. echo "DNS_SYSTEM='named'" >> $VESTA/conf/vesta.conf
  672. fi
  673. # Mail stack
  674. if [ "$exim" = 'yes' ]; then
  675. echo "MAIL_SYSTEM='exim'" >> $VESTA/conf/vesta.conf
  676. if [ "$clamd" = 'yes' ]; then
  677. echo "ANTIVIRUS_SYSTEM='clamav'" >> $VESTA/conf/vesta.conf
  678. fi
  679. if [ "$spamd" = 'yes' ]; then
  680. echo "ANTISPAM_SYSTEM='spamassassin'" >> $VESTA/conf/vesta.conf
  681. fi
  682. if [ "$dovecot" = 'yes' ]; then
  683. echo "IMAP_SYSTEM='dovecot'" >> $VESTA/conf/vesta.conf
  684. fi
  685. fi
  686. # Cron daemon
  687. echo "CRON_SYSTEM='crond'" >> $VESTA/conf/vesta.conf
  688. # Firewall stack
  689. if [ "$iptables" = 'yes' ]; then
  690. echo "FIREWALL_SYSTEM='iptables'" >> $VESTA/conf/vesta.conf
  691. fi
  692. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  693. echo "FIREWALL_EXTENSION='fail2ban'" >> $VESTA/conf/vesta.conf
  694. fi
  695. # Disk quota
  696. if [ "$quota" = 'yes' ]; then
  697. echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
  698. fi
  699. # Backups
  700. echo "BACKUP_SYSTEM='local'" >> $VESTA/conf/vesta.conf
  701. # Language
  702. echo "LANGUAGE='$lang'" >> $VESTA/conf/vesta.conf
  703. # Version
  704. echo "VERSION='0.9.8'" >> $VESTA/conf/vesta.conf
  705. # Installing hosting packages
  706. cp -rf $vestacp/packages $VESTA/data/
  707. # Installing templates
  708. cp -rf $vestacp/templates $VESTA/data/
  709. # Copying index.html to default documentroot
  710. cp $VESTA/data/templates/web/skel/public_html/index.html /var/www/html/
  711. sed -i 's/%domain%/It worked!/g' /var/www/html/index.html
  712. # Installing firewall rules
  713. chkconfig firewalld off >/dev/null 2>&1
  714. cp -rf $vestacp/firewall $VESTA/data/
  715. # Configuring server hostname
  716. $VESTA/bin/v-change-sys-hostname $servername 2>/dev/null
  717. # Generating SSL certificate
  718. $VESTA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  719. 'San Francisco' 'Vesta Control Panel' 'IT' > /tmp/vst.pem
  720. # Parsing certificate file
  721. crt_end=$(grep -n "END CERTIFICATE-" /tmp/vst.pem |cut -f 1 -d:)
  722. key_start=$(grep -n "BEGIN RSA" /tmp/vst.pem |cut -f 1 -d:)
  723. key_end=$(grep -n "END RSA" /tmp/vst.pem |cut -f 1 -d:)
  724. # Adding SSL certificate
  725. cd $VESTA/ssl
  726. sed -n "1,${crt_end}p" /tmp/vst.pem > certificate.crt
  727. sed -n "$key_start,${key_end}p" /tmp/vst.pem > certificate.key
  728. chown root:mail $VESTA/ssl/*
  729. chmod 660 $VESTA/ssl/*
  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" -ge 7 ]; then
  745. mkdir -p /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" -ge '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 -lt 7 ]; then
  769. cd /etc/httpd/conf.d
  770. echo "MEFaccept 127.0.0.1" >> mod_extract_forwarded.conf
  771. echo > proxy_ajp.conf
  772. fi
  773. if [ -e "/etc/httpd/conf.modules.d/00-dav.conf" ]; then
  774. cd /etc/httpd/conf.modules.d
  775. sed -i "s/^/#/" 00-dav.conf 00-lua.conf 00-proxy.conf
  776. fi
  777. echo > /etc/httpd/conf.d/vesta.conf
  778. cd /var/log/httpd
  779. touch access_log error_log suexec.log
  780. chmod 640 access_log error_log suexec.log
  781. chmod -f 777 /var/lib/php/session
  782. chmod a+x /var/log/httpd
  783. mkdir -p /var/log/httpd/domains
  784. chmod 751 /var/log/httpd/domains
  785. if [ "$release" -ge 7 ]; then
  786. mkdir -p /etc/systemd/system/httpd.service.d
  787. cd /etc/systemd/system/httpd.service.d
  788. echo "[Service]" > limits.conf
  789. echo "LimitNOFILE=500000" >> limits.conf
  790. fi
  791. chkconfig httpd on
  792. service httpd start
  793. check_result $? "httpd start failed"
  794. # Workaround for OpenVZ/Virtuozzo
  795. if [ "$release" -ge '7' ] && [ -e "/proc/vz/veinfo" ]; then
  796. echo "#Vesta: workraround for networkmanager" >> /etc/rc.local
  797. echo "sleep 2 && service httpd restart" >> /etc/rc.local
  798. fi
  799. fi
  800. #----------------------------------------------------------#
  801. # Configure PHP-FPM #
  802. #----------------------------------------------------------#
  803. if [ "$phpfpm" = 'yes' ]; then
  804. cp -f $vestacp/php-fpm/www.conf /etc/php-fpm.d/
  805. chkconfig php-fpm on
  806. service php-fpm start
  807. check_result $? "php-fpm start failed"
  808. fi
  809. #----------------------------------------------------------#
  810. # Configure PHP #
  811. #----------------------------------------------------------#
  812. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  813. if [ -e '/etc/sysconfig/clock' ]; then
  814. source /etc/sysconfig/clock
  815. fi
  816. if [ -z "$ZONE" ]; then
  817. ZONE='UTC'
  818. fi
  819. for pconf in $(find /etc/php* -name php.ini); do
  820. sed -i "s/;date.timezone =/date.timezone = $ZONE/g" $pconf
  821. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  822. done
  823. #----------------------------------------------------------#
  824. # Configure Vsftpd #
  825. #----------------------------------------------------------#
  826. if [ "$vsftpd" = 'yes' ]; then
  827. cp -f $vestacp/vsftpd/vsftpd.conf /etc/vsftpd/
  828. chkconfig vsftpd on
  829. service vsftpd start
  830. check_result $? "vsftpd start failed"
  831. # To be deleted after release 0.9.8-18
  832. echo "/sbin/nologin" >> /etc/shells
  833. fi
  834. #----------------------------------------------------------#
  835. # Configure ProFTPD #
  836. #----------------------------------------------------------#
  837. if [ "$proftpd" = 'yes' ]; then
  838. cp -f $vestacp/proftpd/proftpd.conf /etc/
  839. chkconfig proftpd on
  840. service proftpd start
  841. check_result $? "proftpd start failed"
  842. fi
  843. #----------------------------------------------------------#
  844. # Configure MySQL/MariaDB #
  845. #----------------------------------------------------------#
  846. if [ "$mysql" = 'yes' ]; then
  847. mycnf="my-small.cnf"
  848. if [ $memory -gt 1200000 ]; then
  849. mycnf="my-medium.cnf"
  850. fi
  851. if [ $memory -gt 3900000 ]; then
  852. mycnf="my-large.cnf"
  853. fi
  854. mkdir -p /var/lib/mysql
  855. chown mysql:mysql /var/lib/mysql
  856. mkdir -p /etc/my.cnf.d
  857. if [ $release -lt 7 ]; then
  858. service='mysqld'
  859. else
  860. service='mariadb'
  861. fi
  862. cp -f $vestacp/$service/$mycnf /etc/my.cnf
  863. chkconfig $service on
  864. service $service start
  865. if [ "$?" -ne 0 ]; then
  866. if [ -e "/proc/user_beancounters" ]; then
  867. # Fix for aio on OpenVZ
  868. sed -i "s/#innodb_use_native/innodb_use_native/g" /etc/my.cnf
  869. fi
  870. service $service start
  871. check_result $? "$service start failed"
  872. fi
  873. # Securing MySQL installation
  874. mysqladmin -u root password $vpass
  875. echo -e "[client]\npassword='$vpass'\n" > /root/.my.cnf
  876. chmod 600 /root/.my.cnf
  877. mysql -e "DELETE FROM mysql.user WHERE User=''"
  878. mysql -e "DROP DATABASE test" >/dev/null 2>&1
  879. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  880. mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
  881. mysql -e "FLUSH PRIVILEGES"
  882. # Configuring phpMyAdmin
  883. if [ "$apache" = 'yes' ]; then
  884. cp -f $vestacp/pma/phpMyAdmin.conf /etc/httpd/conf.d/
  885. fi
  886. cp -f $vestacp/pma/config.inc.conf /etc/phpMyAdmin/config.inc.php
  887. sed -i "s/%blowfish_secret%/$(gen_pass)/g" /etc/phpMyAdmin/config.inc.php
  888. fi
  889. #----------------------------------------------------------#
  890. # Configure PostgreSQL #
  891. #----------------------------------------------------------#
  892. if [ "$postgresql" = 'yes' ]; then
  893. if [ $release -eq 5 ]; then
  894. service postgresql start
  895. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$vpass'"
  896. service postgresql stop
  897. cp -f $vestacp/postgresql/pg_hba.conf /var/lib/pgsql/data/
  898. service postgresql start
  899. else
  900. service postgresql initdb
  901. cp -f $vestacp/postgresql/pg_hba.conf /var/lib/pgsql/data/
  902. service postgresql start
  903. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$vpass'"
  904. fi
  905. # Configuring phpPgAdmin
  906. if [ "$apache" = 'yes' ]; then
  907. cp -f $vestacp/pga/phpPgAdmin.conf /etc/httpd/conf.d/
  908. fi
  909. cp -f $vestacp/pga/config.inc.php /etc/phpPgAdmin/
  910. fi
  911. #----------------------------------------------------------#
  912. # Configure Bind #
  913. #----------------------------------------------------------#
  914. if [ "$named" = 'yes' ]; then
  915. cp -f $vestacp/named/named.conf /etc/
  916. chown root:named /etc/named.conf
  917. chmod 640 /etc/named.conf
  918. chkconfig named on
  919. service named start
  920. check_result $? "named start failed"
  921. fi
  922. #----------------------------------------------------------#
  923. # Configure Exim #
  924. #----------------------------------------------------------#
  925. if [ "$exim" = 'yes' ]; then
  926. gpasswd -a exim mail
  927. cp -f $vestacp/exim/exim.conf /etc/exim/
  928. cp -f $vestacp/exim/dnsbl.conf /etc/exim/
  929. cp -f $vestacp/exim/spam-blocks.conf /etc/exim/
  930. touch /etc/exim/white-blocks.conf
  931. if [ "$spamd" = 'yes' ]; then
  932. sed -i "s/#SPAM/SPAM/g" /etc/exim/exim.conf
  933. fi
  934. if [ "$clamd" = 'yes' ]; then
  935. sed -i "s/#CLAMD/CLAMD/g" /etc/exim/exim.conf
  936. fi
  937. chmod 640 /etc/exim/exim.conf
  938. rm -rf /etc/exim/domains
  939. mkdir -p /etc/exim/domains
  940. rm -f /etc/alternatives/mta
  941. ln -s /usr/sbin/sendmail.exim /etc/alternatives/mta
  942. chkconfig sendmail off 2>/dev/null
  943. service sendmail stop 2>/dev/null
  944. chkconfig postfix off 2>/dev/null
  945. service postfix stop 2>/dev/null
  946. chkconfig exim on
  947. service exim start
  948. check_result $? "exim start failed"
  949. fi
  950. #----------------------------------------------------------#
  951. # Configure Dovecot #
  952. #----------------------------------------------------------#
  953. if [ "$dovecot" = 'yes' ]; then
  954. gpasswd -a dovecot mail
  955. cp -rf $vestacp/dovecot /etc/
  956. cp -f $vestacp/logrotate/dovecot /etc/logrotate.d/
  957. chown -R root:root /etc/dovecot*
  958. chkconfig dovecot on
  959. service dovecot start
  960. check_result $? "dovecot start failed"
  961. fi
  962. #----------------------------------------------------------#
  963. # Configure ClamAV #
  964. #----------------------------------------------------------#
  965. if [ "$clamd" = 'yes' ]; then
  966. useradd clam -s /sbin/nologin -d /var/lib/clamav 2>/dev/null
  967. gpasswd -a clam exim
  968. gpasswd -a clam mail
  969. cp -f $vestacp/clamav/clamd.conf /etc/
  970. cp -f $vestacp/clamav/freshclam.conf /etc/
  971. mkdir -p /var/log/clamav /var/run/clamav
  972. chown clam:clam /var/log/clamav /var/run/clamav
  973. chown -R clam:clam /var/lib/clamav
  974. if [ "$release" -ge '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" -ge '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" -ge '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. 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 admin 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. # Configuring firewall
  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 PostgreSQL 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. # Adding cron jobs
  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 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