images/debian-build-netboot.sh

67 lines
1.9 KiB
Bash
Raw Normal View History

2020-10-04 19:52:58 +02:00
#!/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, LVM2.
chroot "$chroot_dir" apt-get install -y openssh-server rdnssd lvm2
# Useful things for cdist manifests to run properly.
chroot "$chroot_dir" apt-get install -y lsb-release ca-certificates
2020-10-04 19:52:58 +02:00
# 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, set default password.
2020-10-04 19:52:58 +02:00
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"
# Configure networking.
cat << EOF > "$chroot_dir/etc/network/interfaces"
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
iface eth0 inet6 auto
EOF
2020-10-04 19:52:58 +02:00
# Build initramfs from generated installation.
(cd "$chroot_dir"; find . | cpio -H newc -o | gzip -9 > "../initramfs-$basename")