2005-12-05 15:11:09 +01:00
|
|
|
source $stdenv/setup
|
2003-11-02 18:42:19 +01:00
|
|
|
|
2007-08-23 17:22:30 +02:00
|
|
|
header "downloading file $name with $outputHashAlgo hash $outputHash..."
|
2003-11-02 18:42:19 +01:00
|
|
|
|
2007-08-23 17:22:30 +02: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
|
|
|
|
# cryptographic hash of the output anyway).
|
|
|
|
curl="curl \
|
|
|
|
--location --max-redirs 20 \
|
|
|
|
--disable-epsv \
|
|
|
|
--cookie-jar cookies \
|
|
|
|
--insecure"
|
2003-11-02 18:42:19 +01:00
|
|
|
|
2007-08-23 17:22:30 +02:00
|
|
|
|
|
|
|
tryDownload() {
|
|
|
|
local url="$1"
|
|
|
|
echo
|
|
|
|
header "trying $url"
|
|
|
|
success=
|
|
|
|
if $curl --fail "$url" --output "$out"; then
|
|
|
|
success=1
|
2005-02-22 16:34:58 +01:00
|
|
|
fi
|
2007-08-23 17:22:30 +02:00
|
|
|
stopNest
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
finish() {
|
|
|
|
# On old versions of Nix, verify the hash of the output. On newer
|
|
|
|
# versions, Nix verifies the hash itself.
|
|
|
|
if test "$NIX_OUTPUT_CHECKED" != "1"; then
|
|
|
|
if test "$outputHashAlgo" != "md5"; then
|
|
|
|
echo "hashes other than md5 are unsupported in Nix <= 0.7, upgrade to Nix 0.8"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
actual=$(md5sum -b "$out" | cut -c1-32)
|
|
|
|
if test "$actual" != "$id"; then
|
|
|
|
echo "hash is $actual, expected $id"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
stopNest
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-27 14:44:01 +02:00
|
|
|
tryHashedMirrors() {
|
2007-09-11 15:48:53 +02:00
|
|
|
if test -n "$NIX_HASHED_MIRRORS"; then
|
|
|
|
hashedMirrors="$NIX_HASHED_MIRRORS"
|
|
|
|
fi
|
|
|
|
|
2007-08-27 14:44:01 +02:00
|
|
|
for mirror in $hashedMirrors; do
|
|
|
|
url="$mirror/$outputHashAlgo/$outputHash"
|
|
|
|
if $curl --fail --silent --show-error --head "$url" \
|
|
|
|
--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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
urls2=
|
|
|
|
for url in $urls; do
|
|
|
|
if test "${url:0:9}" != "mirror://"; then
|
|
|
|
urls2="$urls2 $url"
|
2007-08-23 17:22:30 +02:00
|
|
|
else
|
2007-08-27 14:44:01 +02: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
|
|
|
|
# bandwidth than nix.cs.uu.nl.
|
|
|
|
preferHashedMirrors=
|
2007-09-11 17:00:49 +02: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 14:44:01 +02:00
|
|
|
urls2="$urls2 $url3$fileName";
|
|
|
|
done
|
2007-08-23 17:22:30 +02:00
|
|
|
fi
|
2005-02-22 16:23:56 +01:00
|
|
|
fi
|
2007-08-23 17:22:30 +02:00
|
|
|
done
|
2007-08-27 14:44:01 +02:00
|
|
|
urls="$urls2"
|
|
|
|
|
2007-08-23 17:22:30 +02:00
|
|
|
|
2007-08-27 14:44:01 +02:00
|
|
|
if test -n "$preferHashedMirrors"; then
|
|
|
|
tryHashedMirrors
|
|
|
|
fi
|
2007-08-23 17:22:30 +02:00
|
|
|
|
|
|
|
success=
|
|
|
|
for url in $urls; do
|
|
|
|
tryDownload "$url"
|
|
|
|
if test -n "$success"; then finish; fi
|
|
|
|
done
|
|
|
|
|
2007-08-27 14:44:01 +02:00
|
|
|
if test -z "$preferHashedMirrors"; then
|
|
|
|
tryHashedMirrors
|
|
|
|
fi
|
|
|
|
|
2005-02-22 16:23:56 +01:00
|
|
|
|
2007-08-23 17:22:30 +02:00
|
|
|
echo "error: cannot download $name from any mirror"
|
|
|
|
exit 1
|