Add microSD /media/sdcard automount, user permissions, dosfstools PATH, and docs

This commit is contained in:
Luxferre committed 2026-11-23 15:17:26 +02:00
1 parent e01806f3c8
commit e3abc6d993
13 files changed
+483 -11

No files matched your search

+4 -1
View File
@@ -158,12 +158,15 @@ if [ -e "$TARGET_ROOTFS/etc/init.d/geminux-usb-gadget" ]; then
fi
rm -f "$TARGET_ROOTFS/etc/runlevels/default/geminux-usb-gadget"
for svc in geminux-hwinit geminux-ccci geminux-powerd geminux-leds bluetooth polkit; do
for svc in geminux-hwinit geminux-sdcard geminux-ccci geminux-powerd geminux-leds bluetooth polkit; do
if [ -e "$TARGET_ROOTFS/etc/init.d/$svc" ]; then
mkdir -p "$TARGET_ROOTFS/etc/runlevels/default"
ln -sf "/etc/init.d/$svc" "$TARGET_ROOTFS/etc/runlevels/default/$svc"
fi
done
mkdir -p "$TARGET_ROOTFS/media/sdcard"
chmod 0755 "$TARGET_ROOTFS/media/sdcard" 2>/dev/null || true
chmod 0755 "$TARGET_ROOTFS/usr/sbin/geminux-sdcard-mount" "$TARGET_ROOTFS/etc/init.d/geminux-sdcard" 2>/dev/null || true
for fdir in misc TTF OTF; do
mkdir -p "$TARGET_ROOTFS/usr/share/fonts/$fdir"
+12 -1
View File
@@ -292,6 +292,16 @@ 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",
"etc/udev/rules.d/95-geminux-sdcard.rules",
"etc/init.d/geminux-sdcard",
"etc/runlevels/default/geminux-sdcard",
"media/sdcard",
"sbin/fsck.fat",
"sbin/fsck.vfat",
"sbin/mkfs.fat",
"sbin/mkfs.vfat",
"sbin/fatlabel",
"usr/sbin/geminux-sdcard-mount",
"usr/sbin/geminux-wifi-nvram", "usr/sbin/geminux-tzctl",
"usr/sbin/geminux-dnsctl",
"usr/bin/geminux-datetime",
@@ -496,7 +506,7 @@ if readelf -Ws "$ROOTFS_DIR/usr/bin/Xorg" | grep -q systemd_logind_take_fd; then
fi
(cd "$IMAGES_DIR" && sha256sum -c SHA256SUMS)
echo "[8/8] Running all 7 Python unit/verification suites..."
echo "[8/8] Running all 8 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"
@@ -504,6 +514,7 @@ python3 "$BASE_DIR/scripts/test-ccci-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"
+178
View File
@@ -0,0 +1,178 @@
#!/usr/bin/env python3
"""Host unit test for dosfstools preinstall and /dev/mmcblk1p1 -> /media/sdcard automounting."""
import os
import pathlib
import stat
import subprocess
import sys
import tempfile
BASE = pathlib.Path(__file__).resolve().parent.parent
SCRIPT = BASE / "overlay/rootfs/usr/sbin/geminux-sdcard-mount"
INIT_SCRIPT = BASE / "overlay/rootfs/etc/init.d/geminux-sdcard"
UDEV_RULE = BASE / "overlay/rootfs/etc/udev/rules.d/95-geminux-sdcard.rules"
PACKAGES = BASE / "scripts/rootfs-packages.txt"
def make_stub(bin_dir, name, body):
p = bin_dir / name
p.write_text("#!/bin/sh\n" + body + "\n", encoding="utf-8")
p.chmod(0o755)
def run_mount(cmd_args, env):
return subprocess.run(
[str(SCRIPT)] + cmd_args, env=env,
capture_output=True, text=True, check=False,
)
def main():
for path in (SCRIPT, INIT_SCRIPT):
if not path.is_file():
raise SystemExit(f"missing {path}")
subprocess.run(["sh", "-n", str(path)], check=True)
if not (SCRIPT.stat().st_mode & stat.S_IXUSR):
raise SystemExit(f"{SCRIPT} is not executable")
if not (INIT_SCRIPT.stat().st_mode & stat.S_IXUSR):
raise SystemExit(f"{INIT_SCRIPT} is not executable")
pkgs = {
line.strip()
for line in PACKAGES.read_text(encoding="utf-8").splitlines()
if line.strip() and not line.lstrip().startswith("#")
}
if "dosfstools" not in pkgs:
raise SystemExit("scripts/rootfs-packages.txt is missing dosfstools")
rule_txt = UDEV_RULE.read_text(encoding="utf-8")
for needle in ('KERNEL=="mmcblk1|mmcblk1p[0-9]*", GROUP="plugdev", MODE="0660"',
'KERNEL=="mmcblk1p1"', "/usr/sbin/geminux-sdcard-mount add %k",
"/usr/sbin/geminux-sdcard-mount remove %k"):
if needle not in rule_txt:
raise SystemExit(f"95-geminux-sdcard.rules missing '{needle}'")
with tempfile.TemporaryDirectory(prefix="geminux-sdcard-test-") as tmp:
root = pathlib.Path(tmp)
bin_dir = root / "bin"
dev_dir = root / "dev"
mnt_dir = root / "media/sdcard"
run_dir = root / "run"
bin_dir.mkdir()
dev_dir.mkdir()
mnt_dir.mkdir(parents=True)
run_dir.mkdir()
mounts_file = root / "proc_mounts"
mounts_file.write_text("", encoding="utf-8")
passwd_file = root / "passwd"
passwd_file.write_text("root:x:0:0:root:/root:/bin/bash\nalice:x:10000:10000::/home/alice:/bin/bash\n", encoding="utf-8")
group_file = root / "group"
group_file.write_text("root:x:0:\nwheel:x:10:alice\nplugdev:x:106:alice\n", encoding="utf-8")
log_file = root / "calls.log"
fstype_file = root / "fstype"
fstype_file.write_text("vfat", encoding="utf-8")
make_stub(bin_dir, "blkid", f'cat "{fstype_file}"')
make_stub(bin_dir, "modprobe", f'echo "modprobe $*" >> "{log_file}"')
make_stub(bin_dir, "fsck.fat", f'echo "fsck.fat $*" >> "{log_file}"')
make_stub(bin_dir, "fsck.exfat", f'echo "fsck.exfat $*" >> "{log_file}"')
make_stub(bin_dir, "e2fsck", f'echo "e2fsck $*" >> "{log_file}"')
make_stub(bin_dir, "chown", f'echo "chown $*" >> "{log_file}"')
make_stub(bin_dir, "chmod", f'echo "chmod $*" >> "{log_file}"')
make_stub(bin_dir, "logger", "true")
make_stub(bin_dir, "mount", f'''
echo "mount $*" >> "{log_file}"
fs=""
opts=""
prev=""
for a in "$@"; do
if [ "$prev" = "-t" ]; then fs="$a"; fi
if [ "$prev" = "-o" ]; then opts="$a"; fi
prev="$a"
done
printf "%s %s %s %s 0 0\\n" "{dev_dir}/mmcblk1p1" "{mnt_dir}" "$fs" "$opts" > "{mounts_file}"
''')
make_stub(bin_dir, "umount", f'''
echo "umount $*" >> "{log_file}"
: > "{mounts_file}"
''')
env = os.environ.copy()
env["PATH"] = f"{bin_dir}:{env.get('PATH', '/usr/bin:/bin')}"
env["GEMINUX_DEV_ROOT"] = str(dev_dir)
env["GEMINUX_SDCARD_MNT"] = str(mnt_dir)
env["GEMINUX_PROC_MOUNTS"] = str(mounts_file)
env["GEMINUX_PASSWD_FILE"] = str(passwd_file)
env["GEMINUX_GROUP_FILE"] = str(group_file)
env["GEMINUX_LOCK_DIR"] = str(run_dir / "sdcard.lock")
env["GEMINUX_TEST_BLOCK"] = "1"
# 1. Empty slot: clean exit 0, zero mount calls
res = run_mount(["add", "mmcblk1p1"], env)
assert res.returncode == 0, res.stderr
assert not log_file.exists() or log_file.read_text(encoding="utf-8").strip() == ""
st = run_mount(["status"], env)
assert st.returncode == 0 and st.stdout.strip() == "slot empty", st.stdout
# Create mock /dev/mmcblk1p1
(dev_dir / "mmcblk1p1").write_text("", encoding="utf-8")
# 2. vfat card -> fsck.fat + mount with uid=10000,gid=106,0002 masks,quiet,utf8
res = run_mount(["add", "mmcblk1p1"], env)
assert res.returncode == 0, res.stderr
calls = log_file.read_text(encoding="utf-8")
assert f"fsck.fat -a {dev_dir}/mmcblk1p1" in calls, calls
assert ("uid=10000,gid=106,fmask=0002,dmask=0002,allow_utime=0020,quiet,"
"shortname=mixed,utf8") in calls and "-t vfat" in calls, calls
# 3. Repeated add while already mounted -> idempotent no-op
before = calls
res = run_mount(["add", "mmcblk1p1"], env)
assert res.returncode == 0
assert log_file.read_text(encoding="utf-8") == before
# 4. Remove -> umount
res = run_mount(["remove", "mmcblk1p1"], env)
assert res.returncode == 0
assert mounts_file.read_text(encoding="utf-8") == ""
# 5. exfat card -> modprobe exfat + fsck.exfat + mount with uid=10000,gid=106 (no quiet)
log_file.write_text("", encoding="utf-8")
fstype_file.write_text("exfat", encoding="utf-8")
res = run_mount(["add", "mmcblk1p1"], env)
assert res.returncode == 0, res.stderr
calls = log_file.read_text(encoding="utf-8")
assert "modprobe exfat" in calls and f"fsck.exfat -p {dev_dir}/mmcblk1p1" in calls, calls
assert ("-t exfat" in calls and
"uid=10000,gid=106,fmask=0002,dmask=0002,allow_utime=0020,iocharset=utf8" in calls), calls
assert ",quiet" not in calls, calls
res = run_mount(["stop"], env)
assert res.returncode == 0 and mounts_file.read_text(encoding="utf-8") == ""
# 6. ext4 card -> e2fsck -p + mount WITHOUT uid= or gid= + POSIX uid/gid/perms sync
(mnt_dir / "lost+found").mkdir(exist_ok=True)
(mnt_dir / "lost+found" / "orphan").write_text("x", encoding="utf-8")
(mnt_dir / "subdir").mkdir(exist_ok=True)
os.chmod(mnt_dir / "subdir", 0o755)
(mnt_dir / "note.txt").write_text("hi", encoding="utf-8")
os.chmod(mnt_dir / "note.txt", 0o644)
log_file.write_text("", encoding="utf-8")
fstype_file.write_text("ext4", encoding="utf-8")
res = run_mount(["add", "mmcblk1p1"], env)
assert res.returncode == 0, res.stderr
calls = log_file.read_text(encoding="utf-8")
assert f"e2fsck -p {dev_dir}/mmcblk1p1" in calls, calls
assert "-t ext4" in calls and "uid=" not in calls, calls
assert f"chown 10000:106 {mnt_dir}" in calls, calls
assert f"chmod 02775 {mnt_dir}" in calls, calls
assert f"chown -h 10000:106" in calls and "note.txt" in calls and "subdir" in calls, calls
assert "chmod u+rwX,g+rwX" in calls, calls
assert "lost+found" not in calls and "orphan" not in calls, calls
print("[PASS] dosfstools and /dev/mmcblk1p1 -> /media/sdcard automount verified")
return 0
if __name__ == "__main__":
sys.exit(main())