Skip to content

Commit 7a2e1a7

Browse files
Fix regex capture in sed commands
Made sure that the proper amount of spaces (`\s`) are present when searching for the text. Also made sure to match any extra characters that come after ";", so it is possible to have comments afterwards. Without this, any extra stuff outside the regex would be echoed. Also added the `-r` flag in order to be able to make the regex a little bit more readable.
1 parent dcbf749 commit 7a2e1a7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/scripts/util.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ create_dhparam() {
5454
# /etc/letsencrypt/live/<primary_domain_name>/privkey.pem
5555
#
5656
parse_primary_domains() {
57-
sed -n -e 's&^\s*ssl_certificate_key\s*\/etc/letsencrypt/live/\(.*\)/privkey.pem;&\1&p' "$1" | xargs -n1 echo | uniq
57+
sed -n -r -e 's&^\s*ssl_certificate_key\s+\/etc/letsencrypt/live/(.*)/privkey.pem;.*&\1&p' "$1" | xargs -n1 echo | uniq
5858
}
5959

6060
# Nginx will answer to any domain name that is written on the line which starts
@@ -70,27 +70,27 @@ parse_primary_domains() {
7070
# certificates. Should however work fine but is not best practice.
7171
#
7272
parse_server_names() {
73-
sed -n -e 's&^\s*server_name \s*\(.*\);&\1&p' "$1" | xargs -n1 echo | uniq
73+
sed -n -r -e 's&^\s*server_name\s+(.*);.*&\1&p' "$1" | xargs -n1 echo | uniq
7474
}
7575

7676
# Return all unique "ssl_certificate_key" file paths.
7777
parse_keyfiles() {
78-
sed -n -e 's&^\s*ssl_certificate_key\s*\(.*\);&\1&p' "$1" | xargs -n1 echo | uniq
78+
sed -n -r -e 's&^\s*ssl_certificate_key\s+(.*);.*&\1&p' "$1" | xargs -n1 echo | uniq
7979
}
8080

8181
# Return all unique "ssl_certificate" file paths.
8282
parse_fullchains() {
83-
sed -n -e 's&^\s*ssl_certificate \s*\(.*\);&\1&p' "$1" | xargs -n1 echo | uniq
83+
sed -n -r -e 's&^\s*ssl_certificate\s+(.*);.*&\1&p' "$1" | xargs -n1 echo | uniq
8484
}
8585

8686
# Return all unique "ssl_trusted_certificate" file paths.
8787
parse_chains() {
88-
sed -n -e 's&^\s*ssl_trusted_certificate\s*\(.*\);&\1&p' "$1" | xargs -n1 echo | uniq
88+
sed -n -r -e 's&^\s*ssl_trusted_certificate\s+(.*);.*&\1&p' "$1" | xargs -n1 echo | uniq
8989
}
9090

9191
# Return all unique "dhparam" file paths.
9292
parse_dhparams() {
93-
sed -n -e 's&^\s*ssl_dhparam\s*\(.*\);&\1&p' "$1" | xargs -n1 echo | uniq
93+
sed -n -r -e 's&^\s*ssl_dhparam\s+(.*);.*&\1&p' "$1" | xargs -n1 echo | uniq
9494
}
9595

9696
# Given a config file path, return 0 if all SSL related files exist (or there

0 commit comments

Comments
 (0)