69e1c52db3a1eaa3a4d543f350ca1f1c1fdff0cb
[automated-distro-installer] / fai / config / distro-install-common / libreboot_grub.cfg
1 #!/bin/sh
2 # shebang is for editor file mode detection only
3
4 function save_vars {
5 if [ -s $envfile ]; then
6 for var in $@; do
7 save_env --file $envfile $var
8 done
9 fi
10 }
11
12 function save_chosen {
13 save_vars did_fai_check last_boot
14 }
15
16 # fai_check is so we can act like a pxe boot, but just for fai, and by
17 # using /debian_bootstrap to do it. We toggle on and off the grub var
18 # did_fai_check so we can do the check every other boot. Then
19 # /debian_bootstrap checks for that var on boot and if we want to do a
20 # fai check, it does it, then reboots. But it also sets did_fai_check to
21 # a 3rd state os_true which means we did the fai check, and we don't
22 # want to do it again. This is useful for systems without libreboot.
23
24 # We don't set this to fai check so we can't get into
25 # an infinite reboot cycle. We depend on the os to
26 # create the initial grubenv file.
27 set default=/debianstable_bootstrap # could use 0 here.
28 set timeout=1
29
30 for part in (ahci*4) (ata*4); do
31 envfile=$part/grubenv
32 if [ -s $envfile ]; then
33 load_env --file $envfile
34 if [ x$did_fai_check == xfalse -a x$last_boot != x$default ]; then
35 set default=fai-check
36 elif [ ! -z $last_boot ]; then
37 set default=$last_boot
38 fi
39 break
40 fi
41 done
42
43 did_fai_check=false
44
45 bs_dir=/debianstable_bootstrap
46 menuentry $bs_dir --id=$bs_dir {
47 # note, we might be able to use $chosen and avoid setting this here,
48 # and set it inside save_chosen. but I haven't tested it,
49 # it's just one less line of repitition.
50 last_boot=$1
51 save_chosen
52 configfile $bs_dir/boot/grub/grub.cfg
53 }
54
55 for dir in /boot_*; do
56 if [ $dir == '/boot_*' ]; then
57 break
58 fi
59 menuentry $dir --id=$dir {
60 last_boot=$1
61 save_chosen
62 configfile $1/grub/grub.cfg
63 }
64 done
65
66 menuentry fai-check --id=fai-check {
67 did_fai_check=true
68 save_vars did_fai_check
69 configfile $bs_dir/boot/grub/grub.cfg
70 }