SmartFox: launcher, Siri Remote driver, Debian image and installer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tamas Csikel
2026-10-24 09:06:06 +02:00
commit 79b03cac95
91 changed files with 15874 additions and 0 deletions

72
image/build-iso.sh Normal file
View File

@@ -0,0 +1,72 @@
#!/usr/bin/env bash
# Builds the SmartFox installer ISO (UEFI, x86-64) for a USB stick.
# Run as root inside WSL Debian:
# sudo bash /mnt/g/source/smartfox/image/build-iso.sh
# Writes image/out/smartfox-installer.iso (in the source tree, so Rufus on
# Windows can pick it up). Rufus: "ISO image mode", GPT, UEFI, FAT32.
# Raw writers (Etcher, dd) work too: the ISO carries a GPT with an ESP holding
# the UKI, so UEFI firmware sees the stick as bootable.
#
# SKIP_BUILD=1 reuses the last SmartFox image instead of running build.sh.
# Don't do that after booting it in run-qemu.sh: the VM writes into that file.
set -euo pipefail
SRC="$(cd "$(dirname "$0")/.." && pwd)"
WORK="${SMARTFOX_WORK:-/root/smartfox}"
OUT_DIR="$SRC/image/out"
if [ "${SKIP_BUILD:-0}" != 1 ]; then
bash "$SRC/image/build.sh"
else
echo "== sync installer sources"
rsync -a --delete --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r "$SRC/image/installer/" "$WORK/image/installer/" \
--exclude /mkosi.output --exclude /mkosi.cache
fi
RAW="$WORK/image/mkosi.output/smartfox.raw"
[ -f "$RAW" ] || { echo "missing $RAW"; exit 1; }
for tool in xorriso mcopy mkfs.vfat zstd; do
command -v "$tool" >/dev/null || { apt-get update -qq && apt-get install -y -qq xorriso mtools dosfstools zstd; break; }
done
echo "== installer (mkosi)"
cd "$WORK/image/installer"
chmod +x mkosi.postinst.chroot mkosi.extra/usr/bin/sf-install
mkdir -p mkosi.cache
mkosi -f build
UKI="$WORK/image/installer/mkosi.output/smartfox-installer.efi"
[ -f "$UKI" ] || { echo "missing $UKI"; exit 1; }
echo "== payload"
STAGE="$WORK/image/iso"
rm -rf "$STAGE"
mkdir -p "$STAGE/tree/EFI/BOOT" "$STAGE/tree/smartfox"
cp "$UKI" "$STAGE/tree/EFI/BOOT/BOOTX64.EFI"
stat -c %s "$RAW" >"$STAGE/tree/smartfox/smartfox.size"
echo "SmartFox $(grep -m1 '^version' "$WORK/Cargo.toml" | cut -d'"' -f2) · $(date +%Y-%m-%d)" >"$STAGE/tree/smartfox/version"
zstd -T0 -10 -q "$RAW" -o "$STAGE/tree/smartfox/smartfox.raw.zst"
# Rufus puts the files on FAT32: no single file may reach 4 GiB.
[ "$(stat -c %s "$STAGE/tree/smartfox/smartfox.raw.zst")" -lt 4294967296 ] || { echo "payload too big for FAT32"; exit 1; }
echo "== EFI boot image"
EFI_IMG="$STAGE/efiboot.img"
size_kb=$(( $(stat -c %s "$UKI") / 1024 + 4096 ))
mkfs.vfat -C -n SFBOOT "$EFI_IMG" "$size_kb" >/dev/null
mmd -i "$EFI_IMG" ::/EFI ::/EFI/BOOT
mcopy -i "$EFI_IMG" "$UKI" ::/EFI/BOOT/BOOTX64.EFI
echo "== iso"
ISO="$STAGE/smartfox-installer.iso"
xorriso -as mkisofs \
-iso-level 3 -full-iso9660-filenames -joliet -joliet-long -rational-rock \
-volid SMARTFOX -appid "SmartFox installer" \
-partition_offset 16 \
-append_partition 2 C12A7328-F81F-11D2-BA4B-00A0C93EC93B "$EFI_IMG" -appended_part_as_gpt \
-e --interval:appended_partition_2:all:: -no-emul-boot \
-o "$ISO" "$STAGE/tree" 2>&1 | grep -v '^xorriso : UPDATE' || true
[ -f "$ISO" ] || { echo "xorriso failed"; exit 1; }
mkdir -p "$OUT_DIR"
cp "$ISO" "$OUT_DIR/smartfox-installer.iso"
ls -lh "$OUT_DIR/smartfox-installer.iso"
echo "Rufus: válaszd ki az ISO-t, Partíciós séma: GPT, Cél: UEFI, majd ISO kép mód."

