Files
os/image/build.sh
2026-10-25 14:11:49 +01:00

83 lines
4.0 KiB
Bash

#!/usr/bin/env bash
# Builds the Fennec OS 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 '*/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 -p sf-core -p sf-miracast -p sf-compositor
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"
for b in sf-core sf-miracast sf-compositor; do
install -Dm755 "target/release/$b" "$STAGE/usr/bin/$b"
done
# 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"
# Official apps only: a folder with its own .git is a store app developed in
# place (docs/store-app-guide.md), not part of the image.
mkdir -p "$STAGE/usr/share/smartfox/apps"
for d in apps/*/; do
[ -e "$d/.git" ] && continue
cp -r "$d" "$STAGE/usr/share/smartfox/apps/"
done
# Apps with a packaging hook (Steam: the official steam-launcher from Valve).
for hook in tools/pkg/*/package.sh; do
id=$(basename "$(dirname "$hook")")
[ -d "$STAGE/usr/share/smartfox/apps/$id" ] || continue
echo "== $id $(bash "$hook" "$STAGE/usr/share/smartfox/apps/$id" | tail -1)"
done
chmod -R a+x "$STAGE"/usr/share/smartfox/apps/*/bin 2>/dev/null || true
# Steam's controller rules (uinput, Steam Controller, DualSense...) and the
# key of Valve's repository (mkosi.postinst.chroot: the 32-bit libraries).
if [ -d "$STAGE/usr/share/smartfox/apps/steam/udev" ]; then
mkdir -p "$STAGE/usr/lib/udev/rules.d"
cp "$STAGE"/usr/share/smartfox/apps/steam/udev/*.rules "$STAGE/usr/lib/udev/rules.d/"
install -Dm644 tools/pkg/steam/valve-archive-keyring.gpg "$STAGE/usr/share/keyrings/valve-archive-keyring.gpg"
fi
# 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 "$STAGE"/usr/share/smartfox/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 docs/store.md "$STAGE/usr/share/doc/smartfox/"
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/