Files
os/image/build.sh
Tamas Csikel d5be90443d 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>
2026-10-24 09:27:59 +02:00

60 lines
2.8 KiB
Bash

#!/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 -p sf-update
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"
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"
# 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).
mkdir -p image/mkosi.cache
cd image
mkosi -f build
ls -lh mkosi.output/