41
image/build.sh Normal file
View File

@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Builds the SmartFox binaries and the OS disk image.
# Run as root inside WSL Debian (or any Debian/Ubuntu host):
# sudo bash /mnt/g/source/smartfox/image/build.sh
set -euo pipefail
SRC="$(cd "$(dirname "$0")/.." && pwd)"
WORK="${SMARTFOX_WORK:-/root/smartfox}"
echo "== sync $SRC -> $WORK"
mkdir -p "$WORK"
# Files on NTFS show up as 0777; normalize, the image must not get world-writable files.
rsync -a --delete --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r \
--exclude /target --exclude /image/mkosi.output --exclude /image/mkosi.cache --exclude /image/stage --exclude /image/ovmf-vars.fd \
--exclude /image/installer/mkosi.output --exclude /image/installer/mkosi.cache --exclude /image/iso --exclude /image/out \
"$SRC/" "$WORK/"
cd "$WORK"
echo "== cargo build"
if ! command -v cargo >/dev/null; then
[ -x "$HOME/.cargo/bin/cargo" ] || curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
export PATH="$HOME/.cargo/bin:$PATH"
fi
cargo build --release -p sf-launcher -p sf-remote
echo "== stage"
STAGE="$WORK/image/stage"
rm -rf "$STAGE"
install -Dm755 target/release/sf-launcher "$STAGE/usr/bin/sf-launcher"
install -Dm755 target/release/sf-remote "$STAGE/usr/bin/sf-remote"
install -Dm755 tools/siri-remote/fastpair.py "$STAGE/usr/bin/sf-pair"
mkdir -p "$STAGE/usr/share/smartfox"
cp -r apps "$STAGE/usr/share/smartfox/apps"
chmod +x image/mkosi.postinst.chroot image/mkosi.extra/usr/bin/sf-session image/mkosi.extra/usr/bin/sf-launcher-start image/mkosi.extra/usr/bin/sf-remote-debug image/mkosi.extra/usr/bin/sf-diag image/*.sh tools/vm/*.sh tools/siri-remote/*.sh tools/siri-remote/*.py
echo "== mkosi"
# Cache and output stay on the Linux filesystem (NTFS mounts break mkosi).
mkdir -p image/mkosi.cache
cd image
mkosi -f build
ls -lh mkosi.output/

View File

@@ -0,0 +1,39 @@
# SmartFox installer: a tiny Debian that runs entirely from RAM (packed as a
# UKI) and writes the SmartFox disk image from the install stick to a disk.
# Built by ../build-iso.sh; not meant to be built on its own.
[Distribution]
Distribution=debian
Release=trixie
Architecture=x86-64
Repositories=main,contrib,non-free,non-free-firmware
[Output]
Format=uki
ImageId=smartfox-installer
OutputDirectory=mkosi.output
CacheDirectory=mkosi.cache
[Content]
Hostname=smartfox-installer
Locale=C.UTF-8
WithDocs=no
KernelCommandLine=console=tty1 quiet loglevel=3 systemd.show_status=false rd.udev.log_level=3 vt.global_cursor_default=1
Packages=
systemd
systemd-sysv
systemd-boot-efi
udev
kmod
linux-image-amd64
util-linux
fdisk
gdisk
e2fsprogs
dosfstools
zstd
efibootmgr
procps
less
kbd
console-setup-linux

View File

@@ -0,0 +1,175 @@
#!/bin/bash
# SmartFox installer: writes the SmartFox disk image from the install stick
# onto an internal disk. The disk is wiped completely.
#
# The stick (written by Rufus in ISO mode, or dd) carries:
# smartfox/smartfox.raw.zst the disk image (zstd)
# smartfox/smartfox.size its uncompressed size in bytes
#
# After writing, the GPT backup header is moved to the end of the disk and the
# GUIDs are made unique. On first boot the installed system creates its data
# partition (/var) in the remaining space (systemd-repart).
set -u
SRC=/run/sf-src
PAYLOAD=smartfox/smartfox.raw.zst
say() { printf '%s\n' "$*"; }
banner() {
clear
say ""
say " SmartFox telepítő"
say " ================="
say ""
}
finish() {
say ""
say " Enter: újraindítás · k + Enter: kikapcsolás · s + Enter: parancssor"
read -r a
case "$a" in
s | S) exec /bin/bash -l ;;
k | K) systemctl poweroff ;;
*) systemctl reboot ;;
esac
sleep infinity
}
die() {
say ""
say " HIBA: $*"
finish
}
# Finds the partition (or whole disk, for dd-written sticks) with the payload
# and mounts it at $SRC. USB sticks can take a few seconds to show up.
find_payload() {
mkdir -p "$SRC"
for _ in $(seq 40); do
while read -r dev fstype; do
case "$fstype" in vfat | iso9660 | exfat | ntfs) ;; *) continue ;; esac
mount -o ro "$dev" "$SRC" 2>/dev/null || continue
if [ -f "$SRC/$PAYLOAD" ]; then
echo "$dev"
return 0
fi
umount "$SRC"
done < <(lsblk -rpno NAME,FSTYPE)
sleep 1
done
return 1
}
# Latin-2 console font (ő, ű), large on TV-sized screens.
font=Lat2-Terminus16
w=$(cut -d, -f1 /sys/class/graphics/fb0/virtual_size 2>/dev/null || echo 0)
[ "${w:-0}" -ge 1600 ] && font=Lat2-Terminus32x16
setfont "$font" 2>/dev/null
human() { numfmt --to=iec --suffix=B --format=%.1f "$1"; }
banner
say " A telepítő pendrive keresése…"
SRC_DEV=$(find_payload) || die "Nem találom a telepítő fájlokat ($PAYLOAD) egyik meghajtón sem."
SRC_DISK=$(lsblk -npo PKNAME "$SRC_DEV" | head -1)
[ -n "$SRC_DISK" ] || SRC_DISK=$SRC_DEV
NEED=$(cat "$SRC/smartfox/smartfox.size" 2>/dev/null || echo 0)
VERSION=$(cat "$SRC/smartfox/version" 2>/dev/null || echo "")
# Candidate disks: everything except the stick itself, optical/loop/zram
# devices and disks too small for the image.
mapfile -t DISKS < <(
lsblk -dbpno NAME,SIZE,TYPE | while read -r name size type; do
[ "$type" = disk ] || continue
[ "$name" = "$SRC_DISK" ] && continue
case "$name" in /dev/loop* | /dev/zram* | /dev/sr* | /dev/ram*) continue ;; esac
[ "$size" -ge $((NEED + 1024 * 1024 * 1024)) ] || continue
echo "$name"
done
)
describe() {
local d=$1 size model tran
size=$(lsblk -dbno SIZE "$d")
model=$(lsblk -dno MODEL "$d" | sed 's/ *$//')
tran=$(lsblk -dno TRAN "$d" | sed 's/ *$//')
printf '%s · %s · %s%s' "$d" "$(human "$size")" "${model:-ismeretlen típus}" "${tran:+ ($tran)}"
}
banner
[ -n "$VERSION" ] && say " Verzió: $VERSION" && say ""
[ "${#DISKS[@]}" -gt 0 ] || die "Nincs olyan belső lemez, amire telepíteni lehetne (legalább $(human $((NEED + 1024 * 1024 * 1024))) kell)."
say " Melyik lemezre telepítsem a SmartFoxot?"
say ""
for i in "${!DISKS[@]}"; do
say " $((i + 1))) $(describe "${DISKS[$i]}")"
lsblk -no NAME,SIZE,FSTYPE,LABEL "${DISKS[$i]}" | tail -n +2 | sed 's/^/ /'
done
say ""
while :; do
if [ "${#DISKS[@]}" -eq 1 ]; then
printf ' Válassz (1, vagy q = kilépés): '
else
printf ' Válassz (1-%s, vagy q = kilépés): ' "${#DISKS[@]}"
fi
read -r pick
case "$pick" in q | Q) finish ;; esac
if [[ "$pick" =~ ^[0-9]+$ ]] && [ "$pick" -ge 1 ] && [ "$pick" -le "${#DISKS[@]}" ]; then
TARGET=${DISKS[$((pick - 1))]}
break
fi
done
banner
say " FIGYELEM: a lemezen MINDEN adat törlődik:"
say ""
say " $(describe "$TARGET")"
say ""
printf ' A folytatáshoz írd be: igen '
read -r ok
[ "$ok" = igen ] || finish
banner
say " Telepítés ide: $(describe "$TARGET")"
say ""
say " 1/3 Lemez törlése…"
umount -q "$TARGET"* 2>/dev/null
wipefs -qa "$TARGET" || die "A lemez törlése nem sikerült."
say " 2/3 Kiírás ($(human "$NEED"))…"
zstd -dcq "$SRC/$PAYLOAD" | dd of="$TARGET" bs=4M iflag=fullblock oflag=direct status=progress
st=("${PIPESTATUS[@]}")
[ "${st[0]}" = 0 ] && [ "${st[1]}" = 0 ] || die "A kiírás nem sikerült."
sync
say ""
say " 3/3 Befejezés…"
# Backup GPT to the real end of the disk, fresh GUIDs for this machine.
sgdisk -q -e -G -A 2:clear:59 "$TARGET" >/dev/null || die "A partíciós tábla javítása nem sikerült."
partx -u "$TARGET" 2>/dev/null
udevadm settle
# A unique machine id (DHCP lease, journal) on the otherwise read-only root.
ROOT=$(lsblk -rpno NAME,PARTN "$TARGET" | awk '$2 == 2 { print $1 }')
if [ -n "$ROOT" ] && mkdir -p /run/sf-root && mount "$ROOT" /run/sf-root; then
systemd-id128 new >/run/sf-root/etc/machine-id
umount /run/sf-root
fi
# Boot entry, so firmware that ignores the fallback path still finds it.
ESP=$(lsblk -rpno NAME,PARTN "$TARGET" | awk '$2 == 1 { print $1 }')
if [ -d /sys/firmware/efi/efivars ] && [ -n "$ESP" ]; then
efibootmgr -q -c -d "$TARGET" -p 1 -L SmartFox -l '\EFI\systemd\systemd-bootx64.efi' 2>/dev/null ||
say " (A UEFI boot bejegyzés nem jött létre, a gép a tartalék útvonalról indul.)"
fi
sync
umount "$SRC" 2>/dev/null
banner
say " Kész! A SmartFox telepítve: $TARGET"
say ""
say " Húzd ki a pendrive-ot, majd nyomj Entert az újraindításhoz."
say " Az első indításkor a rendszer létrehozza az adatpartíciót, ez néhány másodperc."
finish

View File

@@ -0,0 +1,21 @@
[Unit]
Description=SmartFox installer
After=systemd-udevd.service systemd-udev-trigger.service
Conflicts=getty@tty1.service
[Service]
Type=idle
ExecStart=/usr/bin/sf-install
StandardInput=tty
StandardOutput=tty
StandardError=tty
TTYPath=/dev/tty1
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
# Never leave a blank screen: start over if the script dies.
Restart=on-failure
RestartSec=2
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
# The whole image is the initrd: the kernel starts /init.
ln -sf /usr/lib/systemd/systemd /init
chmod +x /usr/bin/sf-install
systemctl enable sf-install.service
systemctl mask getty@tty1.service serial-getty@ttyS0.service systemd-firstboot.service
systemctl set-default multi-user.target

85
image/mkosi.conf Normal file
View File

@@ -0,0 +1,85 @@
# SmartFox OS image (dev build). Build with image/build.sh inside WSL/Linux.
[Distribution]
Distribution=debian
Release=trixie
Architecture=x86-64
Repositories=main,contrib,non-free,non-free-firmware
[Output]
Format=disk
ImageId=smartfox
OutputDirectory=mkosi.output
CacheDirectory=mkosi.cache
[Content]
Bootable=yes
Bootloader=systemd-boot
Hostname=smartfox
Timezone=Europe/Bratislava
Locale=C.UTF-8
# Dev image: root password for ssh/console debugging.
RootPassword=smartfox
WithDocs=no
KernelCommandLine=ro video=Virtual-1:1920x1080 quiet loglevel=3 systemd.show_status=auto rd.udev.log_level=3 vt.global_cursor_default=0
ExtraTrees=mkosi.extra
ExtraTrees=stage
Packages=
systemd
systemd-sysv
systemd-boot
systemd-boot-efi
systemd-resolved
udev
dbus
linux-image-amd64/trixie-backports
login
passwd
firmware-misc-nonfree
firmware-mediatek/trixie-backports
firmware-intel-graphics
firmware-iwlwifi/trixie-backports
firmware-realtek/trixie-backports
intel-media-va-driver-non-free
iproute2
iputils-ping
ca-certificates
openssh-server
less
nano
usbutils
iwd
wireless-regdb
pciutils
kmod
iw
rfkill
ethtool
lshw
mesa-utils
intel-gpu-tools
htop
bluez
systemd-repart
e2fsprogs
python3-dbus
python3-gi
cage
wlr-randr
chromium
fonts-noto-core
fonts-dejavu-core
libgl1-mesa-dri
libegl1
libgles2
libgbm1
libfontconfig1
libfreetype6
libxkbcommon0
libwayland-client0
libwayland-egl1
pipewire
pipewire-pulse
wireplumber
avahi-daemon
uxplay

View File

@@ -0,0 +1,5 @@
Types: deb
URIs: http://deb.debian.org/debian
Suites: trixie-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

View File

@@ -0,0 +1,4 @@
# Root is read-only (gpt-auto, "ro" on the kernel command line).
# Everything that must survive a reboot lives on the data partition at /var.
# nofail: without it the TV still boots (settings just aren't saved).
PARTLABEL=sf-data /var ext4 defaults,noatime,nofail,x-systemd.before=local-fs.target,x-systemd.after=systemd-repart.service,x-systemd.device-timeout=30s 0 2

View File

@@ -0,0 +1,4 @@
# Start the SmartFox session on the first console.
if [ "$(tty)" = "/dev/tty1" ]; then
exec /usr/bin/sf-session
fi

View File

@@ -0,0 +1,2 @@
# Dev image only.
PermitRootLogin yes

View File

@@ -0,0 +1,5 @@
[Match]
Name=en* eth*
[Network]
DHCP=yes

View File

@@ -0,0 +1,6 @@
[Match]
Name=wl*
[Network]
DHCP=yes
IgnoreCarrierLoss=3s

View File

@@ -0,0 +1,4 @@
# sf-remote reads the Siri Remote's HID reports itself; BlueZ's HoG plugin drops them.
[Service]
ExecStart=
ExecStart=/usr/libexec/bluetooth/bluetoothd --noplugin=input,hog

View File

@@ -0,0 +1,3 @@
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin tv --noclear --skip-login --nonewline --noissue %I $TERM

View File

@@ -0,0 +1,79 @@
#!/bin/sh
# Hardware report for remote debugging: WiFi, GPU and rendering speed.
# ssh root@<IP> sf-diag > report.txt
# Read-only, changes nothing.
s() { printf '\n===== %s\n' "$*"; }
run() { s "$*"; "$@" 2>&1; }
run uname -a
run cat /proc/cmdline
run systemd-detect-virt
s "dmi"; cat /sys/class/dmi/id/sys_vendor /sys/class/dmi/id/product_name /sys/class/dmi/id/board_name /sys/class/dmi/id/bios_version 2>&1
# ---- WiFi
run lspci -nnk
run lsusb
run ip -br link
run rfkill list
run iw dev
run networkctl list
run systemctl --no-pager status iwd
run id tv
s "iwd D-Bus as tv (what the Wi-Fi settings see)"
runuser -u tv -- busctl --json=short call net.connman.iwd / org.freedesktop.DBus.ObjectManager GetManagedObjects 2>&1 | head -c 2000; echo
s "loaded wifi modules"; lsmod | grep -E 'iwl|rtw|rtl|mt7|ath|cfg80211|mac80211'
s "kernel log: wifi/firmware"
journalctl -k -b --no-pager | grep -iE 'firmware|iwlwifi|rtw|rtl8|mt79|mt76|ath1|wlan|wlp|cfg80211|regdom|pcie.*(error|fail)'
s "firmware files"; ls /lib/firmware | head -100
# ---- GPU and rendering
run ls -l /dev/dri
run id tv
s "kernel log: graphics"
journalctl -k -b --no-pager | grep -iE 'i915|xe |drm|guc|huc|dmc'
s "drm modes"
for c in /sys/class/drm/card*-*; do
[ "$(cat "$c/status" 2>/dev/null)" = connected ] || continue
echo "$c"; head -5 "$c/modes"
done
s "gpu / cpu clocks"
cat /sys/class/drm/card*/gt_cur_freq_mhz /sys/class/drm/card*/gt_max_freq_mhz 2>/dev/null
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq 2>/dev/null
run free -h
# ---- Standby / wake from suspend (Settings > Energia)
run cat /sys/power/state /sys/power/mem_sleep
s "acpi wakeup"; cat /proc/acpi/wakeup 2>&1
s "bluetooth controller wakeup"
for h in /sys/class/bluetooth/hci*; do
case "$h" in *:*) continue ;; esac
d=$(readlink -f "$h/device")
while [ -n "$d" ] && [ "$d" != / ] && [ "$d" != /sys/devices ]; do
[ -f "$d/power/wakeup" ] && echo "$d: $(cat "$d/power/wakeup")"
d=${d%/*}
done
done
command -v btmgmt >/dev/null && run btmgmt info
s "sf-remote: standby / suspend / wake"
journalctl -b --no-pager -u sf-remote | grep -iE 'standby|suspend|wake|power' | tail -40
s "kernel log: suspend / resume"
journalctl -k -b --no-pager | grep -iE 'PM: suspend|PM: resume|ACPI: PM|wake' | tail -30
# The cage session of user tv.
RT=/run/user/1000
for w in "$RT"/wayland-*; do
case "$w" in *.lock) continue ;; esac
[ -S "$w" ] || continue
s "wlr-randr ($w)"
runuser -u tv -- env XDG_RUNTIME_DIR="$RT" WAYLAND_DISPLAY="${w##*/}" wlr-randr 2>&1
s "eglinfo -B ($w)"
runuser -u tv -- env XDG_RUNTIME_DIR="$RT" WAYLAND_DISPLAY="${w##*/}" eglinfo -B -p wayland 2>&1 | head -40
break
done
s "launcher log (OpenGL, fps, errors)"
LOG=/var/home/tv/smartfox.log
grep -iE 'opengl|fps|error|warn|panic|llvmpipe|softpipe' "$LOG" 2>/dev/null | tail -60
s "launcher log tail"; tail -40 "$LOG" 2>/dev/null
s "top"; top -b -n1 | head -25

