#!/bin/sh # shebang is for editor file mode detection only function save_vars { if [ -s $envfile ]; then for var in $@; do save_env --file $envfile $var done fi } function save_chosen { save_vars did_fai_check last_boot } # we don't set this to fai check so we can't get into # an infinite reboot cycle. We depend on the os to # create the initial grubenv file. set default=/debianstable_bootstrap # could use 0 here. set timeout=1 for part in (ahci*4) (ata*4); do envfile=$part/grubenv if [ -s $envfile ]; then load_env --file $envfile if [ x$did_fai_check != xtrue -a x$last_boot != x$default ]; then set default=fai-check elif [ ! -z $last_boot ]; then set default=$last_boot fi break fi done did_fai_check=false bs_dir=/debianstable_bootstrap menuentry $bs_dir --id=$bs_dir { # note, we might be able to use $chosen and avoid setting this here, # and set it inside save_chosen. but I haven't tested it, # it's just one less line of repitition. last_boot=$1 save_chosen configfile $bs_dir/boot/grub/grub.cfg } for dir in /boot_*; do if [ $dir == '/boot_*' ]; then break fi menuentry $dir --id=$dir { last_boot=$1 save_chosen configfile $1/grub/grub.cfg } done menuentry fai-check --id=fai-check { did_fai_check=true save_vars did_fai_check configfile $bs_dir/boot/grub/grub.cfg }