catalyst-browser: init at 3.9.4 (#350552)
[NixPkgs.git] / pkgs / build-support / fetchcvs / nix-prefetch-cvs
blob6b8fcf5f82c67058309f94edfaa56aa5e130a50d
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 # nix>=2.20 rejects adding symlinked paths to the store, so use realpath
24 # to resolve to a physical path. https://github.com/NixOS/nix/issues/11941
25 tmpPath="$(realpath "$(mktemp -d --tmpdir nix-prefetch-csv-XXXXXXXX)")"
26 trap removeTempDir EXIT
29 removeTempDir() {
30 rm -rf "$tmpPath"
34 # If the hash was given, a file with that hash may already be in the
35 # store.
36 if test -n "$expHash"; then
37 finalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" cvs-export)
38 if ! nix-store --check-validity "$finalPath" 2> /dev/null; then
39 finalPath=
41 hash=$expHash
45 # If we don't know the hash or a path with that hash doesn't exist,
46 # download the file and add it to the store.
47 if test -z "$finalPath"; then
49 mkTempDir
50 tmpFile=$tmpPath/cvs-export
51 #mkdir $tmpPath
53 # Perform the checkout.
54 if test -z "$tag"; then
55 args=(-D "now")
56 elif test "$USE_DATE" = "1"; then
57 args=(-D "$tag")
58 else
59 args=(-r "$tag")
61 (cd "$tmpPath" && cvs -f -z0 -d $cvsRoot export "${args[*]}" -d cvs-export $module >&2)
63 # Compute the hash.
64 hash=$(nix-hash --type $hashType ${hashFormat:-"--sri"} $tmpFile)
65 if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
67 # Add the downloaded file to the Nix store.
68 finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)
70 if test -n "$expHash" -a "$expHash" != "$hash"; then
71 echo "hash mismatch for CVS root \`$cvsRoot'"
72 exit 1
76 if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi
78 echo $hash
80 if test -n "$PRINT_PATH"; then
81 echo $finalPath