29bb1fbb7272813e1755b349000bef79bd7c3cd4
[automated-distro-installer] / fai / config / files / root / fai-check / STABLE_BOOTSTRAP
1 #!/bin/bash
2
3 set -eE -o pipefail
4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
5
6 fai_check=false
7 check-fai() {
8 # we could just as well check if last_boot != /debianstable_boostrap
9 # the intent with this one is just a little clearer.
10 if [[ $did_fai_check == true ]]; then
11 fai_check=true
12 pxe-kexec -n --ignore-whitelist -l fai-generated faiserver ||:
13 else
14 return 0
15 fi
16 }
17
18 first=true
19 for dev in $(btrfs fi show / | sed -rn 's#^\s*devid\s.*\s([^0-9 ]+)\S+$#\1#p' \
20 |sort); do
21 dev+=4
22 mount $dev /mnt
23 if $first; then
24 if [[ -e /mnt/grubenv ]]; then
25 source <(grub-editenv /mnt/grubenv list)
26 fi
27 first=false
28 check-fai
29 else
30 # we make sure there is only 1 grubenv,
31 # so grub can just find the first one, in whatever order
32 # if looks at them, which may not be the same as us.
33 # If the disk dies, we just lose the default boot option,
34 # we will have to do manual steps to replace it anyways.
35 rm -f /mnt/gruvenv
36 fi
37 umount /mnt
38 done
39
40 if $fai_check && [[ $last_boot != /debianstable_boostrap ]]; then
41 # no need to reboot if we actually want to boot into this os.
42 reboot
43 fi