From 35f89c406423344b19dcf3e3f95ff6296f329e42 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sun, 12 Feb 2017 13:51:42 -0800 Subject: Detect both wget/curl and allow user to select the agent Signed-off-by: Alexey Neyman --- scripts/functions | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'scripts/functions') diff --git a/scripts/functions b/scripts/functions index 9f852b39..65ce4981 100644 --- a/scripts/functions +++ b/scripts/functions @@ -663,29 +663,34 @@ CT_DoGetFile() { local url="${1}" local dest="${CT_TARBALLS_DIR}/${url##*/}" local tmp="${dest}.tmp-dl" + local ok + local T # Remove potential left-over from a previous run rm -f "${tmp}" - # We also retry a few times, in case there is a transient error (eg. behind - # a dynamic IP that changes during the transfer...) - # With automated download as we are doing, it can be very dangerous to - # continue the downloads. It's far better to simply overwrite the - # destination file. - # Some company networks have firewalls to connect to the internet, but it's - # not easy to detect them, so force a global ${CT_CONNECT_TIMEOUT}-second - # timeout. - if [ ${CT_CONNECT_TIMEOUT} = -1 ]; then - T= - else - T="-T ${CT_CONNECT_TIMEOUT}" + # Replace a special value of '-1' with empty string + if [ ${CT_CONNECT_TIMEOUT} != -1 ]; then + T="${CT_CONNECT_TIMEOUT}" + fi + + if [ "${CT_DOWNLOAD_AGENT_WGET}" = "y" ]; then + if CT_DoExecLog ALL wget ${CT_DOWNLOAD_WGET_OPTIONS} \ + ${T:+-T ${T}} \ + -O "${tmp}" \ + "${url}"; then + ok=y + fi + elif [ "${CT_DOWNLOAD_AGENT_CURL}" = "y" ]; then + if CT_DoExecLog ALL curl ${CT_DOWNLOAD_CURL_OPTIONS} \ + ${T:+--connect-timeout ${T}} \ + -o "${tmp}" \ + "${url}"; then + ok=y + fi fi - if CT_DoExecLog ALL wget --passive-ftp --tries=3 -nc \ - --progress=dot:binary \ - ${T} \ - -O "${tmp}" \ - "${url}" - then + + if [ "${ok}" = "y" ]; then # Success, we got it, good! mv "${tmp}" "${dest}" CT_DoLog DEBUG "Got it from: \"${url}\"" -- cgit v1.2.3