2021-03-16 11:45:19 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell -i bash -p bash coreutils curl jq gnupg
|
2020-03-22 16:14:20 +00:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
|
|
|
|
|
2021-03-16 11:45:19 +00:00
|
|
|
repo=fort-nix/nix-bitcoin
|
|
|
|
if [[ ! -v version ]]; then
|
|
|
|
version=$(curl --silent "https://api.github.com/repos/$repo/releases/latest" | jq -r '.tag_name' | tail -c +2)
|
2020-03-22 16:14:20 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
TMPDIR=$(mktemp -d)
|
2021-03-16 11:45:19 +00:00
|
|
|
trap "rm -rf $TMPDIR" EXIT
|
|
|
|
|
|
|
|
GPG_HOME=$TMPDIR/gpg-home
|
|
|
|
mkdir -p -m 700 "$GPG_HOME"
|
2020-03-22 16:14:20 +00:00
|
|
|
|
|
|
|
cd $TMPDIR
|
2021-03-16 11:45:19 +00:00
|
|
|
baseUrl=https://github.com/$repo/releases/download/v$version
|
|
|
|
curl --silent -L -O $baseUrl/SHA256SUMS.txt
|
|
|
|
curl --silent -L -O $baseUrl/SHA256SUMS.txt.asc
|
2020-03-22 16:14:20 +00:00
|
|
|
|
2021-03-16 11:45:19 +00:00
|
|
|
# Import key
|
2020-03-22 16:14:20 +00:00
|
|
|
gpg --homedir $GPG_HOME --import "$scriptDir/key-jonasnick.bin" &> /dev/null
|
2021-03-16 11:45:19 +00:00
|
|
|
# Verify key fingerprint
|
2020-03-22 16:14:20 +00:00
|
|
|
gpg --homedir $GPG_HOME --list-keys 36C71A37C9D988BDE82508D9B1A70E4F8DCD0366 > /dev/null
|
|
|
|
|
2021-03-16 11:45:19 +00:00
|
|
|
# Verify signature for SHA256SUMS.txt
|
2020-03-22 16:14:20 +00:00
|
|
|
gpg --homedir $GPG_HOME --verify SHA256SUMS.txt.asc &> /dev/null || {
|
2021-03-16 11:45:19 +00:00
|
|
|
echo "Error: Signature verification failed. Please open an issue in the project repository."
|
2020-03-22 16:14:20 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-03-16 11:45:19 +00:00
|
|
|
sha256=$(cat SHA256SUMS.txt | cut -d\ -f1)
|
2020-03-22 16:14:20 +00:00
|
|
|
cat <<EOF
|
|
|
|
{
|
2021-03-16 11:45:19 +00:00
|
|
|
url = "$baseUrl/nix-bitcoin-$version.tar.gz";
|
|
|
|
sha256 = "$sha256";
|
2020-03-22 16:14:20 +00:00
|
|
|
}
|
|
|
|
EOF
|