From 597dbb999379aba312f37f83d1c503ac1440ae85 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Mon, 23 Mar 2020 09:49:39 +0100
Subject: Set up possibilities to find a usable downloading tool
---
lib/util.bash | 22 ++++++++++++++++------
1 file 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
--
cgit v1.1