This repository has no description
2.4 kB
65 lines
1#!/usr/bin/env bash
2set -euo pipefail
3
4# realwallpaper has no version of its own; it pins two upstream GitHub assets
5# by commit. Bump each to the head of its default branch and refresh its hash.
6# Run by update-pkgs from the flake root ($0 is a read-only store copy).
7attr=realwallpaper
8dir=pkgs/realwallpaper
9system=$(nix eval --raw --impure --expr 'builtins.currentSystem')
10build_attr=".#packages.$system.$attr"
11
12# file | owner/repo | branch | URL prefix up to (and excluding) the 40-char rev
13assets=(
14 "$dir/grib2json.nix|krebs/grib2json-bin|master|https://github.com/krebs/grib2json-bin/archive/"
15 "$dir/package.nix|ofrohn/d3-celestial|master|https://raw.githubusercontent.com/ofrohn/d3-celestial/"
16)
17
18# The probe build is *expected* to fail (hash mismatch); `|| true` keeps
19# pipefail/errexit from turning that into an empty `got`. awk must not
20# `exit` early or tee dies of SIGPIPE and takes the pipeline with it.
21probe_hash() {
22 { nix build --no-link "$build_attr" 2>&1 || true; } | tee /dev/stderr \
23 | awk '/got:/ && !seen { print $2; seen = 1 }' || true
24}
25
26changed=0
27for asset in "${assets[@]}"; do
28 IFS='|' read -r file repo branch prefix <<<"$asset"
29 prefix_re=${prefix//./\\.}
30
31 old_rev=$(grep -oE "${prefix_re}[0-9a-f]{40}" "$file" | sed "s|^${prefix_re}||")
32 new_rev=$(curl -fsSL "https://api.github.com/repos/$repo/commits/$branch" | jq -r .sha)
33 if [ -z "$old_rev" ] || [ -z "$new_rev" ] || [ "$new_rev" = null ]; then
34 echo "$attr: could not determine revisions for $repo (old='$old_rev' new='$new_rev')" >&2
35 exit 1
36 fi
37 if [ "$old_rev" = "$new_rev" ]; then
38 echo "$attr: $repo already at $new_rev"
39 continue
40 fi
41
42 # Bump the rev and blank the hash that follows the URL: with the old hash in
43 # place nix would reuse the cached FOD and "succeed" on stale content.
44 sed -i \
45 -e "s|${prefix_re}${old_rev}|${prefix}${new_rev}|" \
46 -e "\|${prefix_re}${new_rev}|,\|hash = |s|hash = \"[^\"]*\"|hash = \"\"|" \
47 "$file"
48
49 # Only this asset's hash is blank, so the first mismatch belongs to it.
50 got=$(probe_hash)
51 if [ -z "$got" ]; then
52 echo "$attr: no hash mismatch reported for $repo" >&2
53 exit 1
54 fi
55 sed -i "\|${prefix_re}${new_rev}|,\|hash = |s|hash = \"\"|hash = \"$got\"|" "$file"
56 echo "$attr: $repo $old_rev → $new_rev ($got)"
57 changed=1
58done
59
60if [ "$changed" = 0 ]; then
61 echo "$attr: already up to date"
62 exit 0
63fi
64
65nix build --no-link "$build_attr"