a bunch of fixes and improvements
[automated-distro-installer] / fai-wrapper
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4
5 # For using some fai commands outside of fai.
6 # Usually this is sourced from another script. Note this has
7 # paths specific to Ian's machine.
8 # to set fai classes, export CLASS_CLASSNAME=true
9 # This wrapper can be detected by using this var:
10 export FAI_WRAPPER=true
11
12 ifclass() {
13 local var=${1/#/CLASS_}
14 [[ $HOSTNAME == $1 || ${!var} ]]
15 }
16 fai-setclass() {
17 for class in "$@"; do
18 # export class vars with CLASS_ in front to avoid name collisions.
19 classes+=" $class"
20 export CLASS_$class=true
21 done
22 classes="${classes# }"
23 export classes
24 }
25 eval-fai-classfile() {
26 file=$1
27 if [[ ! -s $file ]]; then
28 echo "$0: probably an error: eval-fai-classfile no such file: $file"
29 return 0
30 fi
31 fai-setclass $(bash $file)
32 }
33 export -f ifclass
34 classes=DEFAULT # used by fcopy
35 export CLASS_DEFAULT=true
36 if [[ ! -d $FAI_ROOT ]]; then
37 export FAI_ROOT=/
38 fi
39 if [[ ! -d $FAI ]]; then
40 if [[ -d /a/bin/fai/fai/config ]]; then
41 export FAI=/a/bin/fai/fai/config
42 else
43 echo "$0: error: could not find directory to set for FAI. currently FAI=$FAI"
44 return 1
45 fi
46 fi
47
48 eval-fai-classfile $FAI/class/50-host-classes
49 eval-fai-classfile $FAI/class/51-multi-boot