From 3f696d479cfd7a9eb3f34de33cdb69c835ffe65d Mon Sep 17 00:00:00 2001 From: Daniel Valentine Date: Mon, 26 Sep 2022 20:42:09 -0600 Subject: [PATCH] allow for use of custom User-Agent --- generate-instances-json.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/generate-instances-json.sh b/generate-instances-json.sh index 01001e2..eeec459 100755 --- a/generate-instances-json.sh +++ b/generate-instances-json.sh @@ -32,6 +32,10 @@ TODAY="$(date -I -u)" # jq is required for JSON processing. DEPENDENCIES=(curl jq) +# If USER_AGENT is specified in the envs, we'll pass this argument to curl +# using the -A flag to set a custom User-Agent. +USER_AGENT="${USER_AGENT:-}" + # check_tor # # Returns true if tor is running; false otherwise. @@ -341,12 +345,18 @@ get () return 103 fi + # Use a custom User-Agent if provided. + if [[ -n "${USER_AGENT?}" ]] + then + curl_cmd=("${curl_cmd[@]}" -A "${USER_AGENT}") + fi + # Do the GET. Try up to the number of times specified in the tries variable. for (( i = tries; i > 0; i-- )) do "${curl_cmd[@]}" -m"${timeout}" -fsL -- "${scheme}://${url_no_scheme}" - rc=$? - + rc=$? + if [[ ${rc} -eq 0 ]] then return @@ -482,7 +492,7 @@ create_instance_entry () # helpdoc # -# TODO +# Print usage information to stdout. helpdoc () { cat <