biglybt: 3.5.0.0 -> 3.6.0.0
[NixPkgs.git] / pkgs / applications / blockchains / nbxplorer / util / update-common.sh
blob1354588a75491239623ddf8bfbdd60fe73f41c95
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p coreutils curl jq common-updater-scripts dotnet-sdk_6 git gnupg nixFlakes
3 set -euo pipefail
5 # This script uses the following env vars:
6 # getVersionFromTags
7 # refetch
9 trap 'echo "Error at ${BASH_SOURCE[0]}:$LINENO"' ERR
11 pkgName=$1
13 : ${getVersionFromTags:=}
14 : ${refetch:=}
16 scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
17 nixpkgs=$(realpath "$scriptDir"/../../../../..)
19 evalNixpkgs() {
20 nix eval --impure --raw --expr "(with import \"$nixpkgs\" {}; $1)"
23 getRepo() {
24 url=$(evalNixpkgs $pkgName.src.meta.homepage)
25 echo $(basename $(dirname $url))/$(basename $url)
28 getLatestVersionTag() {
29 "$nixpkgs"/pkgs/common-updater/scripts/list-git-tags --url=https://github.com/$(getRepo) 2>/dev/null \
30 | sort -V | tail -1 | sed 's|^v||'
33 oldVersion=$(evalNixpkgs "$pkgName.version")
34 if [[ $getVersionFromTags ]]; then
35 newVersion=$(getLatestVersionTag)
36 else
37 newVersion=$(curl -s "https://api.github.com/repos/$(getRepo)/releases" | jq -r '.[0].name')
40 if [[ $newVersion == $oldVersion && ! $refetch ]]; then
41 echo "nixpkgs already has the latest version $newVersion"
42 echo "Run this script with env var refetch=1 to re-verify the content hash via GPG"
43 echo "and to recreate deps.nix. This is useful for reviewing a version update."
44 exit 0
47 # Fetch release and GPG-verify the content hash
48 tmpdir=$(mktemp -d /tmp/$pkgName-verify-gpg.XXX)
49 repo=$tmpdir/repo
50 trap "rm -rf $tmpdir" EXIT
51 git clone --depth 1 --branch v${newVersion} -c advice.detachedHead=false https://github.com/$(getRepo) $repo
52 export GNUPGHOME=$tmpdir
53 # Fetch Nicolas Dorier's key (64-bit key ID: 6618763EF09186FE)
54 gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys AB4CFA9895ACA0DBE27F6B346618763EF09186FE 2> /dev/null
55 # Fetch Andrew Camilleri's key (64-bit key ID: 8E5530D9D1C93097)
56 gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 836C08CF3F523BB7A8CB8ECF8E5530D9D1C93097 2> /dev/null
57 echo
58 echo "Verifying commit"
59 git -C $repo verify-commit HEAD
60 rm -rf $repo/.git
61 newHash=$(nix hash-path $repo)
62 rm -rf $tmpdir
63 echo
65 # Update pkg version and hash
66 echo "Updating $pkgName: $oldVersion -> $newVersion"
67 if [[ $newVersion == $oldVersion ]]; then
68 # Temporarily set a source version that doesn't equal $newVersion so that $newHash
69 # is always updated in the next call to update-source-version.
70 (cd "$nixpkgs" && update-source-version "$pkgName" "0" "0000000000000000000000000000000000000000000000000000")
72 (cd "$nixpkgs" && update-source-version "$pkgName" "$newVersion" "$newHash")
73 echo
75 # Create deps file
76 $(nix-build "$nixpkgs" -A $pkgName.fetch-deps --no-out-link)