Browse Source

Prefer curl in download()

bryan 2 weeks ago
parent
commit
9eed36d353
1 changed files with 9 additions and 23 deletions
  1. 9 23
      installJRMC

+ 9 - 23
installJRMC

@@ -1787,38 +1787,24 @@ execute() {
 download() {
   local url="$1"
   local output="${2:-}"
-  local -a download_cmd
+  local -a cmd
 
-  if command -v curl &>/dev/null; then
+  if command -v curl &>/dev/null || install_package --silent curl; then
+    cmd=(curl --silent --fail --location)
     if [[ -n "$output" ]]; then
-      download_cmd=(curl --silent --location --output "$output" "$url")
+      cmd+=(--output "$output")
     else
-      download_cmd=(curl --silent --location -O "$url")
-    fi
-  elif command -v wget &>/dev/null; then
-    if [[ -n "$output" ]]; then
-      download_cmd=(wget --quiet "--output-document=$output" "$url")
-    else
-      download_cmd=(wget --quiet "$url")
-    fi
-  elif install_package --silent curl; then
-    if [[ -n "$output" ]]; then
-      download_cmd=(curl --silent --location --output "$output" "$url")
-    else
-      download_cmd=(curl --silent --location -O "$url")
-    fi
-  elif install_package --silent wget; then
-    if [[ -n "$output" ]]; then
-      download_cmd=(wget --quiet "--output-document=$output" "$url")
-    else
-      download_cmd=(wget --quiet "$url")
+      cmd+=(-O)
     fi
+  elif command -v wget &>/dev/null || install_package --silent wget; then
+    cmd=(wget --quiet)
+    [[ -n "$output" ]] && cmd+=("--output-document=$output")
   else
     err "Unable to install wget or curl"
     return 1
   fi
 
-  "${download_cmd[@]}"
+  "${cmd[@]}" "$url"
 }
 
 # Roughly turn debugging on for pre-init