X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=fai%2Fconfig%2Ffiles%2Froot%2Ffai-check%2FSTABLE_BOOTSTRAP;fp=fai%2Fconfig%2Ffiles%2Froot%2Ffai-check%2FSTABLE_BOOTSTRAP;h=29bb1fbb7272813e1755b349000bef79bd7c3cd4;hb=d6df8985152a6c17523cedc3fee62694544eeaf2;hp=0000000000000000000000000000000000000000;hpb=ec9227898fa68bd89de454c87bce8ea051a8d783;p=automated-distro-installer diff --git a/fai/config/files/root/fai-check/STABLE_BOOTSTRAP b/fai/config/files/root/fai-check/STABLE_BOOTSTRAP new file mode 100755 index 0000000..29bb1fb --- /dev/null +++ b/fai/config/files/root/fai-check/STABLE_BOOTSTRAP @@ -0,0 +1,43 @@ +#!/bin/bash + +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR + +fai_check=false +check-fai() { + # we could just as well check if last_boot != /debianstable_boostrap + # the intent with this one is just a little clearer. + if [[ $did_fai_check == true ]]; then + fai_check=true + pxe-kexec -n --ignore-whitelist -l fai-generated faiserver ||: + else + return 0 + fi +} + +first=true +for dev in $(btrfs fi show / | sed -rn 's#^\s*devid\s.*\s([^0-9 ]+)\S+$#\1#p' \ + |sort); do + dev+=4 + mount $dev /mnt + if $first; then + if [[ -e /mnt/grubenv ]]; then + source <(grub-editenv /mnt/grubenv list) + fi + first=false + check-fai + else + # we make sure there is only 1 grubenv, + # so grub can just find the first one, in whatever order + # if looks at them, which may not be the same as us. + # If the disk dies, we just lose the default boot option, + # we will have to do manual steps to replace it anyways. + rm -f /mnt/gruvenv + fi + umount /mnt +done + +if $fai_check && [[ $last_boot != /debianstable_boostrap ]]; then + # no need to reboot if we actually want to boot into this os. + reboot +fi