minor updates
[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 #
20
21 set -eE -o pipefail
22 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
23
24 usage() {
25 cat <<EOF
26 Usage: ${0##*/}
27 Setup arch pxe boot server from the base image
28
29 Requires manually downloading image. Image path is hardcoded below to
30 /a/opt/image_name. Run pxe-server HOST|default arch to enable it.
31
32 -h|--help Print help and exit.
33 EOF
34 exit $1
35 }
36
37 case $1 in
38 -h|--help) usage ;;
39 esac
40
41
42 x="$(readlink -f "$BASH_SOURCE")"
43 script_dir="${x%/*}"
44 cd /a/opt
45 iso="archlinux-2017.02.01-dual"
46 sfs=$iso/arch/x86_64/airootfs.sfs
47 rm -rf $iso
48 ex $iso.iso
49 sed -i --follow-symlinks -f - $iso/arch/boot/syslinux/archiso_pxe64.cfg <<EOF
50 1itotaltimeout 1
51 /^LABEL arch64_nfs/a menu default
52 s/^APPEND .*/\0 script=arch-iso-init/
53 EOF
54 # based on https://blog.chendry.org/2015/02/06/automating-arch-linux-installation.html
55 # and https://wiki.archlinux.org/index.php/Remastering_the_Install_ISO
56
57 s rm -rf squashfs-root # remove any existing folder
58 s unsquashfs $sfs
59 s mkdir -p squashfs-root/root/.ssh
60 s chmod 755 squashfs-root/root/.ssh
61 s cp ~/.ssh/id_rsa.pub squashfs-root/root/.ssh/authorized_keys
62
63 s cp $script_dir/arch-iso-init squashfs-root/root
64 s rm $sfs
65 s mksquashfs squashfs-root $sfs -comp xz
66 # file transfer to wrt is slow, so remove some useless files
67 rm $iso/arch/i686/airootfs.sfs $iso/arch/boot/i686/archiso.img
68 pushd $(dirname $sfs); md5sum ${sfs##*/} > airootfs.md5; popd
69
70 # seems if you've done a pxe boot, mounted the nfs,
71 # then shutdown, it's still busy.
72 ssh wrt "/etc/init.d/nfsd stop; \
73 { ! mount | grep /run/archiso/bootmnt || umount /run/archiso/bootmnt; } && \
74 rm -rf /mnt/usb/$iso"
75 scp -r $iso wrt:/mnt/usb
76 ssh wrt "cd /mnt/usb && rm -f tftpboot && ln -s $iso tftpboot"
77
78 # The default settings in the installer expect to find the NFS at /run/archiso/bootmnt
79
80 # background: great documentation at
81 # https://wiki.archlinux.org/index.php/PXE
82 # arch can do netboot like ubuntu etc, but the docs look a little
83 # complicated, so fuck it, we use nfs cuz it's easy
84
85 rm -rf $iso
86 s rm -rf squashfs-root