vst-install-amazon.sh 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  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. -x, --exim Install Exim [yes|no] default: yes
  41. -z, --dovecot Install Dovecot [yes|no] default: yes
  42. -c, --clamav Install ClamAV [yes|no] default: yes
  43. -t, --spamassassin Install SpamAssassin [yes|no] default: yes
  44. -i, --iptables Install Iptables [yes|no] default: yes
  45. -b, --fail2ban Install Fail2ban [yes|no] default: yes
  46. -r, --remi Install Remi repo [yes|no] default: yes
  47. -o, --softaculous Install Softaculous [yes|no] default: yes
  48. -q, --quota Filesystem Quota [yes|no] default: no
  49. -l, --lang Default language default: en
  50. -y, --interactive Interactive install [yes|no] default: yes
  51. -s, --hostname Set hostname
  52. -u, --ssl Add LE SSL for hostname [yes|no] default: no
  53. -e, --email Set admin email
  54. -d, --port Set Vesta port
  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. --exim) args="${args}-x " ;;
  120. --dovecot) args="${args}-z " ;;
  121. --clamav) args="${args}-c " ;;
  122. --spamassassin) args="${args}-t " ;;
  123. --iptables) args="${args}-i " ;;
  124. --fail2ban) args="${args}-b " ;;
  125. --remi) args="${args}-r " ;;
  126. --softaculous) args="${args}-o " ;;
  127. --quota) args="${args}-q " ;;
  128. --lang) args="${args}-l " ;;
  129. --interactive) args="${args}-y " ;;
  130. --hostname) args="${args}-s " ;;
  131. --ssl) args="${args}-u " ;;
  132. --email) args="${args}-e " ;;
  133. --port) args="${args}-d " ;;
  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:x:z:c:t:i:b:r:o:q:l:y:s:u:e:d: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. x) exim=$OPTARG ;; # Exim
  154. z) dovecot=$OPTARG ;; # Dovecot
  155. c) clamd=$OPTARG ;; # ClamAV
  156. t) spamd=$OPTARG ;; # SpamAssassin
  157. i) iptables=$OPTARG ;; # Iptables
  158. b) fail2ban=$OPTARG ;; # Fail2ban
  159. r) remi=$OPTARG ;; # Remi repo
  160. o) softaculous=$OPTARG ;; # Softaculous plugin
  161. q) quota=$OPTARG ;; # FS Quota
  162. l) lang=$OPTARG ;; # Language
  163. y) interactive=$OPTARG ;; # Interactive install
  164. s) servername=$OPTARG ;; # Hostname
  165. u) ssl=$OPTARG ;; # Add Let's Encrypt SSL for hostname
  166. e) email=$OPTARG ;; # Admin email
  167. d) port=$OPTARG ;; # Vesta port
  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 for Vesta port
  357. if [ -z "$port" ]; then
  358. read -p 'Please enter Vesta port number (press enter for 8083): ' port
  359. fi
  360. # Asking to set FQDN hostname
  361. if [ -z "$servername" ]; then
  362. read -p "Please enter FQDN hostname [$(hostname)]: " servername
  363. fi
  364. fi
  365. # Generating admin password if it wasn't set
  366. if [ -z "$vpass" ]; then
  367. vpass=$(gen_pass)
  368. fi
  369. # Set hostname if it wasn't set
  370. if [ -z "$servername" ]; then
  371. servername=$(hostname -f)
  372. fi
  373. # Set FQDN if it wasn't set
  374. mask1='(([[:alnum:]](-?[[:alnum:]])*)\.)'
  375. mask2='*[[:alnum:]](-?[[:alnum:]])+\.[[:alnum:]]{2,}'
  376. if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
  377. if [ ! -z "$servername" ]; then
  378. servername="$servername.example.com"
  379. else
  380. servername="example.com"
  381. fi
  382. echo "127.0.0.1 $servername" >> /etc/hosts
  383. fi
  384. # Set email if it wasn't set
  385. if [ -z "$email" ]; then
  386. email="admin@$servername"
  387. fi
  388. # Set port if it wasn't set
  389. if [ -z "$port" ]; then
  390. port="8083"
  391. fi
  392. # Defining backup directory
  393. vst_backups="/root/vst_install_backups/$(date +%s)"
  394. echo "Installation backup directory: $vst_backups"
  395. # Printing start message and sleeping for 5 seconds
  396. echo -e "\n\n\n\nInstallation will take about 15 minutes ...\n"
  397. sleep 5
  398. #----------------------------------------------------------#
  399. # Checking swap #
  400. #----------------------------------------------------------#
  401. # Checking swap on small instances
  402. if [ -z "$(swapon -s)" ] && [ $memory -lt 1000000 ]; then
  403. fallocate -l 1G /swapfile
  404. chmod 600 /swapfile
  405. mkswap /swapfile
  406. swapon /swapfile
  407. echo "/swapfile none swap sw 0 0" >> /etc/fstab
  408. fi
  409. #----------------------------------------------------------#
  410. # Install repositories #
  411. #----------------------------------------------------------#
  412. # Updating system
  413. yum -y update
  414. check_result $? 'yum update failed'
  415. # Enabling EPEL repository
  416. sed "1,10s/enabled=0/enabled=1/" -i /etc/yum.repos.d/epel.repo
  417. yum -y update
  418. check_result $? "Can't install EPEL repository"
  419. # Installing Nginx repository
  420. nrepo="/etc/yum.repos.d/nginx.repo"
  421. echo "[nginx]" > $nrepo
  422. echo "name=nginx repo" >> $nrepo
  423. echo "baseurl=http://nginx.org/packages/centos/$release/\$basearch/" >> $nrepo
  424. echo "gpgcheck=0" >> $nrepo
  425. echo "enabled=1" >> $nrepo
  426. # Installing Vesta repository
  427. vrepo='/etc/yum.repos.d/vesta.repo'
  428. echo "[vesta]" > $vrepo
  429. echo "name=Vesta - $REPO" >> $vrepo
  430. echo "baseurl=http://$RHOST/$REPO/$release/\$basearch/" >> $vrepo
  431. echo "enabled=1" >> $vrepo
  432. echo "gpgcheck=1" >> $vrepo
  433. echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA" >> $vrepo
  434. wget c.vestacp.com/GPG.txt -O /etc/pki/rpm-gpg/RPM-GPG-KEY-VESTA
  435. #----------------------------------------------------------#
  436. # Backup #
  437. #----------------------------------------------------------#
  438. # Creating backup directory tree
  439. mkdir -p $vst_backups
  440. cd $vst_backups
  441. mkdir nginx httpd php php-fpm vsftpd proftpd named exim dovecot clamd \
  442. spamassassin mysql postgresql mongodb vesta
  443. # Backup Nginx configuration
  444. service nginx stop > /dev/null 2>&1
  445. cp -r /etc/nginx/* $vst_backups/nginx > /dev/null 2>&1
  446. # Backup Apache configuration
  447. service httpd stop > /dev/null 2>&1
  448. cp -r /etc/httpd/* $vst_backups/httpd > /dev/null 2>&1
  449. # Backup PHP-FPM configuration
  450. service php-fpm stop >/dev/null 2>&1
  451. cp /etc/php.ini $vst_backups/php > /dev/null 2>&1
  452. cp -r /etc/php.d $vst_backups/php > /dev/null 2>&1
  453. cp /etc/php-fpm.conf $vst_backups/php-fpm > /dev/null 2>&1
  454. mv -f /etc/php-fpm.d/* $vst_backups/php-fpm/ > /dev/null 2>&1
  455. # Backup Bind configuration
  456. yum remove bind-chroot > /dev/null 2>&1
  457. service named stop > /dev/null 2>&1
  458. cp /etc/named.conf $vst_backups/named >/dev/null 2>&1
  459. # Backup Vsftpd configuration
  460. service vsftpd stop > /dev/null 2>&1
  461. cp /etc/vsftpd/vsftpd.conf $vst_backups/vsftpd >/dev/null 2>&1
  462. # Backup ProFTPD configuration
  463. service proftpd stop > /dev/null 2>&1
  464. cp /etc/proftpd.conf $vst_backups/proftpd >/dev/null 2>&1
  465. # Backup Exim configuration
  466. service exim stop > /dev/null 2>&1
  467. cp -r /etc/exim/* $vst_backups/exim >/dev/null 2>&1
  468. # Backup ClamAV configuration
  469. service clamd stop > /dev/null 2>&1
  470. cp /etc/clamd.conf $vst_backups/clamd >/dev/null 2>&1
  471. cp -r /etc/clamd.d $vst_backups/clamd >/dev/null 2>&1
  472. # Backup SpamAssassin configuration
  473. service spamassassin stop > /dev/null 2>&1
  474. cp -r /etc/mail/spamassassin/* $vst_backups/spamassassin >/dev/null 2>&1
  475. # Backup Dovecot configuration
  476. service dovecot stop > /dev/null 2>&1
  477. cp /etc/dovecot.conf $vst_backups/dovecot > /dev/null 2>&1
  478. cp -r /etc/dovecot/* $vst_backups/dovecot > /dev/null 2>&1
  479. # Backup MySQL/MariaDB configuration and data
  480. service mysql stop > /dev/null 2>&1
  481. service mysqld stop > /dev/null 2>&1
  482. service mariadb stop > /dev/null 2>&1
  483. mv /var/lib/mysql $vst_backups/mysql/mysql_datadir >/dev/null 2>&1
  484. cp /etc/my.cnf $vst_backups/mysql > /dev/null 2>&1
  485. cp /etc/my.cnf.d $vst_backups/mysql > /dev/null 2>&1
  486. mv /root/.my.cnf $vst_backups/mysql > /dev/null 2>&1
  487. # Backup MySQL/MariaDB configuration and data
  488. service postgresql stop > /dev/null 2>&1
  489. mv /var/lib/pgsql/data $vst_backups/postgresql/ >/dev/null 2>&1
  490. # Backup Vesta
  491. service vesta stop > /dev/null 2>&1
  492. mv $VESTA/data/* $vst_backups/vesta > /dev/null 2>&1
  493. mv $VESTA/conf/* $vst_backups/vesta > /dev/null 2>&1
  494. #----------------------------------------------------------#
  495. # Package Excludes #
  496. #----------------------------------------------------------#
  497. # Excluding packages
  498. if [ "$nginx" = 'no' ]; then
  499. software=$(echo "$software" | sed -e "s/^nginx//")
  500. fi
  501. if [ "$apache" = 'no' ]; then
  502. software=$(echo "$software" | sed -e "s/httpd//")
  503. software=$(echo "$software" | sed -e "s/mod_ssl//")
  504. software=$(echo "$software" | sed -e "s/mod_fcgid//")
  505. software=$(echo "$software" | sed -e "s/mod_ruid2//")
  506. fi
  507. if [ "$phpfpm" = 'no' ]; then
  508. software=$(echo "$software" | sed -e "s/php-fpm//")
  509. fi
  510. if [ "$vsftpd" = 'no' ]; then
  511. software=$(echo "$software" | sed -e "s/vsftpd//")
  512. fi
  513. if [ "$proftpd" = 'no' ]; then
  514. software=$(echo "$software" | sed -e "s/proftpd//")
  515. fi
  516. if [ "$named" = 'no' ]; then
  517. software=$(echo "$software" | sed -e "s/bind //")
  518. fi
  519. if [ "$exim" = 'no' ]; then
  520. software=$(echo "$software" | sed -e "s/exim//")
  521. software=$(echo "$software" | sed -e "s/dovecot//")
  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. software=$(echo "$software" | sed -e "s/spamassassin//")
  526. software=$(echo "$software" | sed -e "s/dovecot//")
  527. software=$(echo "$software" | sed -e "s/roundcubemail//")
  528. fi
  529. if [ "$clamd" = 'no' ]; then
  530. software=$(echo "$software" | sed -e "s/clamd//")
  531. software=$(echo "$software" | sed -e "s/clamav-server//")
  532. software=$(echo "$software" | sed -e "s/clamav-update//")
  533. fi
  534. if [ "$spamd" = 'no' ]; then
  535. software=$(echo "$software" | sed -e 's/spamassassin//')
  536. fi
  537. if [ "$dovecot" = 'no' ]; then
  538. software=$(echo "$software" | sed -e "s/dovecot//")
  539. fi
  540. if [ "$mysql" = 'no' ]; then
  541. software=$(echo "$software" | sed -e 's/mysql //')
  542. software=$(echo "$software" | sed -e 's/mysql-server//')
  543. software=$(echo "$software" | sed -e 's/mariadb //')
  544. software=$(echo "$software" | sed -e 's/mariadb-server//')
  545. software=$(echo "$software" | sed -e 's/php-mysql//')
  546. software=$(echo "$software" | sed -e 's/phpMyAdmin//')
  547. software=$(echo "$software" | sed -e 's/roundcubemail//')
  548. fi
  549. if [ "$postgresql" = 'no' ]; then
  550. software=$(echo "$software" | sed -e 's/postgresql //')
  551. software=$(echo "$software" | sed -e 's/postgresql-server//')
  552. software=$(echo "$software" | sed -e 's/postgresql-contrib//')
  553. software=$(echo "$software" | sed -e 's/php-pgsql//')
  554. software=$(echo "$software" | sed -e 's/phpPgAdmin//')
  555. fi
  556. if [ "$softaculous" = 'no' ]; then
  557. software=$(echo "$software" | sed -e 's/vesta-softaculous//')
  558. fi
  559. if [ "$iptables" = 'no' ] || [ "$fail2ban" = 'no' ]; then
  560. software=$(echo "$software" | sed -e 's/fail2ban//')
  561. fi
  562. #----------------------------------------------------------#
  563. # Install packages #
  564. #----------------------------------------------------------#
  565. # Installing rpm packages
  566. yum -y install $software
  567. check_result $? "yum install failed"
  568. # Installing roundcube
  569. if [ "$exim" != 'no' ]; then
  570. yum -y install --exclude=php-pear-Auth-SASL-0:1.0.4-1.2.amzn1.noarch \
  571. --exclude=php5\* --exclude=httpd24\* roundcubemail
  572. check_result $? "yum install failed"
  573. fi
  574. #----------------------------------------------------------#
  575. # Configure system #
  576. #----------------------------------------------------------#
  577. # Restarting rsyslog
  578. service rsyslog restart > /dev/null 2>&1
  579. # Checking ipv6 on loopback interface
  580. check_lo_ipv6=$(/sbin/ip addr | grep 'inet6')
  581. check_rc_ipv6=$(grep 'scope global dev lo' /etc/rc.local)
  582. if [ ! -z "$check_lo_ipv6)" ] && [ -z "$check_rc_ipv6" ]; then
  583. ip addr add ::2/128 scope global dev lo
  584. echo "# Vesta: Workraround for openssl validation func" >> /etc/rc.local
  585. echo "ip addr add ::2/128 scope global dev lo" >> /etc/rc.local
  586. chmod a+x /etc/rc.local
  587. fi
  588. # Disabling SELinux
  589. if [ -e '/etc/sysconfig/selinux' ]; then
  590. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  591. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  592. setenforce 0 2>/dev/null
  593. fi
  594. # Disabling iptables
  595. service iptables stop
  596. # Configuring NTP synchronization
  597. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  598. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  599. chmod 775 /etc/cron.daily/ntpdate
  600. ntpdate -s pool.ntp.org
  601. # Disabling webalizer routine
  602. rm -f /etc/cron.daily/00webalizer
  603. # Adding backup user
  604. adduser backup 2>/dev/null
  605. ln -sf /home/backup /backup
  606. chmod a+x /backup
  607. # Set directory color
  608. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  609. # Changing default systemd interval
  610. if [ "$release" -eq '7' ]; then
  611. # Hi Lennart
  612. echo "DefaultStartLimitInterval=1s" >> /etc/systemd/system.conf
  613. echo "DefaultStartLimitBurst=60" >> /etc/systemd/system.conf
  614. systemctl daemon-reexec
  615. fi
  616. #----------------------------------------------------------#
  617. # Configure VESTA #
  618. #----------------------------------------------------------#
  619. # Installing sudo configuration
  620. mkdir -p /etc/sudoers.d
  621. cp -f $vestacp/sudo/admin /etc/sudoers.d/
  622. chmod 440 /etc/sudoers.d/admin
  623. # Configuring system env
  624. echo "export VESTA='$VESTA'" > /etc/profile.d/vesta.sh
  625. chmod 755 /etc/profile.d/vesta.sh
  626. source /etc/profile.d/vesta.sh
  627. echo 'PATH=$PATH:'$VESTA'/bin' >> /root/.bash_profile
  628. echo 'export PATH' >> /root/.bash_profile
  629. source /root/.bash_profile
  630. # Configuring logrotate for vesta logs
  631. cp -f $vestacp/logrotate/vesta /etc/logrotate.d/
  632. # Building directory tree and creating some blank files for vesta
  633. mkdir -p $VESTA/conf $VESTA/log $VESTA/ssl $VESTA/data/ips \
  634. $VESTA/data/queue $VESTA/data/users $VESTA/data/firewall \
  635. $VESTA/data/sessions
  636. touch $VESTA/data/queue/backup.pipe $VESTA/data/queue/disk.pipe \
  637. $VESTA/data/queue/webstats.pipe $VESTA/data/queue/restart.pipe \
  638. $VESTA/data/queue/traffic.pipe $VESTA/log/system.log \
  639. $VESTA/log/nginx-error.log $VESTA/log/auth.log
  640. chmod 750 $VESTA/conf $VESTA/data/users $VESTA/data/ips $VESTA/log
  641. chmod -R 750 $VESTA/data/queue
  642. chmod 660 $VESTA/log/*
  643. rm -f /var/log/vesta
  644. ln -s $VESTA/log /var/log/vesta
  645. chmod 770 $VESTA/data/sessions
  646. # Generating vesta configuration
  647. rm -f $VESTA/conf/vesta.conf 2>/dev/null
  648. touch $VESTA/conf/vesta.conf
  649. chmod 660 $VESTA/conf/vesta.conf
  650. # Web stack
  651. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  652. echo "WEB_SYSTEM='httpd'" >> $VESTA/conf/vesta.conf
  653. echo "WEB_RGROUPS='apache'" >> $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='mod_ssl'" >> $VESTA/conf/vesta.conf
  657. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  658. fi
  659. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  660. echo "WEB_SYSTEM='httpd'" >> $VESTA/conf/vesta.conf
  661. echo "WEB_RGROUPS='apache'" >> $VESTA/conf/vesta.conf
  662. echo "WEB_PORT='8080'" >> $VESTA/conf/vesta.conf
  663. echo "WEB_SSL_PORT='8443'" >> $VESTA/conf/vesta.conf
  664. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  665. echo "PROXY_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  666. echo "PROXY_PORT='80'" >> $VESTA/conf/vesta.conf
  667. echo "PROXY_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  668. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  669. fi
  670. if [ "$apache" = 'no' ] && [ "$nginx" = 'yes' ]; then
  671. echo "WEB_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  672. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  673. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  674. echo "WEB_SSL='openssl'" >> $VESTA/conf/vesta.conf
  675. if [ "$phpfpm" = 'yes' ]; then
  676. echo "WEB_BACKEND='php-fpm'" >> $VESTA/conf/vesta.conf
  677. fi
  678. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  679. fi
  680. # FTP stack
  681. if [ "$vsftpd" = 'yes' ]; then
  682. echo "FTP_SYSTEM='vsftpd'" >> $VESTA/conf/vesta.conf
  683. fi
  684. if [ "$proftpd" = 'yes' ]; then
  685. echo "FTP_SYSTEM='proftpd'" >> $VESTA/conf/vesta.conf
  686. fi
  687. # DNS stack
  688. if [ "$named" = 'yes' ]; then
  689. echo "DNS_SYSTEM='named'" >> $VESTA/conf/vesta.conf
  690. fi
  691. # Mail stack
  692. if [ "$exim" = 'yes' ]; then
  693. echo "MAIL_SYSTEM='exim'" >> $VESTA/conf/vesta.conf
  694. if [ "$clamd" = 'yes' ]; then
  695. echo "ANTIVIRUS_SYSTEM='clamav'" >> $VESTA/conf/vesta.conf
  696. fi
  697. if [ "$spamd" = 'yes' ]; then
  698. echo "ANTISPAM_SYSTEM='spamassassin'" >> $VESTA/conf/vesta.conf
  699. fi
  700. if [ "$dovecot" = 'yes' ]; then
  701. echo "IMAP_SYSTEM='dovecot'" >> $VESTA/conf/vesta.conf
  702. fi
  703. fi
  704. # Cron daemon
  705. echo "CRON_SYSTEM='crond'" >> $VESTA/conf/vesta.conf
  706. # Firewall stack
  707. if [ "$iptables" = 'yes' ]; then
  708. echo "FIREWALL_SYSTEM='iptables'" >> $VESTA/conf/vesta.conf
  709. fi
  710. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  711. echo "FIREWALL_EXTENSION='fail2ban'" >> $VESTA/conf/vesta.conf
  712. fi
  713. # Disk quota
  714. if [ "$quota" = 'yes' ]; then
  715. echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
  716. fi
  717. # Backups
  718. echo "BACKUP_SYSTEM='local'" >> $VESTA/conf/vesta.conf
  719. # Language
  720. echo "LANGUAGE='$lang'" >> $VESTA/conf/vesta.conf
  721. # Version
  722. echo "VERSION='0.9.8'" >> $VESTA/conf/vesta.conf
  723. # Installing hosting packages
  724. cp -rf $vestacp/packages $VESTA/data/
  725. # Installing templates
  726. cp -rf $vestacp/templates $VESTA/data/
  727. # Copying index.html to default documentroot
  728. cp $VESTA/data/templates/web/skel/public_html/index.html /var/www/html/
  729. sed -i 's/%domain%/It worked!/g' /var/www/html/index.html
  730. # Installing firewall rules
  731. chkconfig firewalld off >/dev/null 2>&1
  732. cp -rf $vestacp/firewall $VESTA/data/
  733. # Configuring server hostname
  734. $VESTA/bin/v-change-sys-hostname $servername 2>/dev/null
  735. # Generating SSL certificate
  736. $VESTA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  737. 'San Francisco' 'Vesta Control Panel' 'IT' > /tmp/vst.pem
  738. # Parsing certificate file
  739. crt_end=$(grep -n "END CERTIFICATE-" /tmp/vst.pem |cut -f 1 -d:)
  740. key_start=$(grep -n "BEGIN RSA" /tmp/vst.pem |cut -f 1 -d:)
  741. key_end=$(grep -n "END RSA" /tmp/vst.pem |cut -f 1 -d:)
  742. # Adding SSL certificate
  743. cd $VESTA/ssl
  744. sed -n "1,${crt_end}p" /tmp/vst.pem > certificate.crt
  745. sed -n "$key_start,${key_end}p" /tmp/vst.pem > certificate.key
  746. chown root:mail $VESTA/ssl/*
  747. chmod 660 $VESTA/ssl/*
  748. rm /tmp/vst.pem
  749. #----------------------------------------------------------#
  750. # Configure Nginx #
  751. #----------------------------------------------------------#
  752. if [ "$nginx" = 'yes' ]; then
  753. rm -f /etc/nginx/conf.d/*.conf
  754. cp -f $vestacp/nginx/nginx.conf /etc/nginx/
  755. cp -f $vestacp/nginx/status.conf /etc/nginx/conf.d/
  756. cp -f $vestacp/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  757. cp -f $vestacp/nginx/phppgadmin.inc /etc/nginx/conf.d/
  758. cp -f $vestacp/nginx/webmail.inc /etc/nginx/conf.d/
  759. cp -f $vestacp/logrotate/nginx /etc/logrotate.d/
  760. echo > /etc/nginx/conf.d/vesta.conf
  761. mkdir -p /var/log/nginx/domains
  762. if [ "$release" -ge 7 ]; then
  763. mkdir -p /etc/systemd/system/nginx.service.d
  764. cd /etc/systemd/system/nginx.service.d
  765. echo "[Service]" > limits.conf
  766. echo "LimitNOFILE=500000" >> limits.conf
  767. fi
  768. chkconfig nginx on
  769. service nginx start
  770. check_result $? "nginx start failed"
  771. # Workaround for OpenVZ/Virtuozzo
  772. if [ "$release" -ge '7' ] && [ -e "/proc/vz/veinfo" ]; then
  773. echo "#Vesta: workraround for networkmanager" >> /etc/rc.local
  774. echo "sleep 3 && service nginx restart" >> /etc/rc.local
  775. fi
  776. fi
  777. #----------------------------------------------------------#
  778. # Configure Apache #
  779. #----------------------------------------------------------#
  780. if [ "$apache" = 'yes' ]; then
  781. cp -f $vestacp/httpd/httpd.conf /etc/httpd/conf/
  782. cp -f $vestacp/httpd/status.conf /etc/httpd/conf.d/
  783. cp -f $vestacp/httpd/ssl.conf /etc/httpd/conf.d/
  784. cp -f $vestacp/httpd/ruid2.conf /etc/httpd/conf.d/
  785. cp -f $vestacp/logrotate/httpd /etc/logrotate.d/
  786. if [ $release -lt 7 ]; then
  787. cd /etc/httpd/conf.d
  788. echo "MEFaccept 127.0.0.1" >> mod_extract_forwarded.conf
  789. echo > proxy_ajp.conf
  790. fi
  791. if [ -e "/etc/httpd/conf.modules.d/00-dav.conf" ]; then
  792. cd /etc/httpd/conf.modules.d
  793. sed -i "s/^/#/" 00-dav.conf 00-lua.conf 00-proxy.conf
  794. fi
  795. echo > /etc/httpd/conf.d/vesta.conf
  796. cd /var/log/httpd
  797. touch access_log error_log suexec.log
  798. chmod 640 access_log error_log suexec.log
  799. chmod -f 777 /var/lib/php/session
  800. chmod a+x /var/log/httpd
  801. mkdir -p /var/log/httpd/domains
  802. chmod 751 /var/log/httpd/domains
  803. if [ "$release" -ge 7 ]; then
  804. mkdir -p /etc/systemd/system/httpd.service.d
  805. cd /etc/systemd/system/httpd.service.d
  806. echo "[Service]" > limits.conf
  807. echo "LimitNOFILE=500000" >> limits.conf
  808. fi
  809. chkconfig httpd on
  810. service httpd start
  811. check_result $? "httpd start failed"
  812. # Workaround for OpenVZ/Virtuozzo
  813. if [ "$release" -ge '7' ] && [ -e "/proc/vz/veinfo" ]; then
  814. echo "#Vesta: workraround for networkmanager" >> /etc/rc.local
  815. echo "sleep 2 && service httpd restart" >> /etc/rc.local
  816. fi
  817. fi
  818. #----------------------------------------------------------#
  819. # Configure PHP-FPM #
  820. #----------------------------------------------------------#
  821. if [ "$phpfpm" = 'yes' ]; then
  822. cp -f $vestacp/php-fpm/www.conf /etc/php-fpm.d/
  823. chkconfig php-fpm on
  824. service php-fpm start
  825. check_result $? "php-fpm start failed"
  826. fi
  827. #----------------------------------------------------------#
  828. # Configure PHP #
  829. #----------------------------------------------------------#
  830. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  831. if [ -e '/etc/sysconfig/clock' ]; then
  832. source /etc/sysconfig/clock
  833. fi
  834. if [ -z "$ZONE" ]; then
  835. ZONE='UTC'
  836. fi
  837. for pconf in $(find /etc/php* -name php.ini); do
  838. sed -i "s/;date.timezone =/date.timezone = $ZONE/g" $pconf
  839. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  840. done
  841. #----------------------------------------------------------#
  842. # Configure Vsftpd #
  843. #----------------------------------------------------------#
  844. if [ "$vsftpd" = 'yes' ]; then
  845. cp -f $vestacp/vsftpd/vsftpd.conf /etc/vsftpd/
  846. chkconfig vsftpd on
  847. service vsftpd start
  848. check_result $? "vsftpd start failed"
  849. # To be deleted after release 0.9.8-18
  850. echo "/sbin/nologin" >> /etc/shells
  851. fi
  852. #----------------------------------------------------------#
  853. # Configure ProFTPD #
  854. #----------------------------------------------------------#
  855. if [ "$proftpd" = 'yes' ]; then
  856. cp -f $vestacp/proftpd/proftpd.conf /etc/
  857. chkconfig proftpd on
  858. service proftpd start
  859. check_result $? "proftpd start failed"
  860. fi
  861. #----------------------------------------------------------#
  862. # Configure MySQL/MariaDB #
  863. #----------------------------------------------------------#
  864. if [ "$mysql" = 'yes' ]; then
  865. mycnf="my-small.cnf"
  866. if [ $memory -gt 1200000 ]; then
  867. mycnf="my-medium.cnf"
  868. fi
  869. if [ $memory -gt 3900000 ]; then
  870. mycnf="my-large.cnf"
  871. fi
  872. mkdir -p /var/lib/mysql
  873. chown mysql:mysql /var/lib/mysql
  874. mkdir -p /etc/my.cnf.d
  875. if [ $release -lt 7 ]; then
  876. service='mysqld'
  877. else
  878. service='mariadb'
  879. fi
  880. cp -f $vestacp/$service/$mycnf /etc/my.cnf
  881. chkconfig $service on
  882. service $service start
  883. if [ "$?" -ne 0 ]; then
  884. if [ -e "/proc/user_beancounters" ]; then
  885. # Fix for aio on OpenVZ
  886. sed -i "s/#innodb_use_native/innodb_use_native/g" /etc/my.cnf
  887. fi
  888. service $service start
  889. check_result $? "$service start failed"
  890. fi
  891. # Securing MySQL installation
  892. mpass=$(gen_pass)
  893. mysqladmin -u root password $mpass
  894. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  895. chmod 600 /root/.my.cnf
  896. mysql -e "DELETE FROM mysql.user WHERE User=''"
  897. mysql -e "DROP DATABASE test" >/dev/null 2>&1
  898. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  899. mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
  900. mysql -e "FLUSH PRIVILEGES"
  901. # Configuring phpMyAdmin
  902. if [ "$apache" = 'yes' ]; then
  903. cp -f $vestacp/pma/phpMyAdmin.conf /etc/httpd/conf.d/
  904. fi
  905. cp -f $vestacp/pma/config.inc.conf /etc/phpMyAdmin/config.inc.php
  906. sed -i "s#%blowfish_secret#$blowfish_secret#g" /etc/phpMyAdmin/config.inc.php
  907. fi
  908. #----------------------------------------------------------#
  909. # Configure PostgreSQL #
  910. #----------------------------------------------------------#
  911. if [ "$postgresql" = 'yes' ]; then
  912. ppass=$(gen_pass)
  913. if [ $release -eq 5 ]; then
  914. service postgresql start
  915. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'"
  916. service postgresql stop
  917. cp -f $vestacp/postgresql/pg_hba.conf /var/lib/pgsql/data/
  918. service postgresql start
  919. else
  920. service postgresql initdb
  921. cp -f $vestacp/postgresql/pg_hba.conf /var/lib/pgsql/data/
  922. service postgresql start
  923. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'"
  924. fi
  925. # Configuring phpPgAdmin
  926. if [ "$apache" = 'yes' ]; then
  927. cp -f $vestacp/pga/phpPgAdmin.conf /etc/httpd/conf.d/
  928. fi
  929. cp -f $vestacp/pga/config.inc.php /etc/phpPgAdmin/
  930. fi
  931. #----------------------------------------------------------#
  932. # Configure Bind #
  933. #----------------------------------------------------------#
  934. if [ "$named" = 'yes' ]; then
  935. cp -f $vestacp/named/named.conf /etc/
  936. chown root:named /etc/named.conf
  937. chmod 640 /etc/named.conf
  938. chkconfig named on
  939. service named start
  940. check_result $? "named start failed"
  941. fi
  942. #----------------------------------------------------------#
  943. # Configure Exim #
  944. #----------------------------------------------------------#
  945. if [ "$exim" = 'yes' ]; then
  946. gpasswd -a exim mail
  947. cp -f $vestacp/exim/exim.conf /etc/exim/
  948. cp -f $vestacp/exim/dnsbl.conf /etc/exim/
  949. cp -f $vestacp/exim/spam-blocks.conf /etc/exim/
  950. touch /etc/exim/white-blocks.conf
  951. if [ "$spamd" = 'yes' ]; then
  952. sed -i "s/#SPAM/SPAM/g" /etc/exim/exim.conf
  953. fi
  954. if [ "$clamd" = 'yes' ]; then
  955. sed -i "s/#CLAMD/CLAMD/g" /etc/exim/exim.conf
  956. fi
  957. chmod 640 /etc/exim/exim.conf
  958. rm -rf /etc/exim/domains
  959. mkdir -p /etc/exim/domains
  960. rm -f /etc/alternatives/mta
  961. ln -s /usr/sbin/sendmail.exim /etc/alternatives/mta
  962. chkconfig sendmail off 2>/dev/null
  963. service sendmail stop 2>/dev/null
  964. chkconfig postfix off 2>/dev/null
  965. service postfix stop 2>/dev/null
  966. chkconfig exim on
  967. service exim start
  968. check_result $? "exim start failed"
  969. fi
  970. #----------------------------------------------------------#
  971. # Configure Dovecot #
  972. #----------------------------------------------------------#
  973. if [ "$dovecot" = 'yes' ]; then
  974. gpasswd -a dovecot mail
  975. cp -rf $vestacp/dovecot /etc/
  976. cp -f $vestacp/logrotate/dovecot /etc/logrotate.d/
  977. chown -R root:root /etc/dovecot*
  978. chkconfig dovecot on
  979. service dovecot start
  980. check_result $? "dovecot start failed"
  981. fi
  982. #----------------------------------------------------------#
  983. # Configure ClamAV #
  984. #----------------------------------------------------------#
  985. if [ "$clamd" = 'yes' ]; then
  986. useradd clam -s /sbin/nologin -d /var/lib/clamav 2>/dev/null
  987. gpasswd -a clam exim
  988. gpasswd -a clam mail
  989. cp -f $vestacp/clamav/clamd.conf /etc/
  990. cp -f $vestacp/clamav/freshclam.conf /etc/
  991. mkdir -p /var/log/clamav /var/run/clamav
  992. chown clam:clam /var/log/clamav /var/run/clamav
  993. chown -R clam:clam /var/lib/clamav
  994. if [ "$release" -ge '7' ]; then
  995. cp -f $vestacp/clamav/clamd.service /usr/lib/systemd/system/
  996. systemctl --system daemon-reload
  997. fi
  998. /usr/bin/freshclam
  999. if [ "$release" -ge '7' ]; then
  1000. sed -i "s/nofork/foreground/" /usr/lib/systemd/system/clamd.service
  1001. systemctl daemon-reload
  1002. fi
  1003. chkconfig clamd on
  1004. service clamd start
  1005. #check_result $? "clamd start failed"
  1006. fi
  1007. #----------------------------------------------------------#
  1008. # Configure SpamAssassin #
  1009. #----------------------------------------------------------#
  1010. if [ "$spamd" = 'yes' ]; then
  1011. chkconfig spamassassin on
  1012. service spamassassin start
  1013. check_result $? "spamassassin start failed"
  1014. if [ "$release" -ge '7' ]; then
  1015. groupadd -g 1001 spamd
  1016. useradd -u 1001 -g spamd -s /sbin/nologin -d \
  1017. /var/lib/spamassassin spamd
  1018. mkdir /var/lib/spamassassin
  1019. chown spamd:spamd /var/lib/spamassassin
  1020. fi
  1021. fi
  1022. #----------------------------------------------------------#
  1023. # Configure RoundCube #
  1024. #----------------------------------------------------------#
  1025. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1026. if [ "$apache" = 'yes' ]; then
  1027. cp -f $vestacp/roundcube/roundcubemail.conf /etc/httpd/conf.d/
  1028. fi
  1029. cp -f $vestacp/roundcube/main.inc.php /etc/roundcubemail/config.inc.php
  1030. cd /usr/share/roundcubemail/plugins/password
  1031. cp -f $vestacp/roundcube/vesta.php drivers/vesta.php
  1032. cp -f $vestacp/roundcube/config.inc.php config.inc.php
  1033. sed -i "s/localhost/$servername/g" config.inc.php
  1034. chmod a+r /etc/roundcubemail/*
  1035. chmod -f 777 /var/log/roundcubemail
  1036. r="$(gen_pass)"
  1037. mysql -e "CREATE DATABASE roundcube"
  1038. mysql -e "GRANT ALL ON roundcube.* TO
  1039. roundcube@localhost IDENTIFIED BY '$r'"
  1040. sed -i "s/%password%/$r/g" /etc/roundcubemail/config.inc.php
  1041. chmod 640 /etc/roundcubemail/config.inc.php
  1042. chown root:apache /etc/roundcubemail/config.inc.php
  1043. if [ -e "/usr/share/roundcubemail/SQL/mysql.initial.sql" ]; then
  1044. mysql roundcube < /usr/share/roundcubemail/SQL/mysql.initial.sql
  1045. else
  1046. mysql roundcube < /usr/share/doc/roundcubemail-*/SQL/mysql.initial.sql
  1047. fi
  1048. fi
  1049. #----------------------------------------------------------#
  1050. # Configure Fail2Ban #
  1051. #----------------------------------------------------------#
  1052. if [ "$fail2ban" = 'yes' ]; then
  1053. cp -rf $vestacp/fail2ban /etc/
  1054. if [ "$dovecot" = 'no' ]; then
  1055. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1056. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1057. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1058. fi
  1059. if [ "$exim" = 'no' ]; then
  1060. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1061. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1062. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1063. fi
  1064. if [ "$vsftpd" = 'yes' ]; then
  1065. #Create vsftpd Log File
  1066. if [ ! -f "/var/log/vsftpd.log" ]; then
  1067. touch /var/log/vsftpd.log
  1068. fi
  1069. fline=$(cat /etc/fail2ban/jail.local |grep -n vsftpd-iptables -A 2)
  1070. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1071. sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1072. fi
  1073. chkconfig fail2ban on
  1074. mkdir -p /var/run/fail2ban
  1075. if [ -e "/usr/lib/systemd/system/fail2ban.service" ]; then
  1076. exec_pre='ExecStartPre=/bin/mkdir -p /var/run/fail2ban'
  1077. sed -i "s|\[Service\]|[Service]\n$exec_pre|g" \
  1078. /usr/lib/systemd/system/fail2ban.service
  1079. systemctl daemon-reload
  1080. fi
  1081. service fail2ban start
  1082. check_result $? "fail2ban start failed"
  1083. fi
  1084. #----------------------------------------------------------#
  1085. # Configure Admin User #
  1086. #----------------------------------------------------------#
  1087. # Deleting old admin user
  1088. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1089. chattr -i /home/admin/conf > /dev/null 2>&1
  1090. userdel -f admin >/dev/null 2>&1
  1091. chattr -i /home/admin/conf >/dev/null 2>&1
  1092. mv -f /home/admin $vst_backups/home/ >/dev/null 2>&1
  1093. rm -f /tmp/sess_* >/dev/null 2>&1
  1094. fi
  1095. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  1096. groupdel admin > /dev/null 2>&1
  1097. fi
  1098. # Adding Vesta admin account
  1099. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  1100. check_result $? "can't create admin user"
  1101. $VESTA/bin/v-change-user-shell admin bash
  1102. $VESTA/bin/v-change-user-language admin $lang
  1103. # Configuring system IPs
  1104. $VESTA/bin/v-update-sys-ip
  1105. # Get main IP
  1106. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1107. # Configuring firewall
  1108. if [ "$iptables" = 'yes' ]; then
  1109. $VESTA/bin/v-update-firewall
  1110. fi
  1111. # Get public IP
  1112. pub_ip=$(curl -s vestacp.com/what-is-my-ip/)
  1113. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1114. echo "$VESTA/bin/v-update-sys-ip" >> /etc/rc.local
  1115. $VESTA/bin/v-change-sys-ip-nat $ip $pub_ip
  1116. ip=$pub_ip
  1117. fi
  1118. # Configuring MySQL host
  1119. if [ "$mysql" = 'yes' ]; then
  1120. $VESTA/bin/v-add-database-host mysql localhost root $mpass
  1121. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  1122. fi
  1123. # Configuring PostgreSQL host
  1124. if [ "$postgresql" = 'yes' ]; then
  1125. $VESTA/bin/v-add-database-host pgsql localhost postgres $ppass
  1126. $VESTA/bin/v-add-database admin db db $(gen_pass) pgsql
  1127. fi
  1128. # Adding default domain
  1129. $VESTA/bin/v-add-domain admin $servername
  1130. # Adding cron jobs
  1131. command="sudo $VESTA/bin/v-update-sys-queue disk"
  1132. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1133. command="sudo $VESTA/bin/v-update-sys-queue traffic"
  1134. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1135. command="sudo $VESTA/bin/v-update-sys-queue webstats"
  1136. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1137. command="sudo $VESTA/bin/v-update-sys-queue backup"
  1138. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1139. command="sudo $VESTA/bin/v-backup-users"
  1140. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1141. command="sudo $VESTA/bin/v-update-user-stats"
  1142. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1143. command="sudo $VESTA/bin/v-update-sys-rrd"
  1144. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1145. service crond restart
  1146. # Building RRD images
  1147. $VESTA/bin/v-update-sys-rrd
  1148. # Enabling file system quota
  1149. if [ "$quota" = 'yes' ]; then
  1150. $VESTA/bin/v-add-sys-quota
  1151. fi
  1152. # Enabling Softaculous plugin
  1153. if [ "$softaculous" = 'yes' ]; then
  1154. $VESTA/bin/v-add-vesta-softaculous
  1155. fi
  1156. # Starting Vesta service
  1157. chkconfig vesta on
  1158. service vesta start
  1159. check_result $? "vesta start failed"
  1160. chown admin:admin $VESTA/data/sessions
  1161. # Adding notifications
  1162. $VESTA/upd/add_notifications.sh
  1163. # Adding cronjob for autoupdates
  1164. $VESTA/bin/v-add-cron-vesta-autoupdate
  1165. if [ "$port" != "8083" ]; then
  1166. echo "=== Set Vesta port: $port"
  1167. $VESTA/bin/v-change-vesta-port $port
  1168. fi
  1169. echo "NOTIFY_ADMIN_FULL_BACKUP='$email'" >> $VESTA/conf/vesta.conf
  1170. #----------------------------------------------------------#
  1171. # Vesta Access Info #
  1172. #----------------------------------------------------------#
  1173. # Comparing hostname and IP
  1174. host_ip=$(host $servername |head -n 1 |awk '{print $NF}')
  1175. if [ "$host_ip" = "$ip" ]; then
  1176. ip="$servername"
  1177. fi
  1178. # Sending notification to admin email
  1179. echo -e "Congratulations, you have just successfully installed \
  1180. Vesta Control Panel
  1181. https://$ip:$port
  1182. username: admin
  1183. password: $vpass
  1184. We hope that you enjoy your installation of Vesta. Please \
  1185. feel free to contact us anytime if you have any questions.
  1186. Thank you.
  1187. --
  1188. Sincerely yours
  1189. vestacp.com team
  1190. " > $tmpfile
  1191. send_mail="$VESTA/web/inc/mail-wrapper.php"
  1192. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  1193. # Congrats
  1194. echo '======================================================='
  1195. echo
  1196. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  1197. echo ' _| _| _| _| _| _| _| '
  1198. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  1199. echo ' _| _| _| _| _| _| _| '
  1200. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  1201. echo
  1202. echo
  1203. cat $tmpfile
  1204. rm -f $tmpfile
  1205. # EOF