anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / build-support / fetchcvs / nix-prefetch-cvs
blob4438f44026f2a6af22cbf47c18a38a2512789ca7
1 #! /bin/sh -e
3 cvsRoot=$1
4 module=$2
5 tag=$3
6 expHash=$4
8 hashType=$NIX_HASH_ALGO
9 if test -z "$hashType"; then
10 hashType=sha256
13 if test -z "$cvsRoot"; then
14 echo "syntax: nix-prefetch-cvs CVSROOT MODULE [TAG [HASH]]" >&2
15 exit 1
16 elif test -z "$module"; then
17 echo "syntax: nix-prefetch-cvs CVSROOT MODULE [TAG [HASH]]" >&2
18 exit 1
22 mkTempDir() {
23 tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/nix-prefetch-cvs-XXXXXXXX")"
24 trap removeTempDir EXIT
27 removeTempDir() {
28 rm -rf "$tmpPath"
32 # If the hash was given, a file with that hash may already be in the
33 # store.
34 if 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=
39 hash=$expHash
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.
45 if test -z "$finalPath"; then
47 mkTempDir
48 tmpFile=$tmpPath/cvs-export
49 #mkdir $tmpPath
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")
59 (cd "$tmpPath" && cvs -f -z0 -d $cvsRoot export "${args[*]}" -d cvs-export $module >&2)
61 # Compute the hash.
62 hash=$(nix-hash --type $hashType ${hashFormat:-"--sri"} $tmpFile)
63 if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
65 # Add the downloaded file to the Nix store.
66 finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)
68 if test -n "$expHash" -a "$expHash" != "$hash"; then
69 echo "hash mismatch for CVS root \`$cvsRoot'"
70 exit 1
74 if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi
76 echo $hash
78 if test -n "$PRINT_PATH"; then
79 echo $finalPath