|
|
e965a0 |
From 10520de65d10d2ab34329e24144aa922a430b229 Mon Sep 17 00:00:00 2001
|
|
|
e965a0 |
From: Dalibor Pospisil <dapospis@redhat.com>
|
|
|
e965a0 |
Date: Wed, 22 Aug 2018 13:09:47 +0200
|
|
|
e965a0 |
Subject: [PATCH 4/4] use wget or curl for web download
|
|
|
e965a0 |
|
|
|
e965a0 |
Now there's a fallback to curl if wget is not available.
|
|
|
e965a0 |
Wget has still a preference as it has got better progress printing while
|
|
|
e965a0 |
the output is redirected to a file.
|
|
|
e965a0 |
---
|
|
|
e965a0 |
src/rpms.sh | 32 +++++++++++++++++++++++++++-----
|
|
|
e965a0 |
1 file changed, 27 insertions(+), 5 deletions(-)
|
|
|
e965a0 |
|
|
|
e965a0 |
diff --git a/src/rpms.sh b/src/rpms.sh
|
|
|
e965a0 |
index 878abba..e51dd4f 100644
|
|
|
e965a0 |
--- a/src/rpms.sh
|
|
|
e965a0 |
+++ b/src/rpms.sh
|
|
|
e965a0 |
@@ -630,7 +630,27 @@ __INTERNAL_rpmInitUrl() {
|
|
|
e965a0 |
}
|
|
|
e965a0 |
|
|
|
e965a0 |
|
|
|
e965a0 |
-__INTERNAL_WGET="wget -t 3 -T 180 -w 20 --waitretry=30 --no-check-certificate --progress=dot:giga"
|
|
|
e965a0 |
+__INTERNAL_WGET() {
|
|
|
e965a0 |
+ local QUIET
|
|
|
e965a0 |
+ [[ "$1" == "--quiet" ]] && { QUIET=1; shift; }
|
|
|
e965a0 |
+ local URL="$2"
|
|
|
e965a0 |
+ local FILE="$1"
|
|
|
e965a0 |
+ local res=0
|
|
|
e965a0 |
+ if which wget &> /dev/null; then
|
|
|
e965a0 |
+ rlLogDebug "$FUNCNAME(): using wget for download"
|
|
|
e965a0 |
+ QUIET="${QUIET:+--quiet}"
|
|
|
e965a0 |
+ wget $QUIET -t 3 -T 180 -w 20 --waitretry=30 --no-check-certificate --progress=dot:giga -O $FILE $URL || let res++
|
|
|
e965a0 |
+ elif which curl &> /dev/null; then
|
|
|
e965a0 |
+ rlLogDebug "$FUNCNAME(): using curl for download"
|
|
|
e965a0 |
+ QUIET="${QUIET:+--silent}"
|
|
|
e965a0 |
+ [[ -t 2 ]] || QUIET="${QUIET:---silent --show-error}"
|
|
|
e965a0 |
+ curl $QUIET --location --retry-connrefused --retry-delay 3 --retry-max-time 3600 --retry 3 --connect-timeout 180 --max-time 1800 --insecure -o $FILE "$URL" || let res++
|
|
|
e965a0 |
+ else
|
|
|
e965a0 |
+ rlLogError "$FUNCNAME(): no tool for downloading web content is available"
|
|
|
e965a0 |
+ let res++
|
|
|
e965a0 |
+ fi
|
|
|
e965a0 |
+ return $res
|
|
|
e965a0 |
+}
|
|
|
e965a0 |
|
|
|
e965a0 |
# __INTERNAL_rpmGetNextUrl N V R A | --source N V R
|
|
|
e965a0 |
__INTERNAL_rpmGetNextUrl() {
|
|
|
e965a0 |
@@ -673,9 +695,9 @@ __INTERNAL_rpmGetNextUrl() {
|
|
|
e965a0 |
rlLogDebug "$FUNCNAME(): get rpm info"
|
|
|
e965a0 |
local rpm_info
|
|
|
e965a0 |
if [[ -n "$source" ]]; then
|
|
|
e965a0 |
- rpm_info=$($__INTERNAL_WGET -O - "$base_url/search?match=exact&type=rpm&terms=$N-$V-$R.src.rpm")
|
|
|
e965a0 |
+ rpm_info=$(__INTERNAL_WGET - "$base_url/search?match=exact&type=rpm&terms=$N-$V-$R.src.rpm")
|
|
|
e965a0 |
else
|
|
|
e965a0 |
- rpm_info=$($__INTERNAL_WGET -O - "$base_url/search?match=exact&type=rpm&terms=$N-$V-$R.$A.rpm")
|
|
|
e965a0 |
+ rpm_info=$(__INTERNAL_WGET - "$base_url/search?match=exact&type=rpm&terms=$N-$V-$R.$A.rpm")
|
|
|
e965a0 |
fi
|
|
|
e965a0 |
[[ $? -ne 0 || -z "$rpm_info" ]] && {
|
|
|
e965a0 |
rlLogError "could not download rpm information"
|
|
|
e965a0 |
@@ -692,7 +714,7 @@ __INTERNAL_rpmGetNextUrl() {
|
|
|
e965a0 |
rlLogDebug "$FUNCNAME(): extracted buildurl='$buildurl'"
|
|
|
e965a0 |
[[ "$buildurl" =~ http ]] || buildurl="$base_url/$buildurl"
|
|
|
e965a0 |
rlLogDebug "$FUNCNAME(): using buildurl='$buildurl'"
|
|
|
e965a0 |
- local buildinfo=$($__INTERNAL_WGET -O - "$buildurl")
|
|
|
e965a0 |
+ local buildinfo=$(__INTERNAL_WGET - "$buildurl")
|
|
|
e965a0 |
[[ $? -ne 0 || -z "$buildinfo" ]] && {
|
|
|
e965a0 |
rlLogError "could not download build information"
|
|
|
e965a0 |
let res++
|
|
|
e965a0 |
@@ -752,7 +774,7 @@ __INTERNAL_rpmDirectDownload() {
|
|
|
e965a0 |
url="$__INTERNAL_RETURN_VALUE"; unset __INTERNAL_RETURN_VALUE
|
|
|
e965a0 |
local pkg=$(basename "$url")
|
|
|
e965a0 |
rlLog "trying download from '$url'"
|
|
|
e965a0 |
- if $__INTERNAL_WGET $quiet -O $pkg "$url"; then
|
|
|
e965a0 |
+ if __INTERNAL_WGET $quiet $pkg "$url"; then
|
|
|
e965a0 |
rlLogDebug "$FUNCNAME(): package '$pkg' was successfully downloaded"
|
|
|
e965a0 |
echo "$pkg"
|
|
|
e965a0 |
return 0
|
|
|
e965a0 |
--
|
|
|
e965a0 |
2.17.1
|