Skip to content

Commit 51c1b67

Browse files
authored
Merge pull request #713 from h0tw1r3/apt-helper
install support download with apt-helper
2 parents 5d8cbe7 + 11cf1ac commit 51c1b67

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

tasks/install_shell.sh

+31-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ assert_unmodified_apt_config() {
6969
fi
7070
}
7171

72+
# Check whether apt-helper is available
73+
exists_apt_helper() {
74+
test -x /usr/lib/apt/apt-helper
75+
}
76+
7277
# Check whether python3 and urllib.request are available
7378
exists_python3_urllib() {
7479
python3 -c 'import urllib.request' >/dev/null 2>&1
@@ -430,6 +435,27 @@ do_fetch() {
430435
return 0
431436
}
432437

438+
do_apt_helper() {
439+
info "Trying apt-helper..."
440+
run_cmd "/usr/lib/apt/apt-helper download-file '$1' '$2'" 2>$tmp_stderr
441+
rc=$?
442+
443+
# check for 404
444+
grep "E: Failed to fetch .* 404 " $tmp_stderr 2>&1 >/dev/null
445+
if test $? -eq 0; then
446+
critical "ERROR 404"
447+
unable_to_retrieve_package
448+
fi
449+
450+
# check for bad return status or empty output
451+
if test $rc -ne 0 && test ! -s "$2" ; then
452+
capture_tmp_stderr "apthelper"
453+
return 1
454+
fi
455+
456+
return 0
457+
}
458+
433459
do_python3_urllib() {
434460
info "Trying python3 (urllib.request)..."
435461
run_cmd "python3 -c 'import urllib.request ; urllib.request.urlretrieve(\"$1\", \"$2\")'" 2>$tmp_stderr
@@ -523,7 +549,11 @@ do_download() {
523549
do_python3_urllib $1 $2 && return 0
524550
fi
525551

526-
critical "Cannot download package as none of wget/curl/fetch/perl-LWP-Simple/perl-File-Fetch/python3 is found"
552+
if exists_apt_helper; then
553+
do_apt_helper $1 $2 && return 0
554+
fi
555+
556+
critical "Cannot download package as none of wget/curl/fetch/perl-LWP-Simple/perl-File-Fetch/python3/apt-helper is found"
527557
unable_to_retrieve_package
528558
}
529559

0 commit comments

Comments
 (0)