require gnused for all prefetch scripts
This commit is contained in:
parent
400b94e120
commit
9bd8dffd77
@ -1,14 +1,13 @@
|
|||||||
#! /bin/sh -e
|
#! /bin/sh -e
|
||||||
|
|
||||||
usage(){
|
usage(){
|
||||||
echo >&2 "syntax: nix-prefetch-zip [options]
|
echo >&2 "syntax: nix-prefetch-zip [OPTIONS] [URL [EXPECTED-HASH]]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--url name The url of the archive to fetch.
|
--url url The url of the archive to fetch.
|
||||||
--name name The name to use for the store path (defaults to \`basename \$url\`).
|
--name name The name to use for the store path (defaults to \`basename \$url\`).
|
||||||
--hash name The hash of unpacked archive.
|
--hash hash The hash of unpacked archive.
|
||||||
--hash-type hash Use the specified cryptographic hash algorithm, which can be one of md5, sha1, and sha256.
|
--hash-type type Use the specified cryptographic hash algorithm, which can be one of md5, sha1, and sha256.
|
||||||
--base32 Print/accept the hash in a base-32 representation rather than hexadecimal.
|
|
||||||
--leave-root Keep the root directory of the archive.
|
--leave-root Keep the root directory of the archive.
|
||||||
--help Show this help text.
|
--help Show this help text.
|
||||||
"
|
"
|
||||||
@ -25,13 +24,18 @@ for arg; do
|
|||||||
--name) argfun=set_name;;
|
--name) argfun=set_name;;
|
||||||
--hash) argfun=set_expHash;;
|
--hash) argfun=set_expHash;;
|
||||||
--hash-type) argfun=set_hashType;;
|
--hash-type) argfun=set_hashType;;
|
||||||
--base32) hashFormat="--base32";;
|
|
||||||
--leave-root) leaveRoot=true;;
|
--leave-root) leaveRoot=true;;
|
||||||
--help) usage;;
|
--help) usage;;
|
||||||
*)
|
*) argi=$(($argi + 1))
|
||||||
echo "Unexpected argument: $arg" >&2
|
case $argi in
|
||||||
usage
|
1) url=$arg;;
|
||||||
;;
|
2) rev=$arg;;
|
||||||
|
3) expHash=$arg;;
|
||||||
|
*) echo "Unexpected argument: $arg" >&2
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
case $argfun in
|
case $argfun in
|
||||||
@ -57,11 +61,13 @@ if test -z "$hashType"; then
|
|||||||
hashType=sha256
|
hashType=sha256
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tmp=$(mktemp -d 2>/dev/null || mktemp -d -t "$$")
|
hashFormat="--base32"
|
||||||
trap "rm -rf \"\$tmp\"" EXIT
|
|
||||||
|
|
||||||
TMPDIR=$tmp/unpacked/$name
|
tmp=$(mktemp -d 2>/dev/null || mktemp -d -t "$$")
|
||||||
mkdir -p $TMPDIR
|
trap "rm -rf '$tmp'" EXIT
|
||||||
|
|
||||||
|
unpackDir=$tmp/unpacked/$name
|
||||||
|
mkdir -p $unpackDir
|
||||||
downloadedFile=$tmp/$name
|
downloadedFile=$tmp/$name
|
||||||
|
|
||||||
unpackFile() {
|
unpackFile() {
|
||||||
@ -110,27 +116,27 @@ if test -z "$finalPath"; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $TMPDIR
|
cd $unpackDir
|
||||||
unpackFile "$downloadedFile"
|
unpackFile "$downloadedFile"
|
||||||
|
|
||||||
# FIXME: handle zip files that contain a single regular file.
|
# FIXME: handle zip files that contain a single regular file.
|
||||||
if [ -z "$leaveRoot" ]; then
|
if [ -z "$leaveRoot" ]; then
|
||||||
shopt -s dotglob
|
shopt -s dotglob
|
||||||
if [ $(ls -d $TMPDIR/* | wc -l) != 1 ]; then
|
if [ $(ls -d $unpackDir/* | wc -l) != 1 ]; then
|
||||||
echo "error: zip file must contain a single directory."
|
echo "error: zip file must contain a single directory."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fn=$(cd "$TMPDIR" && echo *)
|
fn=$(cd "$unpackDir" && echo *)
|
||||||
mv $TMPDIR/$fn/* "$TMPDIR/"
|
mv $unpackDir/$fn/* "$unpackDir/"
|
||||||
rmdir "$TMPDIR/$fn"
|
rmdir "$unpackDir/$fn"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Compute the hash.
|
# Compute the hash.
|
||||||
hash=$(nix-hash --type $hashType $hashFormat $TMPDIR)
|
hash=$(nix-hash --type $hashType $hashFormat $unpackDir)
|
||||||
if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
|
if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
|
||||||
|
|
||||||
# Add the downloaded file to the Nix store.
|
# Add the downloaded file to the Nix store.
|
||||||
finalPath=$(nix-store --add-fixed --recursive "$hashType" $TMPDIR)
|
finalPath=$(nix-store --add-fixed --recursive "$hashType" $unpackDir)
|
||||||
|
|
||||||
if test -n "$expHash" -a "$expHash" != "$hash"; then
|
if test -n "$expHash" -a "$expHash" != "$hash"; then
|
||||||
echo "hash mismatch for URL \`$url'"
|
echo "hash mismatch for URL \`$url'"
|
@ -11,20 +11,21 @@ stdenv.mkDerivation {
|
|||||||
function copyScript {
|
function copyScript {
|
||||||
local name=nix-prefetch-$1;
|
local name=nix-prefetch-$1;
|
||||||
local src=$2;
|
local src=$2;
|
||||||
|
local wrapArgs=""
|
||||||
cp $src $out/bin/$name;
|
cp $src $out/bin/$name;
|
||||||
for dep in ''${@:3}; do
|
for dep in ''${@:3}; do
|
||||||
local exe=$dep/bin;
|
wrapArgs="$wrapArgs --prefix PATH : $dep/bin"
|
||||||
local wrapArgs="$wrapArgs --prefix PATH : $exe"
|
|
||||||
done
|
done
|
||||||
|
wrapArgs="$wrapArgs --prefix PATH : ${gnused}/bin"
|
||||||
wrapProgram $out/bin/$name $wrapArgs
|
wrapProgram $out/bin/$name $wrapArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
copyScript "hg" ${../../../build-support/fetchhg/nix-prefetch-hg} ${mercurial}
|
copyScript "hg" ${../../../build-support/fetchhg/nix-prefetch-hg} ${mercurial}
|
||||||
copyScript "git" ${../../../build-support/fetchgit/nix-prefetch-git} ${git}
|
copyScript "git" ${../../../build-support/fetchgit/nix-prefetch-git} ${git}
|
||||||
copyScript "svn" ${../../../build-support/fetchsvn/nix-prefetch-svn} ${subversion}
|
copyScript "svn" ${../../../build-support/fetchsvn/nix-prefetch-svn} ${subversion}
|
||||||
copyScript "bzr" ${../../../build-support/fetchbzr/nix-prefetch-bzr} ${bazaar} ${gnused}
|
copyScript "bzr" ${../../../build-support/fetchbzr/nix-prefetch-bzr} ${bazaar}
|
||||||
copyScript "cvs" ${../../../build-support/fetchcvs/nix-prefetch-cvs} ${cvs}
|
copyScript "cvs" ${../../../build-support/fetchcvs/nix-prefetch-cvs} ${cvs}
|
||||||
copyScript "zip" ${./nix-prefetch-zip} ${unzip} ${curl}
|
copyScript "zip" ${../../../build-support/fetchzip/nix-prefetch-zip} ${unzip} ${curl}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = with stdenv.lib; {
|
meta = with stdenv.lib; {
|
||||||
|
Loading…
Reference in New Issue
Block a user