pirogue-images/raspberrypi/recipes/pi3-pi4.sh
Cyril Brulebois a9332126bb Work around longstanding bug regarding SSH host keys.
The original image leads to repeated failures to start for sshd.service
since there are no host keys initially. Make sure the unit in charge of
getting those keys generated runs before sshd.

The following block gets repeated otherwise:

    systemd[1]: Starting ssh.service - OpenBSD Secure Shell server...
    sshd[795]: sshd: no hostkeys available -- exiting.
    systemd[1]: ssh.service: Control process exited, code=exited, status=1/FAILURE
    systemd[1]: ssh.service: Failed with result 'exit-code'.
    systemd[1]: Failed to start ssh.service - OpenBSD Secure Shell server.
    systemd[1]: ssh.service: Scheduled restart job, restart counter is at 1.
    systemd[1]: Stopped ssh.service - OpenBSD Secure Shell server.
2024-07-20 14:06:47 +02:00

30 lines
1.3 KiB
Bash

# This recipe is sourced by the toaster, don't try to run it!
# shellcheck disable=SC2086
toast_me() {
echo "nameserver 1.1.1.1" > $MNT/etc/resolv.conf
# Install minimal tools
chroot $MNT apt-get update
chroot $MNT apt-get install -y wget sudo avahi-daemon
chroot $MNT apt-get clean
# Ensure we have the pi user
chroot $MNT adduser --disabled-password --gecos '' pi
chroot $MNT adduser pi sudo
chroot $MNT adduser pi plugdev
echo "pi:raspberry" | chroot $MNT chpasswd
# Force generate SSH host keys if they exist
rm -f $MNT/etc/ssh/ssh_host_*
# Work around longstanding bug (ssh fails to start until host keys
# have been generated on the target), until it's fixed upstream:
if ! grep -qs ^Before= $MNT/etc/systemd/system/rpi-generate-ssh-host-keys.service; then
sed '/^Description=/a Before=sshd.service' -i $MNT/etc/systemd/system/rpi-generate-ssh-host-keys.service
fi
# Change the hostname
echo "127.0.1.1 pirogue.local pirogue" >> $MNT/etc/hosts
echo "::1 pirogue.local pirogue" >> $MNT/etc/hosts
echo "pirogue" > $MNT/etc/hostname
# Add PTS PPA
chroot $MNT wget -O /etc/apt/sources.list.d/pirogue.list https://pts-project.org/debian-12/pirogue.list
chroot $MNT wget -O /etc/apt/trusted.gpg.d/pirogue.asc https://pts-project.org/debian-12/Key.gpg
}