ungleich-tools/debian-devuan-netboot.sh

114 lines
2.9 KiB
Bash
Raw Normal View History

2019-12-11 14:33:24 +00:00
#!/bin/sh
# Nico Schottelius, 2019-12-09
2019-12-11 21:56:54 +00:00
# the ugly code is llnu
2020-06-02 16:31:06 +00:00
set -e
set -x
2019-12-11 14:33:24 +00:00
2019-12-14 15:57:25 +00:00
if [ $# -ne 2 ]; then
echo $0 suite out-directory
echo out-directory: into which directory to place resulting files
2019-12-11 14:33:24 +00:00
echo suite is for instance ascii, beowulf, etc
exit 1
fi
2019-12-14 15:57:25 +00:00
2019-12-11 14:33:24 +00:00
suite=$1; shift
2019-12-14 15:57:25 +00:00
outdir=$1; shift
2019-12-11 14:33:24 +00:00
date=$(date +%F)
2020-06-02 16:31:06 +00:00
mkdir -p ${outdir}
2019-12-11 14:33:24 +00:00
2019-12-14 16:24:25 +00:00
basename=${suite}-${date}
2020-06-02 16:31:06 +00:00
abs_outdir=$(cd ${outdir} && pwd -P)
chroot_dir=${abs_outdir}/${basename}
kernel=${abs_outdir}/kernel-${basename}
initramfs=${abs_outdir}/initramfs-${basename}
2019-12-11 14:33:24 +00:00
keyurl=https://code.ungleich.ch/ungleich-public/__ungleich_staff_ssh_access/raw/master/files
2020-06-02 16:31:06 +00:00
debootstrap "${suite}" "${chroot_dir}"
2019-12-14 16:14:13 +00:00
# need non-free for firmware-bnx2
2020-06-02 16:31:06 +00:00
echo "deb http://pkgmaster.devuan.org/merged ${suite} main contrib non-free" > ${chroot_dir}/etc/apt/sources.list
2019-12-11 14:33:24 +00:00
2020-06-02 16:31:06 +00:00
chroot ${chroot_dir} apt update
2020-06-14 19:20:43 +00:00
chroot ${chroot_dir} apt install -y openssh-server rdnssd linux-image-amd64 firmware-bnx2 ifenslave vlan
2019-12-11 14:33:24 +00:00
2020-06-02 16:31:06 +00:00
echo "unconfigured-host" > ${chroot_dir}/etc/hostname
2019-12-11 14:33:24 +00:00
2020-06-02 16:31:06 +00:00
cp ${chroot_dir}/boot/vmlinuz-* ${kernel}
2019-12-11 21:56:54 +00:00
2020-06-02 16:31:06 +00:00
echo '* * * * * root ip -o -6 addr show | grep -E -v " lo |one" > /etc/issue' > ${chroot_dir}/etc/cron.d/ipv6addr
2019-12-11 21:56:54 +00:00
2020-06-02 16:31:06 +00:00
mkdir -p ${chroot_dir}/root/.ssh
2019-12-11 14:33:24 +00:00
2020-06-24 06:53:37 +00:00
for key in fnux balazs dominique jinguk nico; do
2020-06-02 16:31:06 +00:00
curl -s ${keyurl}/${key}.pub >> ${chroot_dir}/root/.ssh/authorized_keys
2019-12-11 14:33:24 +00:00
done
2020-06-02 15:20:12 +00:00
# Fix possible permission issue from above
2020-06-02 16:31:06 +00:00
chown -R root:root ${chroot_dir}/root/
2020-06-02 15:20:12 +00:00
2019-12-14 16:14:13 +00:00
################################################################################
# networking
2020-06-14 19:20:43 +00:00
# echo bonding
2020-06-02 16:31:06 +00:00
cat > ${chroot_dir}/etc/network/interfaces << EOF
2019-12-14 16:14:13 +00:00
auto lo
iface lo inet loopback
2020-06-14 19:20:43 +00:00
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
2019-12-14 16:14:13 +00:00
EOF
2020-06-14 19:20:43 +00:00
# find the boot interfaces at boot - not needed, always eth0/eth1
# 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')
2019-12-14 16:14:13 +00:00
2020-06-14 19:20:43 +00:00
# cat > /etc/network/interfaces.d/bootinterface << eof
# auto \$dev
# iface \$dev inet6 auto
# eof
2019-12-14 16:14:13 +00:00
2020-06-14 19:20:43 +00:00
# ifup "\${dev}"
2019-12-14 16:14:13 +00:00
2020-06-14 19:20:43 +00:00
# exit 0
# EOF
2019-12-14 16:14:13 +00:00
2020-06-14 19:20:43 +00:00
# chmod a+rx "${chroot_dir}/etc/rc.local"
2019-12-14 16:42:12 +00:00
2019-12-11 14:33:24 +00:00
# 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
2020-06-02 16:31:06 +00:00
ln -fs /sbin/init ${chroot_dir}/init
2019-12-11 14:33:24 +00:00
2019-12-14 16:24:25 +00:00
# Finally building the initramfs
2020-06-02 16:31:06 +00:00
( cd ${chroot_dir} ; find . | cpio -H newc -o | gzip -9 > ${initramfs} )
2020-06-02 18:14:28 +00:00
# Fix paranoid permissions
chmod a+rx ${abs_outdir}
chmod a+r ${kernel} ${initramfs}