gui-init: add support for auto-booting default target

if CONFIG_AUTO_BOOT_TIMEOUT exists and is set, and if HOTP
validation was successful, then attempt to boot the default
target after CONFIG_AUTO_BOOT_TIMEOUT seconds if not interrupted
by key press

Signed-off-by: Matt DeVillier <matt.devillier@puri.sm>
This commit is contained in:
Matt DeVillier 2020-01-14 17:04:28 -06:00 committed by tlaurion
parent 89c457706f
commit 055165d61a

View File

@ -9,6 +9,8 @@ export BG_COLOR_ERROR="${CONFIG_ERROR_BG_COLOR:-"--background-gradient 0 0 0 150
. /etc/functions
. /tmp/config
first_pass=true
mount_boot()
{
@ -239,16 +241,34 @@ while true; do
HOTP='N/A'
fi
whiptail $MAIN_MENU_BG_COLOR --clear --title "$MAIN_MENU_TITLE" \
--menu "$date\nTOTP: $TOTP | HOTP: $HOTP" 20 90 10 \
'y' ' Default boot' \
'r' ' Refresh TOTP/HOTP' \
'a' ' Options -->' \
'S' ' System Info' \
'P' ' Power Off' \
2>/tmp/whiptail || recovery "GUI menu failed"
if [[ "$HOTP" = "Success" && $CONFIG_AUTO_BOOT_TIMEOUT && $first_pass = true ]]; then
# save IFS before changing, restore after read
IFS_DEF=$IFS
IFS=''
first_pass=false
echo -e "\nHOTP verification success\n\n"
read -t $CONFIG_AUTO_BOOT_TIMEOUT -s -n 1 -p "Automatic boot in $CONFIG_AUTO_BOOT_TIMEOUT seconds unless interrupted by keypress... "
if [[ $? -ne 0 ]]; then
IFS=$IFS_DEF
# skip to default boot
totp_confirm='y'
echo -e "\n\nAttempting default boot...\n\n"
fi
IFS=$IFS_DEF
fi
totp_confirm=$(cat /tmp/whiptail)
if [ "$totp_confirm" != "y" -o -z "$totp_confirm" ]; then
whiptail $MAIN_MENU_BG_COLOR --clear --title "$MAIN_MENU_TITLE" \
--menu "$date\nTOTP: $TOTP | HOTP: $HOTP" 20 90 10 \
'y' ' Default boot' \
'r' ' Refresh TOTP/HOTP' \
'a' ' Options -->' \
'S' ' System Info' \
'P' ' Power Off' \
2>/tmp/whiptail || recovery "GUI menu failed"
totp_confirm=$(cat /tmp/whiptail)
fi
fi
if [ "$totp_confirm" = "a" ]; then