2004-04-14 12:55:33 +02:00
|
|
|
#! /bin/sh -e
|
|
|
|
|
|
|
|
url=$1
|
|
|
|
rev=$2
|
2004-12-17 12:04:18 +01:00
|
|
|
hash=$3
|
2004-04-14 12:55:33 +02:00
|
|
|
|
|
|
|
if test -z "$url"; then
|
|
|
|
echo "syntax: nix-prefetch-svn URL [REVISION]" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
test -n "$rev" || rev="HEAD"
|
|
|
|
|
2004-12-17 12:04:18 +01: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 12:55:33 +02:00
|
|
|
|
2004-12-17 12:04:18 +01:00
|
|
|
# !!! race? should be relatively safe, `svn export' barfs if $tmpPath exists.
|
|
|
|
tmpPath1=$storeDir/svn-checkout-tmp-$$
|
2004-04-14 12:55:33 +02:00
|
|
|
|
2004-12-17 12:04:18 +01:00
|
|
|
# Perform the checkout.
|
|
|
|
svn export -r "$rev" "$url" $tmpPath1 >&2
|
2004-04-14 12:55:33 +02:00
|
|
|
|
2004-12-17 12:04:18 +01:00
|
|
|
# Compute the hash.
|
|
|
|
hash=$(nix-hash $tmpPath1)
|
|
|
|
echo "hash is $hash" >&2
|
2004-04-14 12:55:33 +02:00
|
|
|
|
2004-12-17 12:04:18 +01:00
|
|
|
# Rename it so that the fetchsvn builder can find it.
|
|
|
|
tmpPath2=$storeDir/svn-checkout-tmp-$hash
|
|
|
|
test -e $tmpPath2 || mv $tmpPath1 $tmpPath2 # !!! race
|
|
|
|
|
|
|
|
fi
|
2004-04-14 12:55:33 +02:00
|
|
|
|
|
|
|
# Create a Nix expression that does a fetchsvn.
|
|
|
|
nixExpr=$(dirname $(readlink -f $0))/../../system/i686-linux.nix
|
|
|
|
storeExpr=$( \
|
|
|
|
echo "(import $nixExpr).fetchsvn {url=\"$url\"; rev=\"$rev\"; md5=\"$hash\";}" \
|
|
|
|
| nix-instantiate -)
|
|
|
|
|
|
|
|
# Realise it.
|
|
|
|
finalPath=$(nix-store -qnB --force-realise $storeExpr)
|
|
|
|
|
|
|
|
echo "path is $finalPath" >&2
|
|
|
|
|
2004-12-17 12:04:18 +01:00
|
|
|
if test -n "$tmpPath2"; then
|
|
|
|
rm -rf $tmpPath2 || true
|
|
|
|
fi
|
2004-04-14 12:55:33 +02:00
|
|
|
|
|
|
|
echo $hash
|
2004-12-17 11:40:00 +01:00
|
|
|
|
|
|
|
if test -n "$PRINT_PATH"; then
|
|
|
|
echo $finalPath
|
|
|
|
fi
|