Files
onefinity-firmware/scripts/install.sh
Henrik Muehe 3d73e6c59d install.sh: mask sysstat, replace dphys-swapfile with fstab entry
Round-3 cold-boot trims:
- mask sysstat.service (sadc CPU/IO logger; nothing reads it).
- mask dphys-swapfile.service and add /var/swap to /etc/fstab so swap
  is brought up by systemd at local-fs.target instead of by an LSB
  wrapper that re-checks the swap file size on every boot.

Both are reversible: `systemctl unmask <unit>` and remove the fstab
line. Before doing the dphys swap, install.sh verifies /var/swap
exists; on a fresh image where the file hasn't been created yet,
nothing is changed and dphys-swapfile keeps running normally.

Userspace boot 11.5s -> 10.7-11.4s on clean runs; bbctrl listen
unchanged at boot+10.4s (the saving moves to chromium/multi-user).
2026-05-01 10:31:40 +02:00

233 lines
6.8 KiB
Bash
Executable File

#!/bin/bash
UPDATE_AVR=true
UPDATE_PY=true
REBOOT=false
while [ $# -gt 0 ]; do
case "$1" in
--no-avr) UPDATE_AVR=false ;;
--no-py) UPDATE_PY=false ;;
esac
shift 1
done
if $UPDATE_PY; then
systemctl stop bbctrl
# Update service
rm -f /etc/init.d/bbctrl
cp scripts/bbctrl.service /etc/systemd/system/
# Cold-boot fast path:
# - bbserial-rebind.service replaces the bbserial unbind/reload
# that used to live in rc.local AFTER bbctrl was already
# listening on /dev/ttyAMA0. Doing it as a unit ordered
# Before=bbctrl.service eliminates a full bbctrl restart
# mid-boot (~5s saved).
cp scripts/bbserial-rebind.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable bbctrl
systemctl enable bbserial-rebind.service
fi
if $UPDATE_AVR; then
chmod +x ./scripts/avr109-flash.py
./scripts/avr109-flash.py src/avr/bbctrl-avr-firmware.hex
fi
# Update config.txt
./scripts/edit-boot-config max_usb_current=1
./scripts/edit-boot-config config_hdmi_boost=8
# TODO Enable GPU
#./scripts/edit-boot-config dtoverlay=vc4-kms-v3d
#./scripts/edit-boot-config gpu_mem=16
#chmod ug+s /usr/lib/xorg/Xorg
# Use the full screen resolution
# grep "^framebuffer_width=1280$" /boot/config.txt >/dev/null
# if [ $? -eq 0 ]; then
# mount -o remount,rw /boot &&
# sed -i 's/^\(framebuffer_.*\)$/#\1/g' /boot/config.txt
# mount -o remount,ro /boot
# REBOOT=true
# fi
# Fix camera
grep dwc_otg.fiq_fsm_mask /boot/cmdline.txt >/dev/null
if [ $? -ne 0 ]; then
mount -o remount,rw /boot &&
sed -i 's/\(.*\)/\1 dwc_otg.fiq_fsm_mask=0x3/' /boot/cmdline.txt
mount -o remount,ro /boot
REBOOT=true
fi
# Enable memory cgroups
grep cgroup_memory /boot/cmdline.txt >/dev/null
if [ $? -ne 0 ]; then
mount -o remount,rw /boot &&
sed -i 's/\(.*\)/\1 cgroup_memory=1/' /boot/cmdline.txt
mount -o remount,ro /boot
REBOOT=true
fi
# Remove Hawkeye
if [ -e /etc/init.d/hawkeye ]; then
apt-get remove --purge -y hawkeye
fi
# Decrease boot delay
sed -i 's/^TimeoutStartSec=.*$/TimeoutStartSec=1/' \
/etc/systemd/system/network-online.target.wants/networking.service
# Change to US keyboard layout
sed -i 's/^XKBLAYOUT="gb"$/XKBLAYOUT="us" # Comment stops change on upgrade/' \
/etc/default/keyboard
# Setup USB stick automount
diff ./scripts/11-automount.rules /etc/udev/rules.d/11-automount.rules \
>/dev/null
if [ $? -ne 0 ]; then
cp ./scripts/11-automount.rules /etc/udev/rules.d/
sed -i 's/^\(MountFlags=slave\)/#\1/' \
/lib/systemd/system/systemd-udevd.service
REBOOT=true
fi
# Increase swap
grep 'CONF_SWAPSIZE=1000' /etc/dphys-swapfile >/dev/null
if [ $? -ne 0 ]; then
sed -i 's/^CONF_SWAPSIZE=.*$/CONF_SWAPSIZE=1000/' /etc/dphys-swapfile
REBOOT=true
fi
# Install .Xresources & .xinitrc
cp scripts/Xresources ~pi/.Xresources
chown pi:pi ~pi/.Xresources
cp scripts/xinitrc ~pi/.xinitrc
chmod +x ~pi/.xinitrc
chown pi:pi ~pi/.xinitrc
#Configure the "ratpoison" window manager
if [ ! -e ~pi/.ratpoisonrc ]; then
cp scripts/ratpoisonrc ~pi/.ratpoisonrc
chmod 644 ~pi/.ratpoisonrc
chown pi:pi ~pi/.ratpoisonrc
fi
# Install bbserial
MODSRC=src/bbserial/bbserial.ko
MODDST=/lib/modules/$(uname -r)/kernel/drivers/tty/serial/bbserial.ko
diff -q $MODSRC $MODDST 2>/dev/null >/dev/null
if [ $? -ne 0 ]; then
cp $MODSRC $MODDST
depmod
REBOOT=true
fi
# Install rc.local. Use the slimmed "fast" variant if it exists in this
# checkout (preferred); fall back to the legacy rc.local for older
# firmware tarballs that don't ship rc.local.fast yet.
if [ -f scripts/rc.local.fast ]; then
cp scripts/rc.local.fast /etc/rc.local
else
cp scripts/rc.local /etc/rc.local
fi
chmod +x /etc/rc.local
# Cold-boot: mask units that contribute to userspace startup time but
# do not benefit a deployed Onefinity Pi. Each is reversible with
# `systemctl unmask <unit>`.
# plymouth-read-write : 4s of work for a splash that rc.local kills
# immediately with `plymouth quit`.
# plymouth-quit-wait : holds graphical.target until the splash is
# fully gone; redundant once the splash is
# masked.
# raspi-config : one-shot first-boot config; on a deployed
# image it's a 2s no-op.
# sysstat : sadc CPU/IO stats logger; not used.
# Use --now so the change also applies to the running system; harmless
# on a fresh install where the units are inactive.
for unit in \
plymouth-read-write.service \
plymouth-quit-wait.service \
raspi-config.service \
sysstat.service; do
systemctl mask --now "$unit" 2>/dev/null || true
done
# Cold-boot: switch swap activation from dphys-swapfile (~4.3s LSB
# wrapper that re-checks the swap file size on every boot) to a plain
# fstab entry. The swap file itself is already created at
# /var/swap by the previous boot; we only need to make sure it gets
# `swapon`'d at local-fs.target instead.
SWAPFILE=/var/swap
if [ -f "$SWAPFILE" ]; then
if ! grep -qE "^[^#]*${SWAPFILE//\//\\/}[[:space:]]+swap" /etc/fstab; then
echo "$SWAPFILE none swap sw 0 0" >> /etc/fstab
fi
systemctl mask --now dphys-swapfile.service 2>/dev/null || true
swapon -a 2>/dev/null || true
fi
# Ensure that the watchdog python library is installed
pip3 list --format=columns | grep watchdog >/dev/null
if [ $? -ne 0 ]; then
pip3 install scripts/pathtools-0.1.2.tar.gz scripts/watchdog-v0.10.6.tar.gz
fi
# Install bbctrl
if $UPDATE_PY; then
rm -rf /usr/local/lib/python*/dist-packages/bbctrl-*
./setup.py install --force
service bbctrl restart
HTTP_DIR=$(find /usr/local/lib/ -type d -name "http")
chmod 777 $HTTP_DIR
fi
# Expand the file system if necessary
chmod +x ./scripts/resize_root_fs.sh
./scripts/resize_root_fs.sh
if [ $? -eq 0 ]; then
REBOOT=true
fi
# Install our logrotate config
cp ./scripts/bbctrl-logrotate /etc/logrotate.d/bbctrl
chown root:root /etc/logrotate.d/bbctrl
# Ensure logrotate runs on every boot (for systems with no network, thus bad clock)
if [ ! -e /etc/cron.d/reboot ]; then
cp ./scripts/cron_d_reboot /etc/cron.d/reboot
mkdir -p /etc/cron.reboot
cp ./scripts/cron_reboot_logrotate /etc/cron.reboot/logrotate
fi
# Delete some cookies that were left behind in older images
chmod +x ./scripts/delete-cookies.py
./scripts/delete-cookies.py
pkill -HUP chromium # Force Chromium to restart, to see the cookie changes
# Get rid of some old files that were left behind in older images
rm -rf /home/pi/hostinfo.txt
rm -rf /home/pi/ssidinfo.txt
rm -rf /home/Downloads/bbctrl-20200415.json
rm -rf /home/bbmc/bbctrl-1.0.0.tar.bz2
rm -rf /home/bbmc/hostinfo.sh
rm -rf /home/bbmc/index.html
rm -rf /home/bbmc/favicon.ico
# Force a logrotate to get everything into a good state
logrotate -f /etc/logrotate.conf
sync
if $REBOOT; then
echo "Rebooting"
reboot
fi
echo "Install complete"