@@ -12,31 +12,35 @@ REUSE_ACCOUNT_KEYS="$(lc ${REUSE_ACCOUNT_KEYS:-true})"
12
12
REUSE_PRIVATE_KEYS=" $( lc ${REUSE_PRIVATE_KEYS:- false} ) "
13
13
14
14
function create_link {
15
- local -r target=${1?missing target argument}
16
- local -r source=${2?missing source argument}
17
- [[ -f " $target " ]] && return 1
18
- ln -sf " $source " " $target "
15
+ local -r source=${1?missing source argument}
16
+ local -r target=${2?missing target argument}
17
+ if [[ -f " $target " ]] && [[ " $( readlink " $target " ) " == " $source " ]]; then
18
+ [[ $DEBUG == true ]] && echo " $target already linked to $source "
19
+ return 1
20
+ else
21
+ ln -sf " $source " " $target "
22
+ fi
19
23
}
20
24
21
25
function create_links {
22
26
local -r base_domain=${1?missing base_domain argument}
23
27
local -r domain=${2?missing base_domain argument}
24
28
25
- if [[ ! -f " /etc/nginx/certs/$base_domain " /fullchain.pem || \
26
- ! -f " /etc/nginx/certs/$base_domain " /key.pem ]]; then
29
+ if [[ ! -f " /etc/nginx/certs/$base_domain /fullchain.pem" || \
30
+ ! -f " /etc/nginx/certs/$base_domain /key.pem" ]]; then
27
31
return 1
28
32
fi
29
33
local return_code=1
30
- create_link " / etc/nginx/certs/$domain " .crt " ./ $base_domain " /fullchain.pem
34
+ create_link " ./ $base_domain /fullchain.pem " " / etc/nginx/certs/$domain .crt"
31
35
return_code=$(( $return_code & $? ))
32
- create_link " / etc/nginx/certs/$domain " .key " ./ $base_domain " /key.pem
36
+ create_link " ./ $base_domain /key.pem " " / etc/nginx/certs/$domain .key"
33
37
return_code=$(( $return_code & $? ))
34
38
if [[ -f " /etc/nginx/certs/dhparam.pem" ]]; then
35
- create_link " /etc/nginx/certs/$domain " .dhparam.pem ./dhparam.pem
39
+ create_link ./dhparam.pem " /etc/nginx/certs/$domain .dhparam.pem"
36
40
return_code=$(( $return_code & $? ))
37
41
fi
38
- if [[ -f " /etc/nginx/certs/$base_domain " /chain.pem ]]; then
39
- create_link " / etc/nginx/certs/$domain " .chain.pem " ./ $base_domain " /chain.pem
42
+ if [[ -f " /etc/nginx/certs/$base_domain /chain.pem" ]]; then
43
+ create_link " ./ $base_domain /chain.pem " " / etc/nginx/certs/$domain .chain.pem"
40
44
return_code=$(( $return_code & $? ))
41
45
fi
42
46
return $return_code
0 commit comments