Package-based updates: sf-update, signed shell and app packages

- sf-update (root): lists sf-shell / sf-app-* in the Gitea generic registry,
  downloads, checks the Ed25519 signature and unpacks to /var/lib/sf-pkg,
  switches via current/previous/staged symlinks; the factory copies on the
  read-only root stay as fallback. A new shell is on trial and rolls back
  after 3 failed starts.
- Launcher: apps from factory + installed packages (newer version wins),
  Settings > System > Updates (check, install now), shell trial confirm.
- Image: sf-update units (boot apply, 6-hourly download, launcher requests),
  sf-shell-exec wrapper for sf-remote, factory versions, registry token.
- CI: .gitea/workflows/packages.yml builds, signs and uploads packages whose
  version isn't published yet (tools/pkg/packages.sh).
- docs/updates.md: protocol and layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tamas Csikel
2026-10-24 09:27:59 +02:00
parent 79b03cac95
commit d5be90443d
32 changed files with 1892 additions and 16 deletions

View File

@@ -21,7 +21,7 @@ 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
cargo build --release -p sf-launcher -p sf-remote -p sf-update
echo "== stage"
STAGE="$WORK/image/stage"
@@ -29,9 +29,27 @@ 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"
install -Dm755 target/release/sf-update "$STAGE/usr/bin/sf-update"
# Registry login for sf-update (read:package only). Kept out of git; without it
# the TV can only update if the registry allows anonymous downloads.
if [ -f image/secrets/update-token ]; then
install -Dm600 image/secrets/update-token "$STAGE/usr/share/smartfox/update-token"
else
echo "warning: image/secrets/update-token is missing, sf-update will log in anonymously"
fi
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
# Versions of the factory copies: sf-update only installs newer packages.
{
echo "sf-shell = \"$(sed -n '/^\[workspace.package\]/,/^\[/ s/^version *= *"\(.*\)"/\1/p' Cargo.toml)\""
for d in apps/*/; do
v=$(sed -n 's/^version *= *"\(.*\)".*/\1/p' "$d/app.toml" | head -1)
[ -n "$v" ] && echo "sf-app-$(basename "$d") = \"$v\""
done
} >"$STAGE/usr/share/smartfox/factory-versions.toml"
mkdir -p "$STAGE/usr/share/doc/smartfox"
cp docs/updates.md "$STAGE/usr/share/doc/smartfox/updates.md"
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/mkosi.extra/usr/bin/sf-shell-exec 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).

View File

@@ -5,4 +5,30 @@ if [ -n "${SMARTFOX_MODE:-}" ]; then
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
# The launcher from the installed sf-shell package, else the factory copy.
# A new shell is on trial until it has run for a while (it then drops a
# "confirm" request). If it doesn't get there in 3 starts, ask sf-update to
# roll it back and start the factory launcher meanwhile (docs/updates.md).
PKG=/var/lib/sf-pkg/sf-shell
REQ=/var/lib/smartfox/update-requests
TRIES=/var/lib/smartfox/shell-tries
LAUNCHER=/usr/bin/sf-launcher
if [ -x "$PKG/current/bin/sf-launcher" ]; then
LAUNCHER="$PKG/current/bin/sf-launcher"
if [ -f "$PKG/trial" ]; then
n=$(($(cat "$TRIES" 2>/dev/null || echo 0) + 1))
echo "$n" >"$TRIES"
if [ "$n" -gt 3 ]; then
echo "sf-launcher-start: shell $(cat "$PKG/trial") failed $((n - 1)) times, rolling back"
rm -f "$TRIES"
touch "$REQ/rollback"
LAUNCHER=/usr/bin/sf-launcher
else
export SMARTFOX_SHELL_TRIAL=1
fi
else
rm -f "$TRIES"
fi
fi
exec "$LAUNCHER" --fullscreen --apps /usr/share/smartfox/apps --apps /var/lib/sf-pkg/apps

View File

