lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v192 82 lines 1.9 kB view raw
1#! /bin/sh -e 2 3url=$1 4rev=$2 5expHash=$3 6 7hashType=$NIX_HASH_ALGO 8if test -z "$hashType"; then 9 hashType=sha256 10fi 11if test -z "$hashFormat"; then 12 hashFormat=--base32 13fi 14 15if test -z "$url"; then 16 echo "syntax: nix-prefetch-hg URL [rev [EXPECTED-HASH]]" >&2 17 exit 1 18fi 19 20if test "$fetchSubrepos" == 1; then 21 subrepoClause=S 22else 23 subrepoClause= 24fi 25 26test -n "$rev" || rev="tip" 27 28 29# If the hash was given, a file with that hash may already be in the 30# store. 31if test -n "$expHash"; then 32 finalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" hg-archive) 33 if ! nix-store --check-validity "$finalPath" 2> /dev/null; then 34 finalPath= 35 fi 36 hash=$expHash 37fi 38 39 40# If we don't know the hash or a path with that hash doesn't exist, 41# download the file and add it to the store. 42if test -z "$finalPath"; then 43 44 tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/hg-checkout-tmp-XXXXXXXX")" 45 trap "rm -rf \"$tmpPath\"" EXIT 46 47 tmpArchive="$tmpPath/hg-archive" 48 49 # Perform the checkout. 50 if [[ $url != /* ]]; then 51 tmpClone=$tmpPath/hg-clone 52 hg clone -q -y -U "$url" $tmpClone >&2 53 else 54 tmpClone=$url 55 fi 56 hg archive -q$subrepoClause -y -r "$rev" --cwd $tmpClone $tmpArchive 57 rm -f $tmpArchive/.hg_archival.txt 58 59 echo "hg revision is $(cd $tmpClone; hg id -r "$rev" -i)" 60 61 # Compute the hash. 62 hash=$(nix-hash --type $hashType $hashFormat $tmpArchive) 63 if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi 64 65 # Add the downloaded file to the Nix store. 66 finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpArchive) 67 68 if test -n "$expHash" -a "$expHash" != "$hash"; then 69 echo "hash mismatch for URL \`$url'" 70 exit 1 71 fi 72 73 74fi 75 76if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi 77 78echo $hash 79 80if test -n "$PRINT_PATH"; then 81 echo $finalPath 82fi