Skip to content

Commit 2e77a53

Browse files
committed
New installer for Ubuntu
1 parent 9427075 commit 2e77a53

File tree

1 file changed

+146
-103
lines changed

1 file changed

+146
-103
lines changed

install/vst-install-ubuntu.sh

Lines changed: 146 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Vesta Ubuntu installer v.01
3+
# Vesta Ubuntu installer v.04
44

55
#----------------------------------------------------------#
66
# Variables&Functions #
@@ -14,17 +14,21 @@ software="nginx apache2 apache2-utils apache2-suexec-custom
1414
libapache2-mod-ruid2 libapache2-mod-rpaf libapache2-mod-fcgid bind9 idn
1515
mysql-server mysql-common mysql-client php5-common php5-cgi php5-mysql
1616
php5-curl libapache2-mod-php5 vsftpd mc exim4 exim4-daemon-heavy
17-
clamav-daemon flex dovecot-imapd dovecot-pop3d phpMyAdmin awstats
18-
webalizer jwhois rssh git spamassassin roundcube roundcube-mysql
17+
clamav-daemon flex dovecot-imapd dovecot-pop3d phpMyAdmin awstats e2fslibs
18+
webalizer jwhois rssh git spamassassin roundcube roundcube-mysql quota
1919
roundcube-plugins apparmor-utils sudo bc ftp lsof ntpdate rrdtool
2020
dnsutils vesta vesta-nginx vesta-php"
2121

2222
help() {
2323
echo "usage: $0 [OPTIONS]
24-
-e, --email Define email address
25-
-h, --help Print this help and exit
24+
-e, --email Set email address
2625
-f, --force Force installation
27-
-n, --noupdate Do not run apt-get upgrade command"
26+
-h, --help Print this help and exit
27+
-n, --noupdate Do not run yum update command
28+
-m, --mysql-password Set MySQL password instead of generating it
29+
-p, --password Set admin password instead of generating it
30+
-s, --hostname Set server hostname
31+
-q, --quota Enable File System Quota"
2832
exit 1
2933
}
3034

@@ -48,23 +52,31 @@ gen_pass() {
4852
for arg; do
4953
delim=""
5054
case "$arg" in
51-
--help) args="${args}-h " ;;
52-
--force) args="${args}-f " ;;
53-
--email) args="${args}-e " ;;
54-
--noupdate) args="${args}-n " ;;
55+
--email) args="${args}-e " ;;
56+
--force) args="${args}-f " ;;
57+
--help) args="${args}-h " ;;
58+
--noupdate) args="${args}-n " ;;
59+
--mysql-password) args="${args}-m " ;;
60+
--password) args="${args}-p " ;;
61+
--hostname) args="${args}-s " ;;
62+
--quota) args="${args}-q " ;;
5563
*) [[ "${arg:0:1}" == "-" ]] || delim="\""
5664
args="${args}${delim}${arg}${delim} ";;
5765
esac
5866
done
5967
eval set -- "$args"
6068

6169
# Getopt
62-
while getopts "dhfne:" Option; do
70+
while getopts "dhfnqe:m:p:s:" Option; do
6371
case $Option in
6472
h) help ;; # Help
6573
e) email=$OPTARG ;; # Set email
66-
f) force='yes' ;; # Force apt-get install
67-
n) noupdate='yes' ;; # Disable apt-get upgrade
74+
f) force='yes' ;; # Force install
75+
n) noupdate='yes' ;; # Disable yum update
76+
m) mpass=$OPTARG ;; # MySQL pasword
77+
p) vpass=$OPTARG ;; # Admin password
78+
s) servername=$OPTARG ;; # Server hostname
79+
q) quota='yes' ;; # Enable quota
6880
*) help ;; # Default
6981
esac
7082
done
@@ -89,9 +101,9 @@ else
89101
fi
90102
os=$(head -n 1 /etc/issue | cut -f 1 -d ' ')
91103
release=$(head -n 1 /etc/issue | cut -f 2 -d ' ' )
92-
codename=$(lsb_release -cs | grep "[precise|raring|saucy]")
104+
codename=$(lsb_release -cs | egrep "precise|quantal|raring|saucy|trusty")
93105
if [ -z "$codename" ]; then
94-
echo 'Error: only Ubuntu 12.04, 13.04 and 13.10 is supported'
106+
echo "Error: Ubuntu $(lsb_release -r|awk '{print $2}') is not supported"
95107
exit 1
96108
fi
97109

