Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 80 lines 1.8 kB view raw
1#! /bin/sh -e 2 3cvsRoot=$1 4module=$2 5tag=$3 6expHash=$4 7 8hashType=$NIX_HASH_ALGO 9if test -z "$hashType"; then 10 hashType=sha256 11fi 12 13if test -z "$cvsRoot"; then 14 echo "syntax: nix-prefetch-cvs CVSROOT MODULE [TAG [HASH]]" >&2 15 exit 1 16elif test -z "$module"; then 17 echo "syntax: nix-prefetch-cvs CVSROOT MODULE [TAG [HASH]]" >&2 18 exit 1 19fi 20 21 22mkTempDir() { 23 tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/nix-prefetch-cvs-XXXXXXXX")" 24 trap removeTempDir EXIT 25} 26 27removeTempDir() { 28 rm -rf "$tmpPath" 29} 30 31 32# If the hash was given, a file with that hash may already be in the 33# store. 34if test -n "$expHash"; then 35 finalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" cvs-export) 36 if ! nix-store --check-validity "$finalPath" 2> /dev/null; then 37 finalPath= 38 fi 39 hash=$expHash 40fi 41 42 43# If we don't know the hash or a path with that hash doesn't exist, 44# download the file and add it to the store. 45if test -z "$finalPath"; then 46 47 mkTempDir 48 tmpFile=$tmpPath/cvs-export 49 #mkdir $tmpPath 50 51 # Perform the checkout. 52 if test -z "$tag"; then 53 args=(-D "now") 54 elif test "$USE_DATE" = "1"; then 55 args=(-D "$tag") 56 else 57 args=(-r "$tag") 58 fi 59 (cd "$tmpPath" && cvs -f -z0 -d $cvsRoot export "${args[*]}" -d cvs-export $module >&2) 60 61 # Compute the hash. 62 hash=$(nix-hash --type $hashType $hashFormat $tmpFile) 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" $tmpFile) 67 68 if test -n "$expHash" -a "$expHash" != "$hash"; then 69 echo "hash mismatch for CVS root \`$cvsRoot'" 70 exit 1 71 fi 72fi 73 74if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi 75 76echo $hash 77 78if test -n "$PRINT_PATH"; then 79 echo $finalPath 80fi