Created
April 20, 2018 09:54
-
-
Save danbst/1b7d6b97401ebdc34df0a03b8f3a1424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env nix-shell | |
#!nix-shell -i bash -p gitMinimal nix-prefetch-git jq | |
set -e | |
project="$1" | |
branch="${2:-master}" | |
owner=$(echo "$project" | cut -d/ -f1) | |
repo=$(echo "$project" | cut -d/ -f2) | |
rev=$(git ls-remote "git://github.com/$project.git" "$branch" | head -n1 | awk '{print $1}') | |
rev=${rev:-$2} | |
hash=$(nix-prefetch-url "https://github.com/$project/archive/$rev.tar.gz") | |
function show() { | |
cat << EOF | |
{ | |
"owner": "$owner", | |
"repo": "$repo", | |
"rev": "$rev", | |
"sha256": "$hash" | |
} | |
EOF | |
} | |
show | |
hash=$(nix-prefetch-git "github.com/$project.git" --rev "$rev" --quiet | jq -r .sha256) | |
show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment