2018-12-06 18:43:34 +00:00
#!/bin/sh
#
set -e -o pipefail
. /etc/functions
2020-07-10 17:58:32 +00:00
. /etc/gui_functions
2018-12-06 23:24:28 +00:00
. /tmp/config
2018-12-06 18:43:34 +00:00
2019-07-09 03:20:45 +00:00
param = $1
2018-12-06 18:43:34 +00:00
while true; do
2019-07-09 03:20:45 +00:00
if [ ! -z " $param " ] ; then
# use first char from parameter
menu_choice = ${ param : : 1 }
unset param
else
2019-07-09 03:23:04 +00:00
unset menu_choice
2021-09-23 17:56:17 +00:00
whiptail $BG_COLOR_MAIN_MENU --clear --title "Config Management Menu" \
2018-12-06 21:51:46 +00:00
--menu "This menu lets you change settings for the current BIOS session.\n\nAll changes will revert after a reboot,\n\nunless you also save them to the running BIOS." 20 90 10 \
2018-12-06 18:43:34 +00:00
'b' ' Change the /boot device' \
's' ' Save the current configuration to the running BIOS' \
2019-07-09 14:02:46 +00:00
'r' ' Clear GPG key(s) and reset all user settings' \
2019-07-09 03:20:45 +00:00
'x' ' Return to Main Menu' \
2018-12-06 18:43:34 +00:00
2>/tmp/whiptail || recovery "GUI menu failed"
2019-07-09 03:23:04 +00:00
menu_choice = $( cat /tmp/whiptail)
2019-07-09 03:20:45 +00:00
fi
2018-12-06 18:43:34 +00:00
case " $menu_choice " in
"x" )
exit 0
; ;
"b" )
2018-12-07 00:45:40 +00:00
CURRENT_OPTION = ` grep 'CONFIG_BOOT_DEV=' /tmp/config | tail -n1 | cut -f2 -d '=' | tr -d '"' `
2021-09-23 18:07:07 +00:00
if ! fdisk -l | grep "Disk" | cut -f2 -d " " | cut -f1 -d ":" > /tmp/disklist.txt ; then
whiptail $BG_COLOR_ERROR --title 'ERROR: No bootable devices found' \
--msgbox " $ERROR \n\n " 16 60
exit 1
fi
2019-07-09 03:23:04 +00:00
# filter out extraneous options
> /tmp/boot_device_list.txt
for i in ` cat /tmp/disklist.txt` ; do
# remove block device from list if numeric partitions exist, since not bootable
2020-02-27 20:39:13 +00:00
DEV_NUM_PARTITIONS = $(( ` ls -1 $i * | wc -l` - 1 ))
2019-07-09 03:23:04 +00:00
if [ ${ DEV_NUM_PARTITIONS } -eq 0 ] ; then
echo $i >> /tmp/boot_device_list.txt
else
ls $i * | tail -${ DEV_NUM_PARTITIONS } >> /tmp/boot_device_list.txt
fi
done
file_selector "/tmp/boot_device_list.txt" \
" Choose the default /boot device.\n\nCurrently set to $CURRENT_OPTION . " \
"Boot Device Selection"
2018-12-06 18:43:34 +00:00
if [ " $FILE " = = "" ] ; then
return
else
SELECTED_FILE = $FILE
fi
2020-02-29 00:54:14 +00:00
# unmount /boot if needed
if grep -q /boot /proc/mounts ; then
umount /boot 2>/dev/null
fi
2019-08-29 02:47:45 +00:00
# mount newly selected /boot device
2020-02-29 00:54:14 +00:00
if ! mount -o ro $SELECTED_FILE /boot 2>/tmp/error ; then
2019-08-29 02:47:45 +00:00
ERROR = ` cat /tmp/error`
2020-10-23 23:07:34 +00:00
whiptail $BG_COLOR_ERROR --title 'ERROR: unable to mount /boot' \
2020-02-29 00:54:14 +00:00
--msgbox " $ERROR \n\n " 16 60
2019-08-29 02:47:45 +00:00
exit 1
fi
2020-02-29 00:54:14 +00:00
replace_config /etc/config.user "CONFIG_BOOT_DEV" " $SELECTED_FILE "
combine_configs
2018-12-06 18:43:34 +00:00
whiptail --title 'Config change successful' \
--msgbox " The /boot device was successfully changed to $SELECTED_FILE " 16 60
; ;
"s" )
/bin/flash.sh -r /tmp/config-gui.rom
if [ ! -s /tmp/config-gui.rom ] ; then
2020-10-23 23:07:34 +00:00
whiptail $BG_COLOR_ERROR --title 'ERROR: BIOS Read Failed!' \
2018-12-06 18:43:34 +00:00
--msgbox "Unable to read BIOS" 16 60
exit 1
fi
2018-12-06 23:24:28 +00:00
if ( cbfs -o /tmp/config-gui.rom -l | grep -q "heads/initrd/etc/config.user" ) then
cbfs -o /tmp/config-gui.rom -d "heads/initrd/etc/config.user"
2018-12-06 18:43:34 +00:00
fi
2018-12-06 23:24:28 +00:00
cbfs -o /tmp/config-gui.rom -a "heads/initrd/etc/config.user" -f /etc/config.user
2019-11-18 17:13:27 +00:00
if ( whiptail --title 'Update ROM?' \
--yesno "This will reflash your BIOS with the updated version\n\nDo you want to proceed?" 16 90) then
/bin/flash.sh /tmp/config-gui.rom
whiptail --title 'BIOS Updated Successfully' \
--msgbox "BIOS updated successfully.\n\nIf your keys have changed, be sure to re-sign all files in /boot\nafter you reboot.\n\nPress Enter to reboot" 16 60
/bin/reboot
else
exit 0
fi
2019-07-09 14:02:46 +00:00
; ;
"r" )
# prompt for confirmation
2021-09-23 17:56:17 +00:00
if ( whiptail $BG_COLOR_WARNING --title 'Reset Configuration?' \
2019-07-09 14:02:46 +00:00
--yesno " This will clear all GPG keys, clear boot signatures and checksums,
\n reset the /boot device, clear/reset the TPM ( if present) ,
\n and reflash your BIOS with the cleaned configuration.
\n \n Do you want to proceed?" 16 90) then
# read current firmware
/bin/flash.sh -r /tmp/config-gui.rom
if [ ! -s /tmp/config-gui.rom ] ; then
2020-10-23 23:07:34 +00:00
whiptail $BG_COLOR_ERROR --title 'ERROR: BIOS Read Failed!' \
2019-07-09 14:02:46 +00:00
--msgbox "Unable to read BIOS" 16 60
exit 1
fi
# clear local keyring
rm /.gnupg/* | true
# clear /boot signatures/checksums
mount -o remount,rw /boot
rm /boot/kexec* | true
mount -o remount,ro /boot
# clear GPG keys and user settings
for i in ` cbfs -o /tmp/config-gui.rom -l | grep -e "heads/" ` ; do
cbfs -o /tmp/config-gui.rom -d $i
done
# flash cleared ROM
/bin/flash.sh -c /tmp/config-gui.rom
# reset TPM if present
if [ " $CONFIG_TPM " = "y" ] ; then
/bin/tpm-reset
fi
whiptail --title 'Configuration Reset Updated Successfully' \
--msgbox "Configuration reset and BIOS updated successfully.\n\nPress Enter to reboot" 16 60
2018-12-06 18:43:34 +00:00
/bin/reboot
2019-11-18 17:13:27 +00:00
else
exit 0
2018-12-06 18:43:34 +00:00
fi
; ;
esac
done
exit 0