2005-12-05 17:11:09 +03:00
|
|
|
source $stdenv/setup
|
2003-11-02 20:42:19 +03:00
|
|
|
|
2008-08-22 19:53:21 +04:00
|
|
|
source $mirrorsFile
|
|
|
|
|
2003-11-02 20:42:19 +03:00
|
|
|
|
2007-08-23 19:22:30 +04:00
|
|
|
# Curl flags to handle redirects, not use EPSV, handle cookies for
|
|
|
|
# servers to need them during redirects, and work on SSL without a
|
|
|
|
# certificate (this isn't a security problem because we check the
|
2013-02-06 18:15:28 +04:00
|
|
|
# cryptographic hash of the output anyway).
|
2007-08-23 19:22:30 +04:00
|
|
|
curl="curl \
|
|
|
|
--location --max-redirs 20 \
|
2010-05-27 22:59:19 +04:00
|
|
|
--retry 3
|
2007-08-23 19:22:30 +04:00
|
|
|
--disable-epsv \
|
|
|
|
--cookie-jar cookies \
|
2010-05-27 22:59:19 +04:00
|
|
|
--insecure \
|
2013-05-16 12:18:12 +04:00
|
|
|
$curlOpts \
|
2010-05-28 10:49:32 +04:00
|
|
|
$NIX_CURL_FLAGS"
|
2003-11-02 20:42:19 +03:00
|
|
|
|
2007-08-23 19:22:30 +04:00
|
|
|
|
2014-05-08 16:57:20 +04:00
|
|
|
downloadedFile="$out"
|
|
|
|
if [ -n "$downloadToTemp" ]; then downloadedFile="$TMPDIR/file"; fi
|
|
|
|
|
|
|
|
|
2007-08-23 19:22:30 +04:00
|
|
|
tryDownload() {
|
|
|
|
local url="$1"
|
|
|
|
echo
|
|
|
|
header "trying $url"
|
|
|
|
success=
|
2014-05-08 16:57:20 +04:00
|
|
|
if $curl --fail "$url" --output "$downloadedFile"; then
|
2009-07-16 21:17:23 +04:00
|
|
|
success=1
|
2005-02-22 18:34:58 +03:00
|
|
|
fi
|
2007-08-23 19:22:30 +04:00
|
|
|
stopNest
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
finish() {
|
2014-05-08 16:57:20 +04:00
|
|
|
set +o noglob
|
|
|
|
runHook postFetch
|
2007-08-23 19:22:30 +04:00
|
|
|
stopNest
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-27 16:44:01 +04:00
|
|
|
tryHashedMirrors() {
|
2007-09-11 17:48:53 +04:00
|
|
|
if test -n "$NIX_HASHED_MIRRORS"; then
|
|
|
|
hashedMirrors="$NIX_HASHED_MIRRORS"
|
|
|
|
fi
|
2013-02-06 18:15:28 +04:00
|
|
|
|
2007-08-27 16:44:01 +04:00
|
|
|
for mirror in $hashedMirrors; do
|
|
|
|
url="$mirror/$outputHashAlgo/$outputHash"
|
2013-02-06 18:15:28 +04:00
|
|
|
if $curl --retry 0 --connect-timeout "${NIX_CONNECT_TIMEOUT:-15}" \
|
|
|
|
--fail --silent --show-error --head "$url" \
|
2007-08-27 16:44:01 +04:00
|
|
|
--write-out "%{http_code}" --output /dev/null > code 2> log; then
|
|
|
|
tryDownload "$url"
|
|
|
|
if test -n "$success"; then finish; fi
|
|
|
|
else
|
|
|
|
# Be quiet about 404 errors, which we interpret as the file
|
|
|
|
# not being present on this particular mirror.
|
|
|
|
if test "$(cat code)" != 404; then
|
|
|
|
echo "error checking the existence of $url:"
|
|
|
|
cat log
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-08 21:00:33 +04:00
|
|
|
# URL list may contain ?. No glob expansion for that, please
|
|
|
|
set -o noglob
|
|
|
|
|
2007-08-27 16:44:01 +04:00
|
|
|
urls2=
|
|
|
|
for url in $urls; do
|
|
|
|
if test "${url:0:9}" != "mirror://"; then
|
|
|
|
urls2="$urls2 $url"
|
2007-08-23 19:22:30 +04:00
|
|
|
else
|
2007-08-27 16:44:01 +04:00
|
|
|
url2="${url:9}"; echo "${url2/\// }" > split; read site fileName < split
|
|
|
|
#varName="mirror_$site"
|
|
|
|
varName="$site" # !!! danger of name clash, fix this
|
|
|
|
if test -z "${!varName}"; then
|
|
|
|
echo "warning: unknown mirror:// site \`$site'"
|
|
|
|
else
|
|
|
|
# Assume that SourceForge/GNU/kernel mirrors have better
|
2008-11-14 19:57:19 +03:00
|
|
|
# bandwidth than nixos.org.
|
2007-08-27 16:44:01 +04:00
|
|
|
preferHashedMirrors=
|
2007-09-11 19:00:49 +04:00
|
|
|
|
|
|
|
mirrors=${!varName}
|
|
|
|
|
|
|
|
# Allow command-line override by setting NIX_MIRRORS_$site.
|
|
|
|
varName="NIX_MIRRORS_$site"
|
|
|
|
if test -n "${!varName}"; then mirrors="${!varName}"; fi
|
|
|
|
|
|
|
|
for url3 in $mirrors; do
|
2007-08-27 16:44:01 +04:00
|
|
|
urls2="$urls2 $url3$fileName";
|
|
|
|
done
|
2007-08-23 19:22:30 +04:00
|
|
|
fi
|
2005-02-22 18:23:56 +03:00
|
|
|
fi
|
2007-08-23 19:22:30 +04:00
|
|
|
done
|
2007-08-27 16:44:01 +04:00
|
|
|
urls="$urls2"
|
|
|
|
|
2009-05-08 21:00:33 +04:00
|
|
|
# Restore globbing settings
|
|
|
|
set +o noglob
|
2007-08-23 19:22:30 +04:00
|
|
|
|
2008-07-23 20:04:10 +04:00
|
|
|
if test -n "$showURLs"; then
|
|
|
|
echo "$urls" > $out
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2007-08-27 16:44:01 +04:00
|
|
|
if test -n "$preferHashedMirrors"; then
|
|
|
|
tryHashedMirrors
|
|
|
|
fi
|
2007-08-23 19:22:30 +04:00
|
|
|
|
2009-05-08 21:00:33 +04:00
|
|
|
# URL list may contain ?. No glob expansion for that, please
|
|
|
|
set -o noglob
|
|
|
|
|
2007-08-23 19:22:30 +04:00
|
|
|
success=
|
|
|
|
for url in $urls; do
|
|
|
|
tryDownload "$url"
|
|
|
|
if test -n "$success"; then finish; fi
|
|
|
|
done
|
|
|
|
|
2009-05-08 21:00:33 +04:00
|
|
|
# Restore globbing settings
|
|
|
|
set +o noglob
|
|
|
|
|
2007-08-27 16:44:01 +04:00
|
|
|
if test -z "$preferHashedMirrors"; then
|
|
|
|
tryHashedMirrors
|
|
|
|
fi
|
|
|
|
|
2005-02-22 18:23:56 +03:00
|
|
|
|
2007-08-23 19:22:30 +04:00
|
|
|
echo "error: cannot download $name from any mirror"
|
|
|
|
exit 1
|