4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
10 Usage: ${0##*/} [OPTION] [HOST]
11 If grub var set, act like pxe rom and pxe-kexec to faiserver
13 -f|--force do kexec if we can reach faiserver
14 -h|--help Print help and exit.
16 Note: Uses GNU getopt options parsing style
23 # Keep it short so we don't delay too much wnen we don't have networking.
24 # In practice, on my home network, on an x200, it took 15 seconds, so
25 # give it an extra 10 seconds, which seems fairly short as I write this.
26 NETWORK_TIMOUT_SECS
=25
29 m
() { printf "%s\n" "$*"; "$@"; }
32 deadline
=$
(( `date +%s` + NETWORK_TIMOUT_SECS
))
33 while ! timeout
-s 9 3 nc
-zu $faiserver 69; do
34 if (( `date +%s` > deadline
)); then
35 echo "fai-check: hit $NETWORK_TIMOUT_SECS s tftp server timeout"
40 m pxe-kexec
-n --ignore-whitelist -l fai-generated
$faiserver ||
:
54 faiserver
=${1:-faiserver.b8.nz}
62 if ! dmidecode
-t system |
grep -F "Version: ThinkPad X200" &>/dev
/null
; then
63 echo "not x200, exiting"
68 for dev
in $
(btrfs
fi show
/ |
sed -rn 's#^\s*devid\s.*\s([^0-9 ]+)\S+$#\1#p' \
72 # Decide which is my grub_ext partition. see partition.DEFAULT file
73 # for details. currently it is 4
74 for (( i
=4; i
<=7; i
++ )); do
75 if [[ $
(blockdev
--getsize64 ${dev}$i) == 8388608 ]]; then
78 echo grub_extn
=$grub_extn
83 echo "$0: error: failed to find grub_ext partition."
86 m mount
$grub_extn /mnt
88 if [[ -e /mnt
/grubenv
]]; then
89 m grub-editenv
/mnt
/grubenv list
90 source <(grub-editenv
/mnt
/grubenv list
)
93 # we could just as well check if last_boot != /debianbullseye_bootstrap
94 # the intent with this one is just a little clearer.
95 if [[ $did_fai_check == true
]]; then
96 m grub-editenv
/mnt
/grubenv
set did_fai_check
=os_true
97 # our service does not wait for network-online.target,
98 # because it will wait for too long when we don't have a network
99 # connection. So, we wait for 10 seconds.
100 # ref: https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
104 # we make sure there is only 1 grubenv,
105 # so grub can just find the first one, in whatever order
106 # if looks at them, which may not be the same as us.
107 # If the disk dies, we just lose the default boot option,
108 # we will have to do manual steps to replace it anyways.
114 # the check for last_boot is not needed afaik, just sanity check.
115 case $did_fai_check in
117 if [[ $last_boot != /debianbullseye_bootstrap
]]; then
118 # no need to reboot if we actually want to boot into this os.
119 echo "last_boot not debianbullseye_bootstrap, rebooting"