From 3cf4cf4b1649e5b561b392930a9277cbd36c5566 Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 24 Jul 2021 20:37:51 +0000 Subject: pkg_download: new function for using alternative downloaders FossilOrigin-Name: a64a103f527bb5cd45b1e63cf1f8488a220222044c6f0c012f6947ae4abe3e40 --- src/cpt-lib.in | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 306c5bd..504829d 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -419,6 +419,21 @@ regesc() { sed 's|\\|\\\\|g;s|\[|\\[|g;s|\$|\\$|g;s|\.|\\.|g;s|\*|\\*|g;s|\^|\\^|g' } +pkg_download() { + # $1: URL + # $2: Output (Optional) + set -- "$1" "${2:-${1##*/}}" + case ${dl_prog##*/} in + aria2c|axel) set -- -o "$2" "$1" ;; + curl) set -- -fLo "$2" "$1" ;; + wget|wget2) set -- -O "$2" "$1" ;; + esac + + "$dl_prog" "$@" || { + rm -f "$2" + return 1 + } +} prompt() { # If a CPT_NOPROMPT variable is set, continue. @@ -688,10 +703,8 @@ pkg_sources() { # interrupt, we handle this ourselves. trap_set handle-int - curl "$src" -fLo "${src##*/}" || { - rm -f "${src##*/}" - die "$1" "Failed to download $src" - } + # Download the source + pkg_download "$src" || die "$1" "Failed to download $src" # Restore original trap value. trap_set cleanup @@ -2117,6 +2130,13 @@ create_cache() { command -v llvm-readelf || command -v eu-readelf)"} || elf_prog=ldd + dl_prog=${CPT_DOWNLOADER:="$( + command -v curl || + command -v wget || + command -v wget2 || + command -v axel || + command -v aria2c)"} || dl_prog=curl + # Make note of the user's current ID to do root checks later on. # This is used enough to warrant a place here. uid=$(id -u) -- cgit v1.2.3