ungleich-tools/debian-devuan-netboot.sh
2021-03-12 15:24:32 +01:00

120 lines
3 KiB
Bash
Executable file

#!/bin/sh
# Nico Schottelius, 2019-12-09
# the ugly code is llnu
set -e
set -x
if [ $# -ne 2 ]; then
echo $0 suite out-directory
echo out-directory: into which directory to place resulting files
echo suite is for instance ascii, beowulf, etc
exit 1
fi
suite=$1; shift
outdir=$1; shift
date=$(date +%F)
mkdir -p ${outdir}
basename=${suite}-${date}
abs_outdir=$(cd ${outdir} && pwd -P)
chroot_dir=${abs_outdir}/${basename}
kernel=${abs_outdir}/kernel-${basename}
initramfs=${abs_outdir}/initramfs-${basename}
#keyurl=https://code.ungleich.ch/ungleich-public/__ungleich_staff_ssh_access/raw/master/files
keyurl=https://key.wf
debootstrap "${suite}" "${chroot_dir}"
# need non-free for firmware-bnx2
echo "deb http://pkgmaster.devuan.org/merged ${suite} main contrib non-free" > ${chroot_dir}/etc/apt/sources.list
chroot ${chroot_dir} apt update
chroot ${chroot_dir} apt install -y openssh-server rdnssd linux-image-amd64 firmware-bnx2 ifenslave vlan
echo "unconfigured-host" > ${chroot_dir}/etc/hostname
cp ${chroot_dir}/boot/vmlinuz-* ${kernel}
echo '* * * * * root ip -o -6 addr show | grep -E -v " lo |one" > /etc/issue' > ${chroot_dir}/etc/cron.d/ipv6addr
mkdir -p ${chroot_dir}/root/.ssh
for key in sami dominique jinguk nico; do
curl -s ${keyurl}/${key} >> ${chroot_dir}/root/.ssh/authorized_keys
done
# Fix possible permission issue from above
chown -R root:root ${chroot_dir}/root/
################################################################################
# networking
# echo bonding
cat > ${chroot_dir}/etc/network/interfaces << EOF
auto lo
iface lo inet loopback
# I would like to have a generic block like this below
# But as long as interface
auto bond0
iface bond0 inet manual
bond-miimon 500
bond-mode 4
post-up /sbin/ip link set \$IFACE mtu 9000
bond-slaves none
auto eth0
iface eth0 inet manual
bond-master bond0
post-up /sbin/ip link set \$IFACE mtu 9000
auto eth1
iface eth1 inet manual
bond-master bond0
post-up /sbin/ip link set \$IFACE mtu 9000
# server network
auto bond0.11
iface bond0.11 inet6 auto
post-up /sbin/ip link set \$IFACE mtu 9000
vlan-raw-device bond0
EOF
# # find the boot interfaces at boot: HP servers still have ifnames=1
# cat > ${chroot_dir}/etc/rc.local <<EOF
# mac=\$(cat /proc/cmdline | tr ' ' '\n' | awk -F= '/bootdev/ { print \$2 }')
# dev=\$(ip -o link | awk -F: "/\$mac/ { print \\\$2 }" | sed 's/ *//g')
# cat >> /etc/network/interfaces << eof
# auto \$dev
# iface \$dev inet6 auto
# eof
# ifup "\${dev}"
# exit 0
# EOF
# chmod a+rx "${chroot_dir}/etc/rc.local"
# ensure there is /init in the initramfs -> otherwise there is a kernel panic
# reason: initramfs is designed to be PRE regular os, so /init usually hands over to /sbin/init
# in our case, they are just the same
ln -fs /sbin/init ${chroot_dir}/init
# Finally building the initramfs
( cd ${chroot_dir} ; find . | cpio -H newc -o | gzip -9 > ${initramfs} )
# Fix paranoid permissions
chmod a+rx ${abs_outdir}
chmod a+r ${kernel} ${initramfs}
exit 0