Begin refactor of method data is supplied by scripts and displayed by menus

This commit is contained in:
nagumii 2025-02-01 00:59:13 +02:00
parent 2b6b6f6847
commit 1a1133d7b1
5 changed files with 133 additions and 137 deletions

View file

@ -0,0 +1,27 @@
#
# Run-time configuration file for dialog
#
# Automatically generated by "dialog --create-rc <file>"
#
#
# Types of values:
#
# Number - <number>
# String - "string"
# Boolean - <ON|OFF>
# Attribute - (foreground,background,highlight?,underline?,reverse?)
# Up arrow color
uarrow_color = (GREEN,WHITE,ON)
# Down arrow color
darrow_color = uarrow_color
# Active form text color
form_active_text_color = button_active_color
# Form text color
form_text_color = (WHITE,CYAN,ON)
# Readonly form item color
form_item_readonly_color = (BLUE,WHITE,ON)

View file

@ -37,13 +37,40 @@ loading() {
dialog --no-collapse --infobox "$1" 5 45
}
# function to pull data from various femto scripts and convert it to the contents of a read only dialog --form
ingest_data() { # usage: `ingest_data "command.sh -argument" key_width value_width`
unset output_array #debug code, delete me
declare -a output_array
# Read the output from femto-meshtasticd-config.sh and store it in the array
while IFS=':' read -r key value; do
# Trim leading/trailing spaces from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
output_array+=("$key=$value") # Use indexed array to preserve order
done < <(eval $1)
form_contents=""
i=1
for pair in "${output_array[@]}"; do
key=$(cut -d'=' -f1 <<< "$pair")
value=$(cut -d'=' -f2- <<< "$pair")
form_contents+="\"$key\" $i 1 \"$value\" $i $2 $3 -1 "
((i++))
done
echo "$form_contents" | sed 's/\x1b\[[0-9;]*m//g'
}
wifi_config() {
local wifi_ssid=""
local wifi_psk=""
local wifi_country=""
wifi_ssid=$(dialog --no-collapse --title "$title2" --inputbox "Enter Wi-Fi SSID:" 8 40 "$(grep -oP '^ *ssid="\K[^"]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current SSID
wifi_psk=$(dialog --no-collapse --title "$title2" --inputbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3)
wifi_country=$(dialog --no-collapse --title "$title2" --inputbox "Enter Country Code (US, DE...):" 8 40 "$(grep -oP '^ *country=\K[^ ]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current country
local title2="Wi-Fi (wlan0) Settings"
local config=$(dialog --no-collapse --title "$title2" --form "↑ ↓ to navigate, [ESC] to cancel." 10 45 0 \
"SSID:" 1 1 "$(grep -oP '^ *ssid="\K[^"]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 1 15 24 32\
"Password:" 2 1 "" 2 15 24 64\
"Country Code:" 3 1 "$(grep -oP '^ *country=\K[^ ]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3 15 24 2\
3>&1 1>&2 2>&3)
# Parse the output
wifi_ssid=$(echo "$config" | sed -n '1p')
wifi_psk=$(echo "$config" | sed -n '2p')
wifi_country=$(echo "$config" | sed -n '3p')
cmd="femto-network-config.sh -s \"$wifi_ssid\" -p \"$wifi_psk\""
[ -n "$wifi_country" ] && cmd="$cmd -c \"$wifi_country\""
cmd="$cmd -r"
@ -63,11 +90,11 @@ wifi_config() {
networking_settings() {
local title="Networking"
local title2="Wi-Fi (wlan0) Settings"
ip=$(hostname -I | sed 's/ / /g'); ip=${ip:+$(printf "IPv4 address:\n%s" "$ip")}
ip=$(hostname -I | sed 's/ / /g'); ip=${ip:+$(printf "IPv4 address: %s" "$ip")}
wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf"
choice="" # zero the choice before loading the submenu
while true; do
networking_choice=$(dialog --no-collapse --cancel-label "Back" --default-item "$networking_choice" --title "$title" --menu "$ip" $([ -z "$ip" ] && echo 16 || echo 18) 40 4 \
networking_choice=$(dialog --no-collapse --cancel-label "Back" --backtitle "$ip" --default-item "$networking_choice" --title "$title" --menu "" $([ -z "$ip" ] && echo 14 || echo 16) 40 4 \
1 "Turn Wi-Fi on/off" \
2 "View Wi-Fi settings" \
3 "Change Wi-Fi settings" \
@ -76,17 +103,12 @@ networking_settings() {
6 "Set hostname" \
7 "Test internet connection" \
" " "" \
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 -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
8 "Back to main menu" 3>&1 1>&2 2>&3)
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $networking_choice in
1) # Turn Wi-Fi on/off)
if ! ip link show wlan0 &>/dev/null; then
dialog --no-collapse --colors --msgbox "\Z1Network adapter wlan0 does not exist.\Zn\n\nIs a wifi adapter connected?" 8 40
dialog --no-collapse --colors --msgbox "\Z1Network adapter wlan0 does not exist.\Zn\n\nIs a Wi-Fi adapter connected?" 8 40
else
while true; do
choice=$(dialog --no-collapse --cancel-label "Back" --default-item "$choice" --title "Enable/disable Wi-Fi" --menu "Tip: Wi-Fi can also be toggled by short-pressing the BOOT button on the Luckfox." 13 50 5 \
@ -94,10 +116,7 @@ networking_settings() {
2 "Turn Wi-Fi off" \
" " "" \
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 -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $choice in
1) femto-network-config.sh -x "up" && break ;;
2) femto-network-config.sh -x "down" && break ;;
@ -143,7 +162,7 @@ networking_settings() {
# utilities
utilities() {
local title="Utilities"
local title="Utilities & Tools"
while true; do
utilities_choice=$(dialog --no-collapse --cancel-label "Back" --default-item "$utilities_choice" --menu "$title" 21 50 4 \
1 "View system info" \
@ -159,14 +178,10 @@ utilities() {
11 "Shutdown" \
" " "" \
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 -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $utilities_choice in
1)
1) #sysinfo)
choice="" # zero the choice before loading the submenu
while true; do
choice=$(dialog --no-collapse --help-button --help-label "Help" --cancel-label "Back" --default-item "$choice" --menu "System info" 17 40 5 \
@ -242,10 +257,7 @@ utilities() {
2 "Disable" \
" " "" \
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 -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $choice in
1) femto-utils.sh -l "enable" ;;
2) femto-utils.sh -l "disable" ;;
@ -261,10 +273,7 @@ utilities() {
2 "Disable" \
" " "" \
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 -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $choice in
1) femto-utils.sh -a "enable" ;;
2) femto-utils.sh -a "disable" ;;
@ -307,13 +316,8 @@ set_lora_radio() {
"AI Thinker ra-01sh" "(SX1262_XTAL)"\
"None" "(simulated radio)"\
" " "" \
"Skip" "" 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
fi
"Skip" "" 3>&1 1>&2 2>&3)
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
local radio=""
case $choice in
"Ebyte e22-900m30s")
@ -367,17 +371,12 @@ meshtastic_settings() {
8 "Upgrade/install Meshtasticd" \
9 "Uninstall Meshtasticd" \
" " "" \
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 -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
10 "Back to main menu" 3>&1 1>&2 2>&3)
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $meshtastic_choice 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
eval "$(echo -e "dialog --no-collapse --no-cancel --form \"Meshtastic node info\" 0 0 0 $(ingest_data "femto-meshtasticd-config.sh -i" 18 0) 2>/dev/null")"
;;
2) # get current configuration URL & QR code)
loading "Getting Meshtastic QR code and URL..."
@ -410,10 +409,7 @@ meshtastic_settings() {
6 "Legacy admin channel" \
" " "" \
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 -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $choice in
1) # view/change public key)
loading "Getting current public key..."
@ -474,10 +470,7 @@ meshtastic_settings() {
2 "Disable (default)" \
" " "" \
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 -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $choice in
1) # enable legacy admin)
dialog --no-collapse --title "Legacy Admin" --yesno "Enable legacy admin channel?\n" 0 0
@ -525,10 +518,7 @@ meshtastic_settings() {
$(if echo "$service_state" | grep -q 'enabled'; then echo "Disable service x"; fi) \
" " " " \
"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 -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $choice in
"View detailed service status")
loading "Getting Meshtasticd service status..."
@ -600,13 +590,8 @@ help_menu() {
6 "About Luckfox" \
7 "About Ubuntu" \
" " "" \
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 -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
8 "Back to main menu" 3>&1 1>&2 2>&3)
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $help_choice in
1) #About Femtofox)
dialog --no-collapse --title "About Femtofox" --default-item "$choice" --backtitle "Foxbuntu $(grep -oP 'major=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'minor=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'patch=\K[0-9]+' /etc/foxbuntu-release)$(grep -oP 'hotfix=\K[a-z]+' /etc/foxbuntu-release)" --msgbox "$(femto-license.sh -a)" 18 65
@ -621,13 +606,7 @@ help_menu() {
4 "Luckfox Pico Mini" \
" " "" \
5 "Back to Help 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
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $choice in
1) dialog --no-collapse --title "Femtofox" --msgbox "$(femto-pinout.sh -f)" 43 68 ;;
2) dialog --no-collapse --title "Femtofox Zero" --msgbox "$(femto-pinout.sh -z)" 34 48 ;;
@ -684,9 +663,7 @@ while getopts ":hlwL:i" opt; do
;;
esac
done
if [ -n "$1" ]; then
exit
fi
[ -n "$1" ] && exit # if there were arguments, exit before loading the menu
# Main menu
while true; do
@ -695,17 +672,11 @@ while true; do
2 "Networking" \
3 "Meshtastic" \
4 "Software manager" \
5 "Utilities" \
5 "Utilities & tools" \
6 "Help" \
" " "" \
7 "Exit" 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
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $main_menu_choice in
1) femto-install-wizard.sh ;;
2) networking_settings ;;
@ -717,4 +688,4 @@ while true; do
esac
done
exit 0
exit 0

View file

@ -81,32 +81,46 @@ while getopts ":higkl:q:uU:rR:aA:cpo:sM:Stwuxm" opt; do
echo -e "$help"
;;
i) # Option -i (Get important node info)
declare -a output_array
output=$(meshtastic --host --info)
preset_or_settings="Use preset? $(echo "$output" | grep -oP '"usePreset":\s*\K\w+')\n"
if echo "$output" | grep -qP '"usePreset":\s*true'; then
preset_or_settings+="Preset: $(echo "$output" | grep -oP '"modemPreset":\s*"\K[^"]+')"
else
preset_or_settings+="\
Bandwidth: $(echo "$output" | grep -oP '"bandwidth":\s*\K\w+')\n\
Spread factor: $(echo "$output" | grep -oP '"spreadFactor":\s*\K\w+')\n\
Coding rate: $(echo "$output" | grep -oP '"codingRate":\s*\K\w+')"
output_array+=("Service status=$(femto-meshtasticd-config.sh -S)")
output_array+=("Version=$(echo "$output" | grep -oP '"firmwareVersion":\s*"\K[^"]+' | head -n 1)")
output_array+=("Node name=$(echo "$output" | grep -oP 'Owner:\s*\K.*' | head -n 1)")
output_array+=("NodeID=$(echo "!$(printf "%08x\n" $(echo "$output" | grep -oP '"myNodeNum":\s*\K\d+' | head -n 1))")")
output_array+=("Nodenum=$(echo "$output" | grep -oP '"myNodeNum":\s*\K\d+' | head -n 1)")
output_array+=("TX enabled=$(echo "$output" | grep -oP '"txEnabled":\s*\K\w+')")
use_preset=$(echo "$output" | grep -oP '"usePreset":\s*\K\w+')
output_array+=("Use preset=$use_preset")
if [ "$use_preset" = "true" ]; then # if use-preset is true, then display the preset
output_array+=("Preset=$(echo "$output" | grep -oP '"modemPreset":\s*"\K[^"]+')")
else # otherwise, display the lora settings
output_array+=("Bandwidth=$(echo "$output" | grep -oP '"bandwidth":\s*\K\w+')")
output_array+=("Spread factor=$(echo "$output" | grep -oP '"spreadFactor":\s*\K\w+')")
output_array+=("Coding rate=$(echo "$output" | grep -oP '"codingRate":\s*\K\w+')")
fi
echo -e "\
Service status: $(femto-meshtasticd-config.sh -S)\n\
Version: $(echo "$output" | grep -oP '"firmwareVersion":\s*"\K[^"]+' | head -n 1)\n\
Node name: $(echo "$output" | grep -oP 'Owner:\s*\K.*' | head -n 1)\n\
NodeID: !$(printf "%08x\n" $(echo "$output" | grep -oP '"myNodeNum":\s*\K\d+' | head -n 1)) (nodenum: $(echo "$output" | grep -oP '"myNodeNum":\s*\K\d+' | head -n 1))\n\
TX enabled? $(txEnabled=$(echo "$output" | grep -oP '"txEnabled":\s*\K\w+'); [[ "$txEnabled" == "true" ]] && echo "\033[0;34menabled\033[0m" || echo "\033[0;31mdisabled\033[0m")\n\
Role: $(echo "$output" | grep -oP '"role":\s*"\K[^"]+' | head -n 1)\n\
$preset_or_settings\n\
Frequency offset: $(echo "$output" | grep -oP '"bandwidth":\s*\K\w+')
Region: $(echo "$output" | grep -oP '"region":\s*"\K[^"]+')\n\
Hop limit: $(echo "$output" | grep -oP '"hopLimit":\s*\K\w+')\n\
$(channelNum=$(echo "$output" | grep -oP '"channelNum":\s*\K\d+' | head -n 1); [[ -n "$channelNum" && "$channelNum" -gt 0 ]] && echo -e "Frequency slot: $channelNum\n")\
$(overrideFrequency=$(echo "$output" | grep -oP '"overrideFrequency":\s*\K[0-9.]+'); [[ -n "$overrideFrequency" && $(echo "$overrideFrequency > 0" | bc) -eq 1 ]] && echo "Override freq: $overrideFrequency\n")\
Public key: $(echo "$output" | grep -oP '"publicKey":\s*"\K[^"]+' | head -n 1)\n\
Nodes in nodedb: $(echo "$output" | grep -oP '"![a-zA-Z0-9]+":\s*\{' | wc -l)\
"
output_array+=("Role=$(echo "$output" | grep -oP '"role":\s*"\K[^"]+' | head -n 1)")
freq_offset=$(echo "$output" | grep -oP '"bandwidth":\s*\K\w+')
if [ "$freq_offset" != 0 ]; then # only display frequency offset if not 0
output_array+=("Override freq=$freq_offset")
fi
output_array+=("Region=$(echo "$output" | grep -oP '"region":\s*"\K[^"]+')")
output_array+=("Hop limit=$(echo "$output" | grep -oP '"hopLimit":\s*\K\w+')")
freq_slot=$(echo "$output" | grep -oP '"channelNum":\s*\K\d+' | head -n 1)
if [ "$freq_slot" != 0 ]; then # only display frequency slot if not 0
freq_slot+=("Override freq=$freq_slot")
fi
override_freq=$(echo "$output" | grep -oP '"overrideFrequency":\s*\K[0-9.]+')
if [ "$override_freq" != "0" ]; then # only display override frequency if not 0
output_array+=("Override freq=$override_freq")
fi
output_array+=("Public key=$(echo "$output" | grep -oP '"publicKey":\s*"\K[^"]+' | head -n 1)")
output_array+=("Nodes in nodedb=$(echo "$output" | grep -oP '"![a-zA-Z0-9]+":\s*\{' | wc -l)")
# now, echo the array
for pair in "${output_array[@]}"; do
key=$(echo "$pair" | cut -d'=' -f1)
value=$(echo "$pair" | cut -d'=' -f2-)
echo "$key:$value"
done
;;
g) # Option -g (get config URL)
url=$(meshtastic --host --qr-all | grep -oP '(?<=Complete URL \(includes all channels\): )https://[^ ]+') #add look for errors

View file

@ -5,9 +5,8 @@ package_dir="/usr/local/bin/packages"
install() {
dialog --no-collapse --title "Install $($package_dir/$1.sh -N)" --yesno "\nInstallation requires internet connectivity.\n\nProceed?" 10 40
if [ $? -eq 1 ]; then #if cancel/no
return 1
fi
[ $? -eq 1 ] && return 1 #if cancel/no
echo "Installing $($package_dir/$1.sh -N)..."
# Run the installation script, capturing the output and displaying it in real time
output=$($package_dir/$1.sh -i)
@ -24,9 +23,7 @@ install() {
uninstall() {
dialog --no-collapse --title "Uninstall $($package_dir/$1.sh -N)" --yesno "\nReinstallation will require internet connectivity.\n\nProceed?" 10 40
if [ $? -eq 1 ]; then #if cancel/no
return 1
fi
[ $? -eq 1 ] && return 1 #if cancel/no
echo "Uninstalling $($package_dir/$1.sh -N)..."
output=$(eval "$package_dir/$1.sh -u 2>&1 | tee /dev/tty")
install_status=$? # Capture the exit status of the eval command
@ -41,9 +38,7 @@ uninstall() {
initialize() {
dialog --no-collapse --title "$title" --yesno "\nIntialize $($package_dir/$1.sh -N)\n\nInitialization runs commands that require user interaction and so can only be run from terminal.\n\nProceed?" 13 50
if [ $? -eq 1 ]; then #if cancel/no
return 1
fi
[ $? -eq 1 ] && return 1 #if cancel/no
clear
echo "Initializing $($package_dir/$1.sh -N)..."
eval "$package_dir/$1.sh -a"
@ -56,9 +51,7 @@ initialize() {
upgrade() {
dialog --no-collapse --title "Upgrade $($package_dir/$1.sh -N)" --yesno "\nUpgrade requires internet connectivity.\n\nProceed?" 10 40
if [ $? -eq 1 ]; then #if cancel/no
return 1
fi
[ $? -eq 1 ] && return 1 #if cancel/no
echo "Upgrading $($package_dir/$1.sh -N)..."
output=$(eval "$package_dir/$1.sh -g 2>&1 | tee /dev/tty")
install_status=$? # Capture the exit status of the eval command
@ -107,13 +100,7 @@ package_menu() {
$(if $package_dir/$1.sh -O | grep -q 'S' && $package_dir/$1.sh -I; then echo "Get service status x"; fi) \
" " "" \
"Back to software manager" "" 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
break
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
# execute the actual commands
case $choice in
"Run software") echo "Launching $($package_dir/$1.sh -N)..." && eval "$package_dir/$1.sh -l" ;;
@ -145,10 +132,7 @@ while true; do
menu_entries+=(" " "") # add blank line and "Back to Main Menu" entry
menu_entries+=("$index" "Back to main menu")
software_option=$(dialog --no-collapse --cancel-label "Back" --default-item "$software_option" --menu "$title" $((9 + index)) 50 $((index + 1)) "${menu_entries[@]}" 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
break
fi
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case_block=" case \$software_option in"
index=1

View file

@ -76,12 +76,12 @@ storage_info() {
local microsd_size="$(df --block-size=1 / | awk 'NR==2 {total=$2; avail=$4; total_human=sprintf("%.2f", total/1024/1024/1024); avail_human=sprintf("%.2f", avail/1024/1024/1024); printf "%.2f GB (%.2f%% free)", total_human, (avail/total)*100}')"
local memory="$(free -m | awk 'NR==2{printf "%d MB (%.2f%% free)\n", $2, 100 - (($3/$2)*100)}')"
local swap="$(free -m | awk 'NR==3 {if ($2 > 1000) {printf "%.2f GB (%.2f%% free)", $2/1024, ($4/$2)*100} else {printf "%d MB (%.2f%% free)", $2, ($4/$2)*100}}')"
local mounted_drives="$([ "$(for dir in /mnt/*/; do echo -n "/mnt${dir#"/mnt"} "; done)" ] && echo "Mounted drives: $(for dir in /mnt/*; do echo -n "/mnt${dir#"/mnt"} "; done | sed 's/\/$//')")"
local mounted_drives="$( [ "$(for dir in /mnt/*/; do [ -d "$dir" ] && echo -n "/mnt${dir#"/mnt"} "; done)" ] && echo "$(for dir in /mnt/*/; do [ -d "$dir" ] && echo -n "/mnt${dir#"/mnt"} "; done | sed 's/\/$//')" || echo "none" )"
echo -e "microSD size: $microsd_size\n\
Memory: $memory\n\
Swap: $swap\n\
$mounted_drives"
Mounted drives: $mounted_drives"
}
os_info() {