ungleich-tools/debian-devuan-netboot.sh

83 lines
2.2 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
#this can only run in the ungleich-tools directory because of the cat magiccommand........
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)
2019-12-14 16:24:25 +00:00
basename=${suite}-${date}
dir=${outdir}/${basename}
kernel=${outdir}/kernel-${basename}
initramfs=${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
debootstrap "${suite}" "${dir}"
2019-12-14 16:14:13 +00:00
# need non-free for firmware-bnx2
2019-12-14 16:24:25 +00:00
echo "deb http://pkgmaster.devuan.org/merged ${suite} main contrib non-free" > ${dir}/etc/apt/sources.list
2019-12-11 14:33:24 +00:00
2019-12-14 16:24:25 +00:00
chroot ${dir} apt update
2019-12-14 16:14:13 +00:00
chroot ${dir} apt install -y openssh-server rdnssd linux-image-amd64 firmware-bnx2
2019-12-11 14:33:24 +00:00
2020-06-02 14:46:44 +00:00
echo "unconfigured-host" > ${dir}/etc/hostname
2019-12-11 14:33:24 +00:00
2019-12-14 15:47:35 +00:00
cp ${dir}/boot/vmlinuz-* ${kernel}
2019-12-11 21:56:54 +00:00
2019-12-14 16:26:49 +00:00
echo '* * * * * root ip -o -6 addr show | grep -E -v " lo |one" > /etc/issue' > ${dir}/etc/cron.d/ipv6addr
2019-12-11 21:56:54 +00:00
2019-12-11 14:33:24 +00:00
mkdir -p ${dir}/root/.ssh
for key in balazs dominique jinguk nico; do
curl -s ${keyurl}/${key}.pub >> ${dir}/root/.ssh/authorized_keys
done
2020-06-02 15:20:12 +00:00
# Fix possible permission issue from above
chown -R root:root ${dir}/root/
2019-12-14 16:14:13 +00:00
################################################################################
# networking
# always lo
cat > ${dir}/etc/network/interfaces << EOF
auto lo
iface lo inet loopback
2019-12-14 16:42:12 +00:00
source-directory /etc/network/interfaces.d
2019-12-14 16:14:13 +00:00
EOF
# find the boot interfaces at boot
cat > ${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.d/bootinterface << eof
auto \$dev
iface \$dev inet6 auto
eof
ifup "\${dev}"
exit 0
EOF
2020-06-02 14:46:44 +00:00
chmod a+rx "${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 15:20:12 +00:00
ln -fs /sbin/init ${dir}/init
2019-12-11 14:33:24 +00:00
2019-12-14 16:24:25 +00:00
# Finally building the initramfs
2019-12-14 15:57:25 +00:00
( cd ${dir} ; find . | cpio -H newc -o | gzip -9 > ${initramfs} )