2021-03-16 11:45:19 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
2021-12-15 14:27:57 +00:00
|
|
|
#!nix-shell -i bash -p bash coreutils curl jq gnupg gnugrep
|
2020-03-22 16:14:20 +00:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
|
|
|
|
|
2021-12-15 14:27:57 +00:00
|
|
|
trap 'echo "Error at ${BASH_SOURCE[0]}, line $LINENO"' ERR
|
|
|
|
|
2021-03-16 11:45:19 +00:00
|
|
|
repo=fort-nix/nix-bitcoin
|
|
|
|
if [[ ! -v version ]]; then
|
2022-05-17 11:18:38 +00:00
|
|
|
version=$(curl -fsS "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)
|
2022-08-16 19:00:00 +00:00
|
|
|
trap 'rm -rf $TMPDIR' EXIT
|
2021-03-16 11:45:19 +00:00
|
|
|
|
2022-02-03 19:46:29 +00:00
|
|
|
export GNUPGHOME=$TMPDIR/gpg-home
|
2022-08-16 19:00:00 +00:00
|
|
|
mkdir -m 700 "$GNUPGHOME"
|
2020-03-22 16:14:20 +00:00
|
|
|
|
2021-03-16 11:45:19 +00:00
|
|
|
# Import key
|
2022-02-03 19:46:29 +00:00
|
|
|
gpg --import "$scriptDir/key-jonasnick.bin" &> /dev/null
|
2021-12-15 14:27:57 +00:00
|
|
|
# Check that exactly one key was imported
|
2022-02-03 19:46:29 +00:00
|
|
|
(($(gpg --list-keys --with-colons | grep -c pub) == 1))
|
2021-03-16 11:45:19 +00:00
|
|
|
# Verify key fingerprint
|
2022-02-03 19:46:29 +00:00
|
|
|
gpg --list-keys "36C7 1A37 C9D9 88BD E825 08D9 B1A7 0E4F 8DCD 0366" > /dev/null
|
2020-03-22 16:14:20 +00:00
|
|
|
|
2021-09-08 15:01:17 +00:00
|
|
|
# Fetch nar-hash of release
|
2022-08-16 19:00:00 +00:00
|
|
|
cd "$TMPDIR"
|
2021-09-08 15:01:17 +00:00
|
|
|
baseUrl=https://github.com/$repo/releases/download/v$version
|
2022-08-16 19:00:00 +00:00
|
|
|
curl -fsS -L -O "$baseUrl/nar-hash.txt"
|
|
|
|
curl -fsS -L -O "$baseUrl/nar-hash.txt.asc"
|
2021-09-08 15:01:17 +00:00
|
|
|
|
|
|
|
# Verify signature for nar-hash
|
2022-02-03 19:46:29 +00:00
|
|
|
gpg --verify nar-hash.txt.asc &> /dev/null || {
|
2021-09-13 08:19:30 +00:00
|
|
|
>&2 echo "Error: Signature verification failed. Please open an issue in the project repository."
|
2020-03-22 16:14:20 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:01:17 +00:00
|
|
|
>&2 echo "Fetched and verified release $version"
|
|
|
|
|
2020-03-22 16:14:20 +00:00
|
|
|
cat <<EOF
|
2021-09-08 15:01:17 +00:00
|
|
|
builtins.fetchTarball {
|
|
|
|
url = "https://github.com/$repo/archive/v$version.tar.gz";
|
|
|
|
sha256 = "$(cat nar-hash.txt)";
|
2020-03-22 16:14:20 +00:00
|
|
|
}
|
|
|
|
EOF
|