add nix-prefetch- scripts for now, were externals in svn
[?]
Oct 29, 2011, 2:12 AM
KX5L74EYLS4YVSFG5H6U5H5TB6BQUFHHFUMLHTUUU6WFJLSRF5ZACDependencies
- [2]
D5QIOJGP* Move everything up one directory.
Change contents
- file addition: nix-prefetch-bzr[2.2543]
#! /bin/sh -eurl=$1rev=$2expHash=$3hashType=$NIX_HASH_ALGOif test -z "$hashType"; thenhashType=sha256fiif test -z "$hashFormat"; thenhashFormat=--base32fiif test -z "$url"; thenecho "syntax: nix-prefetch-bzr URL [REVISION [EXPECTED-HASH]]" >&2exit 1firevarg="-r $rev"test -n "$rev" || revarg=""repoName=$(echo $url | sed 's,.*/\([^/]\+\)/trunk/*$,\1,;ts,.*/\([^/]\+\)/branches/\([^/]\+\)/*$,\1-\2,;ts,.*/\([^/]\+\)/tags/\([^/]\+\)/*$,\1-\2,;ts,.*/\([^/]\+\)/*$,\1,;t')dstFile=$repoName-r$revtest -n "$rev" || dstFile=$repoName# If the hash was given, a file with that hash may already be in the# store.if test -n "$expHash"; thenfinalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" $dstFile)if ! nix-store --check-validity "$finalPath" 2> /dev/null; thenfinalPath=fihash=$expHashfi# If we don't know the hash or a path with that hash doesn't exist,# download the file and add it to the store.if test -z "$finalPath"; thentmpPath=/tmp/bzr-checkout-tmp-$$tmpFile=$tmpPath/$dstFilemkdir $tmpPathtrap "rm -rf $tmpPath" EXIT# Perform the checkout.if test "$NIX_PREFETCH_BZR_LEAVE_DOT_BZR" != 1thenbzr export $revarg "$tmpFile" "$url" >&2elsebzr checkout --lightweight $revarg "$url" "$tmpFile" >&2fi# Compute the hash.hash=$(nix-hash --type $hashType $hashFormat $tmpFile)if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi# Add the downloaded file to the Nix store.finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)if test -n "$expHash" -a "$expHash" != "$hash"; thenecho "hash mismatch for URL \`$url'"exit 1fifiif ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fiecho $hashif test -n "$PRINT_PATH"; thenecho $finalPathfi - file addition: nix-prefetch-git[2.2543]
#! /bin/sh -eurl=$1rev=$2expHash=$3hashType=$NIX_HASH_ALGOdeepClone=$NIX_PREFETCH_GIT_DEEP_CLONEleaveDotGit=$NIX_PREFETCH_GIT_LEAVE_DOT_GITbuilder=if test -n "$deepClone"; thendeepClone=trueelsedeepClone=falsefiif test "$leaveDotGit" != 1; thenleaveDotGit=elseleaveDotGit=truefiargi=0argfun=""for arg; doif test -z "$argfun"; thencase $arg in--out) argfun=set_out;;--url) argfun=set_url;;--rev) argfun=set_rev;;--hash) argfun=set_hashType;;--deepClone) deepClone=true;;--no-deepClone) deepClone=false;;--leave-dotGit) leaveDotGit=true;;--builder) builder=true;;*)argi=$(($argi + 1))case $argi in1) url=$arg;;2) rev=$arg;;3) expHash=$arg;;*) exit 1;;esac;;esacelsecase $argfun inset_*)var=$(echo $argfun | sed 's,^set_,,')eval $var=$arg;;esacargfun=""fidoneusage(){echo >&2 "syntax: nix-prefetch-git [options] [URL [REVISION [EXPECTED-HASH]]]Options:--out path Path where the output would be stored.--url url Any url understand by 'git clone'.--rev ref Any sha1 or references (such as refs/heads/master)--hash h Expected hash.--deepClone Clone submodules recursively.--no-deepClone Do not clone submodules.--leave-dotGit Keep the .git directories.--builder Clone as fetchgit does, but url, rev, and out option are mandatory."exit 1}if test -z "$url"; thenusagefiinit_remote(){local url=$1;git init;git remote add origin $url;}# Return the reference of an hash if it exists on the remote repository.ref_from_hash(){local hash=$1;git ls-remote origin | sed -n "\,$hash\t, { s,\(.*\)\t\(.*\),\2,; p; q}"}# Return the hash of a reference if it exists on the remote repository.hash_from_ref(){local ref=$1git ls-remote origin | sed -n "\,\t$ref, { s,\(.*\)\t\(.*\),\1,; p; q}"}# Fetch everything and checkout the right sha1checkout_hash(){local hash="$1";local ref="$2";if test -z "$hash"; thenhash=$(hash_from_ref $ref);fi;git fetch ${builder:+--progress} origin || return 1git checkout -b fetchgit $hash || return 1}# Fetch only a branch/tag and checkout it.checkout_ref(){local hash="$1";local ref="$2";if "$deepClone"; then# The caller explicitly asked for a deep clone. Deep clones# allow "git describe" and similar tools to work. See# http://thread.gmane.org/gmane.linux.distributions.nixos/3569# for a discussion.return 1fiif test -z "$ref"; thenref=$(ref_from_hash $hash);fi;if test -n "$ref"; then# --depth option is ignored on http repository.git fetch ${builder:+--progress} --depth 1 origin +"$ref" || return 1git checkout -b fetchgit FETCH_HEAD || return 1elsereturn 1;fi;}# Update submodulesinit_submodules(){# Add urls into .git/config filegit submodule init# list submodule directories and their hashesgit submodule status |while read l; do# checkout each submodulelocal hash=$(echo $l | sed 's,^-\([0-9a-f]*\) \(.*\)$,\1,');local dir=$(echo $l | sed 's,^-\([0-9a-f]*\) \(.*\)$,\2,');local url=$(sed -n "\,$dir, { :loop; n; s,^.*url = ,,; T loop; p; q }" .git/config);clone "$dir" "$url" "$hash" "";done;}clone(){local top=$(pwd)local dir="$1"local url="$2"local hash="$3"local ref="$4"cd $dir;# Initialize the repository.init_remote "$url";# Download data from the repository.checkout_ref "$hash" "$ref" ||checkout_hash "$hash" "$ref" || (echo 1>&2 "Unable to checkout $hash$ref from $url.";exit 1;)# Checkout linked sources.init_submodules;if [ -z "$builder" -a -f .topdeps ]; thenif tg help 2>&1 > /dev/nullthenecho "populating TopGit branches..."tg remote --populate originelseecho "WARNING: would populate TopGit branches but TopGit is not available" >&2echo "WARNING: install TopGit to fix the problem" >&2fificd $top;}clone_user_rev() {local dir="$1"local url="$2"local rev="$3"# Perform the checkout.case "$rev" inHEAD|refs/*)clone "$dir" "$url" "" "$rev" 1>&2;;[0-9a-f]*)if test -z "$(echo $rev | tr -d 0123456789abcdef)"; thenclone "$dir" "$url" "$rev" "" 1>&2;elseecho 1>&2 "Bad commit hash or bad reference.";exit 1;fi;;"")clone "$dir" "$url" "" "HEAD" 1>&2;;esac# Allow doing additional processing before .git removaleval "$NIX_PREFETCH_GIT_CHECKOUT_HOOK"if test -z "$leaveDotGit"; thenecho "removing \`.git'..." >&2find $dir -name .git\* | xargs rm -rffi}if test -n "$builder"; thentest -n "$out" -a -n "$url" -a -n "$rev" || usagemkdir $outclone_user_rev "$out" "$url" "$rev"elseif test -z "$hashType"; thenhashType=sha256fi# If the hash was given, a file with that hash may already be in the# store.if test -n "$expHash"; thenfinalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" git-export)if ! nix-store --check-validity "$finalPath" 2> /dev/null; thenfinalPath=fihash=$expHashfi# If we don't know the hash or a path with that hash doesn't exist,# download the file and add it to the store.if test -z "$finalPath"; thentmpPath=/tmp/git-checkout-tmp-$$tmpFile=$tmpPath/git-exportmkdir $tmpPath $tmpFiletrap "rm -rf $tmpPath" EXIT# Perform the checkout.clone_user_rev "$tmpFile" "$url" "$rev"# Compute the hash.hash=$(nix-hash --type $hashType $hashFormat $tmpFile)if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi# Add the downloaded file to the Nix store.finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)if test -n "$expHash" -a "$expHash" != "$hash"; thenecho "hash mismatch for URL \`$url'"exit 1fifiif ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fiecho $hashif test -n "$PRINT_PATH"; thenecho $finalPathfifi - file addition: nix-prefetch-hg[2.2543]
#! /bin/sh -eurl=$1rev=$2expHash=$3hashType=$NIX_HASH_ALGOif test -z "$hashType"; thenhashType=sha256fiif test -z "$hashFormat"; thenhashFormat=--base32fiif test -z "$url"; thenecho "syntax: nix-prefetch-hg URL [rev [EXPECTED-HASH]]" >&2exit 1fitest -n "$rev" || rev="tip"# If the hash was given, a file with that hash may already be in the# store.if test -n "$expHash"; thenfinalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" hg-archive)if ! nix-store --check-validity "$finalPath" 2> /dev/null; thenfinalPath=fihash=$expHashfi# If we don't know the hash or a path with that hash doesn't exist,# download the file and add it to the store.if test -z "$finalPath"; thentmpPath=/tmp/hg-checkout-tmp-$$tmpArchive=$tmpPath/hg-archivemkdir $tmpPathtrap "rm -rf $tmpPath" EXIT# Perform the checkout.if [[ $url != /* ]]; thentmpClone=$tmpPath/hg-clonehg clone -q -y -U "$url" $tmpClone >&2elsetmpClone=$urlfihg archive -q -y -r "$rev" --cwd $tmpClone $tmpArchive# Compute the hash.hash=$(nix-hash --type $hashType $hashFormat $tmpArchive)if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi# Add the downloaded file to the Nix store.finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpArchive)if test -n "$expHash" -a "$expHash" != "$hash"; thenecho "hash mismatch for URL \`$url'"exit 1fifiif ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fiecho $hashif test -n "$PRINT_PATH"; thenecho $finalPathfi - file addition: nix-prefetch-svn[2.2543]
#! /bin/sh -eurl=$1rev=$2expHash=$3hashType=$NIX_HASH_ALGOif test -z "$hashType"; thenhashType=sha256fiif test -z "$hashFormat"; thenhashFormat=--base32fiif test -z "$url"; thenecho "syntax: nix-prefetch-svn URL [REVISION [EXPECTED-HASH]]" >&2exit 1fitest -n "$rev" || rev="HEAD"repoName=$(echo $url | sed 's,.*/\([^/]\+\)/trunk/*$,\1,;ts,.*/\([^/]\+\)/branches/\([^/]\+\)/*$,\1-\2,;ts,.*/\([^/]\+\)/tags/\([^/]\+\)/*$,\1-\2,;ts,.*/\([^/]\+\)/*$,\1,;t')dstFile=$repoName-r$rev# If the hash was given, a file with that hash may already be in the# store.if test -n "$expHash"; thenfinalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" $dstFile)if ! nix-store --check-validity "$finalPath" 2> /dev/null; thenfinalPath=fihash=$expHashfi# If we don't know the hash or a path with that hash doesn't exist,# download the file and add it to the store.if test -z "$finalPath"; thentmpPath=/tmp/svn-checkout-tmp-$$tmpFile=$tmpPath/$dstFilemkdir $tmpPathtrap "rm -rf $tmpPath" EXIT# Perform the checkout.if test "$NIX_PREFETCH_SVN_LEAVE_DOT_SVN" != 1thencommand="export"elsecommand="checkout"fiecho p | svn "$command" --quiet -r "$rev" "$url" "$tmpFile" >&2# Compute the hash.hash=$(nix-hash --type $hashType $hashFormat $tmpFile)if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi# Add the downloaded file to the Nix store.finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)if test -n "$expHash" -a "$expHash" != "$hash"; thenecho "hash mismatch for URL \`$url'"exit 1fifiif ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fiecho $hashif test -n "$PRINT_PATH"; thenecho $finalPathfi