just docs
[automated-distro-installer] / arch-pxe
1 #!/bin/bash -lx
2 # Copyright (C) 2016 Ian Kelling
3
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 # Setup arch pxe boot server from the base image.
19 # Requires manually downloading image to /a/opt, and set it's name below.
20
21 set -eE -o pipefail
22 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
23
24 x="$(readlink -f "$BASH_SOURCE")"
25 script_dir="${x%/*}"
26 cd /a/opt
27 iso="archlinux-2016.05.01-dual"
28 sfs=$iso/arch/x86_64/airootfs.sfs
29 rm -rf $iso
30 ex $iso.iso
31 sed -i --follow-symlinks -f - $iso/arch/boot/syslinux/archiso_pxe64.cfg <<EOF
32 1itotaltimeout 1
33 /^LABEL arch64_nfs/a menu default
34 s/^APPEND .*/\0 script=arch-iso-init/
35 EOF
36 # based on https://blog.chendry.org/2015/02/06/automating-arch-linux-installation.html
37 # and https://wiki.archlinux.org/index.php/Remastering_the_Install_ISO
38
39 s rm -rf squashfs-root # remove any existing folder
40 s unsquashfs $sfs
41 s mkdir -p squashfs-root/root/.ssh
42 s chmod 755 squashfs-root/root/.ssh
43 s cp ~/.ssh/id_rsa.pub squashfs-root/root/.ssh/authorized_keys
44
45 s cp $script_dir/arch-iso-init squashfs-root/root
46 s rm $sfs
47 s mksquashfs squashfs-root $sfs -comp xz
48 # file transfer to wrt is slow, so remove some useless files
49 rm $iso/arch/i686/airootfs.sfs $iso/arch/boot/i686/archiso.img
50 c $(dirname $sfs); md5sum ${sfs##*/} > airootfs.md5; b
51
52 # seems if you've done a pxe boot, mounted the nfs,
53 # then shutdown, it's still busy.
54 ssh wrt "/etc/init.d/nfsd stop; \
55 { ! mount | grep /run/archiso/bootmnt || umount /run/archiso/bootmnt; } && \
56 rm -rf /mnt/usb/$iso"
57 scp -r $iso wrt:/mnt/usb
58 ssh wrt "cd /mnt/usb && rm -f tftpboot && ln -s $iso tftpboot"
59
60 # The default settings in the installer expect to find the NFS at /run/archiso/bootmnt
61
62 pxe-server default arch
63
64 # background:
65 # great documentation at https://wiki.archlinux.org/index.php/PXE
66 # background: arch can do netboot like ubuntu etc, but the docs look a little complicated, so fuck it,
67 # we use nfs cuz it's easy
68
69 rm -rf $iso
70 s rm -rf squashfs-root