summary refs log tree commit diff
path: root/pkgs/applications/blockchains/nbxplorer/util
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-08-04 10:43:07 +0000
committerAlyssa Ross <hi@alyssa.is>2021-08-04 10:43:07 +0000
commit62614cbef7da005c1eda8c9400160f6bcd6546b8 (patch)
treec2630f69080637987b68acb1ee8676d2681fe304 /pkgs/applications/blockchains/nbxplorer/util
parentd9c82ed3044c72cecf01c6ea042489d30914577c (diff)
parente24069138dfec3ef94f211f1da005bb5395adc11 (diff)
downloadnixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar
nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.gz
nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.bz2
nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.lz
nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.xz
nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.zst
nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.zip
Merge branch 'nixpkgs-update' into master
Diffstat (limited to 'pkgs/applications/blockchains/nbxplorer/util')
-rwxr-xr-xpkgs/applications/blockchains/nbxplorer/util/create-deps.sh46
-rwxr-xr-xpkgs/applications/blockchains/nbxplorer/util/update-common.sh75
2 files changed, 121 insertions, 0 deletions
diff --git a/pkgs/applications/blockchains/nbxplorer/util/create-deps.sh b/pkgs/applications/blockchains/nbxplorer/util/create-deps.sh
new file mode 100755
index 00000000000..fb10446142e
--- /dev/null
+++ b/pkgs/applications/blockchains/nbxplorer/util/create-deps.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p dotnet-sdk_3
+set -euo pipefail
+
+# Writes deps for dotnet package in $pkgSrc to $depsFile.
+# Expects $pkgSrc to contain a single .sln file.
+
+pkgSrc=$1
+depsFile=$(realpath "$2")
+customFlags=$3
+
+sln=$(cd "$pkgSrc"; find * -maxdepth 0 -name '*.sln' | head -1)
+[[ $sln ]] || { echo "No .sln file in $pkgSrc" ; exit 1; }
+
+tmpdir=$(mktemp -d /tmp/$pkgName-src.XXX)
+echo "Using tmp dir: $tmpdir"
+cp -rT "$pkgSrc" "$tmpdir"
+chmod -R +w "$tmpdir"
+
+pushd "$tmpdir" > /dev/null
+mkdir home
+echo "Running dotnet restore for $sln"
+HOME=home DOTNET_CLI_TELEMETRY_OPTOUT=1 \
+  dotnet restore $customFlags -v normal --no-cache "$sln" > restore_log
+
+echo "{ fetchNuGet }: [" > "$depsFile"
+while read pkgSpec; do
+  { read name; read version; } < <(
+    # Ignore build version part: 1.0.0-beta2+77df2220 -> 1.0.0-beta2
+    sed -nE 's/.*<id>([^<]*).*/\1/p; s/.*<version>([^<+]*).*/\1/p' "$pkgSpec"
+  )
+  sha256=$(nix-hash --type sha256 --flat --base32 "$(dirname "$pkgSpec")"/*.nupkg)
+  cat >> "$depsFile" <<EOF
+  (fetchNuGet {
+    name = "$name";
+    version = "$version";
+    sha256 = "$sha256";
+  })
+EOF
+done < <(find home/.nuget/packages -name '*.nuspec' | LC_ALL=C sort)
+echo "]" >> "$depsFile"
+
+echo "Created $depsFile"
+
+popd > /dev/null
+rm -r $tmpdir
diff --git a/pkgs/applications/blockchains/nbxplorer/util/update-common.sh b/pkgs/applications/blockchains/nbxplorer/util/update-common.sh
new file mode 100755
index 00000000000..a9912b8b368
--- /dev/null
+++ b/pkgs/applications/blockchains/nbxplorer/util/update-common.sh
@@ -0,0 +1,75 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p coreutils curl jq common-updater-scripts dotnet-sdk_3 git gnupg
+set -euo pipefail
+
+# This script uses the following env vars:
+# getVersionFromTags
+# refetch
+
+pkgName=$1
+depsFile=$2
+customFlags=$3
+
+: ${getVersionFromTags:=}
+: ${refetch:=}
+
+scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
+nixpkgs=$(realpath "$scriptDir"/../../../../..)
+
+evalNixpkgs() {
+  nix eval --raw "(with import \"$nixpkgs\" {}; $1)"
+}
+
+getRepo() {
+  url=$(evalNixpkgs $pkgName.src.meta.homepage)
+  echo $(basename $(dirname $url))/$(basename $url)
+}
+
+getLatestVersionTag() {
+  "$nixpkgs"/pkgs/common-updater/scripts/list-git-tags https://github.com/$(getRepo) 2>/dev/null \
+    | sort -V | tail -1 | sed 's|^v||'
+}
+
+oldVersion=$(evalNixpkgs "$pkgName.version")
+if [[ $getVersionFromTags ]]; then
+  newVersion=$(getLatestVersionTag)
+else
+  newVersion=$(curl -s "https://api.github.com/repos/$(getRepo)/releases" | jq -r '.[0].name')
+fi
+
+if [[ $newVersion == $oldVersion && ! $refetch ]]; then
+  echo "nixpkgs already has the latest version $newVersion"
+  echo "Run this script with env var refetch=1 to re-verify the content hash via GPG"
+  echo "and to recreate $(basename "$depsFile"). This is useful for reviewing a version update."
+  exit 0
+fi
+
+# Fetch release and GPG-verify the content hash
+tmpdir=$(mktemp -d /tmp/$pkgName-verify-gpg.XXX)
+repo=$tmpdir/repo
+trap "rm -rf $tmpdir" EXIT
+git clone --depth 1 --branch v${newVersion} -c advice.detachedHead=false https://github.com/$(getRepo) $repo
+export GNUPGHOME=$tmpdir
+# Fetch Nicolas Dorier's key (64-bit key ID: 6618763EF09186FE)
+gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys AB4CFA9895ACA0DBE27F6B346618763EF09186FE 2> /dev/null
+echo
+echo "Verifying commit"
+git -C $repo verify-commit HEAD
+rm -rf $repo/.git
+newHash=$(nix hash-path $repo)
+rm -rf $tmpdir
+echo
+
+# Update pkg version and hash
+echo "Updating $pkgName: $oldVersion -> $newVersion"
+if [[ $newVersion == $oldVersion ]]; then
+  # Temporarily set a source version that doesn't equal $newVersion so that $newHash
+  # is always updated in the next call to update-source-version.
+  (cd "$nixpkgs" && update-source-version "$pkgName" "0" "0000000000000000000000000000000000000000000000000000")
+fi
+(cd "$nixpkgs" && update-source-version "$pkgName" "$newVersion" "$newHash")
+echo
+
+# Create deps file
+storeSrc="$(nix-build "$nixpkgs" -A $pkgName.src --no-out-link)"
+. "$scriptDir"/create-deps.sh "$storeSrc" "$depsFile" "$customFlags"