@@ -214,6 +226,14 @@ if [ -z $email ]; then
214226

215227
# Check email
216228
read -p 'Please enter valid email address: ' email
229+
230+
# Define server hostname
231+
if [ -z "$servername" ]; then
232+
read -p "Please enter hostname [$(hostname)]: " servername
233+
fi
234+
if [ -z "$servername" ]; then
235+
servername=$(hostname)
236+
fi
217237
fi
218238

219239
# Validate email
@@ -252,9 +272,6 @@ apt=/etc/apt/sources.list.d
252272
echo "deb http://nginx.org/packages/ubuntu/ $codename nginx" > $apt/nginx.list
253273
wget http://nginx.org/keys/nginx_signing.key -O /tmp/nginx_signing.key
254274
apt-key add /tmp/nginx_signing.key
255-
if [ $codename = 'trusty' ]; then
256-
sed -i "s/trusty/saucy/g" $apt/nginx.list
257-
fi
258275

259276
# Install vesta repo
260277
echo "deb http://$RHOST/$codename/ $codename vesta" > $apt/vesta.list
@@ -400,7 +417,91 @@ rm -f /usr/sbin/policy-rc.d
400417
# Set writable permission on tmp directory
401418
chmod 777 /tmp
402419

403-
# Enable password auth
420+
# Vesta configuration
421+
echo "export VESTA='/usr/local/vesta'" > /etc/profile.d/vesta.sh
422+
chmod 755 /etc/profile.d/vesta.sh
423+
source /etc/profile.d/vesta.sh
424+
echo 'PATH=$PATH:/usr/local/vesta/bin' >> /root/.bash_profile
425+
echo 'export PATH' >> /root/.bash_profile
426+
source /root/.bash_profile
427+
wget $CHOST/$VERSION/vesta.log -O /etc/logrotate.d/vesta
428+
429+
# Directory tree
430+
mkdir -p $VESTA/conf
431+
mkdir -p $VESTA/log
432+
mkdir -p $VESTA/ssl
433+
mkdir -p $VESTA/data
434+
mkdir -p $VESTA/data/ips
435+
mkdir -p $VESTA/data/queue
436+
mkdir -p $VESTA/data/users
437+
touch $VESTA/data/queue/backup.pipe
438+
touch $VESTA/data/queue/disk.pipe
439+
touch $VESTA/data/queue/webstats.pipe
440+
touch $VESTA/data/queue/restart.pipe
441+
touch $VESTA/data/queue/traffic.pipe
442+
chmod 750 $VESTA/conf
443+
chmod 750 $VESTA/data/users
444+
chmod 750 $VESTA/data/ips
445+
chmod -R 750 $VESTA/data/queue
446+
ln -s /usr/local/vesta/log /var/log/vesta
447+
touch /var/log/vesta/system.log
448+
touch /var/log/vesta/nginx-error.log
449+
touch /var/log/vesta/auth.log
450+
chmod 660 /var/log/vesta/*
451+
adduser backup > /dev/null 2>&1
452+
mkdir -p /home/backup
453+
chown backup:backup /home/backup
454+
ln -s /home/backup /backup
455+
chmod a+x /backup
456+
457+
# vesta.conf
458+
wget $CHOST/$VERSION/vesta.conf -O $VESTA/conf/vesta.conf
459+
if [ "$srv_type" = 'micro' ] || [ "$srv_type" = 'small' ]; then
460+
sed -i "s/clamav-daemon//g" $VESTA/conf/vesta.conf
461+
sed -i "s/spamassassin//g" $VESTA/conf/vesta.conf
462+
fi
463+
464+
# Set server hostname
465+
/usr/local/vesta/bin/v-change-sys-hostname $servername 2>/dev/null
466+
467+
# Templates
468+
cd /usr/local/vesta/data
469+
wget $CHOST/$VERSION/packages.tar.gz -O packages.tar.gz
470+
tar -xzf packages.tar.gz
471+
rm -f packages.tar.gz
472+
cd /usr/local/vesta/data
473+
wget $CHOST/$VERSION/templates.tar.gz -O templates.tar.gz
474+
tar -xzf templates.tar.gz
475+
rm -f templates.tar.gz
476+
if [ "$codename" = 'saucy' ] || [ "$codename" = 'trusty' ]; then
477+
sed -i "s/Include /IncludeOptional /g" \
478+
$VESTA/data/templates/web/apache2/*tpl
479+
fi
480+
chmod -R 755 /usr/local/vesta/data/templates
481+
cp templates/web/skel/public_html/index.html /var/www/
482+
sed -i 's/%domain%/It worked!/g' /var/www/index.html
483+
if [ "$srv_type" = 'micro' ]; then
484+
rm -f /usr/local/vesta/data/templates/web/apache2/phpfcgid.*
485+
fi
486+
487+
# Generating SSL certificate
488+
$VESTA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
489+
'San Francisco' 'Vesta Control Panel' 'IT' > /tmp/vst.pem
490+
491+
# Parsing merged certificate file
492+
crt_end=$(grep -n "END CERTIFICATE-" /tmp/vst.pem |cut -f 1 -d:)
493+
key_start=$(grep -n "BEGIN RSA" /tmp/vst.pem |cut -f 1 -d:)
494+
key_end=$(grep -n "END RSA" /tmp/vst.pem |cut -f 1 -d:)
495+
496+
# Adding SSL certificate
497+
cd /usr/local/vesta/ssl
498+
sed -n "1,${crt_end}p" /tmp/vst.pem > certificate.crt
499+
sed -n "$key_start,${key_end}p" /tmp/vst.pem > certificate.key
500+
chown root:mail /usr/local/vesta/ssl/*
501+
chmod 660 /usr/local/vesta/ssl/*
502+
rm /tmp/vst.pem
503+
504+
# Enable SSH password auth
404505
sed -i "s/rdAuthentication no/rdAuthentication yes/g" /etc/ssh/sshd_config
405506
service ssh restart
406507

@@ -456,9 +557,9 @@ fi
456557
wget $CHOST/$VERSION/apache2-status.conf \
457558
-O /etc/apache2/mods-enabled/status.conf
458559
wget $CHOST/$VERSION/apache2.log -O /etc/logrotate.d/apache2
459-
echo "# Powever by vesta" > /etc/apache2/sites-available/default
460-
echo "# Powever by vesta" > /etc/apache2/sites-available/default-ssl
461-
echo "# Powever by vesta" > /etc/apache2/ports.conf
560+
echo "# Powevered by vesta" > /etc/apache2/sites-available/default
561+
echo "# Powevered by vesta" > /etc/apache2/sites-available/default-ssl
562+
echo "# Powevered by vesta" > /etc/apache2/ports.conf
462563
mkdir -p /etc/apache2/conf.d
463564
rm -f /etc/apache2/conf.d/vesta.conf
464565
echo > /etc/apache2/conf.d/vesta.conf
@@ -491,6 +592,11 @@ if [ "$?" -ne 0 ]; then
491592
exit 1
492593
fi
493594

595+
# Generating MySQL password if it wasn't set
596+
if [ -z "$mpass" ]; then
597+
mpass=$(gen_pass)
598+
fi
599+
494600
# MySQL configuration
495601
mpass=$(gen_pass)
496602
wget $CHOST/$VERSION/my.cnf -O /etc/mysql/my.cnf
@@ -506,7 +612,7 @@ mysqladmin -u root password $mpass
506612
echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
507613
chmod 600 /root/.my.cnf
508614
mysql -e "DELETE FROM mysql.user WHERE User=''"
509-
mysql -e "DROP DATABASE test"
615+
mysql -e "DROP DATABASE test" > /dev/null 2>&1
510616
mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
511617
mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
512618
mysql -e "FLUSH PRIVILEGES"
@@ -564,12 +670,6 @@ tar -xzf dovecot-conf.d.tar.gz
564670
rm -f dovecot-conf.d.tar.gz
565671
chown -R root:root /etc/dovecot
566672
gpasswd -a dovecot mail
567-
if [ "$codename" = 'precise' ]; then
568-
dovecot_ssl_conf="/etc/dovecot/conf.d/10-ssl.conf"
569-
echo "ssl = yes" > $dovecot_ssl_conf
570-
echo "ssl_cert = </etc/ssl/certs/dovecot.pem" >> $dovecot_ssl_conf
571-
echo "ssl_key = </etc/ssl/private/dovecot.pem" >> $dovecot_ssl_conf
572-
fi
573673
update-rc.d dovecot defaults
574674
service dovecot stop > /dev/null 2>&1
575675
service dovecot start
@@ -630,7 +730,8 @@ wget $CHOST/$VERSION/roundcube-driver.php -O \
630730
wget $CHOST/$VERSION/roundcube-pw.conf -O \
631731
/etc/roundcube/plugins/password/config.inc.php
632732
r="$(gen_pass)"
633-
mysql -e "CREATE DATABASE roundcube"
733+
mysql -e "DROP DATABASE roundcube" > /dev/null 2>&1
734+
mysql -e "CREATE DATABASE roundcube"
634735
mysql -e "GRANT ALL ON roundcube.* TO roundcube@localhost IDENTIFIED BY '$r'"
635736
sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
636737
mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
@@ -643,76 +744,7 @@ fi
643744
mkdir -p /var/log/roundcube/error
644745
chmod -R 777 /var/log/roundcube
645746

646-
# Vesta configuration
647-
echo "export VESTA='/usr/local/vesta'" > /etc/profile.d/vesta.sh
648-
chmod 755 /etc/profile.d/vesta.sh
649-
source /etc/profile.d/vesta.sh
650-
echo 'PATH=$PATH:/usr/local/vesta/bin' >> /root/.bash_profile
651-
echo 'export PATH' >> /root/.bash_profile
652-
source /root/.bash_profile
653-
wget $CHOST/$VERSION/vesta.log -O /etc/logrotate.d/vesta
654-
655-
# Directory tree
656-
mkdir -p $VESTA/conf
657-
mkdir -p $VESTA/log
658-
mkdir -p $VESTA/ssl
659-
mkdir -p $VESTA/data
660-
mkdir -p $VESTA/data/ips
661-
mkdir -p $VESTA/data/queue
662-
mkdir -p $VESTA/data/users
663-
touch $VESTA/data/queue/backup.pipe
664-
touch $VESTA/data/queue/disk.pipe
665-
touch $VESTA/data/queue/webstats.pipe
666-
touch $VESTA/data/queue/restart.pipe
667-
touch $VESTA/data/queue/traffic.pipe
668-
chmod 750 $VESTA/conf
669-
chmod 750 $VESTA/data/users
670-
chmod 750 $VESTA/data/ips
671-
chmod -R 750 $VESTA/data/queue
672-
ln -s /usr/local/vesta/log /var/log/vesta
673-
touch /var/log/vesta/system.log
674-
touch /var/log/vesta/nginx-error.log
675-
touch /var/log/vesta/auth.log
676-
chmod 660 /var/log/vesta/*
677-
adduser backup > /dev/null 2>&1
678-
mkdir -p /home/backup
679-
chown backup:backup /home/backup
680-
ln -s /home/backup /backup
681-
chmod a+x /backup
682-
683-
# vesta.conf
684-
wget $CHOST/$VERSION/vesta.conf -O $VESTA/conf/vesta.conf
685-
if [ "$srv_type" = 'micro' ] || [ "$srv_type" = 'small' ]; then
686-
sed -i "s/clamav-daemon//g" $VESTA/conf/vesta.conf
687-
sed -i "s/spamassassin//g" $VESTA/conf/vesta.conf
688-
fi
689-
690-
# Templates
691-
cd /usr/local/vesta/data
692-
wget $CHOST/$VERSION/packages.tar.gz -O packages.tar.gz
693-
tar -xzf packages.tar.gz
694-
rm -f packages.tar.gz
695-
cd /usr/local/vesta/data
696-
wget $CHOST/$VERSION/templates.tar.gz -O templates.tar.gz
697-
tar -xzf templates.tar.gz
698-
rm -f templates.tar.gz
699-
if [ "$codename" = 'saucy' ] || [ "$codename" = 'trusty' ]; then
700-
sed -i "s/Include /IncludeOptional /g" \
701-
$VESTA/data/templates/web/apache2/*tpl
702-
fi
703-
chmod -R 755 /usr/local/vesta/data/templates
704-
cp templates/web/skel/public_html/index.html /var/www/
705-
sed -i 's/%domain%/It worked!/g' /var/www/index.html
706-
if [ "$srv_type" = 'micro' ]; then
707-
rm -f /usr/local/vesta/data/templates/web/apache2/phpfcgid.*
708-
fi
709-
710-
# Default SSL keys
711-
cd /usr/local/vesta/ssl
712-
wget $CHOST/$VERSION/certificate.crt -O certificate.crt
713-
wget $CHOST/$VERSION/certificate.key -O certificate.key
714-
715-
# Adding admin user
747+
# Deleting old admin user account if exists
716748
if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
717749
chattr -i /home/admin/conf > /dev/null 2>&1
718750
userdel -f admin
@@ -723,7 +755,13 @@ fi
723755
if [ ! -z "$(grep ^admin: /etc/group)" ]; then
724756
groupdel admin > /dev/null 2>&1
725757
fi
726-
vpass=$(gen_pass)
758+
759+
# Generating admin password if it wasn't set
760+
if [ -z "$vpass" ]; then
761+
vpass=$(gen_pass)
762+
fi
763+
764+
# Adding admin account
727765
$VESTA/bin/v-add-user admin $vpass $email default System Administrator
728766
if [ $? -ne 0 ]; then
729767
echo "Error: can't create admin user"
@@ -762,7 +800,7 @@ $VESTA/bin/v-add-dns-domain admin default.domain $vst_ip
762800
# Add default mail domain
763801
$VESTA/bin/v-add-mail-domain admin default.domain
764802

765-
# Configuring crond
803+
# Configuring cron jobs
766804
command='sudo /usr/local/vesta/bin/v-update-sys-queue disk'
767805
$VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
768806
command='sudo /usr/local/vesta/bin/v-update-sys-queue traffic'
@@ -778,9 +816,14 @@ $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
778816
command='sudo /usr/local/vesta/bin/v-update-sys-rrd'
779817
$VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
780818

781-
# Build inititall rrd images
819+
# Building inititall rrd images
782820
$VESTA/bin/v-update-sys-rrd
783821

822+
# Enable file system quota
823+
if [ "$quota" = 'yes' ]; then
824+
$VESTA/bin/v-add-sys-quota
825+
fi
826+
784827
# Start system service
785828
update-rc.d vesta defaults
786829
service vesta stop > /dev/null 2>&1

0 commit comments

Comments
 (0)