fix bugs, support multiple distros via subvolumes
[automated-distro-installer] / arch-pxe
1 #!/bin/bash -lx
2
3 # Setup arch pxe boot server from the base image.
4 # Requires manually downloading image to /a/opt, and set it's name below.
5
6 set -eE -o pipefail
7 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
8
9 cd /a/opt
10 #iso="archlinux-2015.11.01-dual"
11 iso="archlinux-2016.01.01-dual"
12 sfs=$iso/arch/x86_64/airootfs.sfs
13 rm -rf $iso
14 ex $iso.iso
15 sed -i -f - $iso/arch/boot/syslinux/archiso_pxe64.cfg <<EOF
16 1itotaltimeout 1
17 /^LABEL arch64_nfs/a menu default
18 s/^APPEND .*/\0 script=myarchinit.sh/
19 EOF
20 # based on https://blog.chendry.org/2015/02/06/automating-arch-linux-installation.html
21 # and https://wiki.archlinux.org/index.php/Remastering_the_Install_ISO
22
23 s rm -rf squashfs-root # remove any existing folder
24 s unsquashfs $sfs
25 s mkdir -p squashfs-root/root/.ssh
26 s chmod 755 squashfs-root/root/.ssh
27 s cp ~/.ssh/id_rsa.pub squashfs-root/root/.ssh/authorized_keys
28 s dd of=squashfs-root/root/myarchinit.sh <<EOF
29 #!/bin/bash
30 echo $(date) > /tmp/myarchinit.log
31 dhcpcd eth0
32 systemctl start sshd
33 EOF
34 s rm $sfs
35 s mksquashfs squashfs-root $sfs -comp xz
36 # file transfer to wrt is slow, so remove some useless files
37 rm $iso/arch/i686/airootfs.sfs $iso/arch/boot/i686/archiso.img
38 c $(dirname $sfs); md5sum ${sfs##*/} > airootfs.md5; b
39
40 # seems if you've done a pxe boot, mounted the nfs,
41 # then shutdown, it's still busy.
42 ssh wrt "/etc/init.d/nfsd stop; \
43 { ! mount | grep /run/archiso/bootmnt || umount /run/archiso/bootmnt; } && \
44 rm -rf /mnt/usb/$iso"
45 scp -r $iso wrt:/mnt/usb
46 ssh wrt "cd /mnt/usb && rm -f tftpboot && ln -s $iso tftpboot"
47
48 # The default settings in the installer expect to find the NFS at /run/archiso/bootmnt
49
50 pxe-server arch
51
52 # background:
53 # great documentation at https://wiki.archlinux.org/index.php/PXE
54 # background: arch can do netboot like ubuntu etc, but the docs look a little complicated, so fuck it,
55 # we use nfs cuz it's easy
56
57 rm -rf $iso
58 s rm -rf squashfs-root