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 . /etc/functions
. /tmp/config . /tmp/config
first_pass=true
mount_boot() mount_boot()
{ {
@ -239,16 +241,34 @@ while true; do
HOTP='N/A' HOTP='N/A'
fi fi
whiptail $MAIN_MENU_BG_COLOR --clear --title "$MAIN_MENU_TITLE" \ if [[ "$HOTP" = "Success" && $CONFIG_AUTO_BOOT_TIMEOUT && $first_pass = true ]]; then
--menu "$date\nTOTP: $TOTP | HOTP: $HOTP" 20 90 10 \ # save IFS before changing, restore after read
'y' ' Default boot' \ IFS_DEF=$IFS
'r' ' Refresh TOTP/HOTP' \ IFS=''
'a' ' Options -->' \ first_pass=false
'S' ' System Info' \ echo -e "\nHOTP verification success\n\n"
'P' ' Power Off' \ read -t $CONFIG_AUTO_BOOT_TIMEOUT -s -n 1 -p "Automatic boot in $CONFIG_AUTO_BOOT_TIMEOUT seconds unless interrupted by keypress... "
2>/tmp/whiptail || recovery "GUI menu failed" 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 fi
if [ "$totp_confirm" = "a" ]; then if [ "$totp_confirm" = "a" ]; then