-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathletsencryp-to-zerossl-acme.sh
More file actions
85 lines (75 loc) · 2.21 KB
/
Copy pathletsencryp-to-zerossl-acme.sh
File metadata and controls
85 lines (75 loc) · 2.21 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
email="security@zabiyaka.net"
LANG=C
cmdname=`basename $0`
newtmpdir=`mktemp -d /tmp/${cmdname}.XXXXXX`
spool="$newtmpdir/spool"
spool2="$newtmpdir/spool2"
function cleanup () {
rm -rf "${newtmpdir}"
}
trap 'cleanup' EXIT
trap 'cleanup' SIGTERM
day=`date +%y%m%d-%H-%M-%S`
echo "backup /etc to /backup/${day}"
rsync -a /etc /backup/${day}/
if [ ! -f "/root/.acme.sh/acme.sh" ]
then
curl https://get.acme.sh | sh
/root/.acme.sh/acme.sh --set-default-ca --server zerossl
/root/.acme.sh/acme.sh --register-account -m ${email}
crontab -l | grep -v 'acme.sh' > ${spool}
echo '0 1 * * * /root/.acme.sh/acme.sh --renew-all --renew-hook "/etc/init.d/nginx reload" &> /dev/null' >> ${spool}
crontab ${spool}
cat /dev/null > ${spool}
echo ""
echo "CRONTAB INSTALLED:"
crontab -l |grep 'acme.sh'
echo "INSTALL OK? - CTRL+C to abort"
read
fi
if [ -d /etc/letsencrypt/renewal ]
then
cd /etc/letsencrypt/renewal/
for file in `ls *.conf`
do
domain=`ls ${file} | awk -F '.conf' '{print$1}' | awk -F'-' '{print$1}'`
echo "${domain}" > ${spool}
for subdomain in `grep -A 100 "[[webroot_map]]" $file |grep "=" | awk '{print$1}'`;
do
echo "${subdomain}" >> ${spool}
done
dir=`grep -A 100 "[[webroot_map]]" $file |grep "=" | awk '{print$3}' |sort -u`
if [ "${dir}" == "" ]
then
echo "${domain} has no webroot, please enter webroot manually: (CTRL+C to abort)"
read dir
[ "${dir}" == "" ] && echo "empty, using default /var/www/html" && dir="/var/www/html"
echo -n "/root/.acme.sh/acme.sh --issue -w ${dir} --issue -d ${domain}" > ${spool2}
else
echo -n "/root/.acme.sh/acme.sh --issue -w ${dir} --issue -d ${domain}" > ${spool2}
fi
for dom in `sort -u ${spool} |grep -v "^${domain}$"`
do
echo -n " -d ${dom}" >> ${spool2}
done
cat ${spool2}
echo ""
echo "proceed with renew? CTRL+C to abort, any key to continue..."
read
bash ${spool2}
echo ""
echo "============"
cat ${spool2}
echo ""
echo "============"
echo "Configuration:"
grep -ri -m1 " ${domain}" /etc/nginx | head -n 2
echo "ADD THIS:"
echo "ssl_certificate /root/.acme.sh/${domain}/fullchain.cer;"
echo "ssl_certificate_key /root/.acme.sh/${domain}/${domain}.key;"
echo "nginx -t"
echo "============"
echo ""
done
fi