mirror of
https://github.com/linuxboot/heads.git
synced 2024-12-24 07:06:42 +00:00
e0c03be341
Some prompts were missed when changing to 0 80 the first time around, and some new ones were added thinking that size was intentional. Replace '16 60' with '0 80' globally. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
124 lines
3.6 KiB
Bash
Executable File
124 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Shell functions for common operations using fbwhiptail
|
|
. /etc/functions
|
|
|
|
# Pause for the configured timeout before booting automatically. Returns 0 to
|
|
# continue with automatic boot, nonzero if user interrupted.
|
|
pause_automatic_boot()
|
|
{
|
|
if IFS= read -t "$CONFIG_AUTO_BOOT_TIMEOUT" -s -n 1 -p \
|
|
"Automatic boot in $CONFIG_AUTO_BOOT_TIMEOUT seconds unless interrupted by keypress... "; then
|
|
return 1 # Interrupt automatic boot
|
|
fi
|
|
return 0 # Continue with automatic boot
|
|
}
|
|
|
|
mount_usb()
|
|
{
|
|
TRACE "under gui_functions:mount_usb"
|
|
# Unmount any previous USB device
|
|
if grep -q /media /proc/mounts ; then
|
|
umount /media || die "Unable to unmount /media"
|
|
fi
|
|
# Mount the USB boot device
|
|
mount-usb && USB_FAILED=0 || ( [ $? -eq 5 ] && exit 1 || USB_FAILED=1 )
|
|
if [ $USB_FAILED -ne 0 ]; then
|
|
whiptail $BG_COLOR_ERROR --title 'USB Drive Missing' \
|
|
--msgbox "Insert your USB drive and press Enter to continue." 0 80
|
|
mount-usb && USB_FAILED=0 || ( [ $? -eq 5 ] && exit 1 || USB_FAILED=1 )
|
|
if [ $USB_FAILED -ne 0 ]; then
|
|
whiptail $BG_COLOR_ERROR --title 'ERROR: Mounting /media Failed' \
|
|
--msgbox "Unable to mount USB device" 0 80
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
file_selector()
|
|
{
|
|
TRACE "under gui_functions:file_selector"
|
|
FILE=""
|
|
FILE_LIST=$1
|
|
MENU_MSG=${2:-"Choose the file"}
|
|
MENU_TITLE=${3:-"Select your File"}
|
|
|
|
# create file menu options
|
|
if [ `cat "$FILE_LIST" | wc -l` -gt 0 ]; then
|
|
option=""
|
|
while [ -z "$option" ]
|
|
do
|
|
MENU_OPTIONS=""
|
|
n=0
|
|
while read option
|
|
do
|
|
n=`expr $n + 1`
|
|
option=$(echo $option | tr " " "_")
|
|
MENU_OPTIONS="$MENU_OPTIONS $n ${option}"
|
|
done < $FILE_LIST
|
|
|
|
MENU_OPTIONS="$MENU_OPTIONS a Abort"
|
|
whiptail --title "${MENU_TITLE}" \
|
|
--menu "${MENU_MSG} [1-$n, a to abort]:" 20 120 8 \
|
|
-- $MENU_OPTIONS \
|
|
2>/tmp/whiptail || die "Aborting"
|
|
|
|
option_index=$(cat /tmp/whiptail)
|
|
|
|
if [ "$option_index" = "a" ]; then
|
|
option="a"
|
|
return
|
|
fi
|
|
|
|
option=`head -n $option_index $FILE_LIST | tail -1`
|
|
if [ "$option" == "a" ]; then
|
|
return
|
|
fi
|
|
done
|
|
if [ -n "$option" ]; then
|
|
FILE=$option
|
|
fi
|
|
else
|
|
whiptail $BG_COLOR_ERROR --title 'ERROR: No Files Found' \
|
|
--msgbox "No Files found matching the pattern. Aborting." 0 80
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
show_system_info()
|
|
{
|
|
TRACE "Under /bin/gui-init:show_system_info"
|
|
battery_charge="$(print_battery_charge)"
|
|
battery_health="$(print_battery_health)"
|
|
if [ -n $battery_charge -a -n $battery_health ];then
|
|
battery_status="\nBattery charge: $battery_charge%\nBattery health: $battery_health%\n"
|
|
fi
|
|
|
|
memtotal=$(cat /proc/meminfo | grep 'MemTotal' | tr -s ' ' | cut -f2 -d ' ')
|
|
memtotal=$((${memtotal} / 1024 / 1024 + 1))
|
|
cpustr=$(cat /proc/cpuinfo | grep 'model name' | uniq | sed -r 's/\(R\)//;s/\(TM\)//;s/CPU //;s/model name.*: //')
|
|
kernel=$(uname -s -r)
|
|
|
|
whiptail $BG_COLOR_MAIN_MENU --title 'System Info' \
|
|
--msgbox "${BOARD_NAME}\n\nFW_VER: ${FW_VER}\nKernel: ${kernel}\n\nCPU: ${cpustr}\nRAM: ${memtotal} GB\n$battery_status\n$(fdisk -l | grep -e '/dev/sd.:' -e '/dev/nvme.*:' | sed 's/B,.*/B/')" 0 80
|
|
}
|
|
|
|
# Get "Enable" or "Disable" to display in the configuration menu, based on a
|
|
# setting value
|
|
get_config_display_action()
|
|
{
|
|
[ "$1" = "y" ] && echo "Disable" || echo "Enable"
|
|
}
|
|
|
|
# Invert a config value
|
|
invert_config()
|
|
{
|
|
[ "$1" = "y" ] && echo "n" || echo "y"
|
|
}
|
|
|
|
# Get "Enable" or "Disable" for a config that internally is inverted (because it
|
|
# disables a behavior that is on by default).
|
|
get_inverted_config_display_action()
|
|
{
|
|
get_config_display_action "$(invert_config "$1")"
|
|
}
|