a bunch of fixes and improvements
[automated-distro-installer] / archlike-pxe
1 #!/bin/bash -l
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 without .iso on the end. adjust the code for a new image. After this, run pxe-server.
31 HOST|default arch to enable it.
32
33 -h|--help Print help and exit.
34 EOF
35 exit $1
36 }
37
38 case $1 in
39 -h|--help) usage ;;
40 esac
41
42
43 x="$(readlink -f "$BASH_SOURCE")"
44 script_dir="${x%/*}"
45 cd /a/opt/roms
46 iso="parabola-systemd-cli-x86_64-netinstall-2018.06.02.iso"
47 idir=${iso%.iso}
48 rm -rf $idir
49 ex $iso
50 # should be parabola or arch
51 n=${iso%%-*}
52 sfs=$idir/$n/x86_64/*.sfs
53
54 sed -i --follow-symlinks -f - $idir/$n/boot/syslinux/${n}iso_pxe64.cfg <<EOF
55 1itotaltimeout 1
56 /^LABEL arch64_nfs/a menu default
57 s/^APPEND .*/\0 script=archlike-iso-init/
58 EOF
59 # based on https://blog.chendry.org/2015/02/06/automating-arch-linux-installation.html
60 # and https://wiki.archlinux.org/index.php/Remastering_the_Install_ISO
61
62 s rm -rf squashfs-root # remove any existing folder
63 s unsquashfs $sfs
64 s mkdir -p squashfs-root/root/.ssh
65 s chmod 755 squashfs-root/root/.ssh
66 s cp ~/.ssh/home.pub squashfs-root/root/.ssh/authorized_keys
67
68 s cp $script_dir/archlike-iso-init squashfs-root/root
69 s rm $sfs
70 s mksquashfs squashfs-root $sfs -comp xz
71 # file transfer to wrt is slow, so remove some useless files
72 rm -f $idir/$n/i686/airootfs.sfs $idir/$n/boot/i686/${n}iso.img
73 pushd $(dirname $sfs); md5sum ${sfs##*/} > airootfs.md5; popd
74
75 # seems if you've done a pxe boot, mounted the nfs,
76 # then shutdown, it's still busy.
77 ssh wrt "/etc/init.d/nfsd stop; \
78 umount /run/archiso/bootmnt; \
79 umount /run/parabolaiso/bootmnt; \
80 rm -rf /mnt/usb/$idir"
81
82 scp -r $idir wrt:/mnt/usb
83 ssh wrt "cd /mnt/usb && rm -f tftpboot && ln -s $idir tftpboot"
84
85 # The default settings in the installer expect to find the NFS at /run/archiso/bootmnt
86
87 # background: great documentation at
88 # https://wiki.archlinux.org/index.php/PXE
89 # arch can do netboot like ubuntu etc, but the docs look a little
90 # complicated, so fuck it, we use nfs cuz it's easy
91
92 rm -rf $idir
93 s rm -rf squashfs-root