Skip to content

Commit

Permalink
support download with apt-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
h0tw1r3 committed Apr 13, 2024
1 parent 15f8033 commit e0ebaf1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tasks/install_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ assert_unmodified_apt_config() {
fi
}

# Check whether apt-helper is available
exists_apt_helper() {
test -x /usr/lib/apt/apt-helper
}

# Check whether python3 and urllib.request are available
exists_python3_urllib() {
python3 -c 'import urllib.request' >/dev/null 2>&1
Expand Down Expand Up @@ -432,6 +437,19 @@ do_fetch() {
return 0
}

do_apt_helper() {
info "Trying apt-helper..."
run_cmd "/usr/lib/apt/apt-helper download-file \"$1\" \"$2\"" 2>$tmp_stderr
rc=$?

if test $rc -eq 0 && test -s "$2" ; then
return 0
fi

capture_tmp_stderr "apthelper"
return 1
}

do_python3_urllib() {
info "Trying python3 (urllib.request)..."
run_cmd "python3 -c 'import urllib.request ; urllib.request.urlretrieve(\"$1\", \"$2\")'" 2>$tmp_stderr
Expand Down Expand Up @@ -525,6 +543,10 @@ do_download() {
do_python3_urllib $1 $2 && return 0
fi

if exists_apt_helper; then
do_apt_helper $1 $2 && return 0
fi

critical "Cannot download package as none of wget/curl/fetch/perl-LWP-Simple/perl-File-Fetch/python3 is found"
unable_to_retrieve_package
}
Expand Down

0 comments on commit e0ebaf1

Please sign in to comment.