Exercice for automate generate let's encrypt cartification what acme-client, OpenBSD and nginx
This commit is contained in:
parent
033866ee64
commit
e47ac322ec
@ -1,5 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ./myserver.conf
|
||||||
|
|
||||||
|
|
||||||
|
check_ssl_folder()
|
||||||
|
{
|
||||||
|
[ -d "$FOLDER_CONF/ssl" ] || mkdir -p "$FOLDER_CONF/ssl"
|
||||||
|
}
|
||||||
|
|
||||||
gen_nginx_acme_conf(){
|
gen_nginx_acme_conf(){
|
||||||
domain=$1
|
domain=$1
|
||||||
@ -26,12 +33,18 @@ EOF
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Generate part of acme client for the domain
|
||||||
gen_acme_client_conf(){
|
gen_acme_client_conf(){
|
||||||
domain=$1
|
domain=$1
|
||||||
alt_domain=$2
|
alt_domain=$2
|
||||||
acme_conf_file="my_configuration/ssl/$domain-acme-client.conf"
|
acme_conf_file="$FOLDER_CONF/ssl/acme-client-$1.conf"
|
||||||
# If the file exist, do nothing
|
# If the file exist, do nothing
|
||||||
[ ! -f $acme_conf_file ] || echo "Domain already configured !"; exit 1;
|
if [ -f $acme_conf_file ]
|
||||||
|
then
|
||||||
|
echo "Domain already configured !";
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$alt_domain" == "" ]; then
|
if [ "$alt_domain" == "" ]; then
|
||||||
cat >> $acme_conf_file <<EOF
|
cat >> $acme_conf_file <<EOF
|
||||||
@ -56,36 +69,39 @@ domain $domain {
|
|||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "on est passé dans gen_acme_client_conf "
|
||||||
}
|
}
|
||||||
|
|
||||||
add_acme_domain_to_conf(){
|
add_acme_domain_to_conf(){
|
||||||
domain=$1
|
domain="domain $1 {"
|
||||||
egrep "domain $domain" -A5 /etc/acme-client.conf > /tmp/acme-client.conf
|
acme_conf="$FOLDER_CONF/ssl/acme-client-$1.conf"
|
||||||
|
sed "/$domain/,/}/d" /etc/acme-client.conf > /tmp/acme-client.conf
|
||||||
cp -v /etc/acme-client.conf /etc/acme-client.conf.old
|
cp -v /etc/acme-client.conf /etc/acme-client.conf.old
|
||||||
|
cat $acme_conf >> /tmp/acme-client.conf
|
||||||
cp -v /tmp/acme-client.conf /etc/acme-client.conf
|
cp -v /tmp/acme-client.conf /etc/acme-client.conf
|
||||||
}
|
}
|
||||||
|
|
||||||
install_utils(){
|
install_utils(){
|
||||||
cp -v utils/renew_https_certificate /usr/local/bin/renew_https_certificate
|
|
||||||
|
[ -f /usr/local/bin/renew_https_certificate ] || cp -v utils/renew_https_certificate /usr/local/bin/renew_https_certificate
|
||||||
chmod u+x /usr/local/bin/renew_https_certificate
|
chmod u+x /usr/local/bin/renew_https_certificate
|
||||||
}
|
}
|
||||||
|
|
||||||
get_certificate()
|
get_certificate()
|
||||||
{
|
{
|
||||||
domain=$1
|
domain=$1
|
||||||
/usr/local/bin/renew_https_certificate $domain
|
/usr/local/bin/renew_https_certificate "$domain"
|
||||||
}
|
}
|
||||||
|
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
print "This program ask 3 arguments : \n"
|
print "This program ask 2 arguments : \n"
|
||||||
print "First is email with domain name the second is list of alternatives domains with \" \" \n"
|
print "First is 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\""
|
print "\t $0 domain.tld \"a.domain.tld b.domain.tld c.domain.tld\""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if [ -z $1 ];
|
if [ -z $1 ] || [ $1 == "-h" ] || [ $1 == "--help" ];
|
||||||
then
|
then
|
||||||
usage
|
usage
|
||||||
exit 3;
|
exit 3;
|
||||||
@ -94,4 +110,9 @@ fi
|
|||||||
domain=$1
|
domain=$1
|
||||||
alt_domain=$2
|
alt_domain=$2
|
||||||
|
|
||||||
gen_nginx_acme_conf $domain
|
check_ssl_folder
|
||||||
|
gen_acme_client_conf $domain $alt_domain
|
||||||
|
gen_nginx_acme_conf $domain $alt_domain
|
||||||
|
add_acme_domain_to_conf $domain
|
||||||
|
install_utils
|
||||||
|
get_certificate $domain
|
||||||
|
|||||||
@ -2,10 +2,15 @@
|
|||||||
## Par défault le domain est le nom d'hote de la machine mais il est possible de le personnaliser
|
## Par défault le domain est le nom d'hote de la machine mais il est possible de le personnaliser
|
||||||
## comme l'exemple ce-dessous
|
## comme l'exemple ce-dessous
|
||||||
# DOMAIN="example.com"
|
# DOMAIN="example.com"
|
||||||
|
|
||||||
|
FOLDER_CONF="./my_configuration"
|
||||||
DOMAIN=`hostname`
|
DOMAIN=`hostname`
|
||||||
SSL="manual"
|
SSL="manual"
|
||||||
SERVICE_MAIL="yes"
|
SERVICE_MAIL="yes"
|
||||||
SERVICE_XMPP="yes"
|
SERVICE_XMPP="yes"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
xmpp_passphrase_for_filesuploads='Changez cette valeur'
|
xmpp_passphrase_for_filesuploads='Changez cette valeur'
|
||||||
postresql_root_password='Changez cette valeur'
|
postresql_root_password='Changez cette valeur'
|
||||||
# Laissez le port ssh par défault (22) est en général une mauvaise idée
|
# Laissez le port ssh par défault (22) est en général une mauvaise idée
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user