From 6f6e21add230ae1bc156ea2de23eac9e45a6eec3 Mon Sep 17 00:00:00 2001 From: Jimver Date: Wed, 26 Aug 2020 16:38:35 +0200 Subject: [PATCH 1/4] Fix wildcard expansion, absolute path handling and output to stderr --- include/functions | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/include/functions b/include/functions index e0f75a64..60e213be 100644 --- a/include/functions +++ b/include/functions @@ -2180,7 +2180,8 @@ for I in ${FIND}; do I=$(echo ${I} | sed 's/:space:/ /g' | sed 's/;$//' | sed 's/ #.*$//') OPTION=$(echo ${I} | awk '{ print $1 }') - VALUE=$(echo ${I}| cut -d' ' -f2-) + # Use quotes here to prevent wildcard expansion + VALUE=$(echo "${I}"| cut -d' ' -f2-) LogText "Result: found option ${OPTION} in ${CONFIG_FILE} with value '${VALUE}'" STORE_SETTING=1 case ${OPTION} in @@ -2303,9 +2304,21 @@ done if [ ${FOUND} -eq 0 ]; then NGINX_CONF_FILES_ADDITIONS="${NGINX_CONF_FILES_ADDITIONS} ${VALUE}"; fi # Check for additional config files included as follows - # "include sites-enabled/*.conf" - elif [ $(echo ${VALUE} | grep -F -c "*.conf") -gt 0 ]; then - for FOUND_CONF in $(ls ${CONFIG_FILE%nginx.conf}${VALUE%;*}); do + # "include sites-enabled/*.conf" (relative path) + # "include /etc/nginx/sites-enabled/*.conf" (absolute path) + elif [ $(echo "${VALUE}" | grep -F -c "*.conf") -gt 0 ]; then + # Check if path is absolute or relative + case $VALUE in + /*) + # Absolute path, so list files directly from that path + CONF_LS=$(${LSBINARY} ${VALUE%;*} 2>/dev/null) # Will error if wildcard doesn't match anything, so pipe stderr to /dev/null + ;; + *) + # Relative path, so construct absolute path first to list files for + CONF_LS=$(${LSBINARY} ${CONFIG_FILE%nginx.conf}${VALUE%;*} 2>/dev/null) + ;; + esac + for FOUND_CONF in CONF_LS; do FOUND=0 for CONF in ${NGINX_CONF_FILES}; do if [ "${CONF}" = "${FOUND_CONF}" ]; then FOUND=1; LogText "Found this file already in our configuration files array, not adding to queue"; fi From cd94da34492ff18eb83b9f2dae89e8e68866ca3d Mon Sep 17 00:00:00 2001 From: Jimver Date: Thu, 27 Aug 2020 12:50:48 +0200 Subject: [PATCH 2/4] Use shell wildcard expansion now --- include/functions | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/functions b/include/functions index 60e213be..b88a7261 100644 --- a/include/functions +++ b/include/functions @@ -2310,15 +2310,20 @@ # Check if path is absolute or relative case $VALUE in /*) - # Absolute path, so list files directly from that path - CONF_LS=$(${LSBINARY} ${VALUE%;*} 2>/dev/null) # Will error if wildcard doesn't match anything, so pipe stderr to /dev/null + # Absolute path, so wildcard pattern is already correct + CONF_WILDCARD=${VALUE%;*} ;; *) - # Relative path, so construct absolute path first to list files for - CONF_LS=$(${LSBINARY} ${CONFIG_FILE%nginx.conf}${VALUE%;*} 2>/dev/null) + # Relative path, so construct absolute path for wildcard pattern + CONF_WILDCARD=${CONFIG_FILE%nginx.conf}${VALUE%;*} ;; esac - for FOUND_CONF in CONF_LS; do + for FOUND_CONF in ${CONF_WILDCARD}; do + if [ "${FOUND_CONF}" = "${CONF_WILDCARD}" ]; then + + LogText "Found no match for ${CONF_WILDCARD}" + break + fi FOUND=0 for CONF in ${NGINX_CONF_FILES}; do if [ "${CONF}" = "${FOUND_CONF}" ]; then FOUND=1; LogText "Found this file already in our configuration files array, not adding to queue"; fi From e6891feeb458055571a1d48c53009ebc99036708 Mon Sep 17 00:00:00 2001 From: Jimver Date: Thu, 27 Aug 2020 12:52:59 +0200 Subject: [PATCH 3/4] Remove newline --- include/functions | 1 - 1 file changed, 1 deletion(-) diff --git a/include/functions b/include/functions index b88a7261..f5eb2f98 100644 --- a/include/functions +++ b/include/functions @@ -2320,7 +2320,6 @@ esac for FOUND_CONF in ${CONF_WILDCARD}; do if [ "${FOUND_CONF}" = "${CONF_WILDCARD}" ]; then - LogText "Found no match for ${CONF_WILDCARD}" break fi From 554dd2d5e90ade460e2c8f318dde3d7e0031cdce Mon Sep 17 00:00:00 2001 From: Jimver Date: Thu, 27 Aug 2020 12:57:22 +0200 Subject: [PATCH 4/4] Better log message --- include/functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/functions b/include/functions index f5eb2f98..4af4cd7b 100644 --- a/include/functions +++ b/include/functions @@ -2320,7 +2320,7 @@ esac for FOUND_CONF in ${CONF_WILDCARD}; do if [ "${FOUND_CONF}" = "${CONF_WILDCARD}" ]; then - LogText "Found no match for ${CONF_WILDCARD}" + LogText "Found no match for wildcard pattern: ${CONF_WILDCARD}" break fi FOUND=0