···11+#!/usr/bin/env bash
22+set -euo pipefail
33+44+# realwallpaper has no version of its own; it pins two upstream GitHub assets
55+# by commit. Bump each to the head of its default branch and refresh its hash.
66+# Run by update-pkgs from the flake root ($0 is a read-only store copy).
77+attr=realwallpaper
88+dir=pkgs/realwallpaper
99+system=$(nix eval --raw --impure --expr 'builtins.currentSystem')
1010+build_attr=".#packages.$system.$attr"
1111+1212+# file | owner/repo | branch | URL prefix up to (and excluding) the 40-char rev
1313+assets=(
1414+ "$dir/grib2json.nix|krebs/grib2json-bin|master|https://github.com/krebs/grib2json-bin/archive/"
1515+ "$dir/package.nix|ofrohn/d3-celestial|master|https://raw.githubusercontent.com/ofrohn/d3-celestial/"
1616+)
1717+1818+# The probe build is *expected* to fail (hash mismatch); `|| true` keeps
1919+# pipefail/errexit from turning that into an empty `got`. awk must not
2020+# `exit` early or tee dies of SIGPIPE and takes the pipeline with it.
2121+probe_hash() {
2222+ { nix build --no-link "$build_attr" 2>&1 || true; } | tee /dev/stderr \
2323+ | awk '/got:/ && !seen { print $2; seen = 1 }' || true
2424+}
2525+2626+changed=0
2727+for asset in "${assets[@]}"; do
2828+ IFS='|' read -r file repo branch prefix <<<"$asset"
2929+ prefix_re=${prefix//./\\.}
3030+3131+ old_rev=$(grep -oE "${prefix_re}[0-9a-f]{40}" "$file" | sed "s|^${prefix_re}||")
3232+ new_rev=$(curl -fsSL "https://api.github.com/repos/$repo/commits/$branch" | jq -r .sha)
3333+ if [ -z "$old_rev" ] || [ -z "$new_rev" ] || [ "$new_rev" = null ]; then
3434+ echo "$attr: could not determine revisions for $repo (old='$old_rev' new='$new_rev')" >&2
3535+ exit 1
3636+ fi
3737+ if [ "$old_rev" = "$new_rev" ]; then
3838+ echo "$attr: $repo already at $new_rev"
3939+ continue
4040+ fi
4141+4242+ # Bump the rev and blank the hash that follows the URL: with the old hash in
4343+ # place nix would reuse the cached FOD and "succeed" on stale content.
4444+ sed -i \
4545+ -e "s|${prefix_re}${old_rev}|${prefix}${new_rev}|" \
4646+ -e "\|${prefix_re}${new_rev}|,\|hash = |s|hash = \"[^\"]*\"|hash = \"\"|" \
4747+ "$file"
4848+4949+ # Only this asset's hash is blank, so the first mismatch belongs to it.
5050+ got=$(probe_hash)
5151+ if [ -z "$got" ]; then
5252+ echo "$attr: no hash mismatch reported for $repo" >&2
5353+ exit 1
5454+ fi
5555+ sed -i "\|${prefix_re}${new_rev}|,\|hash = |s|hash = \"\"|hash = \"$got\"|" "$file"
5656+ echo "$attr: $repo $old_rev → $new_rev ($got)"
5757+ changed=1
5858+done
5959+6060+if [ "$changed" = 0 ]; then
6161+ echo "$attr: already up to date"
6262+ exit 0
6363+fi
6464+6565+nix build --no-link "$build_attr"