From 055165d61a3c312e7e03998ea832447452a86d71 Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Tue, 14 Jan 2020 17:04:28 -0600 Subject: [PATCH] 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 --- initrd/bin/gui-init | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/initrd/bin/gui-init b/initrd/bin/gui-init index ecd7df33..6a2b18a2 100755 --- a/initrd/bin/gui-init +++ b/initrd/bin/gui-init @@ -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