11#! /bin/bash
2- # info: update hosts certificates for exim, dovecot & vesta-web
2+ # info: update hosts certificates for exim, dovecot & vesta-nginx
33# options: user
44# options: hostname
55#
1010# Variable&Function #
1111# ----------------------------------------------------------#
1212
13+ whoami=$( whoami)
14+ if [ " $whoami " != " root" ] && [ " $whoami " != " admin" ] ; then
15+ echo " You must be root or admin to execute this script" ;
16+ exit 1;
17+ fi
18+
19+
1320# Argument definition
1421user=$1
1522hostname=$2
@@ -33,6 +40,11 @@ is_object_unsuspended 'user' 'USER' "$user"
3340is_object_valid ' web' ' DOMAIN' " $hostname "
3441is_object_unsuspended ' web' ' DOMAIN' " $hostname "
3542
43+ if [ ! -f " /home/$user /conf/web/ssl.$hostname .pem" ]; then
44+ echo " This domain does not have certificate" ;
45+ exit 1;
46+ fi
47+
3648# ----------------------------------------------------------#
3749# Action #
3850# ----------------------------------------------------------#
@@ -48,9 +60,16 @@ backup_datetime=`date '+%Y-%m-%d_%H-%M-%S'`
4860cp /home/$user /conf/web/ssl.$hostname .pem $VESTA /ssl/certificate.crt
4961cp /home/$user /conf/web/ssl.$hostname .key $VESTA /ssl/certificate.key
5062
63+ # Checking exim username for later chowning
64+ exim_user=" exim" ;
65+ check_exim_username=$( grep -c ' ^Debian-exim:' /etc/passwd)
66+ if [ " $check_exim_username " -eq 1 ]; then
67+ exim_user=" Debian-exim"
68+ fi
69+
5170# Assign exim permissions
52- chown exim :mail $VESTA /ssl/certificate.crt
53- chown exim :mail $VESTA /ssl/certificate.key
71+ chown $exim_user :mail $VESTA /ssl/certificate.crt
72+ chown $exim_user :mail $VESTA /ssl/certificate.key
5473
5574# Restart exim, dovecot & vesta
5675v-restart-mail
@@ -64,4 +83,4 @@ v-restart-web-backend
6483# Logging
6584log_event " $OK " " $ARGUMENTS "
6685
67- exit
86+ exit 0 ;
0 commit comments