-
Notifications
You must be signed in to change notification settings - Fork 3
/
renew-ssl.sh
executable file
·58 lines (45 loc) · 1.35 KB
/
renew-ssl.sh
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
#!/bin/bash
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
esc() {
ret=( )
for i in "$@"; do
ret+=( "$(printf '%q' "$i")" )
done
echo "${ret[@]}"
}
cd /etc/apache2/ssl
simple=(simp_le -f account_key.json -f cert.pem -f chain.pem -f key.pem --default_root /etc/apache2/htdocs)
if [ ! -z "$ACME_EMAIL" ]; then
simple+=(--email "$ACME_EMAIL")
fi
commands=""
for i in ${!HOST_*}; do
id="${i#HOST_}"
host="$(echo "$id" | sed -e s/__/-/g | sed -e s/_/./g)"
[ ! -e "$host" ] && mkdir "$host"
if [ ! -e account_key.json ]; then
cd "$host" || continue
echo "${simple[@]}" -d "$host"
"${simple[@]}" -d "$host" || exit $?
mv account_key.json ..
ln -s ../account_key.json
cd ..
else
[ ! -e "$host/account_key.json" ] && ln -s ../account_key.json "$host/"
commands="$(echo "$commands"; echo "cd $(esc "$host") && echo "$(esc "${simple[@]}" -d "$host")" && $(esc "${simple[@]}" -d "$host")")"
fi
done
if [ ! -z "$commands" ]; then
echo "$commands" | parallel -j5
fi
for i in ${!HOST_*}; do
id="${i#HOST_}"
host="$(echo "$id" | sed -e s/__/-/g | sed -e s/_/./g)"
[ ! -e "$host/privkey.pem" ] && ln -s key.pem "$host/privkey.pem"
(cat "$host/cert.pem"; echo; cat "$host/chain.pem") > "$host/fullchain.pem"
(cat "$host/chain.pem"; echo; cat "$host/cert.pem") > "$host/fullchain-reverse.pem"
done