mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-05 14:19:56 -05:00
Earlier commit hand-rolled six Type=Link launchers from scratch. The repo already had the canonical files at etc/raspberrypios/wrolpi.desktop, wrolpi-help.desktop, wrolpi-help-files.desktop, and controller.desktop, used on the RPi/Debian bare-metal deployments. Switching the chroot hook to `cp` those files into ~/Desktop/ keeps the live ISO in sync with the other deployments — when those .desktop files get edited (URL changes, new icon, etc.), the live ISO inherits the change with no chroot-hook edit needed. Drops the Kiwix Library, WROLPi Files, and Disk Management entries the previous commit added; the user requested the four canonical entries only. The trust autostart from the previous commit continues to mark all *.desktop in ~/Desktop, so the surviving icons launch on double-click. All four icons tested on the live ISO at 10.0.0.17: WROLPi App https://127.0.0.1 ✓ WROLPi Controller http://127.0.0.1 ✓ WROLPi Help http://127.0.0.1:9086 ✓ WROLPi Help Files file:///opt/wrolpi-help/docs ✓ Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
247 lines
10 KiB
Bash
247 lines
10 KiB
Bash
#!/usr/bin/bash
|
|
# Chroot hook for the combined WROLPi Live + Installer ISO.
|
|
#
|
|
# Composes the full WROLPi stack into the live system during live-build's
|
|
# chroot phase. The resulting squashfs is what runs in live mode AND what
|
|
# the Calamares installer (phase 2) will copy onto the target disk, so any
|
|
# customisation here applies to both deployments.
|
|
|
|
set -e
|
|
set -x
|
|
|
|
# Generate and set default locale to avoid perl warnings.
|
|
# Users can change this later via: sudo dpkg-reconfigure locales
|
|
sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
|
|
locale-gen
|
|
echo 'LANG=en_US.UTF-8' > /etc/default/locale
|
|
export LANG=en_US.UTF-8
|
|
|
|
cat >>/etc/profile <<'EOF'
|
|
alias ll='ls -lh'
|
|
alias la='ll -a'
|
|
EOF
|
|
|
|
# Pre-create the wrolpi user. Same account is used for interactive desktop
|
|
# login (password 'wrolpi') AND as the User= for the wrolpi-* systemd
|
|
# services. live-config sees this existing user at boot and skips its own
|
|
# user creation (preserving our chosen password); the boot params set
|
|
# live-config.username=wrolpi so live-config's other scripts (sudo,
|
|
# lightdm autologin) target this account.
|
|
useradd -m -s /bin/bash -U -G sudo,audio,video,cdrom,plugdev,netdev wrolpi
|
|
echo "wrolpi:wrolpi" | chpasswd
|
|
|
|
# Rebrand from generic Debian so users don't think they have the wrong USB.
|
|
echo "wrolpi" > /etc/hostname
|
|
sed -i 's/127\.0\.1\.1.*/127.0.1.1\twrolpi/' /etc/hosts 2>/dev/null || \
|
|
echo "127.0.1.1 wrolpi" >> /etc/hosts
|
|
cat > /etc/issue <<'EOF'
|
|
WROLPi \n (\l)
|
|
|
|
EOF
|
|
cat > /etc/issue.net <<'EOF'
|
|
WROLPi %h
|
|
|
|
EOF
|
|
|
|
git --version
|
|
|
|
WROLPI_BRANCH="release"
|
|
[ -f /opt/wrolpi-branch ] && WROLPI_BRANCH=$(cat /opt/wrolpi-branch)
|
|
git clone -b "${WROLPI_BRANCH}" https://github.com/lrnselfreliance/wrolpi.git /opt/wrolpi
|
|
rm -f /opt/wrolpi-branch
|
|
|
|
# Install webapp.
|
|
cd /opt/wrolpi/app
|
|
npm --version
|
|
node --version
|
|
npm install
|
|
|
|
# Build the React production bundle. Without this, /opt/wrolpi/app/build/
|
|
# does not exist and wrolpi-app.service (`serve build -l 3000 ...`) returns
|
|
# 404 for every request. Baking the build into the squashfs means the
|
|
# live image works offline immediately and the installed deployment skips
|
|
# a multi-minute first-boot step.
|
|
BROWSERSLIST_IGNORE_OLD_DATA=true npm run build
|
|
|
|
# Install Node console commands.
|
|
npm i -g serve@12.0.1 single-file-cli@2.0.73 readability-extractor@0.0.6
|
|
|
|
# Install Deno runtime. Hash pinned to detect tampering of the upstream release artifact.
|
|
DENO_VERSION="v2.2.4"
|
|
DENO_SHA256="9a260a624cab6e61f7603957f94f638d68739d8c6ac8c38bc337521266603a7c"
|
|
curl -fsSL "https://github.com/denoland/deno/releases/download/${DENO_VERSION}/deno-x86_64-unknown-linux-gnu.zip" -o /tmp/deno.zip
|
|
echo "${DENO_SHA256} /tmp/deno.zip" | sha256sum -c -
|
|
unzip /tmp/deno.zip -d /usr/local/bin/
|
|
chmod +x /usr/local/bin/deno
|
|
rm /tmp/deno.zip
|
|
deno --version
|
|
|
|
# Install Python requirements. Try multiple times because pypi may stop responding.
|
|
python3 --version
|
|
python3 -m venv /opt/wrolpi/venv
|
|
/opt/wrolpi/venv/bin/pip3 install -r /opt/wrolpi/requirements.txt ||
|
|
/opt/wrolpi/venv/bin/pip3 install -r /opt/wrolpi/requirements.txt ||
|
|
/opt/wrolpi/venv/bin/pip3 install -r /opt/wrolpi/requirements.txt
|
|
|
|
# Install Controller with separate venv.
|
|
echo "Pre-installing WROLPi Controller..."
|
|
python3 -m venv /opt/wrolpi/controller/venv
|
|
/opt/wrolpi/controller/venv/bin/pip install --upgrade pip
|
|
/opt/wrolpi/controller/venv/bin/pip install -r /opt/wrolpi/controller/requirements.txt ||
|
|
/opt/wrolpi/controller/venv/bin/pip install -r /opt/wrolpi/controller/requirements.txt ||
|
|
/opt/wrolpi/controller/venv/bin/pip install -r /opt/wrolpi/controller/requirements.txt
|
|
echo "Controller pre-installed"
|
|
|
|
# Install Caddy from official apt repo.
|
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
|
|
apt-get update
|
|
apt-get install -y caddy
|
|
|
|
# Configure Caddy.
|
|
mkdir -p /etc/caddy
|
|
cp /opt/wrolpi/etc/raspberrypios/Caddyfile /etc/caddy/Caddyfile
|
|
mkdir -p /var/www
|
|
cp /opt/wrolpi/etc/raspberrypios/50x.html /var/www/50x.html
|
|
|
|
# WROLPi needs a few privileged commands.
|
|
cp /opt/wrolpi/etc/raspberrypios/90-wrolpi /etc/sudoers.d/90-wrolpi
|
|
chmod 0440 /etc/sudoers.d/90-wrolpi
|
|
# Verify this new file is valid.
|
|
visudo -c -f /etc/sudoers.d/90-wrolpi
|
|
|
|
mkdir /media/wrolpi
|
|
|
|
# Verify blob files were copied in by includes.chroot (downloaded by build.sh).
|
|
[[ -f /opt/wrolpi-blobs/map-fonts.tar.gz && -s /opt/wrolpi-blobs/map-fonts.tar.gz ]] || \
|
|
(echo "ERROR: map-fonts.tar.gz missing from /opt/wrolpi-blobs!" && exit 1)
|
|
[[ -f /opt/wrolpi-blobs/map-overview.pmtiles && -s /opt/wrolpi-blobs/map-overview.pmtiles ]] || \
|
|
(echo "ERROR: map-overview.pmtiles missing from /opt/wrolpi-blobs!" && exit 1)
|
|
|
|
# Bake in pmtiles CLI so first boot does not need internet.
|
|
# Mirrors scripts/install_protomaps.sh; duplicated here because that script's
|
|
# migration logic relies on a running systemd, which is not present in chroot.
|
|
# Hash pinned to detect tampering of the upstream release artifact.
|
|
PMTILES_VERSION="v1.30.1"
|
|
PMTILES_SHA256="23a2a2222f658320b539ccd06ac3b9b3b803ecbdd39a6cb5249d2ce2e16e38ae"
|
|
curl -fsSL "https://github.com/protomaps/go-pmtiles/releases/download/${PMTILES_VERSION}/go-pmtiles_${PMTILES_VERSION#v}_Linux_x86_64.tar.gz" \
|
|
-o /tmp/pmtiles.tar.gz
|
|
echo "${PMTILES_SHA256} /tmp/pmtiles.tar.gz" | sha256sum -c -
|
|
tar -xz -C /usr/local/bin/ -f /tmp/pmtiles.tar.gz pmtiles
|
|
rm /tmp/pmtiles.tar.gz
|
|
chmod +x /usr/local/bin/pmtiles
|
|
pmtiles version
|
|
|
|
# Build and bake in tippecanoe (used to build map search indexes).
|
|
# Hash pinned to detect tampering of the upstream release tarball.
|
|
TIPPECANOE_VERSION="2.79.0"
|
|
TIPPECANOE_SHA256="b0fd9df49b6efc988288ea48774822c6de19eb48428017f27ee0b3b01d44f05d"
|
|
TIPPECANOE_BUILD_DIR=$(mktemp -d)
|
|
curl -fsSL "https://github.com/felt/tippecanoe/archive/refs/tags/${TIPPECANOE_VERSION}.tar.gz" \
|
|
-o /tmp/tippecanoe.tar.gz
|
|
echo "${TIPPECANOE_SHA256} /tmp/tippecanoe.tar.gz" | sha256sum -c -
|
|
tar -xz -C "${TIPPECANOE_BUILD_DIR}" --strip-components=1 -f /tmp/tippecanoe.tar.gz
|
|
rm /tmp/tippecanoe.tar.gz
|
|
(cd "${TIPPECANOE_BUILD_DIR}" && make -j"$(nproc)" && make install)
|
|
rm -rf "${TIPPECANOE_BUILD_DIR}"
|
|
tippecanoe --version
|
|
|
|
# Install WROLPi Help.
|
|
/opt/wrolpi/scripts/install_help_service.sh
|
|
|
|
cp /opt/wrolpi/etc/raspberrypios/wrolpi-*.service /etc/systemd/system/
|
|
cp /opt/wrolpi/etc/raspberrypios/wrolpi-*.timer /etc/systemd/system/
|
|
cp /opt/wrolpi/etc/raspberrypios/wrolpi.target /etc/systemd/system/
|
|
# Copy MOTD scripts, delete original.
|
|
cp /opt/wrolpi/etc/raspberrypios/motd/20-wrolpi.motd /etc/update-motd.d/20-wrolpi
|
|
cp /opt/wrolpi/etc/raspberrypios/motd/30-wrolpi-first.motd /etc/update-motd.d/30-wrolpi
|
|
chmod +x /etc/update-motd.d/*
|
|
truncate -s 0 /etc/motd
|
|
|
|
# NetworkManager for the hotspot.
|
|
systemctl enable NetworkManager
|
|
|
|
# Enable iperf3 for speed testing.
|
|
systemctl enable iperf3
|
|
# Enable first startup script to generate certificates and start Caddy.
|
|
systemctl enable wrolpi-first-startup.service
|
|
# Enable Controller service to start on boot.
|
|
systemctl enable wrolpi-controller.service
|
|
# Apply controller.yaml drives.mounts at boot (replaces /etc/fstab for
|
|
# secondary mounts so the mount table travels with the drive).
|
|
systemctl enable wrolpi-mounts.service
|
|
# Enable weekly certificate renewal check.
|
|
systemctl enable wrolpi-cert-renew.timer
|
|
|
|
# Bootstrap service: on a Live USB it creates the persistence partition on
|
|
# first boot; on every boot (Live or Installed) it ensures a Postgres
|
|
# cluster exists on /media/wrolpi/config/postgresql and the wrolpi-* runtime
|
|
# services are enabled. Installed deployments find no live medium and
|
|
# short-circuit the partition step.
|
|
chmod +x /usr/local/sbin/wrolpi-bootstrap.sh
|
|
systemctl enable wrolpi-bootstrap.service
|
|
|
|
# Plymouth — replace Debian-branded splash with a minimal theme. live-build's
|
|
# initramfs regeneration at the end of the chroot phase will pick up this
|
|
# change so the new theme is used at boot.
|
|
plymouth-set-default-theme text || true
|
|
|
|
# LightDM greeter — add a WROLPi banner so the login screen identifies the
|
|
# system instead of looking like a stock Debian.
|
|
mkdir -p /etc/lightdm/lightdm-gtk-greeter.conf.d
|
|
cat > /etc/lightdm/lightdm-gtk-greeter.conf.d/50-wrolpi.conf <<'EOF'
|
|
[greeter]
|
|
banner-message-enable=true
|
|
banner-message-text=WROLPi
|
|
EOF
|
|
|
|
# LightDM auto-login — drop straight into the XFCE session as wrolpi without
|
|
# a password prompt. The wrolpi password ('wrolpi') is still required for
|
|
# sudo and screen unlock.
|
|
mkdir -p /etc/lightdm/lightdm.conf.d
|
|
cat > /etc/lightdm/lightdm.conf.d/50-wrolpi-autologin.conf <<'EOF'
|
|
[Seat:*]
|
|
autologin-user=wrolpi
|
|
autologin-user-timeout=0
|
|
autologin-session=xfce
|
|
EOF
|
|
|
|
mkdir -p /home/wrolpi/Desktop
|
|
|
|
# Desktop shortcuts to WROLPi's services. Use the canonical .desktop
|
|
# files from the repo (etc/raspberrypios/) so updates to those files
|
|
# propagate to the live ISO without touching the chroot hook.
|
|
# wrolpi-trust-desktop-icons.desktop autostart marks each as trusted at
|
|
# session start so XFCE will launch them on double-click.
|
|
cp /opt/wrolpi/etc/raspberrypios/wrolpi.desktop /home/wrolpi/Desktop/
|
|
cp /opt/wrolpi/etc/raspberrypios/controller.desktop /home/wrolpi/Desktop/
|
|
cp /opt/wrolpi/etc/raspberrypios/wrolpi-help.desktop /home/wrolpi/Desktop/
|
|
cp /opt/wrolpi/etc/raspberrypios/wrolpi-help-files.desktop /home/wrolpi/Desktop/
|
|
|
|
chmod +x /home/wrolpi/Desktop/*.desktop
|
|
chown -R wrolpi:wrolpi /home/wrolpi/Desktop
|
|
|
|
# Drop the default Postgres cluster created by the postgresql-* package.
|
|
# wrolpi-bootstrap.service creates a fresh cluster on /media/wrolpi/config/postgresql
|
|
# at first boot regardless of deployment shape; the cluster files installed
|
|
# here would be masked by the bind-mount on Live and orphaned on Installed.
|
|
# Version derived from the installed binary so this stays correct if the
|
|
# package list is later bumped past postgresql-15.
|
|
PG_VERSION=$(pg_lsclusters -h | awk 'NR==1{print $1}')
|
|
[ -n "${PG_VERSION}" ] || (echo "ERROR: no Postgres cluster found to drop" && exit 1)
|
|
pg_dropcluster --stop "${PG_VERSION}" main
|
|
|
|
# Protect blob files from accidental modification or deletion.
|
|
if [ -d /opt/wrolpi-blobs ] && ls /opt/wrolpi-blobs/* >/dev/null 2>&1; then
|
|
chown -R root:root /opt/wrolpi-blobs
|
|
chmod 444 /opt/wrolpi-blobs/*
|
|
chattr +i /opt/wrolpi-blobs/*
|
|
fi
|
|
|
|
set +x
|
|
|
|
echo
|
|
echo "======================================================================"
|
|
echo "9999-wrolpi.hook.chroot completed"
|
|
echo "======================================================================"
|
|
echo
|