diff --git a/src/linkcheck.sh b/src/linkcheck.sh index ca7b8f48a..63e27619c 100755 --- a/src/linkcheck.sh +++ b/src/linkcheck.sh @@ -48,6 +48,11 @@ w_download() { urlkey="$(echo "${url}" | tr / _)" echo "${url}" > "${datadir}/${urlkey}.url" } +# shellcheck disable=SC2317 +w_download_to() { + shift + w_download "$@" +} # Extract list of URLs from winetricks extract_all() { @@ -57,7 +62,11 @@ extract_all() { # https://github.com/koalaman/shellcheck/issues/861 # shellcheck disable=SC1003 - grep '^ *w_download ' "${shwinetricks}" | grep -E 'ftp|http' | grep -v "w_linkcheck_ignore=1" | sed 's/^ *//' | tr -d '\\' > url-script-fragment.tmp + grep -E '^[^#]*w_download(_to)? .*(http|ftp)s?://' "${shwinetricks}" \ + | grep -vE "(w_linkcheck_ignore|WINETRICKS_SUPER_QUIET)=(TRUE|1)" \ + | sed 's/^.*w_download/w_download/' \ + | sed -E "s/\\$/%24/g" \ + | tr -d '\\' > url-script-fragment.tmp # shellcheck disable=SC1091 . ./url-script-fragment.tmp diff --git a/tests/shell-checks b/tests/shell-checks index ac5c89520..538862f9c 100755 --- a/tests/shell-checks +++ b/tests/shell-checks @@ -105,8 +105,22 @@ test_shellcheck() { test_linkcheck() { # Check for uses of variables in w_download when w_linkcheck_ignore isn't set # Using w_download https://example.com/${file1} breaks src/linkcheck.sh - # FIXME: technically '$' is valid in a URL, if there's actually a URL using it this will need a tweak - if grep "^ *w_download " src/winetricks | grep -E "ftp|http" | grep -v "w_linkcheck_ignore=1" | sed "s/^ *//" | tr -d "\\\\" | grep "\\$"; then + # Escaped '$', as in '\$' are allowed + + test_func() { + # No comment, only with protocol, skip flagged as ignored, remove indention + # and flags, fix double space, get n-th arg, find vars '$' and ignore '\$'. + func_name=${1} + url_arg=${2} + grep -E '^[^#]*'"${func_name}"' .*(http|ftp)s?://' "src/winetricks" \ + | grep -vE "(w_linkcheck_ignore|WINETRICKS_SUPER_QUIET)=(TRUE|1)" \ + | sed 's/^.*'"${func_name}"'/'"${func_name}"'/' \ + | tr -s " " \ + | cut -d " " -f "${url_arg}" \ + | grep -E "([^\\\\\]+\\$)" + } + + if ( test_func "w_download_to" 3 ) || ( test_func "w_download" 2 ); then w_die "Do not use variables in these URLs, it breaks src/linkcheck.sh" else echo "linkcheck checks passed"