From 5191eef71508a63180322e5709ffa4247ec38c48 Mon Sep 17 00:00:00 2001 From: nagumii Date: Sat, 4 Jan 2025 17:26:25 +0200 Subject: [PATCH 1/4] Fix issue with PSKs not interpreting special characters correctly And a few other small improvements in the network settings wifi configuration menus --- .../etc/update-motd.d/00-header | 4 +-- .../etc/wpa_supplicant/wpa_supplicant.conf | 5 ++-- .../usr/local/bin/femto-config | 27 +++++++++---------- .../usr/local/bin/femto-network-config.sh | 8 +++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/update-motd.d/00-header b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/update-motd.d/00-header index fc159ca..cc65f06 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/update-motd.d/00-header +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/update-motd.d/00-header @@ -15,8 +15,8 @@ fi foxbuntu_version=$(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) spaces=$((11 - ${#foxbuntu_version})) -printf " For settings, run \`sudo femto-config\`\n" +printf " For settings, run \`\033[0;31msudo femto-config\033[0m\`\n" printf " Made for Femtofox https://www.femtofox.com\n" printf " Foxbuntu v$foxbuntu_version%*s%s(%s)\n\n" $spaces "" "$DISTRIB_DESCRIPTION" "$(uname -r)" -printf "IP address: $(hostname -I | sed 's/ / /g') Uptime:$(uptime -p | awk '{$1=""; print $0}' | sed -e 's/ day\b/d/g' -e 's/ hour\b/h/g' -e 's/ hours\b/h/g' -e 's/ minute\b/m/g' -e 's/ minutes\b/m/g' | sed 's/,//g')\n" \ No newline at end of file +printf "IP address: $(hostname -I | sed 's/ / /g') Uptime:$(uptime -p | awk '{$1=""; print $0}' | sed -e 's/ day\b/d/g' -e 's/ hour\b/h/g' -e 's/ hours\b/h/g' -e 's/ minute\b/m/g' -e 's/ minutes\b/m/g' | sed 's/,//g')\n" diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/wpa_supplicant/wpa_supplicant.conf b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/wpa_supplicant/wpa_supplicant.conf index ae31e8f..5603a8e 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/wpa_supplicant/wpa_supplicant.conf +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/wpa_supplicant/wpa_supplicant.conf @@ -2,9 +2,10 @@ ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=US +# the first network in this file is the one edited by the various UIs and tools (USB config, femto-config, web UI, femto-network-config.sh...) network={ - ssid="home" + ssid="ssid" psk="password" key_mgmt=WPA-PSK - priority=100 + priority=100 } diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config index e05601b..59ef0ed 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config @@ -1,7 +1,7 @@ #!/bin/bash # prevents weirdness over tty export NCURSES_NO_UTF8_ACS=1 -export TERM=xterm-256color +export TERM=xterm-8color export LANG=C.UTF-8 if [[ $EUID -ne 0 ]]; then @@ -20,9 +20,9 @@ wifi_config() { local wifi_ssid="" local wifi_psk="" local wifi_country="" - wifi_ssid=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Wi-Fi SSID:" 8 40 3>&1 1>&2 2>&3) - wifi_psk=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3) - wifi_country=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Country Code (e.g., US, DE) - optional:" 9 40 3>&1 1>&2 2>&3) + wifi_ssid=$(dialog --title "$title2" --cancel-label "Skip" --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 --title "$title2" --cancel-label "Skip" --passwordbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3) + wifi_country=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Country Code (US, DE...):" 9 40 "$(grep -oP '^ *country=\K[^ ]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current country cmd="femto-network-config.sh -s \"$wifi_ssid\" -p \"$wifi_psk\"" [ -n "$wifi_country" ] && cmd="$cmd -c \"$wifi_country\"" cmd="$cmd -r" @@ -31,7 +31,10 @@ wifi_config() { return fi eval $cmd - dialog --title "$title2" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: $wifi_psk\nCountry: $wifi_country\nMeshtastic Wi-Fi setting set to ON" 9 40 + dialog --title "$title2" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic Wi-Fi setting set to ON" 9 40 + if [ "$1" = "-w" ]; then # if script was run with an argument that called this function, exit after completion + exit 0 + fi } # Function to handle Wi-Fi settings @@ -182,12 +185,7 @@ then \`depmod\` will be run. To remove support, those modules will be deleted.\n depmod -a 5.10.160 ;; 3) - dialog --title "$title" --yesno "Rerunning the first-boot script will add support for RTC (real time clock), \ -set the eth0 MAC address and Meshtastic nodeID to a derivative of the CPU serial number and enable Wi-Fi in Meshtastic settings. \ -Rerunning the script will not cause any issues if these things are already in place. Femtofox will reboot after execution.\n\nConfirm?" 12 60 - if [ $? -eq 0 ]; then #unless cancel/no - runonce.sh - fi + femto-runonce.sh ;; 4) luckfox-config @@ -266,6 +264,9 @@ set_lora_radio() { return fi done + if [ "$1" = "-l" ]; then # if script was run with an argument that called this function, exit after completion + exit 0 + fi } # Function to handle Meshtasticd settings @@ -376,7 +377,7 @@ meshtasticd_settings() { dialog --title "$title" --yesno "Uninstall Meshtasticd?\n\nFoxbuntu was designed with Meshtasticd integration in mind, and may behave unexpectedly if Meshtasticd is removed." 0 0 if [ $? -eq 0 ]; then femto-meshtasticd-config.sh -x - dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run \`sudo runonce.sh\`." 8 40 + dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run the \"first boot script\" from the misc menu." 8 40 fi ;; 15) @@ -492,11 +493,9 @@ while getopts ":lw" opt; do ;; esac done - if [ -n "$1" ]; then exit fi - # Main menu while true; do choice=$(dialog --title "$(date)" --menu "Femtofox Config" 15 40 5 \ diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh index 2ff189f..f5b723d 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh @@ -45,9 +45,9 @@ while getopts ":hs:p:c:ewn:tr" opt; do echo "Setting SSID to $OPTARG." updated_wifi="true" ;; - p) # Option -p (psk) - sed -i "/psk=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf" - echo "Setting PSK to $OPTARG." +p) # Option -p (psk) + sed -i "/psk=/s/\".*\"/\"$(echo "$OPTARG" | sed 's/&/\\&/g')\"/" "$wpa_supplicant_conf" + echo "Setting PSK to (hidden)." updated_wifi="true" ;; c) # Option -c (country) @@ -73,7 +73,7 @@ MAC Address: $(ifconfig eth0 | grep 'ether ' | awk '{print $2}')\n\ fi echo "\ SSID: $wifi_ssid\n\ -Password: $wifi_psk\n\ +Password: (hidden)\n\ Country: $wifi_country\n\ Meshtastic Wi-Fi: $mesh_wifi_status\n\ \n\ From 2af8a8b00890263624f87c33fddc615dc013b01e Mon Sep 17 00:00:00 2001 From: nagumii Date: Sat, 4 Jan 2025 20:51:45 +0200 Subject: [PATCH 2/4] Add -x argument to femto-network-config.sh & add colors support to femto-config --- .../usr/local/bin/femto-config | 80 ++++++++++++++----- .../usr/local/bin/femto-network-config.sh | 20 +++-- 2 files changed, 73 insertions(+), 27 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config index 59ef0ed..0978d30 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config @@ -1,7 +1,7 @@ #!/bin/bash # prevents weirdness over tty export NCURSES_NO_UTF8_ACS=1 -export TERM=xterm-8color +export TERM=xterm-256color export LANG=C.UTF-8 if [[ $EUID -ne 0 ]]; then @@ -16,6 +16,30 @@ pause() { read -n 1 -s -r } + + +#│ ^[[0;30m Black^[[0m ^[[0;31m Red^[[0m ^[[0;32m │ +#│ Green^[[0m ^[[0;33m Yellow^[[0m ^[[0;34m Blue^[[0m │ +#│ ^[[0;35m Magenta^[[0m ^[[0;36m Cyan^[[0m ^[[0;37m │ +#│ White^[[0m ^[[4m Underlined^[[0m ^[[7m Inverted^[[0m + + +replace_colors() { + input="$1" + input="${input//$(echo -e '\033[0;30m')/\\Z0}" # black + input="${input//$(echo -e '\033[0;31m')/\\Z1}" # red + input="${input//$(echo -e '\033[0;32m')/\\Z2}" # green + input="${input//$(echo -e '\033[0;33m')/\\Z3}" # yellow + input="${input//$(echo -e '\033[0;34m')/\\Z4}" # blue + input="${input//$(echo -e '\033[0;35m')/\\Z5}" # magenta + input="${input//$(echo -e '\033[0;36m')/\\Z6}" # cyan + input="${input//$(echo -e '\033[0;37m')/\\Z7}" # white + input="${input//$(echo -e '\033[7m')/\\Zr}" # invert + input="${input//$(echo -e '\033[4m')/\\Zu}" # underline + input="${input//$(echo -e '\033[0m')/\\Zn}" # reset + echo "$input" +} + wifi_config() { local wifi_ssid="" local wifi_psk="" @@ -32,7 +56,7 @@ wifi_config() { fi eval $cmd dialog --title "$title2" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic Wi-Fi setting set to ON" 9 40 - if [ "$1" = "-w" ]; then # if script was run with an argument that called this function, exit after completion + if [ "$1" = "-w" ]; then exit 0 fi } @@ -45,13 +69,14 @@ networking_settings() { while true; do local option="" option=$(dialog --menu "$title" 15 40 4 \ - 1 "View Wi-Fi settings" \ - 2 "Change Wi-Fi settings" \ - 3 "Restart Wi-Fi" \ - 4 "View ethernet settings" \ - 5 "Set hostname" \ - 6 "Test internet connection" \ - 7 "Back to Main Menu" 3>&1 1>&2 2>&3) + 1 "Turn Wi-Fi on/off" \ + 2 "View Wi-Fi settings" \ + 3 "Change Wi-Fi settings" \ + 4 "Restart Wi-Fi" \ + 5 "View ethernet 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 -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog @@ -59,35 +84,51 @@ networking_settings() { fi case $option in - 1) + 1) # Turn Wi-Fi on/off) + while true; do + choice=$(dialog --title "Wi-Fi Status" --menu "text" 9 40 5 \ + 1 "Turn Wi-Fi on" \ + 2 "Turn Wi-Fi off" 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 + case $choice in + 1) femto-network-config.sh -x "up" && break ;; + 2) femto-network-config.sh -x "down" && break ;; + *) dialog --msgbox "Invalid choice, please try again." 8 40 ;; + esac + done + ;; + 2) # View Wi-Fi settings) echo "Getting Wi-Fi configuration..." dialog --title "$title2" --msgbox "$(femto-network-config.sh -w)" 0 0 ;; - 2) + 3) # Change Wi-Fi settings) wifi_config ;; - 3) + 4) # Restart Wi-Fi) dialog --title "$title2" --yesno "Wi-Fi and Ethernet will be restarted.\nMeshtastic Wi-Fi setting will be set to ON." 7 50 if [ $? -eq 0 ]; then #unless cancel/no femto-network-config.sh -r fi ;; - 4) + 5) # View ethernet settings) echo "Getting ethernet configuration..." - dialog --title "Ethernet (eth0) settings" --msgbox "$(femto-network-config.sh -e)" 0 0 + dialog --title "Ethernet (eth0) settings" --colors --msgbox "$(replace_colors ($femto-network-config.sh -e))" 0 0 ;; - 5) # set hostname) + 6) # set hostname) new_hostname=$(dialog --title "$title" --cancel-label "Skip" --inputbox "Enter new hostname:" 8 40 $(hostname) 3>&1 1>&2 2>&3) if [ $? -eq 0 ]; then #unless cancel/no femto-network-config.sh -n "$new_hostname" dialog --title "$title" --msgbox "Femtofox is now reachable at\n$new_hostname.local" 8 40 fi ;; - 6) + 7) # Test internet connection) echo "Testing internet connection..." - dialog --title "Ethernet (eth0) settings" --msgbox "$(femto-network-config.sh -t)" 8 40 + dialog --title "Internet connection test" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -t)")" 8 40 ;; - 7) + 8) return ;; esac @@ -264,9 +305,6 @@ set_lora_radio() { return fi done - if [ "$1" = "-l" ]; then # if script was run with an argument that called this function, exit after completion - exit 0 - fi } # Function to handle Meshtasticd settings diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh index f5b723d..1935c8a 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh @@ -8,6 +8,7 @@ wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" help=$(cat < Date: Sat, 4 Jan 2025 22:58:51 +0200 Subject: [PATCH 3/4] Refined networking in femto-config, including colors! --- .../usr/local/bin/femto-config | 52 ++++++++-------- .../usr/local/bin/femto-network-config.sh | 62 +++++++++---------- 2 files changed, 56 insertions(+), 58 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config index 0978d30..7dfbaae 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config @@ -44,18 +44,18 @@ wifi_config() { local wifi_ssid="" local wifi_psk="" local wifi_country="" - wifi_ssid=$(dialog --title "$title2" --cancel-label "Skip" --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 --title "$title2" --cancel-label "Skip" --passwordbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3) - wifi_country=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Country Code (US, DE...):" 9 40 "$(grep -oP '^ *country=\K[^ ]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current country + wifi_ssid=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Wi-Fi SSID:" 8 50 "$(grep -oP '^ *ssid="\K[^"]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current SSID + wifi_psk=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Wi-Fi Password:" 8 50 3>&1 1>&2 2>&3) + wifi_country=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Country Code (US, DE...):" 9 50 "$(grep -oP '^ *country=\K[^ ]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current country cmd="femto-network-config.sh -s \"$wifi_ssid\" -p \"$wifi_psk\"" [ -n "$wifi_country" ] && cmd="$cmd -c \"$wifi_country\"" cmd="$cmd -r" if [ -z "$wifi_ssid" ]; then - dialog --title "$title2" --msgbox "\nSSID is required to configure Wi-Fi." 8 40 + dialog --title "$title2" --msgbox "\nSSID is required to configure Wi-Fi." 8 50 return fi eval $cmd - dialog --title "$title2" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic Wi-Fi setting set to ON" 9 40 + dialog --title "$title2" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic Wi-Fi setting set to ON" 9 50 if [ "$1" = "-w" ]; then exit 0 fi @@ -68,12 +68,12 @@ networking_settings() { wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" while true; do local option="" - option=$(dialog --menu "$title" 15 40 4 \ + option=$(dialog --menu "$title" 15 50 4 \ 1 "Turn Wi-Fi on/off" \ 2 "View Wi-Fi settings" \ 3 "Change Wi-Fi settings" \ - 4 "Restart Wi-Fi" \ - 5 "View ethernet settings" \ + 4 "View ethernet settings" \ + 5 "Restart networking" \ 6 "Set hostname" \ 7 "Test internet connection" \ 8 "Back to Main Menu" 3>&1 1>&2 2>&3) @@ -86,7 +86,7 @@ networking_settings() { case $option in 1) # Turn Wi-Fi on/off) while true; do - choice=$(dialog --title "Wi-Fi Status" --menu "text" 9 40 5 \ + choice=$(dialog --title "Wi-Fi Status" --menu "text" 9 50 5 \ 1 "Turn Wi-Fi on" \ 2 "Turn Wi-Fi off" 3>&1 1>&2 2>&3) exit_status=$? # This line checks the exit status of the dialog command @@ -96,37 +96,37 @@ networking_settings() { case $choice in 1) femto-network-config.sh -x "up" && break ;; 2) femto-network-config.sh -x "down" && break ;; - *) dialog --msgbox "Invalid choice, please try again." 8 40 ;; + *) dialog --msgbox "Invalid choice, please try again." 8 50 ;; esac done ;; 2) # View Wi-Fi settings) echo "Getting Wi-Fi configuration..." - dialog --title "$title2" --msgbox "$(femto-network-config.sh -w)" 0 0 + dialog --title "$title2" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -w)")" 0 0 ;; 3) # Change Wi-Fi settings) wifi_config ;; - 4) # Restart Wi-Fi) - dialog --title "$title2" --yesno "Wi-Fi and Ethernet will be restarted.\nMeshtastic Wi-Fi setting will be set to ON." 7 50 + 4) # View ethernet settings) + echo "Getting ethernet configuration..." + dialog --title "Ethernet (eth0) settings" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -e)")" 0 0 + ;; + 5) # Restart networking) + dialog --title "$title2" --yesno "Wi-Fi and Ethernet will be restarted.\nMeshtastic Wi-Fi setting will be set to ON.\n\nProceed?" 8 50 if [ $? -eq 0 ]; then #unless cancel/no femto-network-config.sh -r fi ;; - 5) # View ethernet settings) - echo "Getting ethernet configuration..." - dialog --title "Ethernet (eth0) settings" --colors --msgbox "$(replace_colors ($femto-network-config.sh -e))" 0 0 - ;; 6) # set hostname) - new_hostname=$(dialog --title "$title" --cancel-label "Skip" --inputbox "Enter new hostname:" 8 40 $(hostname) 3>&1 1>&2 2>&3) + new_hostname=$(dialog --title "$title" --cancel-label "Skip" --inputbox "Enter new hostname:" 8 50 $(hostname) 3>&1 1>&2 2>&3) if [ $? -eq 0 ]; then #unless cancel/no femto-network-config.sh -n "$new_hostname" - dialog --title "$title" --msgbox "Femtofox is now reachable at\n$new_hostname.local" 8 40 + dialog --title "$title" --msgbox "Femtofox is now reachable at\n$new_hostname.local" 8 50 fi ;; 7) # Test internet connection) echo "Testing internet connection..." - dialog --title "Internet connection test" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -t)")" 8 40 + dialog --title "Internet connectivity test" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -t)")" 8 50 ;; 8) return @@ -139,7 +139,7 @@ networking_settings() { femto_pinouts() { while true; do local option="" - option=$(dialog --menu "Pinouts" 15 40 5 \ + option=$(dialog --menu "Pinouts" 15 50 5 \ 1 "Femtofox" \ 2 "Femtofox Zero" \ 3 "Femtofox Tiny" \ @@ -168,7 +168,7 @@ misc_settings() { local title="Misc Settings" while true; do local option="" - option=$(dialog --menu "Misc Settings" 15 40 4 \ + option=$(dialog --menu "Misc Settings" 15 50 4 \ 1 "Set system timezone" \ 2 "Ham radio support" \ 3 "Re-run first-boot script" \ @@ -350,7 +350,7 @@ meshtasticd_settings() { fi ;; 3) - dialog --title "LoRa radio" --msgbox "Currently configured LoRa radio: $(femto-meshtasticd-config.sh -k)" 6 40 + dialog --title "LoRa radio" --msgbox "Currently configured LoRa radio: $(femto-meshtasticd-config.sh -k)" 6 50 ;; 4) set_lora_radio @@ -415,7 +415,7 @@ meshtasticd_settings() { dialog --title "$title" --yesno "Uninstall Meshtasticd?\n\nFoxbuntu was designed with Meshtasticd integration in mind, and may behave unexpectedly if Meshtasticd is removed." 0 0 if [ $? -eq 0 ]; then femto-meshtasticd-config.sh -x - dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run the \"first boot script\" from the misc menu." 8 40 + dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run the \"first boot script\" from the misc menu." 8 50 fi ;; 15) @@ -536,7 +536,7 @@ if [ -n "$1" ]; then fi # Main menu while true; do - choice=$(dialog --title "$(date)" --menu "Femtofox Config" 15 40 5 \ + choice=$(dialog --title "$(date)" --menu "Femtofox Config" 15 50 5 \ 1 "Settings wizard" \ 2 "Networking" \ 3 "Meshtasticd" \ @@ -559,6 +559,6 @@ while true; do 5) software_settings ;; 6) help_menu ;; 7) break ;; - *) dialog --msgbox "Invalid choice, please try again." 8 40 ;; + *) dialog --msgbox "Invalid choice, please try again." 8 50 ;; esac done \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh index 1935c8a..287d7ec 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh @@ -64,33 +64,37 @@ while getopts ":hx:s:p:c:ewn:tr" opt; do updated_wifi="true" ;; e) # Option -e (ethernet settings) - echo "Hostname: $(hostname).local\n\ -IPv4 Address: $(ifconfig eth0 | grep 'inet ' | awk '{print $2}')\n -IPv6 Address: $(ifconfig eth0 | grep 'inet6 ' | awk '{print $2}')\n\ -MAC Address: $(ifconfig eth0 | grep 'ether ' | awk '{print $2}')\n\ -" +status=$(ip link show eth0 | grep -o 'state [A-Za-z]*' | awk '{print $2}') +echo -e "Ethernet status: $([ "$status" == "UP" ] && echo -e "\033[4m\033[0;32mconnected\033[0m" || echo -e "\033[0;31mdisconnected\033[0m")" +if [ "$status" == "UP" ]; then + echo "\nIPv4 Address: $(ifconfig eth0 | grep 'inet ' | awk '{print $2}')\n\ +IPv6 Address: $(ifconfig eth0 | grep 'inet6 ' | awk '{print $2}')" +fi +echo "\nMAC Address: $(ifconfig eth0 | grep 'ether ' | awk '{print $2}')\n\ +Hostname: $(hostname).local" ;; w) # Option -w (wifi settings) - wifi_country=$(grep -m 1 "^country=" "$wpa_supplicant_conf" | cut -d '=' -f 2) - wifi_ssid=$(grep -m 1 '^\s*ssid=' "$wpa_supplicant_conf" | cut -d '"' -f 2) - wifi_psk=$(grep -m 1 '^\s*psk=' "$wpa_supplicant_conf" | cut -d '"' -f 2) - if [ "$(cat /root/.portduino/default/prefs/config.proto | protoc --decode_raw | awk '/4 {/, /}/ {if ($1 == "1:") print $2}')" -eq 1 ]; then - mesh_wifi_status="enabled" + if [ "$(cat /etc/wifi_state.txt)" = "up" ]; then + wifi_status="\033[4m\033[0;32menabled\033[0m" else - mesh_wifi_status="disabled" + wifi_status="\033[0;31mdisabled\033[0m" fi - echo "\ -SSID: $wifi_ssid\n\ -Password: (hidden)\n\ -Country: $wifi_country\n\ -Meshtastic Wi-Fi: $mesh_wifi_status\n\ -\n\ -Connected to: $(iwconfig 2>/dev/null | grep -i 'ESSID' | awk -F 'ESSID:"' '{print $2}' | awk -F '"' '{print $1}')\n\ -Signal Strength: $(iwconfig 2>/dev/null | grep -i 'Signal level' | awk -F 'Signal level=' '{print $2}' | awk '{print $1}')\n\ -MAC address: $(ifconfig wlan0 | grep ether | awk '{print $2}')\n\ -Current IP: $(hostname -I | awk '{print $1}')\n\ -Hostname: $(hostname).local\n\ -For more details, enter \`iwconfig\`." + echo -e "\ + $(echo -e "\ + SSID: $(grep -m 1 '^\s*ssid=' "$wpa_supplicant_conf" | cut -d '"' -f 2)\n\ + Password: (hidden)\n\ + Country: $(grep -m 1 "^country=" "$wpa_supplicant_conf" | cut -d '=' -f 2)\n\ + WiFi status: $wifi_status\n\ + \n\ + $(if [[ "$wifi_status" == *"enabled"* ]]; then + echo -e "Connected to: $(iwconfig 2>/dev/null | grep -i 'ESSID' | awk -F 'ESSID:\"' '{print $2}' | awk -F '\"' '{print $1}')\n\ + Signal Strength: $(iwconfig 2>/dev/null | grep -i 'Signal level' | awk -F 'Signal level=' '{print $2}' | awk '{print $1}')\n\ + Current IP: $(hostname -I | awk '{print $1}')\n" + fi)")\n\ + Hostname: $(hostname).local\n\ + MAC address: $(ifconfig wlan0 | grep ether | awk '{print $2}')\n\ + \n\ + For more details, enter \`iwconfig\`." ;; t) # Option -t (test internet connection) # Define ping targets and initialize counter @@ -133,16 +137,10 @@ For more details, enter \`iwconfig\`." done if [ "$updated_wifi" = true ]; then + ip link set wlan0 up systemctl restart wpa_supplicant wpa_cli -i wlan0 reconfigure # <-------- add watch for FAIL response, error out timeout 30s dhclient -v - echo " Wi-Fi restarted. Enabling Meshtastic Wi-Fi setting." - femto-meshtasticd-config.sh -m "--set network.wifi_enabled true" 10 "USB config" #| tee -a /tmp/femtofox-config.log - # if [ $? -eq 1 ]; then - # echo "Update of Meshtastic FAILED." - # exit 1 - # else - # echo "Updated Meshtastic successfully." - # exit 0 - # fi + echo " Wi-Fi enabled and restarted. Enabling Meshtastic Wi-Fi setting." + #femto-meshtasticd-config.sh -m "--set network.wifi_enabled true" 10 "USB config" #| tee -a /tmp/femtofox-config.log fi From fd756298daf1f4ccddc8013b5c8686c9bc5fa9f9 Mon Sep 17 00:00:00 2001 From: nagumii Date: Sun, 5 Jan 2025 00:54:46 +0200 Subject: [PATCH 4/4] Cosmetic improvements to femto-config --- .../usr/local/bin/femto-config | 76 ++++++++++--------- .../usr/local/bin/femto-network-config.sh | 34 +++++---- 2 files changed, 59 insertions(+), 51 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config index 7dfbaae..cab72e1 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config @@ -44,18 +44,18 @@ wifi_config() { local wifi_ssid="" local wifi_psk="" local wifi_country="" - wifi_ssid=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Wi-Fi SSID:" 8 50 "$(grep -oP '^ *ssid="\K[^"]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current SSID - wifi_psk=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Wi-Fi Password:" 8 50 3>&1 1>&2 2>&3) - wifi_country=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Country Code (US, DE...):" 9 50 "$(grep -oP '^ *country=\K[^ ]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current country + wifi_ssid=$(dialog --title "$title2" --cancel-label "Skip" --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 --title "$title2" --cancel-label "Skip" --inputbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3) + wifi_country=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Country Code (US, DE...):" 9 40 "$(grep -oP '^ *country=\K[^ ]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current country cmd="femto-network-config.sh -s \"$wifi_ssid\" -p \"$wifi_psk\"" [ -n "$wifi_country" ] && cmd="$cmd -c \"$wifi_country\"" cmd="$cmd -r" if [ -z "$wifi_ssid" ]; then - dialog --title "$title2" --msgbox "\nSSID is required to configure Wi-Fi." 8 50 + dialog --title "$title2" --msgbox "\nSSID is required to configure Wi-Fi." 8 40 return fi eval $cmd - dialog --title "$title2" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic Wi-Fi setting set to ON" 9 50 + dialog --title "$title2" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic Wi-Fi setting set to ON" 9 40 if [ "$1" = "-w" ]; then exit 0 fi @@ -68,7 +68,7 @@ networking_settings() { wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" while true; do local option="" - option=$(dialog --menu "$title" 15 50 4 \ + option=$(dialog --cancel-label "Back" --menu "$title" 15 40 4 \ 1 "Turn Wi-Fi on/off" \ 2 "View Wi-Fi settings" \ 3 "Change Wi-Fi settings" \ @@ -85,20 +85,24 @@ networking_settings() { case $option in 1) # Turn Wi-Fi on/off) - while true; do - choice=$(dialog --title "Wi-Fi Status" --menu "text" 9 50 5 \ - 1 "Turn Wi-Fi on" \ - 2 "Turn Wi-Fi off" 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 - case $choice in - 1) femto-network-config.sh -x "up" && break ;; - 2) femto-network-config.sh -x "down" && break ;; - *) dialog --msgbox "Invalid choice, please try again." 8 50 ;; - esac - done + if ! ip link show wlan0 &>/dev/null; then + dialog --colors --msgbox "\Z1Network adapter wlan0 does not exist.\Zn\n\nIs a wifi adapter connected?" 8 40 + else + while true; do + choice=$(dialog --cancel-label "Back" --title "Wi-Fi Status" --menu "Enable/disable Wi-Fi" 9 40 5 \ + 1 "Turn Wi-Fi on" \ + 2 "Turn Wi-Fi off" 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 + case $choice in + 1) femto-network-config.sh -x "up" && break ;; + 2) femto-network-config.sh -x "down" && break ;; + *) dialog --msgbox "Invalid choice, please try again." 8 40 ;; + esac + done + fi ;; 2) # View Wi-Fi settings) echo "Getting Wi-Fi configuration..." @@ -112,21 +116,21 @@ networking_settings() { dialog --title "Ethernet (eth0) settings" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -e)")" 0 0 ;; 5) # Restart networking) - dialog --title "$title2" --yesno "Wi-Fi and Ethernet will be restarted.\nMeshtastic Wi-Fi setting will be set to ON.\n\nProceed?" 8 50 + dialog --title "$title2" --yesno "Wi-Fi and Ethernet will be restarted.\nMeshtastic Wi-Fi setting will be set to ON.\n\nProceed?" 8 40 if [ $? -eq 0 ]; then #unless cancel/no femto-network-config.sh -r fi ;; 6) # set hostname) - new_hostname=$(dialog --title "$title" --cancel-label "Skip" --inputbox "Enter new hostname:" 8 50 $(hostname) 3>&1 1>&2 2>&3) + new_hostname=$(dialog --title "$title" --cancel-label "Skip" --inputbox "Enter new hostname:" 8 40 $(hostname) 3>&1 1>&2 2>&3) if [ $? -eq 0 ]; then #unless cancel/no femto-network-config.sh -n "$new_hostname" - dialog --title "$title" --msgbox "Femtofox is now reachable at\n$new_hostname.local" 8 50 + dialog --title "$title" --msgbox "Femtofox is now reachable at\n$new_hostname.local" 8 40 fi ;; 7) # Test internet connection) echo "Testing internet connection..." - dialog --title "Internet connectivity test" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -t)")" 8 50 + dialog --title "Internet connectivity test" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -t)")" 8 40 ;; 8) return @@ -139,7 +143,7 @@ networking_settings() { femto_pinouts() { while true; do local option="" - option=$(dialog --menu "Pinouts" 15 50 5 \ + option=$(dialog --cancel-label "Back" --menu "Pinouts" 15 40 5 \ 1 "Femtofox" \ 2 "Femtofox Zero" \ 3 "Femtofox Tiny" \ @@ -168,7 +172,7 @@ misc_settings() { local title="Misc Settings" while true; do local option="" - option=$(dialog --menu "Misc Settings" 15 50 4 \ + option=$(dialog --cancel-label "Back" --menu "Misc Settings" 15 40 4 \ 1 "Set system timezone" \ 2 "Ham radio support" \ 3 "Re-run first-boot script" \ @@ -220,7 +224,7 @@ TEF6862 Car Radio Enhanced Selectivity Tuner\n\ Texas Instruments WL1273 I2C FM Radio\n\ Renesas Digital Radio Interface (DRIF)" 20 65 dialog --title "$title" --msgbox "To add support, kernel modules for all these will be copied to \`/lib/modules/5.10.160/\`,\ -then \`depmod\` will be run. To remove support, those modules will be deleted.\n\nAfter installation, many redundant network interfaces will appear." 11 50 +then \`depmod\` will be run. To remove support, those modules will be deleted.\n\nAfter installation, many redundant network interfaces will appear." 11 40 #add code to choose add or remove cp /oem/usr/ko/ham/* /lib/modules/5.10.160/ depmod -a 5.10.160 @@ -312,7 +316,7 @@ meshtasticd_settings() { local title="Meshtasticd Settings" while true; do local option="" - option=$(dialog --menu "$title" 22 50 4 \ + option=$(dialog --cancel-label "Back" --menu "$title" 22 50 4 \ 1 "View current configuration URL & QR code" \ 2 "Set new configuration URL" \ 3 "View current lora radio selection" \ @@ -340,7 +344,7 @@ meshtasticd_settings() { pause ;; 2) - newurl=$(dialog --title "Meshtastic URL" --cancel-label "Skip" --inputbox "New Meshtasticd URL (SHIFT+INS to paste):" 8 50 3>&1 1>&2 2>&3) + newurl=$(dialog --title "Meshtastic URL" --cancel-label "Skip" --inputbox "New Meshtasticd URL (SHIFT+INS to paste):" 8 40 3>&1 1>&2 2>&3) if [ -n "$newurl" ]; then #if a URL was entered dialog --title "$title" --yesno "New Meshtasticd URL:\n$newurl\n\nConfirm?" 15 60 if [ $? -eq 0 ]; then #unless cancel/no @@ -350,7 +354,7 @@ meshtasticd_settings() { fi ;; 3) - dialog --title "LoRa radio" --msgbox "Currently configured LoRa radio: $(femto-meshtasticd-config.sh -k)" 6 50 + dialog --title "LoRa radio" --msgbox "Currently configured LoRa radio: $(femto-meshtasticd-config.sh -k)" 6 40 ;; 4) set_lora_radio @@ -360,7 +364,7 @@ meshtasticd_settings() { dialog --title "Admin keys" --msgbox "Up to 3 admin keys are permitted, more will be ignored.\n\nKeys:$(femto-meshtasticd-config.sh -v | tail -n 1 | sed 's/|n/\\n/g')" 0 0 ;; 6) #set admin key) - key=$(dialog --title "Meshtastic Admin Key" --cancel-label "Skip" --inputbox "Meshtastic admin key - up to 3, more will be ignored.\n\n(SHIFT+INS to paste):" 8 50 3>&1 1>&2 2>&3) + key=$(dialog --title "Meshtastic Admin Key" --cancel-label "Skip" --inputbox "Meshtastic admin key - up to 3, more will be ignored.\n\n(SHIFT+INS to paste):" 8 40 3>&1 1>&2 2>&3) if [ -n "$key" ]; then #if a URL was entered femto-meshtasticd-config.sh -a "$key" pause @@ -415,7 +419,7 @@ meshtasticd_settings() { dialog --title "$title" --yesno "Uninstall Meshtasticd?\n\nFoxbuntu was designed with Meshtasticd integration in mind, and may behave unexpectedly if Meshtasticd is removed." 0 0 if [ $? -eq 0 ]; then femto-meshtasticd-config.sh -x - dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run the \"first boot script\" from the misc menu." 8 50 + dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run the \"first boot script\" from the misc menu." 8 40 fi ;; 15) @@ -430,7 +434,7 @@ software_settings() { while true; do local title="Software" local option="" - option=$(dialog --menu "$title" 0 0 6 \ + option=$(dialog --cancel-label "Back" --menu "$title" 0 0 6 \ 1 "Meshing Around by SpudGudMan" \ 2 "The Comms Channel BBS (TC2BBS)" \ "" ""\ @@ -474,7 +478,7 @@ help_menu() { while true; do local title="Help / About" local option="" - option=$(dialog --menu "$title" 0 0 6 \ + option=$(dialog --cancel-label "Back" --menu "$title" 0 0 6 \ 1 "About Femtofox" \ 2 "Display pinout" \ 3 "Femtofox licensing info - short" \ @@ -536,7 +540,7 @@ if [ -n "$1" ]; then fi # Main menu while true; do - choice=$(dialog --title "$(date)" --menu "Femtofox Config" 15 50 5 \ + choice=$(dialog --title "$(date)" --cancel-label "Exit" --menu "Femtofox Config" 15 40 5 \ 1 "Settings wizard" \ 2 "Networking" \ 3 "Meshtasticd" \ @@ -559,6 +563,6 @@ while true; do 5) software_settings ;; 6) help_menu ;; 7) break ;; - *) dialog --msgbox "Invalid choice, please try again." 8 50 ;; + *) dialog --msgbox "Invalid choice, please try again." 8 40 ;; esac done \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh index 287d7ec..ae0d78d 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-network-config.sh @@ -77,24 +77,28 @@ Hostname: $(hostname).local" if [ "$(cat /etc/wifi_state.txt)" = "up" ]; then wifi_status="\033[4m\033[0;32menabled\033[0m" else + if ip link show wlan0 &>/dev/null; then # if wlan0 exists wifi_status="\033[0;31mdisabled\033[0m" + mac_address_line="MAC address: $(ifconfig wlan0 | grep ether | awk '{print $2}')\n\n" + else + wifi_status="\033[0;31mwlan0 not detected\033[0m" + fi fi echo -e "\ - $(echo -e "\ - SSID: $(grep -m 1 '^\s*ssid=' "$wpa_supplicant_conf" | cut -d '"' -f 2)\n\ - Password: (hidden)\n\ - Country: $(grep -m 1 "^country=" "$wpa_supplicant_conf" | cut -d '=' -f 2)\n\ - WiFi status: $wifi_status\n\ - \n\ - $(if [[ "$wifi_status" == *"enabled"* ]]; then - echo -e "Connected to: $(iwconfig 2>/dev/null | grep -i 'ESSID' | awk -F 'ESSID:\"' '{print $2}' | awk -F '\"' '{print $1}')\n\ - Signal Strength: $(iwconfig 2>/dev/null | grep -i 'Signal level' | awk -F 'Signal level=' '{print $2}' | awk '{print $1}')\n\ - Current IP: $(hostname -I | awk '{print $1}')\n" - fi)")\n\ - Hostname: $(hostname).local\n\ - MAC address: $(ifconfig wlan0 | grep ether | awk '{print $2}')\n\ - \n\ - For more details, enter \`iwconfig\`." +$(echo -e "\ +SSID: $(grep -m 1 '^\s*ssid=' "$wpa_supplicant_conf" | cut -d '"' -f 2)\n\ +Password: (hidden)\n\ +Country: $(grep -m 1 "^country=" "$wpa_supplicant_conf" | cut -d '=' -f 2)\n\ +WiFi status: $wifi_status\ +\n\ +$(if [[ "$wifi_status" == *"enabled"* ]]; then + echo -e "\nConnected to: $(iwconfig 2>/dev/null | grep -i 'ESSID' | awk -F 'ESSID:\"' '{print $2}' | awk -F '\"' '{print $1}')\n\ +Signal Strength: $(iwconfig 2>/dev/null | grep -i 'Signal level' | awk -F 'Signal level=' '{print $2}' | awk '{print $1}')\n\ +Current IP: $(hostname -I | awk '{print $1}')\n" +fi)")\n\ +Hostname: $(hostname).local\n\ +$mac_address_line +For more details, enter \`iwconfig\`." ;; t) # Option -t (test internet connection) # Define ping targets and initialize counter