touchosc: make updateScript more readable and robust

Changes:
* factor out different system attrs for nixeval function
* factor out narhash function
* avoid doing work if version has not actually changed
* better support running script directly instead of via
maintainers/scripts/update.nix

+26 -5
+26 -5
pkgs/applications/audio/touchosc/update.sh
··· 1 #!/usr/bin/env nix-shell 2 - #!nix-shell -i bash -p nix curl libxml2 jq common-updater-scripts 3 4 set -euo pipefail 5 ··· 7 8 attr="${UPDATE_NIX_ATTR_PATH:-touchosc}" 9 version="$(curl -sSL https://hexler.net/touchosc/appcast/linux | xmllint --xpath '/rss/channel/item/enclosure/@*[local-name()="version"]' - | cut -d= -f2- | tr -d '"' | head -n1)" 10 11 findpath() { 12 path="$(nix --extra-experimental-features nix-command eval --json --impure -f "$nixpkgs" "$1.meta.position" | jq -r . | cut -d: -f1)" ··· 19 echo "$path" 20 } 21 22 pkgpath="$(findpath "$attr")" 23 24 - sed -i -e "/version\s*=/ s|\"$UPDATE_NIX_OLD_VERSION\"|\"$version\"|" "$pkgpath" 25 26 for system in aarch64-linux armv7l-linux x86_64-linux; do 27 - url="$(nix --extra-experimental-features nix-command eval --json --impure --argstr system "$system" -f "$nixpkgs" "$attr".src.url | jq -r .)" 28 29 - curhash="$(nix --extra-experimental-features nix-command eval --json --impure --argstr system "$system" -f "$nixpkgs" "$attr".src.outputHash | jq -r .)" 30 - newhash="$(nix --extra-experimental-features nix-command store prefetch-file --json "$url" | jq -r .hash)" 31 32 sed -i -e "s|\"$curhash\"|\"$newhash\"|" "$pkgpath" 33 done
··· 1 #!/usr/bin/env nix-shell 2 + #!nix-shell -i bash -p nix curl libxml2 jq 3 4 set -euo pipefail 5 ··· 7 8 attr="${UPDATE_NIX_ATTR_PATH:-touchosc}" 9 version="$(curl -sSL https://hexler.net/touchosc/appcast/linux | xmllint --xpath '/rss/channel/item/enclosure/@*[local-name()="version"]' - | cut -d= -f2- | tr -d '"' | head -n1)" 10 + 11 + narhash() { 12 + nix --extra-experimental-features nix-command store prefetch-file --json "$url" | jq -r .hash 13 + } 14 + 15 + nixeval() { 16 + if [ "$#" -ge 2 ]; then 17 + systemargs=(--argstr system "$2") 18 + else 19 + systemargs=() 20 + fi 21 + 22 + nix --extra-experimental-features nix-command eval --json --impure "${systemargs[@]}" -f "$nixpkgs" "$1" | jq -r . 23 + } 24 25 findpath() { 26 path="$(nix --extra-experimental-features nix-command eval --json --impure -f "$nixpkgs" "$1.meta.position" | jq -r . | cut -d: -f1)" ··· 33 echo "$path" 34 } 35 36 + oldversion="${UPDATE_NIX_OLD_VERSION:-$(nixeval "$attr".version)}" 37 + 38 pkgpath="$(findpath "$attr")" 39 40 + if [ "$version" = "$oldversion" ]; then 41 + echo 'update.sh: New version same as old version, nothing to do.' 42 + exit 0 43 + fi 44 + 45 + sed -i -e "/version\s*=/ s|\"$oldversion\"|\"$version\"|" "$pkgpath" 46 47 for system in aarch64-linux armv7l-linux x86_64-linux; do 48 + url="$(nixeval "$attr".src.url "$system")" 49 50 + curhash="$(nixeval "$attr".src.outputHash "$system")" 51 + newhash="$(narhash "$url")" 52 53 sed -i -e "s|\"$curhash\"|\"$newhash\"|" "$pkgpath" 54 done