aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-03-23 09:49:39 +0100
committerPatrick Spek <p.spek@tyil.nl>2020-03-23 09:49:39 +0100
commit597dbb999379aba312f37f83d1c503ac1440ae85 (patch)
tree6c1d9ad992fbc8778d6ee30133c9338376125fe8 /lib
parentd0d482f93b1bdfaac93912736feb82b2ddd8e5a8 (diff)
Set up possibilities to find a usable downloading tool
Diffstat (limited to 'lib')
-rw-r--r--lib/util.bash22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/util.bash b/lib/util.bash
index 06e20f1..c2d717b 100644
--- a/lib/util.bash
+++ b/lib/util.bash
@@ -63,15 +63,25 @@ fetch_http() {
notice "Downloading $1 to $buffer"
- # TODO: Switch to the most appropriate downloading tool, depending on
- # what is available.
+ for util in curl wget
+ do
+ command -v "$util" > /dev/null || continue
+ "fetch_http_$util" "$1" "$buffer" || continue
+ local exit_code=$?
- curl -Ls "$1" > "$buffer"
- local exit_code=$?
+ printf "%s" "$buffer"
+ return $exit_code
+ done
- printf "%s" "$buffer"
+ die "Unable to download file over HTTP!"
+}
+
+fetch_http_curl() {
+ curl -Ls "$1" > "$2"
+}
- return $exit_code
+fetch_http_wget() {
+ wget --quiet --output-document "$2" "$1"
}
# Pretty print a duration between a starting point (in seconds) and an end