2004-04-14 11:55:33 +01:00
|
|
|
#! /bin/sh -e
|
|
|
|
|
|
|
|
url=$1
|
|
|
|
rev=$2
|
2004-12-17 11:04:18 +00:00
|
|
|
hash=$3
|
2004-04-14 11:55:33 +01:00
|
|
|
|
|
|
|
if test -z "$url"; then
|
|
|
|
echo "syntax: nix-prefetch-svn URL [REVISION]" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
test -n "$rev" || rev="HEAD"
|
|
|
|
|
2005-12-15 17:00:56 +00:00
|
|
|
# Use a restrictive umask to ensure that the output in the Nix store
|
|
|
|
# is not group- or world-writable. Nix 0.10 complains about this.
|
|
|
|
umask 0022
|
|
|
|
|
2004-12-17 11:04:18 +00:00
|
|
|
# Determine the hash, unless it was given.
|
|
|
|
if test -z "$hash"; then
|
|
|
|
|
|
|
|
# !!! hacky; we should have a way to query the location of the store.
|
|
|
|
if storeDir=$(which nix-store); then
|
|
|
|
storeDir=$(dirname $(dirname "$storeDir"))/store
|
|
|
|
else
|
|
|
|
storeDir=/nix/store
|
|
|
|
fi
|
2004-04-14 11:55:33 +01:00
|
|
|
|
2004-12-17 11:04:18 +00:00
|
|
|
# !!! race? should be relatively safe, `svn export' barfs if $tmpPath exists.
|
|
|
|
tmpPath1=$storeDir/svn-checkout-tmp-$$
|
2004-04-14 11:55:33 +01:00
|
|
|
|
2005-02-22 16:27:28 +00:00
|
|
|
# Test whether we have write permission in the store. If not,
|
|
|
|
# fetch to /tmp and don't copy to the store. This is a hack to
|
|
|
|
# make this script at least work somewhat in setuid installations.
|
|
|
|
if ! touch $tmpPath1 2> /dev/null; then
|
|
|
|
echo "(cannot write to the store, result won't be cached)" >&2
|
|
|
|
dummyMode=1
|
|
|
|
tmpPath1=/tmp/nix-prefetch-svn-$$ # !!! security?
|
|
|
|
fi
|
2005-04-12 14:48:36 +01:00
|
|
|
rm -f $tmpPath1
|
2005-02-22 16:27:28 +00:00
|
|
|
|
2004-12-17 11:04:18 +00:00
|
|
|
# Perform the checkout.
|
|
|
|
svn export -r "$rev" "$url" $tmpPath1 >&2
|
2004-04-14 11:55:33 +01:00
|
|
|
|
2004-12-17 11:04:18 +00:00
|
|
|
# Compute the hash.
|
|
|
|
hash=$(nix-hash $tmpPath1)
|
|
|
|
echo "hash is $hash" >&2
|
2004-04-14 11:55:33 +01:00
|
|
|
|
2004-12-17 11:04:18 +00:00
|
|
|
# Rename it so that the fetchsvn builder can find it.
|
2005-02-22 16:27:28 +00:00
|
|
|
if test "$dummyMode" != 1; then
|
|
|
|
tmpPath2=$storeDir/svn-checkout-tmp-$hash
|
|
|
|
test -e $tmpPath2 || mv $tmpPath1 $tmpPath2 # !!! race
|
|
|
|
fi
|
2004-12-17 11:04:18 +00:00
|
|
|
fi
|
2004-04-14 11:55:33 +01:00
|
|
|
|
|
|
|
# Create a Nix expression that does a fetchsvn.
|
2006-05-02 10:21:59 +01:00
|
|
|
scriptDir=$(dirname $(readlink -f $0 2> /dev/null || echo $0))
|
|
|
|
nixExpr=$scriptDir/../../top-level/all-packages.nix
|
2004-04-14 11:55:33 +01:00
|
|
|
storeExpr=$( \
|
2006-03-15 21:35:18 +00:00
|
|
|
echo "(import $nixExpr {}).fetchsvn {url=\"$url\"; rev=\"$rev\"; md5=\"$hash\";}" \
|
2004-04-14 11:55:33 +01:00
|
|
|
| nix-instantiate -)
|
|
|
|
|
|
|
|
# Realise it.
|
2005-02-22 16:27:28 +00:00
|
|
|
finalPath=$(nix-store -r $storeExpr)
|
2004-04-14 11:55:33 +01:00
|
|
|
|
|
|
|
echo "path is $finalPath" >&2
|
|
|
|
|
2005-02-22 16:27:28 +00:00
|
|
|
if test -n "$tmpPath1" -o -n "$tmpPath2"; then
|
|
|
|
rm -rf $tmpPath1 $tmpPath2 || true
|
2004-12-17 11:04:18 +00:00
|
|
|
fi
|
2004-04-14 11:55:33 +01:00
|
|
|
|
|
|
|
echo $hash
|
2004-12-17 10:40:00 +00:00
|
|
|
|
|
|
|
if test -n "$PRINT_PATH"; then
|
|
|
|
echo $finalPath
|
|
|
|
fi
|