conf_server/add_domain_with_acme.sh

98 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
gen_nginx_acme_conf(){
domain=$1
alt_domain=$2
nginx_conf_file="/etc/nginx/sites-enabled/$domain"
[ ! -f $nginx_conf_file ] || rm $nginx_conf_file;
mkdir /var/www/htdocs/$domain
rcctl check nginx
if [ $? == 0 ]; then
cat > $nginx_conf_file <<EOF
server {
listen 80;
server_name $alt_domain $domain;
include snippets/acme-challenge.conf;
root /htdocs/$domain;
}
EOF
rcctl reload nginx
else
echo "Service NGINX not running"
exit 1
fi
}
gen_acme_client_conf(){
domain=$1
alt_domain=$2
acme_conf_file="my_configuration/ssl/$domain-acme-client.conf"
# If the file exist, do nothing
[ ! -f $acme_conf_file ] || echo "Domain already configured !"; exit 1;
if [ "$alt_domain" == "" ]; then
cat >> $acme_conf_file <<EOF
domain $domain {
domain key "/etc/ssl/private/$domain.key"
domain full chain certificate "/etc/ssl/$domain.crt"
sign with letsencrypt
}
EOF
else
cat >> $acme_conf_file <<EOF
domain $domain {
alternative names { $alt_domain }
domain key "/etc/ssl/private/$domain.key"
domain full chain certificate "/etc/ssl/$domain.crt"
sign with letsencrypt
}
EOF
fi
}
add_acme_domain_to_conf(){
domain=$1
egrep "domain $domain" -A5 /etc/acme-client.conf > /tmp/acme-client.conf
cp -v /etc/acme-client.conf /etc/acme-client.conf.old
cp -v /tmp/acme-client.conf /etc/acme-client.conf
}
install_utils(){
cp -v utils/renew_https_certificate /usr/local/bin/renew_https_certificate
chmod u+x /usr/local/bin/renew_https_certificate
}
get_certificate()
{
domain=$1
/usr/local/bin/renew_https_certificate $domain
}
usage()
{
print "This program ask 3 arguments : \n"
print "First is email with domain name the second is list of alternatives domains with \" \" \n"
print "the last arguments is for share the ssl cert with xmpp daemon add xmpp at the end or not"
print "\t $0 domain.tld \"a.domain.tld b.domain.tld c.domain.tld\""
}
if [ -z $1 ];
then
usage
exit 3;
fi
domain=$1
alt_domain=$2
gen_nginx_acme_conf $domain