mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-05 08:02:40 +00:00
The first release with diffs (v2026.10.27.3) was built on a Mac and its first build made no diffs at all. make-diffs.sh checks each base's SHA256SUMS with mu300-update's sig_state, which calls "openssl" from PATH: macOS's LibreSSL has no -rawin, so every base was "notool", treated as unsigned and skipped, though MU300_OPENSSL named OpenSSL 3 for the signing. The release would have gone out without diffs only because of the build machine. - MU300_OPENSSL's directory comes first in PATH for the base checks. - Where the tree has the release key and no openssl here can check Ed25519, make-diffs (and so make-release) stops instead of making no diffs. - Test: a stub openssl without -rawin stops it; MU300_OPENSSL then gives the five diffs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VVN2zDgf76kMDVSuWhHPUE
90 lines
5.2 KiB
Bash
Executable File
90 lines
5.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# Maintainer: the diffs of a release, run by tools/make-release.sh before it writes and signs SHA256SUMS.
|
|
# tools/make-diffs.sh DIR TAG
|
|
# For each image in DIR (mu300-*-rootfs.tar.gz) and each of the MU300_DIFF_BASES releases before TAG (5) that
|
|
# published that image's manifest: DIR/mu300-<image>-rootfs.diff-<BASE>.tar.gz (tools/image-diff.py). SHA256SUMS lists
|
|
# them with the rest, so the release key signs them; mu300-update downloads one instead of the whole image when the
|
|
# device runs its base release, and installs only what the release's signed manifest says the image is.
|
|
# The bases come from this repository's own releases on GitHub (gh), or from MU300_DIFF_BASES_DIR/<tag>/ (tests, a
|
|
# build without the network): each base's manifests are taken only as its SHA256SUMS lists them, and where the tree
|
|
# has the release key, only when that SHA256SUMS is signed with it (mu300-update's own sums_verdict). A diff that
|
|
# saves less than a fifth of the image is not published. Ported from kanoqwq/mu300-linux fb0b28e7 and b9f71e72 (diffs
|
|
# made from an old release's index, tools/release-index.py): his diffs are made on demand from any index; here the
|
|
# release makes them, from the five releases before it.
|
|
set -eu
|
|
D=${1:?usage: tools/make-diffs.sh DIR TAG}
|
|
TAG=${2:?usage: tools/make-diffs.sh DIR TAG}
|
|
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
|
REPO=${MU300_REPO:-dikeckaan/mu300-linux}
|
|
N=${MU300_DIFF_BASES:-5}
|
|
case $N in ''|*[!0-9]*) echo "MU300_DIFF_BASES=$N is not a number" >&2; exit 1 ;; esac
|
|
[ "$N" -gt 0 ] || { echo "no diffs (MU300_DIFF_BASES=0)"; exit 0; }
|
|
. "$TOP/tools/releases.sh"
|
|
# (MU300_DIFF_PUB: another key, for tests)
|
|
PUB=${MU300_DIFF_PUB:-$TOP/rootfs/overlay/opt/mu300/lib/release.pub}
|
|
W=$(umask 077; mktemp -d "${TMPDIR:-/tmp}/mu300-diffs.XXXXXX")
|
|
trap 'rm -rf "${W:?}"' EXIT
|
|
# the key as a file of our own (mu300-update's key_state: root's own, written by nobody else; sudo -E runs this)
|
|
[ ! -s "$PUB" ] || { cat "$PUB" > "$W/release.pub"; chmod 644 "$W/release.pub"; }
|
|
|
|
# the releases before TAG, newest first
|
|
if [ -n "${MU300_DIFF_BASES_DIR:-}" ]; then
|
|
tags=$(ls "$MU300_DIFF_BASES_DIR")
|
|
else
|
|
tags=$(gh release list -R "$REPO" --limit 60 --json tagName,isDraft -q '.[] | select(.isDraft | not) | .tagName') ||
|
|
{ echo "cannot read the releases of $REPO (gh): no diffs" >&2; exit 0; }
|
|
fi
|
|
older=$(for t in $tags; do tag_ok "$t" && newer "$TAG" "$t" && printf '%s %s\n' "$(tag_key "$t")" "$t"; done | sort -rn | cut -d' ' -f2)
|
|
|
|
# the signatures are checked with mu300-update's own code, which calls "openssl": the one the release is signed with
|
|
# (MU300_OPENSSL, tools/sign-release.sh) comes first, since macOS's own (LibreSSL) cannot check Ed25519
|
|
case ${MU300_OPENSSL:-} in */*) PATH=${MU300_OPENSSL%/*}:$PATH; export PATH ;; esac
|
|
# base_ok TAG DIR: DIR/SHA256SUMS is TAG's and as trusted as an update trusts it (signed, where the tree has the key).
|
|
# Status 2 when nothing here can check a signature: then no base is trusted, and a release would go out without
|
|
# diffs only because of this machine, so make-release stops
|
|
base_ok() (
|
|
set +eu
|
|
MU300_LIB=1 MU300_RELEASE_PUB=$W/release.pub
|
|
[ -s "$W/release.pub" ] || MU300_RELEASE_PUB=$W/none
|
|
export MU300_LIB MU300_RELEASE_PUB
|
|
. "$TOP/rootfs/overlay/opt/mu300/bin/mu300-update"
|
|
_bs=$(sig_state "$2/SHA256SUMS" "$2/SHA256SUMS.sig")
|
|
[ "$_bs" != notool ] || [ ! -s "$W/release.pub" ] || return 2
|
|
sums_verdict "$1" "$_bs" "release $1" "$2/SHA256SUMS" >/dev/null
|
|
)
|
|
|
|
sha() { { sha256sum "$1" 2>/dev/null || shasum -a 256 "$1"; } | cut -d' ' -f1; }
|
|
made=0 bases=0
|
|
for b in $older; do
|
|
[ "$bases" -lt "$N" ] || break
|
|
B=$W/$b
|
|
mkdir -p "$B"
|
|
if [ -n "${MU300_DIFF_BASES_DIR:-}" ]; then
|
|
cp "$MU300_DIFF_BASES_DIR/$b"/SHA256SUMS* "$MU300_DIFF_BASES_DIR/$b"/mu300-*-rootfs.manifest.gz "$B/" 2>/dev/null || :
|
|
else
|
|
gh release download "$b" -R "$REPO" -D "$B" -p SHA256SUMS -p SHA256SUMS.sig -p 'mu300-*-rootfs.manifest.gz' 2>/dev/null || :
|
|
fi
|
|
ls "$B"/mu300-*-rootfs.manifest.gz >/dev/null 2>&1 && [ -s "$B/SHA256SUMS" ] || { echo "$b: no manifests, no diffs from it"; continue; }
|
|
_ok=0; base_ok "$b" "$B" || _ok=$?
|
|
[ "$_ok" != 2 ] || { echo "no openssl here checks Ed25519 signatures (OpenSSL 3: MU300_OPENSSL=/path/to/openssl): no base can be trusted" >&2; exit 1; }
|
|
[ "$_ok" = 0 ] || { echo "$b: its SHA256SUMS is not signed with the release key, no diffs from it" >&2; continue; }
|
|
bases=$((bases + 1))
|
|
for img in "$D"/mu300-*-rootfs.tar.gz; do
|
|
a=${img##*/}; s=${a%.tar.gz}; m=$B/$s.manifest.gz
|
|
[ -f "$m" ] || continue
|
|
want=$(awk -v f="$s.manifest.gz" '$2 == f || $2 == "*" f {print $1}' "$B/SHA256SUMS")
|
|
[ -n "$want" ] && [ "$(sha "$m")" = "$want" ] ||
|
|
{ echo "$b: $s.manifest.gz does not match its SHA256SUMS" >&2; exit 1; }
|
|
out=$D/$s.diff-$b.tar.gz
|
|
python3 "$TOP/tools/image-diff.py" make "$m" "$img" "$out"
|
|
python3 "$TOP/tools/image-diff.py" check "$m" "$img" "$out"
|
|
if [ $(( $(wc -c < "$out") * 5 )) -gt $(( $(wc -c < "$img") * 4 )) ]; then
|
|
echo "$s from $b: the diff saves less than a fifth, not published"
|
|
rm -f "$out"
|
|
else
|
|
made=$((made + 1))
|
|
fi
|
|
done
|
|
done
|
|
echo "$made diffs from $bases releases before $TAG"
|