View File

@@ -0,0 +1,8 @@
#!/bin/sh
# Runs inside cage: apply the output mode, then start the launcher.
if [ -n "${SMARTFOX_MODE:-}" ]; then
OUT=$(wlr-randr | awk 'NR==1 {print $1}')
wlr-randr --output "$OUT" --custom-mode "$SMARTFOX_MODE" ||
echo "sf-launcher-start: could not set $SMARTFOX_MODE on $OUT"
fi
exec /usr/bin/sf-launcher --fullscreen --apps /usr/share/smartfox/apps

View File

@@ -0,0 +1,49 @@
#!/bin/sh
# Remote debugging switch: starts or stops sshd from the flag the launcher
# writes (Settings > System). Runs as root:
# sf-remote-debug the flag changed (sf-remote-debug.path)
# sf-remote-debug boot at boot (sf-remote-debug-boot.service)
# sf-remote-debug expire the time limit is up (transient timer)
#
# The flag holds "on" or "off". On real hardware ssh never stays on for long:
# it turns off after LIMIT and on every boot. In a VM it stays on without a
# flag and has no limit, because the dev tools (tools/vm) need ssh.
FLAG=/var/lib/smartfox/remote-debug
LIMIT=1h
TIMER=sf-remote-debug-off
vm() { systemd-detect-virt -q; }
stop_timer() {
systemctl stop "$TIMER.timer" 2>/dev/null
systemctl reset-failed "$TIMER.timer" "$TIMER.service" 2>/dev/null
}
off() {
stop_timer
exec systemctl --no-block stop ssh.service
}
case "${1:-}" in
boot | expire)
# Missing flag = off; tv owns the folder and can write it again.
vm && [ "$1" = boot ] || rm -f "$FLAG"
;;
esac
if [ -f "$FLAG" ]; then
state=$(cat "$FLAG")
elif vm; then
state=on
else
state=off
fi
[ "$state" = on ] || off
stop_timer
if ! vm; then
systemd-run --quiet --unit="$TIMER" --on-active="$LIMIT" --timer-property=AccuracySec=1s \
/usr/bin/sf-remote-debug expire
fi
exec systemctl --no-block start ssh.service

