Skip to content

Commit

Permalink
feat: add update.sh script to besu
Browse files Browse the repository at this point in the history
  • Loading branch information
aldoborrero committed Feb 13, 2024
1 parent 90bdadd commit e5851a2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkgs/besu/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq nix sd

set -e

dirname="$(dirname "$0")"
rootDir="$(git -C "$dirname" rev-parse --show-toplevel)"
pname="besu"

updateVersion() {
local version=$1
sd "version = \"[0-9.]*\";" "version = \"$version\";" "${dirname}/default.nix"
}

updateHash() {
local version=$1
local url="https://hyperledger.jfrog.io/hyperledger/${pname}-binaries/${pname}/${version}/${pname}-${version}.tar.gz"
local sriHash=$(nix store prefetch-file --json "$url" | jq -r .hash)
sd 'hash = "[a-zA-Z0-9/+-=]*";' "hash = \"$sriHash\";" "${dirname}/default.nix"
}

currentVersion=$(nix derivation show "${rootDir}#${pname}" | jq -r '.[].env.version')
latestVersion=$(curl -s "https://hyperledger.jfrog.io/artifactory/api/search/latestVersion?g=org.hyperledger.besu.internal&a=besu")

if [[ "$currentVersion" == "$latestVersion" ]]; then
echo "${pname} is up to date: ${currentVersion}"
exit 0
fi

echo "Updating ${pname} from ${currentVersion} to ${latestVersion}"

updateVersion "$latestVersion"
updateHash "$latestVersion"
2 changes: 2 additions & 0 deletions pkgs/teku/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ stdenv.mkDerivation rec {
wrapProgram $out/bin/${pname} --set JAVA_HOME "${jre}"
'';

passtrhu.updateScript = ./update.sh;

meta = with lib; {
description = "Java Implementation of the Ethereum 2.0 Beacon Chain";
homepage = "https://github.com/ConsenSys/teku";
Expand Down
40 changes: 40 additions & 0 deletions pkgs/teku/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq nix sd

set -e

dirname="$(dirname "$0")"
rootDir="$(git -C "$dirname" rev-parse --show-toplevel)"
pname="teku"

updateVersion() {
local version=$1
sd "version = \"[0-9.]*\";" "version = \"$version\";" "${dirname}/default.nix"
}

updateHash() {
local version=$1
local url="https://artifacts.consensys.net/public/${pname}/raw/names/${pname}.tar.gz/versions/${version}/${pname}-${version}.tar.gz"

local output=$(nix store prefetch-file --json "$url")
local sriHash=$(echo "$output" | jq -r .hash)

sd "\"hash\" = \"[a-zA-Z0-9\/+-=]*\";" "\"hash\" = \"$sriHash\";" "${dirname}/default.nix"
}

currentVersion=$(nix show-derivation "${rootDir}#${pname}" | jq -r '.[].env.version')
latestVersion=$(curl -s "https://api.github.com/repos/ConsenSys/teku/releases/latest" | jq -r '.tag_name')

# Optionally strip leading 'v' if present in the tag name
latestVersion=${latestVersion#v}

if [[ "$currentVersion" == "$latestVersion" ]]; then
echo "${pname} is up to date: ${currentVersion}"
exit 0
fi

echo "Updating ${pname} from ${currentVersion} to ${latestVersion}"

updateVersion "$latestVersion"
updateHash "$latestVersion"

0 comments on commit e5851a2

Please sign in to comment.