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