743859abcf803d65c7495a4424de204ca94adf7f
[automated-distro-installer] / myfai-chboot
1 #!/bin/bash
2 # This file is part of Ian Kelling's automated-distro-installer
3 # Copyright (C) 2024 Ian Kelling
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 set -eE -o pipefail
20 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
21
22 x=$(readlink -f "$BASH_SOURCE"); cd ${x%/*}
23
24 usage() {
25 cat <<EOF
26 usage: ${0##*/} [OPTIONS] [HOSTNAME|IP|default]
27
28 Sets up tftp pxe config and nfs server on host "faiserver".
29
30 If our kernel has no nfs support, uses apache intead of nfs, and depends
31 on another repo of Ian Kelling, basic-https-conf, where the file is at
32 /a/exe/web-conf.
33
34 Usng this, you can boot into fai with pxe-kexec without changing
35 the dhcp server.
36
37 Argument sets the host to enable it for. No argument disables pxe
38 config for all hosts, but leaves nfs server alone. Use faiserver-disable
39 to disable the nfs server.
40
41 -S sets FAI_ACTION=sysinfo, and remove fai flag reboot.
42 Usefull for doing a system recovery. It reboots automatically anyways :(
43 -k Add serial port output for kgped16
44 -i sets FAI_ACTION=inventory and remove fai flag reboot.
45 I'm not sure what this is usefull for.
46 -h|--help Print help and exit.
47
48 EOF
49 exit $1
50 }
51 case $1 in
52 -h|--help) usage ;;
53 esac
54
55
56 faiserver_addr=$(host faiserver | sed -rn 's/^\S+ has address //p;T;q' ||:)
57 host=$(./chost faiserver)
58 if ip a | grep "^ *inet.\? $faiserver_addr" &>/dev/null; then
59 ./myfai-chboot-local "$@"
60 else
61 ssh root@$host bash -s -- "$@" <myfai-chboot-local
62 fi