View File

@@ -0,0 +1,35 @@
#!/bin/sh
# SmartFox session: kiosk compositor (cage) with the launcher.
# Apps the launcher starts (Chromium etc.) appear full screen on top of it.
CONF="$HOME/.config/smartfox"
LOG="$HOME/smartfox.log"
# $HOME is on the data partition (/var). If it's missing, /var is the
# read-only root: still start the TV, just without saving anything.
if ! mkdir -p "$CONF" 2>/dev/null || ! touch "$LOG" 2>/dev/null; then
echo "sf-session: $HOME is read-only, settings will not be saved" >&2
CONF="$XDG_RUNTIME_DIR/smartfox"
LOG="$XDG_RUNTIME_DIR/smartfox.log"
mkdir -p "$CONF"
fi
[ -f "$CONF/settings.toml" ] || cp /usr/share/smartfox/settings.toml "$CONF/settings.toml"
export XDG_CONFIG_HOME="$(dirname "$CONF")"
export SMARTFOX_SOCKET="$XDG_RUNTIME_DIR/smartfox.sock"
export RUST_LOG="${RUST_LOG:-info}"
# No mouse on the TV: a transparent cursor theme (built in mkosi.postinst.chroot).
export XCURSOR_THEME=smartfox-blank XCURSOR_SIZE=24
# Output mode: the TV's preferred mode, except in VMs where the host window
# reports odd sizes. Override with SMARTFOX_MODE=WxH in /etc/default/smartfox.
[ -f /etc/default/smartfox ] && . /etc/default/smartfox
# Same, on the writable data partition (root is read-only), e.g. for debugging:
# echo 'RUST_LOG=sf_launcher=debug' > /var/lib/smartfox/session.env (fps every 5 s)
[ -f /var/lib/smartfox/session.env ] && . /var/lib/smartfox/session.env
export RUST_LOG
if [ -z "${SMARTFOX_MODE:-}" ] && systemd-detect-virt -q; then
SMARTFOX_MODE=1920x1080
fi
export SMARTFOX_MODE
exec cage -d -s -- /usr/bin/sf-launcher-start >>"$LOG" 2>&1

