electrum: implement crude updater

Takes care of the tedium of checking signatures & whatnot. Does not update
checksum for the tests yet ...

Usage
$ nix-shell maintainers/scripts/update.nix --argstr package electrum

Warning: dumps cruft to $PWD

+88 -1
+29 -1
pkgs/applications/misc/electrum/default.nix
··· 1 - { stdenv, fetchurl, fetchFromGitHub, python3, python3Packages, zbar, secp256k1 }: 1 + { stdenv, fetchurl, fetchFromGitHub, python3, python3Packages, zbar, secp256k1 2 + 3 + 4 + # for updater.nix 5 + , writeScript 6 + , common-updater-scripts 7 + , bash 8 + , coreutils 9 + , curl 10 + , gnugrep 11 + , gnupg 12 + , gnused 13 + , nix 14 + }: 2 15 3 16 let 4 17 version = "3.3.6"; ··· 84 97 py.test electrum/tests 85 98 $out/bin/electrum help >/dev/null 86 99 ''; 100 + 101 + passthru.updateScript = import ./update.nix { 102 + inherit (stdenv) lib; 103 + inherit 104 + writeScript 105 + common-updater-scripts 106 + bash 107 + coreutils 108 + curl 109 + gnupg 110 + gnugrep 111 + gnused 112 + nix 113 + ; 114 + }; 87 115 88 116 meta = with stdenv.lib; { 89 117 description = "A lightweight Bitcoin wallet";
+59
pkgs/applications/misc/electrum/update.nix
··· 1 + { lib 2 + , writeScript 3 + , common-updater-scripts 4 + , bash 5 + , coreutils 6 + , curl 7 + , gnugrep 8 + , gnupg 9 + , gnused 10 + , nix 11 + }: 12 + 13 + with lib; 14 + 15 + let 16 + downloadPageUrl = "https://download.electrum.org"; 17 + 18 + signingKeys = ["6694 D8DE 7BE8 EE56 31BE D950 2BD5 824B 7F94 70E6"]; 19 + in 20 + 21 + writeScript "update-electrum" '' 22 + #! ${bash}/bin/bash 23 + 24 + set -eu -o pipefail 25 + 26 + export PATH=${makeBinPath [ 27 + common-updater-scripts 28 + coreutils 29 + curl 30 + gnugrep 31 + gnupg 32 + gnused 33 + nix 34 + ]} 35 + 36 + version=$(curl -L --list-only -- '${downloadPageUrl}' \ 37 + | grep -Po '<a href="\K([[:digit:]]+\.?)+' \ 38 + | sort -Vu \ 39 + | tail -n1) 40 + 41 + srcName=Electrum-$version 42 + srcFile=$srcName.tar.gz 43 + srcUrl="${downloadPageUrl}/$version/$srcFile" 44 + sigUrl=$srcUrl.asc 45 + sigFile=$srcFile.asc 46 + 47 + [[ -e "$srcFile" ]] || curl -L -o "$srcFile" -- "$srcUrl" 48 + [[ -e "$sigFile" ]] || curl -L -o "$sigFile" -- "$sigUrl" 49 + 50 + export GNUPGHOME=$PWD/gnupg 51 + mkdir -m 700 -p "$GNUPGHOME" 52 + 53 + gpg --batch --recv-keys ${concatStringsSep " " (map (x: "'${x}'") signingKeys)} 54 + gpg --batch --verify "$sigFile" "$srcFile" 55 + 56 + sha256=$(nix-prefetch-url --type sha256 "file://$PWD/$srcFile") 57 + 58 + update-source-version electrum "$version" "$sha256" 59 + ''