Improve menus, especially system info

This commit is contained in:
nagumii 2025-01-28 00:54:17 +02:00
parent 1663ffd0d9
commit 03e4af59ab
2 changed files with 108 additions and 38 deletions

View file

@ -74,10 +74,10 @@ networking_settings() {
6 "Set hostname" \
7 "Test internet connection" \
"" "" \
8 "Back to Main Menu" 3>&1 1>&2 2>&3)
8 "Back to main menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
@ -93,7 +93,7 @@ networking_settings() {
"" "" \
3 "Return to previous menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $choice in
@ -145,7 +145,7 @@ utilities() {
while true; do
local option=""
option=$(dialog --no-collapse --cancel-label "Back" --menu "$title" 21 50 4 \
1 "System info" \
1 "View system info" \
2 "Set system time" \
3 "Kernel modules" \
4 "Re-run first-boot script" \
@ -157,17 +157,66 @@ utilities() {
10 "Reboot" \
11 "Shutdown" \
"" "" \
12 "Back to Main Menu" 3>&1 1>&2 2>&3)
12 "Back to main menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $option in
1) # sysinfo)
loading "Loading system info..."
dialog --no-collapse --colors --title "System info" --msgbox "$(replace_colors "$(femto-utils.sh -i)")" 0 0
1)
while true; do
choice=$(dialog --no-collapse --extra-button --extra-label "Help" --cancel-label "Back" --menu "System info" 17 40 5 \
1 "CPU" \
2 "Operating system" \
3 "Storage & memory" \
4 "Peripherals & devices" \
5 "Networking" \
6 "Meshtastic node info" \
7 "Complete system info" \
"" "" \
8 "Back to previous menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
elif [ $exit_status -eq 3 ]; then # Help ("extra") button
dialog --no-collapse --colors --title "System info help" --msgbox "To get system info in terminal (where it can be copied), enter \`\Zusudo femto-utils.sh -i\Zn\`." 7 50
else
case $choice in
1) # CPU)
loading "Loading CPU info..."
dialog --no-collapse --colors --title "CPU info" --msgbox "$(replace_colors "$(femto-utils.sh -c)")" 0 0
;;
2) # Operating system)
loading "Loading operating system info..."
dialog --no-collapse --colors --extra-button --title "Operating system" --msgbox "$(replace_colors "$(femto-utils.sh -o)")" 0 0
;;
3) # Storage & memory)
loading "Loading storage & memory info..."
dialog --no-collapse --colors --title "Storage & memory" --msgbox "$(replace_colors "$(femto-utils.sh -S)")" 0 0
;;
4) # Peripherals & devices)
loading "Loading peripherals & devices info..."
dialog --no-collapse --colors --title "Peripherals & devices" --msgbox "$(replace_colors "$(femto-utils.sh -p)")" 0 0
;;
5) # Networking)
loading "Loading networking info..."
dialog --no-collapse --colors --title "Networking" --msgbox "$(replace_colors "$(femto-utils.sh -n)")" 0 0
;;
6) # Meshtastic node info)
loading "Loading Meshtastic node info..."
dialog --no-collapse --colors --title "Meshtastic node info" --msgbox "$(replace_colors "$(femto-utils.sh -m)")" 0 0
;;
7) # Complete system info)
loading "Loading complete system info..."
dialog --no-collapse --colors --title "System info" --msgbox "$(replace_colors "$(femto-utils.sh -i)")" 0 0
;;
8) break ;;
esac
fi
done
;;
2) femto-set-time.sh ;; # set timezone
3) # Kernel modules)
@ -192,7 +241,7 @@ utilities() {
"" "" \
3 "Return to previous menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $choice in
@ -210,7 +259,7 @@ utilities() {
"" "" \
3 "Return to previous menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $choice in
@ -228,7 +277,7 @@ utilities() {
fi
;;
11) # shutdown)
dialog --no-collapse --title "$title" --yesno "Shut down now?\n\nTo power system back on, disconnect/reconnect power.\n\nThe system shutdown command prevents damage to the filesystem from power interrupts, but does not stop power consumption.\n\nTip: You can also shut down the Femtofox by pressing the BOOT button for 5 seconds or by running \`sudo halt\`." 14 60
dialog --no-collapse --colors --title "$title" --yesno "Shut down now?\n\nTo power system back on, disconnect/reconnect power.\n\nThe system shutdown command prevents damage to the filesystem from power interrupts, but does not stop power consumption.\n\nTip: You can also shut down the Femtofox by pressing the BOOT button for 5 seconds or by running \`\Zusudo halt\Zn\`." 14 60
if [ $? -eq 0 ]; then #unless cancel/no
loading "Shutting down...\n\nPower consumption will not stop."
femto-utils.sh -s
@ -258,7 +307,7 @@ set_lora_radio() {
"Skip" "" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
@ -316,17 +365,17 @@ meshtastic_settings() {
8 "Upgrade/install Meshtasticd" \
9 "Uninstall Meshtasticd" \
"" "" \
10 "Back to Main Menu" 3>&1 1>&2 2>&3)
10 "Back to main menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $option in
1) # view node info)
loading "Getting Node info..."
dialog --no-collapse --colors --title "Node Info" --msgbox "$(replace_colors "$(femto-meshtasticd-config.sh -i)")" 0 0
dialog --no-collapse --colors --title "Node Info" --msgbox "$(replace_colors "$(femto-meshtasticd-config.sh -m)")" 0 0
;;
2) # get current configuration URL & QR code)
loading "Getting Meshtastic QR code and URL..."
@ -359,7 +408,7 @@ meshtastic_settings() {
"" "" \
7 "Return to previous menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $choice in
@ -422,7 +471,7 @@ meshtastic_settings() {
"" "" \
3 "Return to previous menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $choice in
@ -472,7 +521,7 @@ meshtastic_settings() {
" " " " \
"Back to previous menu" "x" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $choice in
@ -498,14 +547,14 @@ meshtastic_settings() {
dialog --no-collapse --title "$title" --yesno "Enable Meshtasticd service?" 6 45
if [ $? -eq 0 ]; then #unless cancel/no
femto-meshtasticd-config.sh -M "enable"
dialog --no-collapse --msgbox "Sent \`systemctl enable meshtasticd\` and \`systemctl start meshtasticd\` commands to system.\n\nMeshtasticd should be running." 10 50
dialog --no-collapse --colors --msgbox "Sent \`\Zusystemctl enable meshtasticd\Zn\` and \`\Zusystemctl start meshtasticd\Zn\` commands to system.\n\nMeshtasticd should be running." 10 50
fi
;;
"Disable service")
dialog --no-collapse --colors --title "$title" --yesno "Disable Meshtasticd service?\n\nThis will take the node \Zu\Z1OFFLINE\Zn and will not restart!" 9 50
if [ $? -eq 0 ]; then #unless cancel/no
femto-meshtasticd-config.sh -M "disable"
dialog --no-collapse --msgbox "Sent \`systemctl disable meshtasticd\` and \`systemctl stop meshtasticd\` commands to system.\n\nMeshtasticd is disabled and stopped." 10 50
dialog --no-collapse --colors --msgbox "Sent \`\Zusystemctl disable meshtasticd\Zn\` and \`\Zusystemctl stop meshtasticd\Zn\` commands to system.\n\nMeshtasticd is disabled and stopped." 10 50
fi
;;
"Back to previous menu") break ;;
@ -523,7 +572,7 @@ meshtastic_settings() {
dialog --no-collapse --colors --title "$title" --yesno "Uninstall Meshtasticd?\n\nFoxbuntu was designed with Meshtasticd integration in mind, and may behave unexpectedly if Meshtasticd is removed.\n\nThis will take the node \Zu\Z1OFFLINE\Zn and will not restart!" 0 0
if [ $? -eq 0 ]; then
femto-meshtasticd-config.sh -x
dialog --no-collapse --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`." 8 40
dialog --no-collapse --colors --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`\Zusudo apt purge\Zn\`." 8 40
fi
;;
10)
@ -547,10 +596,10 @@ help_menu() {
6 "About Luckfox" \
7 "About Ubuntu" \
"" "" \
8 "Back to Main Menu" 3>&1 1>&2 2>&3)
8 "Back to main menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
@ -571,7 +620,7 @@ help_menu() {
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
@ -612,7 +661,7 @@ help_menu() {
help="If script is run without arguments, femto-config menu will load.\n\
Options are:\n\
-h This message\n\
-l Set LoRa radio cpu_model menu\n\
-l Set LoRa radio model menu\n\
-w Set Wi-Fi config menu\
"
while getopts ":hlwL:i" opt; do
@ -649,8 +698,8 @@ while true; do
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
exit 0
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $choice in

View file

@ -16,8 +16,9 @@ Options are:
-p Peripherals info
-c CPU info
-n Networking info
-m Meshtastic node info
-o OS info
-s Storage & RAM info
-S Storage & RAM info
EOF
)
@ -57,13 +58,14 @@ act_led() {
}
cpu_info() {
local cpu_model="$(dmesg | grep "soc_id" | sed -n 's/.*soc_id: //p')"
local core="$(cat /sys/firmware/devicetree/base/model | tr -d '\0')"
local cpu_model="$(dmesg | grep "soc_id" | sed -n 's/.*soc_id: //p' | tr -d '\0')"; cpu_model="${cpu_model:-$(cat /proc/device-tree/compatible | sed 's/.*,\([^,]*\)$/\1/' | tr -d '\0')}"
local cpu_architecture="$(uname -m) ($(dpkg --print-architecture) $(python3 -c "import platform; print(platform.architecture()[0])"))"
local cpu_temp="$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp) / 1000" | bc)°C"
local cpu_speed="$(lscpu | grep "CPU min MHz" | awk '{print int($4)}')-$(lscpu | grep "CPU max MHz" | awk '{print int($4)}')mhz"
local cpu_serial="$(awk '/Serial/ {print $3}' /proc/cpuinfo)"
echo -e "Core: $(cat /sys/firmware/devicetree/base/model)\n\
echo -e "Core: $core\n\
Model: $cpu_model\n\
Architecture: $cpu_architecture\n\
Speed: $cpu_speed x $(nproc) cores\n\
@ -117,10 +119,23 @@ peripherals_info() {
local i2c3_speed="$(awk -F= '/^I2C3_M1_SPEED/ {print $2}' /etc/luckfox.cfg)"
local uart3_state="$([ "$(awk -F= '/^UART3_M1_STATUS/ {print $2}' /etc/luckfox.cfg)" -eq 1 ] && echo "enabled" || echo "disabled")"
local uart4_state="$([ "$(awk -F= '/^UART4_M1_STATUS/ {print $2}' /etc/luckfox.cfg)" -eq 1 ] && echo "enabled" || echo "disabled")"
local lora_radio="$(femto-meshtasticd-config.sh -k)"
local usb_devices="$(lsusb | grep -v 'root hub' | awk 'NR>0{printf "USB: "; for(i=7;i<=NF;i++) printf "%s ", $i; print ""} END {if (NR == 0) printf "USB: None detected"}')"
local i2c_addresses="$(i2cdetect -y 3 | awk 'NR>1 {for(i=2;i<=17;i++) if ($i == "ff" || $i == "UU") { printf "0x%02x ", (i-2) + (NR-2)*16} }' | tr -d '\n' )"
local usb_devices="$(lsusb | grep -v 'root hub' | awk 'NR>0{printf "USB: "; for(i=7;i<=NF;i++) printf "%s ", $i; print ""} END {if (NR == 0) printf "USB: none detected"}')"
# gather i2c addresses
i2c_addresses="" # initialize empty string to collect populated addresses
while IFS= read -r line; do # iterate over each row of output (captured at end of while loop)
if [[ "$line" =~ ^[0-9a-f]+: ]]; then # check if the row contains addresses (skip header row)
columns=($line) # split the line into columns based on spaces
row="${columns[0]:0:1}" # use the first numeral of the row number
for col_idx in "${!columns[@]}"; do # iterate columns
if [[ $col_idx -gt 0 && "${columns[$col_idx]}" != "--" ]]; then # skip first column (row numbers)
[[ "$row" == "0" ]] && col_idx=$((col_idx + 8)) # if first row, we start at #7, so add 8 to the column number reported
i2c_addresses+="0x$(printf "%x" "$((16#$row))")$(printf "%x" $((col_idx - 1))) " # calculate hexadecimal with '0x'
fi
done
fi
done <<< "$(echo "$(sudo i2cdetect -y 3)")"
[[ -z "$i2c_addresses" ]] && i2c_addresses="none detected" # if no addresses found, "none detected"
echo -e "LoRa radio: $lora_radio\n\
$usb_devices\n\
@ -140,8 +155,8 @@ meshtastic_info() {
echo -e "Service status: $meshtasticd_service_status\n\
$meshtasticd_info"
}
# at some point this will have many functions instead of one giant dump
system_info() {
all_system_info() {
echo -e "\
Femtofox\n\
CPU:\n\
@ -185,7 +200,7 @@ logging() {
fi
}
while getopts ":harsl:i" opt; do
while getopts ":harsl:ipcnmoS" opt; do
case ${opt} in
h) # Option -h (help)
echo -e $help
@ -206,7 +221,13 @@ while getopts ":harsl:i" opt; do
l) # Option -l (Logging enable/disable/check)
logging $OPTARG
;;
i) system_info ;; # Option -i (sysinfo)
i) all_system_info ;; # Option -i (sysinfo)
p) peripherals_info ;; # Option -p (Peripherals info)
c) cpu_info ;; # Option -c (CPU info)
n) networking_info ;; # Option -n (Networing info)
m) meshtastic_info ;; # Option -m (Meshtastic node info)
o) os_info ;; # Option -o (OS info)
S) storage_info ;; # Option -S (Storage & RAM info)
\?) # Unknown option)
echo -e "Unknown argument $1.\n$help"
;;