Files
os/image/pi/install.sh
Tamas Csikel 9c710bedb9 Fennec OS 0.3.2: one app at a time, Raspberry Pi shell packages
- sf-core: only one app runs. Home, another app or a cast closes the app
  on screen (after the switch animation) instead of freezing it in the
  background. A frozen app that held a sound stream stalled PipeWire, so
  the next app could not play at all ("Failed to connect stream: No such
  entity" in Netflex after YouTube was sent home mid-video). The
  background limit and the low-memory watcher go with the freezing.
- Raspberry Pi: image/pi (installer on Raspberry Pi OS), aarch64 shell
  packages (sf-shell-<v>-aarch64, arch in pkg.toml, sf-update installs only
  its own architecture), CI builds the aarch64 shell too.
- sf-compositor: volume OSD, screencopy for remote view, blank cursor.
- SDK v0.1.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 19:38:09 +01:00

164 lines
6.7 KiB
Bash

#!/bin/sh
# Installs Fennec OS on a Raspberry Pi (4 or 5) running 64-bit Raspberry Pi OS
# (Debian trixie). The Pi keeps its own system, network (NetworkManager) and
# ssh; Fennec OS takes over the screen: user tv logs in on tty1 and starts
# the TV session instead of the desktop.
#
# sudo ./install.sh install or update, then reboot
# sudo ./install.sh --no-session install, but keep booting to the desktop
# sudo ./install.sh --uninstall back to the desktop (keeps user tv and its data)
# sudo ./install.sh --purge uninstall and delete user tv and all Fennec OS data
#
# Built by image/pi/build.sh.
set -eu
HERE=$(cd "$(dirname "$0")" && pwd)
STATE=/var/lib/smartfox/pi
FILES=$STATE/files
AUTOLOGIN=/etc/systemd/system/getty@tty1.service.d/smartfox-autologin.conf
UNITS="sf-remote.service sf-update-apply.service sf-update-requests.path sf-update-auto.timer"
# Runtime dependencies (the TV image's list, without its kernel, firmware,
# iwd/networkd and Steam parts). Most are already on Raspberry Pi OS.
PACKAGES="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 libspa-0.2-bluetooth pulseaudio-utils avahi-daemon uxplay dbus-user-session libpam-systemd libseat1
libinput10 gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad
gstreamer1.0-libav gstreamer1.0-pipewire glib-networking bubblewrap bluez python3 python3-dbus python3-gi wayvnc"
say() { printf '== %s\n' "$*"; }
die() { printf 'install.sh: %s\n' "$*" >&2; exit 1; }
[ "$(id -u)" = 0 ] || die "run it as root: sudo $0 $*"
uninstall() {
purge=$1
say "Fennec OS: uninstalling"
systemctl disable --now $UNITS 2>/dev/null || true
rm -f "$AUTOLOGIN"
rmdir /etc/systemd/system/getty@tty1.service.d 2>/dev/null || true
if [ -f "$FILES" ]; then
while IFS= read -r f; do rm -f "/$f"; done <"$FILES"
fi
rm -rf /usr/share/smartfox /usr/lib/smartfox /usr/share/icons/smartfox-blank /usr/share/doc/smartfox
rmdir /etc/systemd/system/sf-update-apply.service.d /etc/systemd/system/bluetooth.service.d 2>/dev/null || true
if [ -f "$STATE/icon-theme" ]; then
cp "$STATE/icon-theme" /usr/share/icons/default/index.theme
else
rm -f /usr/share/icons/default/index.theme
fi
target=$(cat "$STATE/default-target" 2>/dev/null || echo graphical.target)
systemctl set-default "$target"
systemctl daemon-reload
systemctl try-restart bluetooth.service || true
rm -rf "$STATE"
if [ "$purge" = 1 ]; then
say "deleting user tv and the Fennec OS data"
pkill -u tv 2>/dev/null || true
sleep 1
userdel -r tv 2>/dev/null || true
rm -rf /var/lib/smartfox /var/lib/sf-pkg
fi
say "done; reboot to get the desktop back (or: systemctl isolate $target)"
}
session=1
case "${1:-}" in
--uninstall) uninstall 0; exit 0 ;;
--purge) uninstall 1; exit 0 ;;
--no-session) session=0 ;;
"") ;;
*) die "unknown option: $1" ;;
esac
[ "$(uname -m)" = aarch64 ] || die "this build is for 64-bit ARM (aarch64), this is $(uname -m)"
[ -d "$HERE/root" ] || die "$HERE/root is missing (unpack the whole tarball)"
say "installing $(cat "$HERE/VERSION" 2>/dev/null || echo 'Fennec OS')"
say "packages"
missing=""
for p in $PACKAGES; do
dpkg-query -W -f='${Status}' "$p" 2>/dev/null | grep -q 'ok installed' || missing="$missing $p"
done
if [ -n "$missing" ]; then
apt-get update -q
# shellcheck disable=SC2086
DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends $missing
fi
say "files"
mkdir -p "$STATE"
# What was here before Fennec OS, for --uninstall (only the first time).
[ -f "$STATE/default-target" ] || systemctl get-default >"$STATE/default-target"
if [ ! -f "$STATE/icon-theme" ] && [ -f /usr/share/icons/default/index.theme ] && ! grep -q smartfox-blank /usr/share/icons/default/index.theme; then
cp /usr/share/icons/default/index.theme "$STATE/icon-theme"
fi
# Files of the previous version that are gone in this one.
new_files=$(cd "$HERE/root" && find . -type f | sed 's#^\./##' | sort)
if [ -f "$FILES" ]; then
printf '%s\n' "$new_files" | comm -23 "$FILES" - | while IFS= read -r f; do rm -f "/$f"; done
fi
rm -rf /usr/share/smartfox/apps
cd "$HERE/root"
printf '%s\n' "$new_files" | while IFS= read -r f; do
mode=$(stat -c %a "$f")
install -D -o root -g root -m "$mode" "$f" "/$f"
done
cd /
printf '%s\n' "$new_files" >"$FILES"
python3 /usr/lib/smartfox/blank-cursor.py
say "user tv"
if ! id tv >/dev/null 2>&1; then
useradd -m -s /bin/bash tv
fi
for g in video render input audio bluetooth netdev; do
getent group "$g" >/dev/null && usermod -aG "$g" tv
done
TV_UID=$(id -u tv)
TV_HOME=$(getent passwd tv | cut -d: -f6)
# The TV image's tv is uid 1000; here 1000 is usually the Pi's own user.
sed -i "s#/run/user/1000#/run/user/$TV_UID#g" /usr/lib/systemd/system/sf-remote.service /usr/bin/sf-diag
cat >"$TV_HOME/.bash_profile" <<'EOF'
# Start the Fennec OS session on the first console (image/pi/install.sh).
if [ "$(tty)" = "/dev/tty1" ]; then
exec /usr/bin/sf-session
fi
EOF
chown tv:tv "$TV_HOME/.bash_profile"
say "services"
systemd-tmpfiles --create /usr/lib/tmpfiles.d/smartfox.conf
[ -f /var/lib/smartfox/store.toml ] || install -o tv -g tv -m644 /usr/share/smartfox/factory-store.toml /var/lib/smartfox/store.toml
systemctl daemon-reload
# shellcheck disable=SC2086
systemctl enable $UNITS
systemctl enable bluetooth.service avahi-daemon.service
# The Siri Remote needs Bluetooth: lift a soft block (Raspberry Pi OS keeps the
# desktop's Bluetooth switch there; systemd-rfkill saves the new state).
for r in /sys/class/rfkill/rfkill*; do
[ "$(cat "$r/type" 2>/dev/null)" = bluetooth ] && echo 0 >"$r/soft"
done
# bluetoothd without its input/HoG plugins: sf-remote reads the Siri Remote itself.
systemctl restart bluetooth.service || true
systemctl restart sf-remote.service || true
say "store apps"
sf-update store || echo "warning: the store apps could not be installed now; the Pi installs them once online" >&2
if [ "$session" = 1 ]; then
say "session: tv on tty1, no desktop"
mkdir -p "$(dirname "$AUTOLOGIN")"
# After the Pi's own autologin.conf (raspi-config), so this one wins.
cat >"$AUTOLOGIN" <<'EOF'
# Fennec OS (image/pi/install.sh --uninstall removes it)
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin tv --noclear --skip-login --nonewline --noissue %I $TERM
EOF
systemctl daemon-reload
systemctl set-default multi-user.target
say "done; reboot to start Fennec OS (or now: systemctl isolate multi-user.target && systemctl restart getty@tty1)"
else
say "done; the Pi still boots to its desktop (start Fennec OS: sudo $0)"
fi