Skip to content

Commit 87bebd3

Browse files
authored
Merge pull request #697 from h0tw1r3/perl-file-fetch
support download with perl file::fetch
2 parents 174fd48 + 5bbeece commit 87bebd3

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

tasks/install_shell.sh

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,19 @@ assert_unmodified_apt_config() {
6767
}
6868

6969
# Check whether perl and LWP::Simple module are installed
70-
exists_perl() {
71-
if perl -e 'use LWP::Simple;' >/dev/null 2>&1
72-
then
70+
exists_perl_lwp() {
71+
if perl -e 'use LWP::Simple;' >/dev/null 2>&1 ; then
72+
return 0
73+
fi
74+
return 1
75+
}
76+
77+
# Check whether perl and File::Fetch module are installed
78+
exists_perl_ff() {
79+
if perl -e 'use File::Fetch;' >/dev/null 2>&1 ; then
7380
return 0
74-
else
75-
return 1
7681
fi
82+
return 1
7783
}
7884

7985
# Get command line arguments
@@ -421,9 +427,9 @@ do_fetch() {
421427
return 0
422428
}
423429

424-
# do_perl URL FILENAME
425-
do_perl() {
426-
info "Trying perl..."
430+
# do_perl_lwp URL FILENAME
431+
do_perl_lwp() {
432+
info "Trying perl (LWP::Simple)..."
427433
run_cmd "perl -e 'use LWP::Simple; getprint(\$ARGV[0]);' '$1' > '$2' 2>$tmp_stderr"
428434
rc=$?
429435

@@ -434,13 +440,33 @@ do_perl() {
434440
unable_to_retrieve_package
435441
fi
436442

437-
# check for bad return status or empty output
438-
if test $rc -ne 0 || test ! -s "$2"; then
439-
capture_tmp_stderr "perl"
440-
return 1
443+
if test $rc -eq 0 && test -s "$2" ; then
444+
return 0
441445
fi
442446

443-
return 0
447+
capture_tmp_stderr "perl"
448+
return 1
449+
}
450+
451+
# do_perl_ff URL FILENAME
452+
do_perl_ff() {
453+
info "Trying perl (File::Fetch)..."
454+
run_cmd "perl -e 'use File::Fetch; use File::Copy; my \$ff = File::Fetch->new(uri => \$ARGV[0]); my \$outfile = \$ff->fetch() or die \$ff->server; copy(\$outfile, \$ARGV[1]) or die \"copy failed: \$!\"; unlink(\$outfile) or die \"delete failed: \$!\";' '$1' '$2' 2>>$tmp_stderr"
455+
rc=$?
456+
457+
# check for 404
458+
grep "HTTP response: 404" $tmp_stderr 2>&1 >/dev/null
459+
if test $? -eq 0 ; then
460+
critical "ERROR 404"
461+
unable_to_retrieve_package
462+
fi
463+
464+
if test $rc -eq 0 && test -s "$2" ; then
465+
return 0
466+
fi
467+
468+
capture_tmp_stderr "perl"
469+
return 1
444470
}
445471

446472
# do_download URL FILENAME
@@ -463,11 +489,15 @@ do_download() {
463489
do_fetch $1 $2 && return 0
464490
fi
465491

466-
if exists_perl; then
467-
do_perl $1 $2 && return 0
492+
if exists_perl_lwp; then
493+
do_perl_lwp $1 $2 && return 0
494+
fi
495+
496+
if exists_perl_ff; then
497+
do_perl_ff $1 $2 && return 0
468498
fi
469499

470-
critical "Cannot download package as none of wget/curl/fetch/perl-LWP-Simple is found"
500+
critical "Cannot download package as none of wget/curl/fetch/perl-LWP-Simple/perl-File-Fetch is found"
471501
unable_to_retrieve_package
472502
}
473503

0 commit comments

Comments
 (0)