@@ -0,0 +1,9 @@
#!/bin/sh
# Runs a shell binary: the installed sf-shell package if there is one, else
# the factory copy in /usr/bin (sf-update, docs/updates.md).
# sf-shell-exec sf-remote --home-socket ...
name=$1
shift
pkg=/var/lib/sf-pkg/sf-shell/current/bin/$name
[ -x "$pkg" ] && exec "$pkg" "$@"
exec "/usr/bin/$name" "$@"

View File

@@ -4,7 +4,7 @@ After=bluetooth.service
Wants=bluetooth.service
[Service]
ExecStart=/usr/bin/sf-remote --home-socket /run/user/1000/smartfox.sock
ExecStart=/usr/bin/sf-shell-exec sf-remote --home-socket /run/user/1000/smartfox.sock
Environment=RUST_LOG=info
Restart=always
RestartSec=2

View File

@@ -0,0 +1,15 @@
[Unit]
Description=SmartFox: switch downloaded packages live before the TV starts
DefaultDependencies=no
RequiresMountsFor=/var
After=local-fs.target sf-data-init.service
Before=getty@tty1.service sf-remote.service
ConditionPathIsMountPoint=/var
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/sf-update apply
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,10 @@
[Unit]
Description=SmartFox: download new shell and app packages (live at next boot)
Wants=network-online.target
After=network-online.target sf-update-apply.service
[Service]
Type=oneshot
ExecStart=/usr/bin/sf-update auto
Nice=10
IOSchedulingClass=idle

View File

@@ -0,0 +1,10 @@
[Unit]
Description=SmartFox: look for package updates a few times a day
[Timer]
OnBootSec=10min
OnUnitActiveSec=6h
RandomizedDelaySec=30min
[Install]
WantedBy=timers.target

View File

@@ -0,0 +1,10 @@
[Unit]
Description=SmartFox: watch for update requests from the launcher
Documentation=file:/usr/share/doc/smartfox/updates.md
[Path]
DirectoryNotEmpty=/var/lib/smartfox/update-requests
Unit=sf-update-requests.service
[Install]
WantedBy=paths.target

View File

@@ -0,0 +1,7 @@
[Unit]
Description=SmartFox: handle update requests (check, install, confirm, rollback)
After=network-online.target sf-update-apply.service
[Service]
Type=oneshot
ExecStart=/usr/bin/sf-update requests

View File

@@ -1,2 +1,6 @@
# The launcher (user tv) writes the remote debugging switch here.
d /var/lib/smartfox 0755 tv tv -
# sf-update: installed packages (root only writes here) and the launcher's
# request files (check, install, confirm, rollback; see docs/updates.md).
d /var/lib/sf-pkg 0755 root root -
d /var/lib/smartfox/update-requests 0755 tv tv -

View File

@@ -0,0 +1,9 @@
# sf-update: where the shell and app packages come from (docs/updates.md).
# Per-TV overrides (another server, a new token): /var/lib/sf-pkg/update.toml
server = "https://gitea.bluefox.support"
owner = "bluefox"
# "user:token" with read:package only; put there by image/build.sh from
# image/secrets/update-token (not in git).
token_file = "/usr/share/smartfox/update-token"
# Ed25519 key that signs every package (private half: CI secret SF_SIGNING_KEY).
public_key = "8CX4spdfqE17SPGoXWMrLxJCusyAxIZndOc/0zvaal4="

View File

@@ -18,7 +18,7 @@ fi
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
systemctl enable systemd-networkd systemd-resolved iwd bluetooth sf-remote.service sf-data-init.service sf-remote-debug-boot.service sf-remote-debug.path sf-update-apply.service sf-update-requests.path sf-update-auto.timer
# 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
@@ -62,7 +62,7 @@ printf '[Icon Theme]\nName=smartfox-blank\nComment=Invisible cursor\n' >/usr/sha
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
chmod +x /usr/bin/sf-session /usr/bin/sf-pair /usr/bin/sf-remote-debug /usr/bin/sf-diag /usr/bin/sf-shell-exec 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