From 2af8a8b00890263624f87c33fddc615dc013b01e Mon Sep 17 00:00:00 2001 From: nagumii Date: Sat, 4 Jan 2025 20:51:45 +0200 Subject: [PATCH] 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 <