aboutsummaryrefslogtreecommitdiff
path: root/src/cpt-lib.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpt-lib.in')
-rw-r--r--src/cpt-lib.in28
1 files 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)