View File

@@ -0,0 +1,8 @@
# Writable data partition: created on first boot in the free space after the
# (read-only) root partition and mounted at /var (see /etc/fstab).
# Holds /var/home (settings, app profiles), Bluetooth pairings, logs.
[Partition]
Type=linux-generic
Label=sf-data
Format=ext4
SizeMinBytes=1G

View File

@@ -0,0 +1,18 @@
[Unit]
Description=SmartFox: fill the new data partition (/var) with the factory defaults
Documentation=file:/usr/lib/repart.d/50-sf-data.conf
DefaultDependencies=no
RequiresMountsFor=/var
ConditionPathIsMountPoint=/var
ConditionPathExists=!/var/.sf-data
After=local-fs.target
Before=sysinit.target systemd-tmpfiles-setup.service systemd-journal-flush.service systemd-random-seed.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/cp -a /usr/share/factory/var/. /var/
ExecStart=/bin/touch /var/.sf-data
[Install]
WantedBy=sysinit.target

View File

@@ -0,0 +1,10 @@
[Unit]
Description=SmartFox: remote debugging (ssh) off after boot
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/sf-remote-debug boot
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,9 @@
[Unit]
Description=SmartFox: watch the remote debugging switch
[Path]
PathModified=/var/lib/smartfox/remote-debug
Unit=sf-remote-debug.service
[Install]
WantedBy=paths.target

