Initial debian-build-netboot.sh script

This commit is contained in:
Timothée Floure 2020-10-04 19:52:58 +02:00
parent e93852f969
commit b1321a3823
1 changed files with 52 additions and 0 deletions

52
debian-build-netboot.sh Executable file
View File

@ -0,0 +1,52 @@
#!/bin/sh
set -e
set -x
if [ $# -ne 1 ]; then
echo "Usage: debian-build-netboot.sh DEBIAN_RELEASE"
exit 1
fi
output_dir=debian-netboot
release=$1
date=$(date +%F)
basename="$release-$date"
chroot_dir="$output_dir/$basename"
# Cleanup output directory.
rm -rf $output_dir
mkdir -p "$chroot_dir"
# Install base system.
debootstrap "$release" "$chroot_dir"
echo "unconfigured-host" > "$chroot_dir/etc/hostname"
# Add non-free repository for firmware-bnx2 network card firmware.
echo "deb http://deb.debian.org/debian/ $release main contrib non-free" > "$chroot_dir/etc/apt/sources.list"
chroot "$chroot_dir" apt-get update
chroot "$chroot_dir" apt-get install -y firmware-bnx2
# SSH server, DNS updates from RAs.
chroot "$chroot_dir" apt-get install -y openssh-server rdnssd
# Install and extract kernel.
chroot "$chroot_dir" apt-get install -y linux-image-amd64
cp "$chroot_dir"/boot/vmlinuz-* "$output_dir/kernel-$basename"
# Deploy SSH keys.
mkdir -p "$chroot_dir/root/.ssh"
for user in tfloure; do
curl "https://meta.recycled.cloud/~$user.keys" >> "$chroot_dir/root/.ssh/authorized_keys"
done
# Make sure there is /init in the initramfs to avoid kernel panic.
# initramfs is designed to be PRE regular os, so /init usually hands over to
# /sbin/init... which are the same in our case.
ln -fs /sbin/init "$chroot_dir/init"
# Display IP addresses on login screen.
echo '* * * * * root ip -6 -o addr show | grep -E -v " lo " > /etc/issue' > "$chroot_dir/etc/cron.d/ipv6addr"
# Build initramfs from generated installation.
(cd "$chroot_dir"; find . | cpio -H newc -o | gzip -9 > "../initramfs-$basename")