add arch support, fixup various things
[automated-distro-installer] / arch-pxe
diff --git a/arch-pxe b/arch-pxe
new file mode 100755 (executable)
index 0000000..5a5b546
--- /dev/null
+++ b/arch-pxe
@@ -0,0 +1,57 @@
+#!/bin/bash -lx
+
+# manually download image to /a/opt, and set it's name below.
+
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
+
+cd /a/opt
+#iso="archlinux-2015.11.01-dual"
+iso="archlinux-2016.01.01-dual"
+sfs=$iso/arch/x86_64/airootfs.sfs
+rm -rf $iso
+ex $iso.iso
+sed -i -f - $iso/arch/boot/syslinux/archiso_pxe64.cfg <<EOF
+1itotaltimeout 1
+/^LABEL arch64_nfs/a menu default
+s/^APPEND .*/\0 script=myarchinit.sh/
+EOF
+# based on https://blog.chendry.org/2015/02/06/automating-arch-linux-installation.html
+# and https://wiki.archlinux.org/index.php/Remastering_the_Install_ISO
+
+s rm -rf squashfs-root # remove any existing folder
+s unsquashfs $sfs
+s mkdir -p squashfs-root/root/.ssh
+s chmod 755 squashfs-root/root/.ssh
+s cp ~/.ssh/id_rsa.pub squashfs-root/root/.ssh/authorized_keys
+s dd of=squashfs-root/root/myarchinit.sh <<EOF
+#!/bin/bash
+echo $(date) > /tmp/myarchinit.log
+dhcpcd eth0
+systemctl start sshd
+EOF
+s rm $sfs
+s mksquashfs squashfs-root $sfs -comp xz
+# file transfer to wrt is slow, so remove some useless files
+rm $iso/arch/i686/airootfs.sfs $iso/arch/boot/i686/archiso.img
+c $(dirname $sfs); md5sum ${sfs##*/} > airootfs.md5; b
+
+# seems if you've done a pxe boot, mounted the nfs,
+# then shutdown, it's still busy.
+ssh wrt "/etc/init.d/nfsd stop; \
+{ ! mount | grep /run/archiso/bootmnt || umount /run/archiso/bootmnt; } && \
+rm -rf /mnt/usb/$iso"
+scp -r $iso wrt:/mnt/usb
+ssh wrt "cd /mnt/usb && rm -f tftpboot && ln -s $iso tftpboot"
+
+# The default settings in the installer expect to find the NFS at /run/archiso/bootmnt
+
+pxe-server arch
+
+# background:
+# great documentation at https://wiki.archlinux.org/index.php/PXE
+# background: arch can do netboot like ubuntu etc, but the docs look a little complicated, so fuck it,
+# we use nfs cuz it's easy
+
+rm -rf $iso
+s rm -rf squashfs-root