2023-02-08 21:01:48 +00:00
|
|
|
#!/bin/bash
|
2020-07-10 17:58:32 +00:00
|
|
|
# Shell functions for common operations using fbwhiptail
|
2023-02-18 17:58:43 +00:00
|
|
|
. /etc/functions
|
2020-07-10 17:58:32 +00:00
|
|
|
|
2022-11-09 19:00:53 +00:00
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
2020-07-10 17:58:32 +00:00
|
|
|
mount_usb()
|
|
|
|
{
|
2023-02-20 16:01:17 +00:00
|
|
|
TRACE "under gui_functions:mount_usb"
|
2020-07-10 18:00:13 +00:00
|
|
|
# Unmount any previous USB device
|
|
|
|
if grep -q /media /proc/mounts ; then
|
|
|
|
umount /media || die "Unable to unmount /media"
|
|
|
|
fi
|
2020-07-10 17:58:32 +00:00
|
|
|
# Mount the USB boot device
|
2020-07-10 18:00:13 +00:00
|
|
|
mount-usb && USB_FAILED=0 || ( [ $? -eq 5 ] && exit 1 || USB_FAILED=1 )
|
|
|
|
if [ $USB_FAILED -ne 0 ]; then
|
2021-09-23 17:56:17 +00:00
|
|
|
whiptail $BG_COLOR_ERROR --title 'USB Drive Missing' \
|
2023-06-30 18:21:11 +00:00
|
|
|
--msgbox "Insert your USB drive and press Enter to continue." 0 80
|
2020-07-10 18:00:13 +00:00
|
|
|
mount-usb && USB_FAILED=0 || ( [ $? -eq 5 ] && exit 1 || USB_FAILED=1 )
|
2020-07-10 17:58:32 +00:00
|
|
|
if [ $USB_FAILED -ne 0 ]; then
|
2020-10-23 23:07:34 +00:00
|
|
|
whiptail $BG_COLOR_ERROR --title 'ERROR: Mounting /media Failed' \
|
2023-06-30 18:21:11 +00:00
|
|
|
--msgbox "Unable to mount USB device" 0 80
|
2020-07-10 18:00:13 +00:00
|
|
|
exit 1
|
2020-07-10 17:58:32 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
file_selector()
|
|
|
|
{
|
2023-02-20 16:01:17 +00:00
|
|
|
TRACE "under gui_functions:file_selector"
|
2020-07-10 17:58:32 +00:00
|
|
|
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"
|
2022-11-15 20:11:58 +00:00
|
|
|
whiptail --title "${MENU_TITLE}" \
|
2020-07-10 17:58:32 +00:00
|
|
|
--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
|
2020-10-23 23:07:34 +00:00
|
|
|
whiptail $BG_COLOR_ERROR --title 'ERROR: No Files Found' \
|
2023-06-30 18:21:11 +00:00
|
|
|
--msgbox "No Files found matching the pattern. Aborting." 0 80
|
2020-07-10 17:58:32 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2022-03-15 16:58:46 +00:00
|
|
|
|
|
|
|
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' \
|
2023-06-30 18:21:11 +00:00
|
|
|
--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
|
2022-03-15 16:58:46 +00:00
|
|
|
}
|
2022-11-10 18:53:56 +00:00
|
|
|
|
|
|
|
# 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"
|
|
|
|
}
|
2022-03-15 17:05:04 +00:00
|
|
|
|
|
|
|
# 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")"
|
|
|
|
}
|