static usb ethnet addresses
[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 Using this, you can boot into fai with pxe-kexec without changing the
35 dhcp server. Note, if you are booting using fai-cd, the pxe config does
36 nothing, and only flags affecting FAI_ACTION will have any affect. You
37 can change the fai flags in the grub config, for example in
38 ./grub.cfg.autodiscover, or at runtime by editing a grub menu option.
39 We could probably also set FAI_FLAGS the same way we set FAI_ACTION,
40 but I haven't tried it.
41
42 HOSTNAME|IP|default Sets the host to enable it for. No argument
43 disables pxe config for all hosts, but leaves nfs
44 server alone. Use faiserver-disable to disable the
45 nfs server.
46
47 -S sets FAI_ACTION=sysinfo, and remove fai flag reboot.
48 Usefull for doing a system recovery. It reboots automatically anyways :(
49 -k Add serial port output for kgped16
50 -i sets FAI_ACTION=inventory and remove fai flag reboot.
51 I'm not sure what this is usefull for.
52 -b Setup bonded ethernet.
53 --no-r Tell fai-chboot not to reboot when its done. This is implied by -i and -S.
54 -h|--help Print help and exit.
55
56 EOF
57 exit $1
58 }
59 case $1 in
60 -h|--help) usage ;;
61 esac
62
63
64 faiserver_addr=$(host faiserver | sed -rn 's/^\S+ has address //p;T;q' ||:)
65 host=$(./chost faiserver)
66 if ip a | grep "^ *inet.\? $faiserver_addr" &>/dev/null; then
67 ./myfai-chboot-local "$@"
68 else
69 ssh root@$host bash -s -- "$@" <myfai-chboot-local
70 fi