View File

@@ -0,0 +1,7 @@
[Unit]
Description=SmartFox: remote debugging (ssh) on or off
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/sf-remote-debug

View File

@@ -0,0 +1,13 @@
[Unit]
Description=SmartFox Siri Remote driver
After=bluetooth.service
Wants=bluetooth.service
[Service]
ExecStart=/usr/bin/sf-remote --home-socket /run/user/1000/smartfox.sock
Environment=RUST_LOG=info
Restart=always
RestartSec=2
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,2 @@
# The launcher (user tv) writes the remote debugging switch here.
d /var/lib/smartfox 0755 tv tv -

View File

@@ -0,0 +1 @@
netflex_server = "https://netflex.furbidden.cloud"

View File

@@ -0,0 +1,73 @@
#!/bin/sh
# Runs inside the image after packages and extra trees are installed.
set -e
# Homes live on the writable data partition (/var); root is read-only.
if [ ! -L /home ]; then
mkdir -p /var/home
cp -a /home/. /var/home/ 2>/dev/null || true
rm -rf /home
ln -s var/home /home
fi
# The TV user (uid 1000): auto-login on tty1 starts the SmartFox session.
if ! id tv >/dev/null 2>&1; then
useradd -m -d /var/home/tv -u 1000 -s /bin/bash -G video,render,input,audio,bluetooth tv
fi
# Wi-Fi settings: iwd's D-Bus policy lets the netdev group manage networks.
getent group netdev >/dev/null || groupadd -r netdev
usermod -aG netdev tv
systemctl enable systemd-networkd systemd-resolved iwd bluetooth sf-remote.service sf-data-init.service sf-remote-debug-boot.service sf-remote-debug.path
# sshd only runs when remote debugging is on (Settings > System, sf-remote-debug).
systemctl disable ssh.service ssh.socket 2>/dev/null || true
systemctl set-default multi-user.target
# No interactive first-boot questions on a TV (locale, timezone, etc. come from mkosi.conf).
systemctl mask systemd-firstboot.service
# Root is read-only and stays its built size; the data partition takes the rest.
systemctl mask systemd-growfs-root.service
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf || true
# Invisible mouse cursor: the TV only has a keyboard and the remote. Every
# cursor name is a 1x1 transparent image; cage, the launcher and Chromium all
# load cursors from this theme (XCURSOR_THEME in sf-session, and "default").
python3 - <<'EOF'
import os, struct
d = "/usr/share/icons/smartfox-blank/cursors"
os.makedirs(d, exist_ok=True)
img = struct.pack("<9I", 36, 0xFFFD0002, 24, 1, 1, 1, 0, 0, 0) + struct.pack("<I", 0)
data = b"Xcur" + struct.pack("<3I", 16, 0x10000, 1) + struct.pack("<3I", 0xFFFD0002, 24, 28) + img
with open(f"{d}/default", "wb") as f:
f.write(data)
names = """
left_ptr arrow top_left_arrow right_ptr pointer hand hand1 hand2 pointing_hand
text xterm ibeam vertical-text wait watch progress left_ptr_watch half-busy
crosshair cross tcross cell move fleur all-scroll grab grabbing openhand
closedhand dnd-move dnd-copy dnd-link dnd-none dnd-ask copy alias no-drop
not-allowed forbidden crossed_circle circle help question_arrow whats_this
context-menu zoom-in zoom-out col-resize row-resize sb_h_double_arrow
sb_v_double_arrow h_double_arrow v_double_arrow ew-resize ns-resize
nesw-resize nwse-resize e-resize w-resize n-resize s-resize ne-resize
nw-resize se-resize sw-resize right_side left_side top_side bottom_side
top_right_corner top_left_corner bottom_right_corner bottom_left_corner
size_hor size_ver size_bdiag size_fdiag split_h split_v sb_left_arrow
sb_right_arrow sb_up_arrow sb_down_arrow center_ptr pencil draft X_cursor
""".split()
for n in names:
p = f"{d}/{n}"
if not os.path.lexists(p):
os.symlink("default", p)
EOF
printf '[Icon Theme]\nName=smartfox-blank\nComment=Invisible cursor\n' >/usr/share/icons/smartfox-blank/index.theme
mkdir -p /usr/share/icons/default
printf '[Icon Theme]\nInherits=smartfox-blank\n' >/usr/share/icons/default/index.theme
chmod +x /usr/bin/sf-session /usr/bin/sf-pair /usr/bin/sf-remote-debug /usr/bin/sf-diag 2>/dev/null || true
# Factory copy of /var: sf-data-init.service fills the empty data partition from it.
rm -rf /usr/share/factory/var
mkdir -p /usr/share/factory
cp -a /var /usr/share/factory/var
rm -rf /usr/share/factory/var/cache/apt/* /usr/share/factory/var/lib/apt/lists/* /usr/share/factory/var/log/*
mkdir -p /usr/share/factory/var/lib/bluetooth
chmod 700 /usr/share/factory/var/lib/bluetooth

View File

@@ -0,0 +1,5 @@
Types: deb
URIs: http://deb.debian.org/debian
Suites: trixie-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

53
image/run-qemu.sh Normal file
View File

@@ -0,0 +1,53 @@
#!/usr/bin/env bash
# Boots the SmartFox image in QEMU (KVM). Under WSL the window shows up via WSLg.
# sudo bash image/run-qemu.sh [--no-gl] [--bt VID:PID]
# ssh into the VM: ssh -p 2222 root@localhost (password: smartfox)
set -euo pipefail
WORK="${SMARTFOX_WORK:-/root/smartfox}"
IMG="$WORK/image/mkosi.output/smartfox.raw"
VARS="$WORK/image/ovmf-vars.fd"
GL=1
BT=""
while [ $# -gt 0 ]; do
case "$1" in
--no-gl) GL=0 ;;
--bt) BT="$2"; shift ;;
esac
shift
done
# Free space for the data partition (/var) that the image creates on first boot.
if [ "$(stat -c %s "$IMG")" -lt $((8 * 1024 * 1024 * 1024)) ]; then
truncate -s 8G "$IMG"
fi
CODE=/usr/share/OVMF/OVMF_CODE_4M.fd
[ -f "$VARS" ] || cp /usr/share/OVMF/OVMF_VARS_4M.fd "$VARS"
if [ "$GL" = 1 ]; then
GPU=(-device virtio-vga-gl,edid=on,xres=1920,yres=1080 -display gtk,gl=on,zoom-to-fit=on)
else
GPU=(-device virtio-vga,edid=on,xres=1920,yres=1080 -display gtk,zoom-to-fit=on)
fi
USB=(-device qemu-xhci,id=xhci)
if [ -n "$BT" ]; then
USB+=(-device "usb-host,bus=xhci.0,vendorid=0x${BT%%:*},productid=0x${BT##*:}")
fi
AUDIO=()
if [ -n "${PULSE_SERVER:-}" ] || [ -S /mnt/wslg/PulseServer ]; then
export PULSE_SERVER="${PULSE_SERVER:-unix:/mnt/wslg/PulseServer}"
AUDIO=(-audiodev pa,id=snd0 -device ich9-intel-hda -device hda-output,audiodev=snd0)
fi
exec qemu-system-x86_64 \
-name SmartFox -machine q35,accel=kvm -cpu host -smp 4 -m 4096 \
-drive if=pflash,format=raw,readonly=on,file="$CODE" \
-drive if=pflash,format=raw,file="$VARS" \
-drive file="$IMG",format=raw,if=virtio \
"${GPU[@]}" "${USB[@]}" "${AUDIO[@]}" \
-device usb-tablet,bus=xhci.0 \
-monitor unix:/root/qemu-monitor.sock,server,nowait \
-nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22