tools/pkgs/d2/update.sh

41 lines
1.2 KiB
Bash
Executable File

#! /usr/bin/env nix-shell
#! nix-shell -i bash -p nix-prefetch-github gnused jq wget
function help() {
echo "Regenerates packaging data for the d2 packages."
echo "Usage: $0 <rev>"
exit 1
}
if [[ $# -gt 1 || $1 == -* ]]; then
help
fi
set -x
cd "$(dirname "$0")"
d2_version="$1"
set -euo pipefail
if [ -z "$d2_version" ]; then
help
fi
tala_version="$(wget -O- "https://api.github.com/repos/terrastruct/TALA/releases?per_page=1" | jq -r '.[0].tag_name')"
d2_hash=$(nix-prefetch-github terrastruct d2 --rev "${d2_version}" | jq -r .sha256)
d2_hash=$(nix hash to-sri --type sha256 "${d2_hash}")
tala_hash=$(nix-prefetch-url "https://github.com/terrastruct/TALA/releases/download/${tala_version}/tala-${tala_version}-linux-amd64.tar.gz")
tala_hash=$(nix hash to-sri --type sha256 "${tala_hash}")
sed -i -E -e "s#rev = \".*\"#rev = \"${d2_version}\"#" d2-unwrapped.nix
sed -i -E -e "s#sha256 = \".*\"#sha256 = \"${d2_hash}\"#" d2-unwrapped.nix
sed -i -E -e "s#version = \".*\"#version = \"$(date +%Y-%m-%d)\"#" d2-unwrapped.nix
sed -i -E -e "s#version = \".*\"#rev = \"${tala_version#v}\"#" d2plugin-tala.nix
sed -i -E -e "s#sha256 = \".*\"#sha256 = \"${tala_hash}\"#" d2plugin-tala.nix