2012-03-09 17:29:17 +00:00
|
|
|
#! /bin/sh -e
|
|
|
|
|
2013-06-04 11:41:59 +01:00
|
|
|
distDir=${NIX_TARBALLS_CACHE:-/tarballs}
|
2012-03-09 17:29:17 +00:00
|
|
|
|
|
|
|
url="$1"
|
2012-03-09 17:53:04 +00:00
|
|
|
file="$2"
|
2012-03-09 17:29:17 +00:00
|
|
|
if [ -z "$url" ]; then echo "syntax: $0 URL"; exit 0; fi
|
|
|
|
|
|
|
|
base="$(basename "$url")"
|
|
|
|
if [ -z "$base" ]; then echo "bad URL"; exit 1; fi
|
|
|
|
dstPath="$distDir/$base"
|
|
|
|
|
2013-01-15 10:18:42 +00:00
|
|
|
if [ -e "$dstPath" ]; then if [ -n "$VERBOSE" ]; then echo "$dstPath already exists"; fi; exit 0; fi
|
2012-03-09 17:29:17 +00:00
|
|
|
|
2012-03-09 17:53:04 +00:00
|
|
|
if [ -z "$file" ]; then
|
2012-03-09 17:29:17 +00:00
|
|
|
|
2012-03-09 17:53:04 +00:00
|
|
|
echo "downloading $url to $dstPath"
|
2012-03-09 17:29:17 +00:00
|
|
|
|
2013-01-15 10:18:42 +00:00
|
|
|
if [ -n "$DRY_RUN" ]; then exit 0; fi
|
2012-03-09 17:53:04 +00:00
|
|
|
|
|
|
|
declare -a res
|
|
|
|
if ! res=($(PRINT_PATH=1 nix-prefetch-url "$url")); then
|
2013-01-15 10:18:42 +00:00
|
|
|
exit
|
2012-03-09 17:53:04 +00:00
|
|
|
fi
|
2013-01-15 10:18:42 +00:00
|
|
|
|
2012-03-09 17:53:04 +00:00
|
|
|
storePath=${res[1]}
|
|
|
|
|
|
|
|
else
|
|
|
|
storePath="$file"
|
2012-03-09 17:29:17 +00:00
|
|
|
fi
|
2013-01-15 10:18:42 +00:00
|
|
|
|
2012-03-09 17:29:17 +00:00
|
|
|
cp $storePath "$dstPath.tmp.$$"
|
|
|
|
mv -f "$dstPath.tmp.$$" "$dstPath"
|
|
|
|
|
|
|
|
echo "hashing $dstPath"
|
|
|
|
|
|
|
|
md5=$(nix-hash --flat --type md5 "$dstPath")
|
|
|
|
ln -sfn "../$base" $distDir/md5/$md5
|
|
|
|
|
|
|
|
sha1=$(nix-hash --flat --type sha1 "$dstPath")
|
|
|
|
ln -sfn "../$base" $distDir/sha1/$sha1
|
|
|
|
|
|
|
|
sha256=$(nix-hash --flat --type sha256 "$dstPath")
|
|
|
|
ln -sfn "../$base" $distDir/sha256/$sha256
|
|
|
|
ln -sfn "../$base" $distDir/sha256/$(nix-hash --type sha256 --to-base32 "$sha256")
|