-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate.sh
More file actions
44 lines (35 loc) · 992 Bytes
/
generate.sh
File metadata and controls
44 lines (35 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
if [ -z "$DOMAINS" ] ; then
echo "No domains set, please fill -e DOMAINS='example.com www.example.com'"
exit 1
fi
if [ -z "$EMAIL" ] ; then
echo "No email set, please fill -e EMAIL='your@email.tld'"
exit 1
fi
# Prepare args
DARRAYS=(${DOMAINS})
NGINX_DOMAINS=${DOMAINS}
EMAIL_ADDRESS=${EMAIL}
LE_DOMAINS=("${DARRAYS[*]/#/-d }")
CERTIFICATES=/etc/letsencrypt/live
# Inform
echo "Creating certificates for: $NGINX_DOMAINS"
# Replace domains
sed -i "s/\$DOMAINS/$NGINX_DOMAINS/g" /etc/nginx/nginx.conf
# Start nginx
echo "- start nginx"
service nginx start
# Run LetsEncrypt
echo "- start letsencrypt"
${LE_BIN} certonly --webroot -w /var/www/acme-certs ${LE_DOMAINS} --email ${EMAIL_ADDRESS} --agree-tos
# Copy created certs
if [ -d ${CERTIFICATES} ] ; then
echo "- copy certificates to /var/www/certs"
cp ${CERTIFICATES}/. /var/www/certs/ -R -L
else
echo "- certificates folder $CERTIFICATES not found"
fi
# Stop nginx
echo "- stop nginx"
service nginx stop