1.1 --- a/scripts/functions Tue Nov 16 10:00:27 2010 +0100
1.2 +++ b/scripts/functions Tue Nov 16 17:49:15 2010 +0100
1.3 @@ -353,54 +353,37 @@
1.4 exit 1
1.5 }
1.6
1.7 -# Download an URL using wget
1.8 -# Usage: CT_DoGetFileWget <URL>
1.9 -CT_DoGetFileWget() {
1.10 - # Need to return true because it is legitimate to not find the tarball at
1.11 - # some of the provided URLs (think about snapshots, different layouts for
1.12 - # different gcc versions, etc...)
1.13 +# Try to retrieve the specified URL (HTTP or FTP)
1.14 +# Usage: CT_DoGetFile <URL>
1.15 +# This functions always returns true (0), as it can be legitimate not
1.16 +# to find the requested URL (think about snapshots, different layouts
1.17 +# for different gcc versions, etc...).
1.18 +CT_DoGetFile() {
1.19 + # OK, just look if we have them...
1.20 + # We are sure at least one is available, ./configure checked for it.
1.21 + local _curl=$(CT_Which curl)
1.22 + local _wget=$(CT_Which wget)
1.23 + _curl="${_curl:-false}"
1.24 + _wget="${_wget:-false}"
1.25 +
1.26 # Some (very old!) FTP server might not support the passive mode, thus
1.27 - # retry without
1.28 - # With automated download as we are doing, it can be very dangerous to use
1.29 - # -c to continue the downloads. It's far better to simply overwrite the
1.30 - # destination file
1.31 + # retry without.
1.32 + # We also retry a few times, in case there is a transient error (eg. behind
1.33 + # a dynamic IP that changes during the transfer...)
1.34 + # With automated download as we are doing, it can be very dangerous to
1.35 + # continue the downloads. It's far better to simply overwrite the
1.36 + # destination file.
1.37 # Some company networks have firewalls to connect to the internet, but it's
1.38 # not easy to detect them, and wget does not timeout by default while
1.39 # connecting, so force a global ${CT_CONNECT_TIMEOUT}-second timeout.
1.40 - CT_DoExecLog ALL wget -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary --tries=3 --passive-ftp "$1" \
1.41 - || CT_DoExecLog ALL wget -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary --tries=3 "$1" \
1.42 + # For curl, no good progress indicator is available. So, be silent.
1.43 + CT_DoExecLog ALL "${_curl}" --ftp-pasv --retry 3 --connect-timeout ${CT_CONNECT_TIMEOUT} -L -f -s -O "$1" \
1.44 + || CT_DoExecLog ALL "${_curl}" --retry 3 --connect-timeout ${CT_CONNECT_TIMEOUT} -L -f -s -O "$1" \
1.45 + || CT_DoExecLog ALL "${_wget}" --passive-ftp --tries=3 -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary "$1" \
1.46 + || CT_DoExecLog ALL "${_wget}" --tries=3 -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary "$1" \
1.47 || rm -f "${1##*/}"
1.48 }
1.49
1.50 -# Download an URL using curl
1.51 -# Usage: CT_DoGetFileCurl <URL>
1.52 -CT_DoGetFileCurl() {
1.53 - # Note: comments about wget method (above) are also valid here
1.54 - # Plus: no good progress indicator is available with curl,
1.55 - # so, be silent.
1.56 - CT_DoExecLog ALL curl -s --ftp-pasv -O --retry 3 "$1" --connect-timeout ${CT_CONNECT_TIMEOUT} -L -f \
1.57 - || CT_DoExecLog ALL curl -s -O --retry 3 "$1" --connect-timeout ${CT_CONNECT_TIMEOUT} -L -f \
1.58 - || rm -f "${1##*/}"
1.59 -}
1.60 -
1.61 -# OK, just look if we have them...
1.62 -_wget=$(CT_Which wget)
1.63 -_curl=$(CT_Which curl)
1.64 -
1.65 -# Wrapper function to call one of, in order of preference:
1.66 -# curl
1.67 -# wget
1.68 -# Usage: CT_DoGetFile <URL>
1.69 -CT_DoGetFile() {
1.70 - if [ -n "${_curl}" ]; then
1.71 - CT_DoGetFileCurl "$1"
1.72 - elif [ -n "${_wget}" ]; then
1.73 - CT_DoGetFileWget "$1"
1.74 - else
1.75 - CT_Abort "Could find neither wget nor curl"
1.76 - fi
1.77 -}
1.78 -
1.79 # This function tries to retrieve a tarball form a local directory
1.80 # Usage: CT_GetLocal <basename> [.extension]
1.81 CT_GetLocal() {