#!/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 \ libglycin mesa-rusticl gdk-pixbuf adwaita-icon-theme imv-x11 \ gst-plugins-bad libnotify \ deno py3-cryptography \ linux-edge linux-lts xorg-server xf86-input-libinput xf86-video-fbdev geminux-mpv; 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 for req_pkg in ffmpeg mpv gst-libav; do if ! grep -Fxq "P:$req_pkg" "$ROOTFS_DIR/lib/apk/db/installed"; then echo "FAIL: expected native package '$req_pkg' is not installed in rootfs" >&2 exit 1 fi done for unblocked in !librsvg !rav1e !rav1e-libs !libheif-rav1e !libdovi !gst-libav; do if grep -Fxq "$unblocked" "$ROOTFS_DIR/etc/apk/world"; then echo "FAIL: '$unblocked' is still blocked in $ROOTFS_DIR/etc/apk/world" >&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}|libglycin)" ) sym_markers = re.compile( r"(rust_eh_personality|rust_begin_unwind|_ZN4core9panicking|_ZN3std9panicking|libstd-[0-9a-f]{8}|libglycin)" ) whitelisted_elf_prefixes = ( "librsvg-2.so", "libpixbufloader-svg.so", "libpixbufloader_svg.so", "rsvg-convert", "librav1e.so", "rav1e", "libdovi.so", ) 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) or name.startswith(whitelisted_elf_prefixes): 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-bantam geminux-gsocket \ geminux-gdk-pixbuf geminux-webarchy 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|libglycin|gdk-pixbuf|deno|py3-cryptography|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/"* \ "$BASE_DIR/prebuilt/bantam/usr/bin/bantam" \ "$BASE_DIR/prebuilt/gsocket/usr/local/bin/gs-netcat" \ "$BASE_DIR/prebuilt/gsocket/usr/local/bin/gsocket_dso.so.0" \ "$BASE_DIR/prebuilt/gsocket/usr/local/bin/gsocket_uchroot_dso.so.0" \ "$BASE_DIR/prebuilt/gdk-pixbuf/usr/bin/gdk-pixbuf-"* \ "$BASE_DIR/prebuilt/gdk-pixbuf/usr/lib/libgdk_pixbuf-2.0.so.0."* \ "$BASE_DIR/prebuilt/webarchy/usr/bin/webarchy" | \ 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" \ "$BASE_DIR/src/initramfs/init" "$BASE_DIR/src/initramfs/init-recovery" <<'PYEOF' import gzip import os import re import struct import subprocess import sys def parse_newc_entries(cpio_bytes): entries = {} pos = 0 total = len(cpio_bytes) while pos + 110 <= total: hdr = cpio_bytes[pos:pos + 110] if hdr[:6] not in (b"070701", b"070702"): raise SystemExit(f"FAIL: invalid cpio newc magic at offset {pos}: {hdr[:6]!r}") filesize = int(hdr[54:62], 16) namesize = int(hdr[94:102], 16) name_start = pos + 110 name_end = name_start + namesize name = cpio_bytes[name_start:name_end].rstrip(b"\x00").decode("utf-8", "replace") if name == "TRAILER!!!": break data_start = (name_end + 3) & ~3 rel = name[2:] if name.startswith("./") else name entries[rel] = cpio_bytes[data_start:data_start + filesize] pos = (data_start + filesize + 3) & ~3 return entries GEMINI_HW_KEYCODES = ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 56, 57, 103, 105, 106, 108, 125, ) for init_script in sys.argv[5:7]: subprocess.run(["sh", "-n", init_script], check=True) with open(init_script, "r", encoding="utf-8") as f: txt = f.read() if "cryptsetup resize" in txt: raise SystemExit(f"FAIL: redundant interactive 'cryptsetup resize' found in {init_script}") for line in txt.splitlines(): if "loadkmap" in line and line.count("<") > 1: raise SystemExit(f"FAIL: double stdin redirection on loadkmap in {init_script}: {line}") if init_script == sys.argv[5]: stripped = line.strip() if stripped.startswith(("resize2fs ", "e2fsck -p ")) and "/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 9 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-ims-protocol.py" python3 "$BASE_DIR/scripts/test-power-policy.py" python3 "$BASE_DIR/scripts/test-webarchy-renderer.py" python3 "$BASE_DIR/scripts/test-webkit-gsettings.py" python3 "$BASE_DIR/scripts/test-sdcard-automount.py" echo "============================================================" echo "ALL GEMINUX CHECKS PASSED CLEANLY" echo "============================================================"