vst-install-amazon.sh 46 KB

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