Files
geminux/scripts/check-rebuild.sh
T

358 lines
16 KiB
Bash
Raw Normal View History

#!/bin/sh
# Comprehensive Geminux verification suite (repo policy, zero-Rust ELF scan,
# Alpine Edge upgrade simulation, aarch64 binaries, image integrity, unit tests).
set -eu
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
ROOTFS_DIR="${ROOTFS_DIR:-$BASE_DIR/rootfs}"
IMAGES_DIR="$BASE_DIR/images"
if [ ! -d "$ROOTFS_DIR/lib/apk/db" ]; then
echo "FAIL: rootfs not bootstrapped at $ROOTFS_DIR" >&2
exit 1
fi
echo "[1/8] Checking APK repositories (pure Alpine Edge + @geminux, zero postmarketOS)..."
grep -q '^@geminux /var/lib/geminux/apk-repo$' "$ROOTFS_DIR/etc/apk/repositories"
grep -q 'alpine/edge/main' "$ROOTFS_DIR/etc/apk/repositories"
grep -q 'alpine/edge/community' "$ROOTFS_DIR/etc/apk/repositories"
grep -q 'alpine/edge/testing' "$ROOTFS_DIR/etc/apk/repositories"
if grep -qi 'postmarketos' "$ROOTFS_DIR/etc/apk/repositories"; then
echo "FAIL: unexpected postmarketos repository in target rootfs" >&2
exit 1
fi
echo "OK"
echo "[2/8] Checking excluded Wayland/Rust/upstream packages..."
for bad_pkg in sway wayfire weston phosh cage xwayland grim slurp wofi \
sudo-rs postmarketos-base-sudo-rs rust cargo librsvg libglycin rav1e \
rav1e-libs libdovi mesa-rusticl gdk-pixbuf adwaita-icon-theme imv-x11 \
gst-libav gst-plugins-bad gst-plugins-good libnotify \
linux-edge linux-lts xorg-server xf86-input-libinput xf86-video-fbdev; do
if grep -Fxq "P:$bad_pkg" "$ROOTFS_DIR/lib/apk/db/installed"; then
echo "FAIL: forbidden package '$bad_pkg' is installed in rootfs" >&2
exit 1
fi
done
echo "OK (zero forbidden packages)"
echo "[3/8] Running full binary ELF Rust scan across $ROOTFS_DIR..."
python3 - "$ROOTFS_DIR" <<'PYEOF'
import os
import re
import subprocess
import sys
root = sys.argv[1]
raw_markers = re.compile(
rb"(core::panicking|rustc_version|libstd-[0-9a-f]{8}|librsvg|libglycin|rav1e|libdovi)"
)
sym_markers = re.compile(
r"(rust_eh_personality|rust_begin_unwind|_ZN4core9panicking|_ZN3std9panicking|libstd-[0-9a-f]{8}|librsvg|libglycin|rav1e|libdovi)"
)
elfs = []
hits = []
for parent, _, names in os.walk(root):
for name in names:
p = os.path.join(parent, name)
if os.path.islink(p) or not os.path.isfile(p):
continue
try:
with open(p, "rb") as f:
if f.read(4) != b"\x7fELF":
continue
f.seek(0)
data = f.read()
except OSError:
continue
elfs.append(p)
m = raw_markers.search(data)
if m:
hits.append((os.path.relpath(p, root), m.group(0).decode("ascii", "replace")))
if elfs:
batch_sz = 200
for i in range(0, len(elfs), batch_sz):
chunk = elfs[i:i + batch_sz]
proc = subprocess.run(
["readelf", "-d", "-Ws"] + chunk,
capture_output=True, text=True, check=False,
)
cur_file = chunk[0]
for line in proc.stdout.splitlines():
if line.startswith("File: "):
cur_file = line[6:].strip()
continue
sm = sym_markers.search(line)
if sm:
hits.append((os.path.relpath(cur_file, root), sm.group(1)))
print(f"Scanned {len(elfs)} ELF binaries/libraries in rootfs -> {len(hits)} Rust marker hit(s)")
if hits:
for path, marker in hits[:20]:
print(f"FAIL: Rust marker '{marker}' in {path}", file=sys.stderr)
sys.exit(1)
PYEOF
echo "[4/8] Simulating Alpine Edge live 'apk upgrade' with locked @geminux packages..."
ROOTFS_HOST="$(realpath "$ROOTFS_DIR")"
docker run --rm --network=host \
-v "$ROOTFS_HOST:/rootfs" \
alpine:3.24 sh -eu -c '
mkdir -p /var/lib/geminux
ln -sfn /rootfs/var/lib/geminux/apk-repo /var/lib/geminux/apk-repo
cp -f /rootfs/etc/apk/keys/*.rsa.pub /etc/apk/keys/ 2>/dev/null || true
apk --root /rootfs --arch aarch64 update
UPG_OUT="$(apk --root /rootfs --arch aarch64 upgrade --simulate 2>&1)"
printf "%s\n" "$UPG_OUT"
for pkg in geminux-kernel-modules geminux-xlibre geminux-suckless \
geminux-dunst geminux-ui geminux-config; do
if ! grep -q "^${pkg}@geminux=" /rootfs/etc/apk/world; then
echo "FAIL: ${pkg} is not exact-version pinned to @geminux in world" >&2
exit 1
fi
if printf "%s\n" "$UPG_OUT" | grep -q -E "(Upgrading|Replacing|Deleting|Downgrading) ${pkg}\b"; then
echo "FAIL: ${pkg} would be modified by upstream upgrade" >&2
exit 1
fi
done
if printf "%s\n" "$UPG_OUT" | grep -q -E "(rust|cargo|librsvg|libglycin|gdk-pixbuf|rav1e|libdovi|xorg-server|linux-edge)"; then
echo "FAIL: upgrade simulation tried to pull forbidden Rust or upstream override package" >&2
exit 1
fi
'
echo "OK"
echo "[5/8] Verifying overlay artifact sync..."
"$BASE_DIR/scripts/sync-prebuilt-overlay.sh" --check
echo "[6/8] Verifying aarch64 ELF architecture on all Geminux custom binaries..."
file \
"$BASE_DIR/prebuilt/xlibre/usr/bin/Xorg" \
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/libglamoregl.so" \
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/extensions/libglx.so" \
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/drivers/modesetting_drv.so" \
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/drivers/fbdev_drv.so" \
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/input/libinput_drv.so" \
"$BASE_DIR/prebuilt/suckless/usr/bin/st" \
"$BASE_DIR/prebuilt/suckless/usr/bin/dwm" \
"$BASE_DIR/prebuilt/suckless/usr/bin/dmenu" \
"$BASE_DIR/prebuilt/suckless/usr/bin/stest" \
"$BASE_DIR/prebuilt/dunst/usr/bin/dunst" \
"$BASE_DIR/prebuilt/dunst/usr/bin/notify-send" \
"$BASE_DIR/prebuilt/geminux/usr/lib/libgemui.so" \
"$BASE_DIR/prebuilt/geminux/usr/bin/"* \
"$BASE_DIR/prebuilt/geminux/usr/sbin/"* | \
awk '!/ARM aarch64/ { print "FAIL: not aarch64: " $0; bad=1 } END { exit bad }'
echo "OK (all aarch64 ELFs verified)"
echo "[7/8] Verifying partition budgets, ext4 image e2fsck, and SHA256SUMS..."
BOOT_SZ="$(stat -c %s "$IMAGES_DIR/boot-geminux.img")"
REC_SZ="$(stat -c %s "$IMAGES_DIR/recovery-geminux.img")"
DTB_SZ="$(stat -c %s "$BASE_DIR/prebuilt/kernel/boot/mt6797-gemini-pda-geminux.dtb")"
[ "$BOOT_SZ" -le 16777216 ] || { echo "FAIL: boot-geminux.img > 16 MiB ($BOOT_SZ)" >&2; exit 1; }
[ "$REC_SZ" -le 16777216 ] || { echo "FAIL: recovery-geminux.img > 16 MiB ($REC_SZ)" >&2; exit 1; }
[ "$DTB_SZ" -le 524288 ] || { echo "FAIL: DTB > 512 KiB ($DTB_SZ)" >&2; exit 1; }
python3 - "$IMAGES_DIR/boot-geminux.img" "$IMAGES_DIR/recovery-geminux.img" \
"$BASE_DIR/prebuilt/kernel/boot/config-7.3.5-geminux" "$ROOTFS_DIR" <<'PYEOF'
import os
import struct
import sys
for path in sys.argv[1:3]:
with open(path, "rb") as f:
hdr = f.read(640)
if hdr[:8] != b"ANDROID!":
raise SystemExit(f"FAIL: invalid boot image magic in {path}")
kernel_addr = struct.unpack("<I", hdr[12:16])[0]
if kernel_addr != 0x40080000:
raise SystemExit(
f"FAIL: {path} kernel_addr={kernel_addr:#010x}, expected 0x40080000 for Gemini LK"
)
cmdline = hdr[64:576].split(b"\x00", 1)[0].decode("ascii", "replace")
for req in ("clk_ignore_unused", "maxcpus=8", "noautodetect"):
if req not in cmdline.split():
raise SystemExit(f"FAIL: {path} cmdline missing '{req}': {cmdline}")
with open(sys.argv[3], "r", encoding="utf-8") as f:
kcfg = f.read()
for line in kcfg.splitlines():
if line.startswith("CONFIG_CMDLINE="):
for req in ("clk_ignore_unused", "maxcpus=8", "noautodetect"):
if req not in line:
raise SystemExit(f"FAIL: {sys.argv[3]} {line} missing '{req}'")
break
else:
raise SystemExit(f"FAIL: {sys.argv[3]} missing CONFIG_CMDLINE")
if "CONFIG_REGULATOR_FIXED_VOLTAGE=y" not in kcfg.splitlines():
raise SystemExit(f"FAIL: {sys.argv[3]} missing CONFIG_REGULATOR_FIXED_VOLTAGE=y")
rootfs = sys.argv[4]
for req_rel in ("etc/pam.d/autologin", "etc/init.d/geminux-hwinit",
"usr/lib/dri/simpledrm_dri.so", "etc/runlevels/boot/geminux-usb-gadget",
"usr/share/X11/xkb/types/custom", "usr/sbin/dnsmasq",
"etc/NetworkManager/conf.d/20-geminux-wifi.conf", "etc/shells",
"usr/sbin/geminux-wifi-nvram", "usr/sbin/geminux-tzctl",
"usr/bin/geminux-datetime",
"etc/NetworkManager/dispatcher.d/30-geminux-chrony",
"etc/polkit-1/rules.d/10-geminux.rules"):
if not os.path.lexists(os.path.join(rootfs, req_rel)):
raise SystemExit(f"FAIL: missing required path {os.path.join(rootfs, req_rel)}")
if os.path.lexists(os.path.join(rootfs, "etc/runlevels/sysinit/hwdrivers")):
raise SystemExit("FAIL: hwdrivers must not be enabled in sysinit")
if os.path.lexists(os.path.join(rootfs, "etc/runlevels/default/wpa_supplicant")):
raise SystemExit("FAIL: wpa_supplicant must not be enabled in default runlevel")
with open(os.path.join(rootfs, "etc/inittab"), "r", encoding="utf-8") as f:
for line in f:
if line.startswith("tty1::respawn:"):
raise SystemExit("FAIL: rootfs/etc/inittab must not run getty on tty1 (reserved for tinydm/XLibre)")
for rel, needle in (
("etc/X11/xorg.conf.d/10-geminux-gpu.conf", 'Option "AccelMethod" "none"'),
("etc/X11/xorg.conf.d/10-geminux-gpu.conf", 'Option "ShadowFB" "true"'),
("etc/X11/xorg.conf.d/30-geminux-keyboard.conf", "custom:types"),
("etc/X11/xorg.conf.d/20-geminux-touch.conf", "0 -1 1 1 0 0 0 0 1"),
("etc/conf.d/geminux-hwinit", 'GEMINUX_ENABLE_MEDIATEK_DRM="yes"'),
("etc/NetworkManager/conf.d/20-geminux-wifi.conf", "wifi.scan-rand-mac-address = no"),
("etc/NetworkManager/conf.d/20-geminux-wifi.conf", "wifi-sec.pmf = 1"),
("etc/shells", "/bin/bash"),
):
p = os.path.join(rootfs, rel)
with open(p, "r", encoding="utf-8") as f:
if needle not in f.read():
raise SystemExit(f"FAIL: {p} missing '{needle}'")
xorg_mode = os.stat(os.path.join(rootfs, "usr/bin/Xorg")).st_mode & 0o7777
if xorg_mode != 0o4755:
raise SystemExit(f"FAIL: rootfs/usr/bin/Xorg mode is {oct(xorg_mode)}, expected 0o4755")
awk_path = os.path.join(rootfs, "usr", "bin", "awk")
if not os.path.lexists(awk_path):
raise SystemExit(f"FAIL: missing BusyBox applet {awk_path}")
bb_path = os.path.join(rootfs, "bin", "busybox")
with open(bb_path, "rb") as f:
bb_data = f.read()
idx = bb_data.find(b"[\x00[[\x00")
if idx < 0:
raise SystemExit(f"FAIL: unable to locate applet table in {bb_path}")
end = bb_data.find(b"\x00\x00", idx)
names = [s.decode("ascii") for s in bb_data[idx:end].split(b"\x00") if s]
missing = [
n for n in names
if not any(os.path.lexists(os.path.join(rootfs, d, n))
for d in ("bin", "sbin", "usr/bin", "usr/sbin"))
]
if missing:
raise SystemExit(f"FAIL: {len(missing)} missing BusyBox applet(s): {' '.join(missing)}")
print(f"OK (kernel_addr=0x40080000, noautodetect, {len(names)} BusyBox applets linked)")
PYEOF
docker run --rm -i -v "$IMAGES_DIR:/images:ro" -v "$BASE_DIR/prebuilt/kernel/boot:/kboot:ro" alpine:3.24 sh -eu <<'SH_EOF'
apk add --no-cache e2fsprogs e2fsprogs-extra dtc >/dev/null
e2fsck -fn /images/geminux-rootfs.img
debugfs -R "stat /usr/bin/Xorg" /images/geminux-rootfs.img | grep -qE "Mode:[[:space:]]*04755\b" || {
echo "FAIL: geminux-rootfs.img /usr/bin/Xorg is not mode 04755" >&2; exit 1;
}
debugfs -R "stat /usr/bin/Xorg" /images/geminux-rootfs.img | grep -qE "User:[[:space:]]*0\b" || {
echo "FAIL: geminux-rootfs.img /usr/bin/Xorg is not UID 0" >&2; exit 1;
}
debugfs -R "stat /usr/bin/doas" /images/geminux-rootfs.img | grep -qE "Mode:[[:space:]]*04755\b" || {
echo "FAIL: geminux-rootfs.img /usr/bin/doas is not mode 04755" >&2; exit 1;
}
debugfs -R "stat /usr/libexec/dbus-daemon-launch-helper" /images/geminux-rootfs.img | grep -qE "Mode:[[:space:]]*04750\b" || {
echo "FAIL: geminux-rootfs.img /usr/libexec/dbus-daemon-launch-helper is not mode 04750" >&2; exit 1;
}
debugfs -R "stat /usr/libexec/dbus-daemon-launch-helper" /images/geminux-rootfs.img | grep -qE "User:[[:space:]]*0\b" || {
echo "FAIL: geminux-rootfs.img /usr/libexec/dbus-daemon-launch-helper is not UID 0" >&2; exit 1;
}
debugfs -R "stat /usr/libexec/dbus-daemon-launch-helper" /images/geminux-rootfs.img | grep -qE "Group:[[:space:]]*103\b" || {
echo "FAIL: geminux-rootfs.img /usr/libexec/dbus-daemon-launch-helper is not GID 103" >&2; exit 1;
}
debugfs -R "stat /etc/polkit-1/rules.d" /images/geminux-rootfs.img | grep -qE "Mode:[[:space:]]*0?4?0750\b" || {
echo "FAIL: geminux-rootfs.img /etc/polkit-1/rules.d is not mode 0750" >&2; exit 1;
}
debugfs -R "stat /etc/polkit-1/rules.d" /images/geminux-rootfs.img | grep -qE "Group:[[:space:]]*110\b" || {
echo "FAIL: geminux-rootfs.img /etc/polkit-1/rules.d is not GID 110" >&2; exit 1;
}
debugfs -R "stat /home/user" /images/geminux-rootfs.img | grep -qE "User:[[:space:]]*10000\b" || {
echo "FAIL: geminux-rootfs.img /home/user is not UID 10000" >&2; exit 1;
}
DTS_OUT="$(dtc -I dtb -O dts /kboot/mt6797-gemini-pda-geminux.dtb 2>/dev/null)"
printf "%s\n" "$DTS_OUT" | grep -qE "^\tmemory \{$" || { echo "FAIL: DTB missing /memory node" >&2; exit 1; }
if printf "%s\n" "$DTS_OUT" | grep -qE "^\tmemory@40000000 \{$"; then
echo "FAIL: DTB still contains root /memory@40000000" >&2
exit 1
fi
if printf "%s\n" "$DTS_OUT" | grep -q "memory@7df00000"; then
echo "FAIL: DTB contains static memory@7df00000 that triggers LK reserved_memory_conflict_check" >&2
exit 1
fi
printf "%s\n" "$DTS_OUT" | grep -q 'compatible = "pwm-backlight";' || {
echo "FAIL: DTB missing pwm-backlight node" >&2
exit 1
}
printf "%s\n" "$DTS_OUT" | awk '
/^\ti2c@11007000 \{/ { in_i2c=1; depth=1; next }
in_i2c {
if ($0 ~ /\{/) depth++
if ($0 ~ /\}/) { depth--; if (depth == 0) in_i2c=0 }
if (in_i2c && depth == 1 && $0 ~ /status = "okay";/) found_ok=1
if (in_i2c && depth == 1 && $0 ~ /status = "disabled";/) found_dis=1
}
/^\tpwm@1100f000 \{/ { in_pwm=1; depth_p=1; next }
in_pwm {
if ($0 ~ /\{/) depth_p++
if ($0 ~ /\}/) { depth_p--; if (depth_p == 0) in_pwm=0 }
if (in_pwm && depth_p == 1 && $0 ~ /status = "okay";/) pwm_ok=1
if (in_pwm && depth_p == 1 && $0 ~ /status = "disabled";/) pwm_dis=1
if (in_pwm && depth_p == 1 && $0 ~ /power-domains[[:space:]]*=/) pwm_pd=1
}
/^\tusb@11271000 \{/ { in_usb=1; depth_u=1; next }
in_usb {
if ($0 ~ /\{/) depth_u++
if ($0 ~ /\}/) { depth_u--; if (depth_u == 0) in_usb=0 }
if (in_usb && depth_u == 1 && $0 ~ /dr_mode = "peripheral";/) usb_periph=1
if (in_usb && depth_u == 1 && $0 ~ /usb-role-switch/) usb_rolesw=1
}
/ldo-vusb33 \{/ { in_vusb=1; next }
in_vusb && /\};/ { in_vusb=0 }
in_vusb && /regulator-always-on;/ { found_vusb=1 }
END {
if (!found_ok || found_dis) {
print "FAIL: DTB i2c@11007000 (&i2c0) must have status = \"okay\"" > "/dev/stderr"
exit 1
}
if (!found_vusb) {
print "FAIL: DTB ldo-vusb33 must have regulator-always-on" > "/dev/stderr"
exit 1
}
if (!pwm_ok || pwm_dis || pwm_pd) {
print "FAIL: DTB pwm@1100f000 (&disp_pwm) must be okay without power-domains" > "/dev/stderr"
exit 1
}
if (!usb_periph || usb_rolesw) {
print "FAIL: DTB usb@11271000 (&ssusb) must have dr_mode = \"peripheral\" and no usb-role-switch" > "/dev/stderr"
exit 1
}
}
'
SH_EOF
if readelf -Ws "$ROOTFS_DIR/usr/bin/Xorg" | grep -q systemd_logind_take_fd; then
echo "FAIL: rootfs/usr/bin/Xorg was still built with systemd_logind support" >&2
exit 1
fi
(cd "$IMAGES_DIR" && sha256sum -c SHA256SUMS)
echo "[8/8] Running all 5 Python unit/verification suites..."
python3 "$BASE_DIR/scripts/test-flash-mtk-gpt.py"
python3 "$BASE_DIR/scripts/test-xkb-keymap.py"
python3 "$BASE_DIR/scripts/test-theme-dunst-sync.py"
python3 "$BASE_DIR/scripts/test-ccci-protocol.py"
python3 "$BASE_DIR/scripts/test-power-policy.py"
echo "============================================================"
echo "ALL GEMINUX CHECKS PASSED CLEANLY"
echo "============================================================"