Skip to content

Commit d606704

Browse files
committed
Fix the link creation functions
The source/target order of create_link() has been made the same as ln to avoid confusions. The function also no longer skip link creation based solely on target existence but check that the target links to the required source.
1 parent fa837ba commit d606704

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

app/letsencrypt_service

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,35 @@ REUSE_ACCOUNT_KEYS="$(lc ${REUSE_ACCOUNT_KEYS:-true})"
1212
REUSE_PRIVATE_KEYS="$(lc ${REUSE_PRIVATE_KEYS:-false})"
1313

1414
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
1923
}
2024

2125
function create_links {
2226
local -r base_domain=${1?missing base_domain argument}
2327
local -r domain=${2?missing base_domain argument}
2428

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
2731
return 1
2832
fi
2933
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"
3135
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"
3337
return_code=$(( $return_code & $? ))
3438
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"
3640
return_code=$(( $return_code & $? ))
3741
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"
4044
return_code=$(( $return_code & $? ))
4145
fi
4246
return $return_code

0 commit comments

Comments
 (0)