forked from JessThrysoee/synology-letsencrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynology-letsencrypt-reload-services.sh
59 lines (42 loc) · 1.83 KB
/
synology-letsencrypt-reload-services.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
59
#!/bin/bash
# Reload services assigned to the certificate with the key `cert_id` in the INFO file.
# Inspired by https://github.com/bartowl/synology-stuff/blob/master/reload-certs.sh
cert_id="$1"
archive_path="/usr/syno/etc/certificate/_archive"
INFO="$archive_path/INFO"
tls_profile_path="/usr/libexec/security-profile/tls-profile"
get() { jq -r --arg cert_id "$cert_id" --arg i "$i" --arg prop "$1" '.[$cert_id].services[$i|tonumber][$prop]' "$INFO" ; }
services_length=$(jq -r --arg cert_id "$cert_id" '.[$cert_id].services|length' "$INFO")
reload_webstation=0
for (( i = 0; i < services_length; i++ )); do
isPkg=$(get isPkg)
subscriber=$(get subscriber)
service=$(get service)
if [[ $isPkg == true ]]; then
exec_path="/usr/local/libexec/certificate.d/$subscriber"
cert_path="/usr/local/etc/certificate/$subscriber/$service"
else
exec_path="/usr/libexec/certificate.d/$subscriber"
cert_path="/usr/syno/etc/certificate/$subscriber/$service"
if [[ -x $tls_profile_path/${subscriber}.sh ]]; then
exec_path="$tls_profile_path/${subscriber}.sh"
fi
if [[ $subscriber == "system" && $service == "default" && -x $tls_profile_path/dsm.sh ]]; then
exec_path="$tls_profile_path/dsm.sh"
fi
if [[ $subscriber == "WebStation" ]]; then
reload_webstation=1
continue
fi
fi
if ! diff -q "$archive_path/$cert_id/cert.pem" "$cert_path/cert.pem" >/dev/null; then
cp "$archive_path/$cert_id/"{cert,chain,fullchain,privkey}.pem "$cert_path/"
if [[ -x $exec_path ]]; then
if [[ $subscriber == "system" && $service == "default" ]]; then "$exec_path" else "$exec_path" "$service"; fi
fi
fi
done
if [[ $reload_webstation == 1 ]]; then
synow3tool --gen-all
systemctl reload nginx
fi