whitespace
[automated-distro-installer] / arch-pxe
index 56e479094cf2a6525b4835baab4e04c7b2d5d9a8..78205442c62e4b3fe9f1623e43ce6f3c6cf1d31d 100755 (executable)
--- a/arch-pxe
+++ b/arch-pxe
@@ -1,21 +1,61 @@
 #!/bin/bash -lx
+# Copyright (C) 2016 Ian Kelling
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 # Setup arch pxe boot server from the base image.
-# Requires manually downloading image to /a/opt, and set it's name below.
+#
 
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
+usage() {
+    cat <<EOF
+Usage: ${0##*/}
+Setup arch pxe boot server from the base image
+
+Requires manually downloading image. Image path is hardcoded below to
+/a/opt/image_name without .iso on the end. adjust the code for a new image. After this, run pxe-server.
+HOST|default arch to enable it.
+
+-h|--help  Print help and exit.
+EOF
+    exit $1
+}
+
+case $1 in
+    -h|--help) usage ;;
+esac
+
+
+x="$(readlink -f "$BASH_SOURCE")"
+script_dir="${x%/*}"
 cd /a/opt
-#iso="archlinux-2015.11.01-dual"
-iso="archlinux-2016.01.01-dual"
-sfs=$iso/arch/x86_64/airootfs.sfs
+iso="parabola-systemd-cli-x86_64-netinstall-2017.10.18-00.07-alpha"
 rm -rf $iso
 ex $iso.iso
-sed -i -f - $iso/arch/boot/syslinux/archiso_pxe64.cfg <<EOF
+n=parabola
+if [[ ! -e $iso/parabola ]]; then
+    n=arch
+fi
+sfs=$iso/$n/x86_64/*.sfs
+
+sed -i --follow-symlinks -f - $iso/$n/boot/syslinux/${n}iso_pxe64.cfg <<EOF
 1itotaltimeout 1
 /^LABEL arch64_nfs/a menu default
-s/^APPEND .*/\0 script=myarchinit.sh/
+s/^APPEND .*/\0 script=arch-iso-init/
 EOF
 # based on https://blog.chendry.org/2015/02/06/automating-arch-linux-installation.html
 # and https://wiki.archlinux.org/index.php/Remastering_the_Install_ISO
@@ -24,18 +64,14 @@ s rm -rf squashfs-root # remove any existing folder
 s unsquashfs $sfs
 s mkdir -p squashfs-root/root/.ssh
 s chmod 755 squashfs-root/root/.ssh
-s cp ~/.ssh/id_rsa.pub squashfs-root/root/.ssh/authorized_keys
-s dd of=squashfs-root/root/myarchinit.sh <<EOF
-#!/bin/bash
-echo $(date) > /tmp/myarchinit.log
-dhcpcd eth0
-systemctl start sshd
-EOF
+s cp ~/.ssh/home.pub squashfs-root/root/.ssh/authorized_keys
+
+s cp $script_dir/arch-iso-init squashfs-root/root
 s rm $sfs
 s mksquashfs squashfs-root $sfs -comp xz
 # file transfer to wrt is slow, so remove some useless files
-rm $iso/arch/i686/airootfs.sfs $iso/arch/boot/i686/archiso.img
-c $(dirname $sfs); md5sum ${sfs##*/} > airootfs.md5; b
+rm -f $iso/$n/i686/airootfs.sfs $iso/$n/boot/i686/${n}iso.img
+pushd $(dirname $sfs); md5sum ${sfs##*/} > airootfs.md5; popd
 
 # seems if you've done a pxe boot, mounted the nfs,
 # then shutdown, it's still busy.
@@ -47,12 +83,10 @@ ssh wrt "cd /mnt/usb && rm -f tftpboot && ln -s $iso tftpboot"
 
 # The default settings in the installer expect to find the NFS at /run/archiso/bootmnt
 
-pxe-server arch
-
-# background:
-# great documentation at https://wiki.archlinux.org/index.php/PXE
-# background: arch can do netboot like ubuntu etc, but the docs look a little complicated, so fuck it,
-# we use nfs cuz it's easy
+# background: great documentation at
+# https://wiki.archlinux.org/index.php/PXE
+# arch can do netboot like ubuntu etc, but the docs look a little
+# complicated, so fuck it, we use nfs cuz it's easy
 
 rm -rf $iso
 s rm -rf squashfs-root