2 # note, this script gets piped to bash, so cant cd to current dir
4 [[ $EUID == 0 ]] ||
exec sudo
"${BASH_SOURCE}" "$@"
7 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
12 fai_reboot_arg
=,reboot
13 while [[ $1 == -* ]]; do
16 echo "see help from myfai-chboot"
41 m
() { printf "$pre %s\n" "$*"; "$@"; }
42 e
() { printf "$pre %s\n" "$*"; }
43 err
() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; }
47 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
49 echo "$0: clearing pxe config and exiting"
53 # assuming ipv4, or else we might need to deal with multiple addresses
54 # in an ipv4 + ipv6 network.
55 my_ip
=$
(ip
-4 route get
8.8.8.8 |
sed -nr 's,^.*src\s+(\S+).*,\1,p')
56 if [[ ! $my_ip ||
$my_ip =~
[[:space
:]] ]]; then
57 echo "$0: error: failed to get \$my_ip, got: $my_ip"
61 if [[ $host == default
]]; then
63 elif [[ $host == [0-9]*.
[0-9]*.
[0-9]*.
[0-9]* ]]; then
66 type -t host &>/dev
/null || apt-get
-y install dnsutils
67 ip
=$
(host $host |
sed -rn 's/^\S+ has address //p;T;q' ||
:)
68 if [[ ! $ip ||
$ip =~
[[:space
:]] ]]; then
69 echo "$0: error: failed to get \$ip, got: $ip"
73 echo "$0: found ip of $host: $ip"
76 if modprobe nfsd
&>/dev
/null
; then
77 std_arg
="-u nfs://faiserver/srv/fai/config"
78 # nfsv4 wont do rw with overlayfs yet
79 # https://lists.uni-koeln.de/pipermail/linux-fai/2017-March/011641.html
80 root_arg
="$my_ip:/srv/fai/nfsroot:vers=3"
81 # fai-setup without -e sets the ip to the local_ip/local_network, eg 192.168.1.3/24
82 # I restrict it to one ip as simple but imperfect access control.
84 # we may chattr +i /etc/exports if we dun want it modified
85 # for example, if we made these exports more widely available
86 # while doing multiple installs or a recovery.
87 if [[ -w /etc
/exports
]]; then
88 sed -ri --follow-symlinks '\%^/srv/fai/%d' /etc
/exports
89 cat >>/etc
/exports
<<EOF
90 /srv/fai/config $ip(async,ro,no_subtree_check,no_root_squash)
91 /srv/fai/nfsroot $ip(async,ro,no_subtree_check,no_root_squash)
95 systemctl start nfs-server
# assumes recent os
97 std_arg
="-u http://faiserver:8080/config.tar.gz"
98 root_arg
="live:http://faiserver:8080/squash.img"
99 /a
/exe
/web-conf
-i -p 8080 - apache2 faiserver
<<EOF
109 # man page doesn't explain this, but this deletes & thus disables
110 # all chboot systems.
111 m fai-chboot
-iv $std_arg default
# set it to default to get a val out of it next
112 kernel
=$
(fai-chboot
-L '^default$' |
awk '{print $3}')
113 default_k_args
=$
(fai-chboot
-L '^default$' | \
114 sed -r "s/^(\S+\s+){3}(.*)/\2/")
115 # example of default_k_args
116 # initrd=initrd.img-3.16.0-4-amd64 ip=dhcp root=192.168.1.3:/srv/fai/nfsroot FAI_CONFIG_SRC=nfs://faiserver/srv/fai/config FAI_ACTION=install
118 # https://wiki.archlinux.org/index.php/Solid_state_drive#Resolving_NCQ_errors
119 # currently on needed on d16 samsung 870 qvo, but better to have this
120 # and not wait for more conditions where its needed.
121 #k_args=(FAI_ACTION=$fai_action libata.force=noncq ifname:bootnet0:08:60:6e:10:f0:fe ifname:bootnet1:08:60:6e:10:f0:98 bond=bond0:bootnet0,bootnet1:mode=balance-rr)
122 #k_args=(FAI_ACTION=$fai_action libata.force=noncq ifname:bootnet0:08:60:6e:10:f0:fe biosdevname=0 bootdev=bootnet0)
123 k_args
=(FAI_ACTION
=$fai_action libata.force
=noncq
)
125 k_args
+=(console
=tty0 console
=ttyS0
,115200)
128 for arg
in $default_k_args; do
130 # default root arg is /srv/fai/nfsroot
131 root
=*) k_args
+=(root
=$root_arg) ;;
132 # note: this works to only dhcp on one interface: ip=eth0:dhcp
135 k_args
+=("bond=bond0:eth0,eth1:mode=balance-rr ip=bond0:dhcp")
143 rm -f /srv
/tftp
/fai
/pxelinux.cfg
/*
144 m fai-chboot
-k "${k_args[*]}" -v -f verbose
,sshd
,createvt
$fai_reboot_arg $std_arg $kernel "$host"
146 # this is needed for autodiscover iso. i'm not sure, it might override
147 # the fai-chboot method of setting this, i'm not sure.
148 echo FAI_ACTION
=$fai_action >> /srv
/fai
/config
/class
/LAST.var