185 lines
4.4 KiB
Bash
Executable File
185 lines
4.4 KiB
Bash
Executable File
#! /bin/bash
|
|
set -ex
|
|
|
|
# runs setup commands inside the image, under qemu arm64.
|
|
|
|
sudo tee mnt/root/tmp/image-build.sh >/dev/null <<'EOF'
|
|
#! /bin/bash
|
|
set -ex
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
mkdir -p /etc/apt/apt.conf.d/disabled
|
|
|
|
for f in \
|
|
/etc/apt/apt.conf.d/*command-not-found* \
|
|
/etc/apt/apt.conf.d/*appstream* \
|
|
/etc/apt/apt.conf.d/*packagekit*
|
|
do
|
|
[ -e "$f" ] && mv "$f" /etc/apt/apt.conf.d/disabled/
|
|
done
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
mkdir -p /var/lib/apt/lists/partial
|
|
|
|
# The preinstalled image may contain packages from noble-updates while only
|
|
# noble and noble-security are enabled. Enable noble-updates before installing
|
|
# -dev packages so apt can resolve exact-version dependencies.
|
|
if grep -q '^Suites: noble$' /etc/apt/sources.list.d/ubuntu.sources; then
|
|
sed -i 's/^Suites: noble$/Suites: noble noble-updates/' /etc/apt/sources.list.d/ubuntu.sources
|
|
fi
|
|
|
|
echo "====> updating apt"
|
|
apt-get update
|
|
|
|
echo "====> installing apt packages"
|
|
apt-get install -y \
|
|
ca-certificates \
|
|
curl \
|
|
jq \
|
|
git \
|
|
locales \
|
|
network-manager \
|
|
wpasupplicant \
|
|
iproute2 \
|
|
isc-dhcp-client \
|
|
libcap2-bin \
|
|
pkg-config \
|
|
libdbus-1-dev \
|
|
avahi-daemon \
|
|
avahi-utils \
|
|
libavahi-client-dev \
|
|
bluez \
|
|
python3-pip \
|
|
sox \
|
|
alsa-utils \
|
|
libasound2-plugins \
|
|
swh-plugins \
|
|
i2c-tools \
|
|
device-tree-compiler \
|
|
unzip \
|
|
sudo
|
|
|
|
# setup locale
|
|
locale-gen en_US.UTF-8
|
|
update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
|
|
|
|
echo "====> configuring Wi-Fi for direct wpa_supplicant control"
|
|
mkdir -p /etc/NetworkManager/conf.d
|
|
cat >/etc/NetworkManager/conf.d/10-unmanaged-wifi.conf <<'EONM'
|
|
[keyfile]
|
|
unmanaged-devices=type:wifi
|
|
EONM
|
|
|
|
echo "====> creating toes user"
|
|
if id -u toes >/dev/null 2>&1; then
|
|
usermod -aG sudo toes
|
|
else
|
|
useradd -m -s /bin/bash -G sudo toes
|
|
fi
|
|
|
|
echo 'toes:nicetrywiseguy' | chpasswd
|
|
|
|
printf 'toes ALL=(ALL) NOPASSWD:ALL\n' >/etc/sudoers.d/90-toes
|
|
chmod 0440 /etc/sudoers.d/90-toes
|
|
visudo -cf /etc/sudoers.d/90-toes
|
|
|
|
# enable serial over usb
|
|
echo 'g_serial' >/etc/modules-load.d/usb-serial-gadget.conf
|
|
systemctl enable serial-getty@ttyGS0.service
|
|
|
|
echo "====> building audio overlay"
|
|
/tmp/build-audio.sh
|
|
systemctl enable init-audio.service
|
|
|
|
echo "====> installing rgbled"
|
|
curl -fsSL https://git.nose.space/nakajima/rgbled/releases/download/v0.1.1/install.sh | bash
|
|
|
|
echo "====> installing matter stack"
|
|
curl -fsSL https://git.fishmt.net/nakajima/toes-matter/releases/download/v0.1.1/install.sh | sh
|
|
if [ ! -x /usr/local/bin/toes-matter ]; then
|
|
echo "missing /usr/local/bin/toes-matter after install" >&2
|
|
exit 1
|
|
fi
|
|
systemctl enable toes-matter.service
|
|
|
|
TOES_HOME="$(getent passwd toes | cut -d: -f6)"
|
|
mkdir -p "$TOES_HOME"
|
|
chown toes:toes "$TOES_HOME"
|
|
|
|
echo "====> installing bun"
|
|
runuser -u toes -- env HOME="$TOES_HOME" USER=toes LOGNAME=toes bash -c \
|
|
'curl -fsSL https://bun.sh/install | bash >/dev/null 2>&1'
|
|
|
|
BUN="$TOES_HOME/.bun/bin/bun"
|
|
if [ ! -x "$BUN" ]; then
|
|
echo "missing bun after install: $BUN" >&2
|
|
exit 1
|
|
fi
|
|
ln -sf "$BUN" /usr/local/bin/bun
|
|
setcap 'cap_net_bind_service=+ep' "$BUN"
|
|
|
|
echo "====> installing toes app as toes"
|
|
runuser -u toes -- env HOME="$TOES_HOME" USER=toes LOGNAME=toes bash <<'EOSU'
|
|
set -ex
|
|
|
|
export PATH="$HOME/.bun/bin:/usr/local/bin:/usr/bin:/bin:$PATH"
|
|
|
|
quiet() {
|
|
"$@"
|
|
}
|
|
|
|
REPO="https://git.nose.space/defunkt/toes"
|
|
DEST="$HOME/toes"
|
|
APPS_DIR="$HOME/apps"
|
|
DATA_DIR="$HOME/data"
|
|
|
|
echo "====> installing baudy"
|
|
if [ ! -d "$HOME/baudy" ]; then
|
|
git clone https://git.nose.space/nakajima/baudy "$HOME/baudy"
|
|
fi
|
|
|
|
if [ -d "$DEST/.git" ]; then
|
|
echo "====> Pulling latest toes"
|
|
git -C "$DEST" fetch origin main
|
|
git -C "$DEST" reset --hard origin/main
|
|
else
|
|
echo "====> Cloning toes"
|
|
git clone "$REPO" "$DEST"
|
|
fi
|
|
|
|
mkdir -p "$APPS_DIR" "$DATA_DIR" "$DATA_DIR/toes"
|
|
|
|
cd "$DEST"
|
|
|
|
echo "====> Installing dependencies"
|
|
bun install
|
|
|
|
echo "====> Building"
|
|
bun run build
|
|
|
|
for app in $BUNDLED_APPS; do
|
|
[ -d "$DEST/apps/$app" ] || continue
|
|
echo " $app"
|
|
cp -r "$DEST/apps/$app" "$APPS_DIR/"
|
|
if [ -f "$APPS_DIR/$app/package.json" ]; then
|
|
quiet bun install --frozen-lockfile --cwd "$APPS_DIR/$app" || quiet bun install --cwd "$APPS_DIR/$app"
|
|
fi
|
|
done
|
|
EOSU
|
|
|
|
echo "====> Installing toes service"
|
|
install -m 644 "$TOES_HOME/toes/scripts/toes.service" /etc/systemd/system/toes.service
|
|
systemctl enable toes.service
|
|
|
|
EOF
|
|
|
|
sudo chmod +x mnt/root/tmp/image-build.sh
|
|
sudo chroot mnt/root /bin/bash /tmp/image-build.sh
|
|
sudo rm -f mnt/root/tmp/image-build.sh
|
|
|
|
if [ ! -s mnt/boot/overlays/toesaudio.dtbo ]; then
|
|
echo "missing mnt/boot/overlays/toesaudio.dtbo after chroot build" >&2
|
|
exit 1
|
|
fi
|