aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2021-07-24 20:37:51 +0000
committermerakor <cem@ckyln.com>2021-07-24 20:37:51 +0000
commit3cf4cf4b1649e5b561b392930a9277cbd36c5566 (patch)
tree77f0c456ef46003796a0eea70d0cc75a8b6e1a1b /src
parentfb6a0c90c066e5ed91c607e125b3806a2fd462a5 (diff)
downloadcpt-3cf4cf4b1649e5b561b392930a9277cbd36c5566.tar.gz
pkg_download: new function for using alternative downloaders
FossilOrigin-Name: a64a103f527bb5cd45b1e63cf1f8488a220222044c6f0c012f6947ae4abe3e40
Diffstat (limited to 'src')
-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)