diff options
author | Kerin Millar <kfm@plushkava.net> | 2024-07-01 03:29:27 +0100 |
---|---|---|
committer | Kerin Millar <kfm@plushkava.net> | 2024-07-01 03:32:27 +0100 |
commit | 23ce043cfccf6b39caf790464c18f2df1d5b7d1b (patch) | |
tree | b73d1b01cc3c897bf2f2440879897b855ef746bb | |
parent | Add the contains_all() and contains_any() functions (diff) | |
download | gentoo-functions-23ce043cfccf6b39caf790464c18f2df1d5b7d1b.tar.gz gentoo-functions-23ce043cfccf6b39caf790464c18f2df1d5b7d1b.tar.bz2 gentoo-functions-23ce043cfccf6b39caf790464c18f2df1d5b7d1b.zip |
Move fetch() to experimental
I'm not yet ready to commit to it being among the core functions for the
inaugural API level.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
-rw-r--r-- | functions.sh | 42 | ||||
-rw-r--r-- | functions/experimental.sh | 42 |
2 files changed, 42 insertions, 42 deletions
diff --git a/functions.sh b/functions.sh index a4fa946..cfaddc3 100644 --- a/functions.sh +++ b/functions.sh @@ -139,48 +139,6 @@ contains_any() } # -# Considers the first parameter as an URL then attempts to fetch it with either -# curl(1) or wget(1). If the URL does not contain a scheme then the https:// -# scheme shall be presumed. Both utilities shall be invoked in a manner that -# suppresses all output unless an error occurs, and whereby HTTP redirections -# are honoured. Upon success, the body of the response shall be printed to the -# standard output. Otherwise, the return value shall be greater than 0. -# -fetch() -{ - if hash curl 2>/dev/null; then - fetch() - { - if [ "$#" -gt 0 ]; then - # Discard any extraneous parameters. - set -- "$1" - fi - curl -f -sS -L --connect-timeout 10 --proto-default https -- "$@" - } - elif hash wget 2>/dev/null; then - fetch() - { - if [ "$#" -gt 0 ]; then - # Discard any extraneous parameters. - case $1 in - ''|ftp://*|ftps://*|https://*) - set -- "$1" - ;; - *) - set -- "https://$1" - esac - fi - wget -nv -O - --connect-timeout 10 -- "$@" - } - else - warn "fetch: this function requires that curl or wget be installed" - return 127 - fi - - fetch "$@" -} - -# # Determines whether the current shell is a subprocess of portage. # from_portage() diff --git a/functions/experimental.sh b/functions/experimental.sh index 4d56cfa..bbbf0fa 100644 --- a/functions/experimental.sh +++ b/functions/experimental.sh @@ -13,6 +13,48 @@ warn "sourcing the experimental module from gentoo-functions; no stability guarantee is provided" # +# Considers the first parameter as an URL then attempts to fetch it with either +# curl(1) or wget(1). If the URL does not contain a scheme then the https:// +# scheme shall be presumed. Both utilities shall be invoked in a manner that +# suppresses all output unless an error occurs, and whereby HTTP redirections +# are honoured. Upon success, the body of the response shall be printed to the +# standard output. Otherwise, the return value shall be greater than 0. +# +fetch() +{ + if hash curl 2>/dev/null; then + fetch() + { + if [ "$#" -gt 0 ]; then + # Discard any extraneous parameters. + set -- "$1" + fi + curl -f -sS -L --connect-timeout 10 --proto-default https -- "$@" + } + elif hash wget 2>/dev/null; then + fetch() + { + if [ "$#" -gt 0 ]; then + # Discard any extraneous parameters. + case $1 in + ''|ftp://*|ftps://*|https://*) + set -- "$1" + ;; + *) + set -- "https://$1" + esac + fi + wget -nv -O - --connect-timeout 10 -- "$@" + } + else + warn "fetch: this function requires that curl or wget be installed" + return 127 + fi + + fetch "$@" +} + +# # Expects three parameters, all of which must be integers, and determines # whether the first is numerically greater than or equal to the second, and # numerically lower than or equal to the third. |