mirror of
https://github.com/femtofox/femtofox.git
synced 2026-10-26 19:02:00 -04:00
Add -x argument to femto-network-config.sh & add colors support to femto-config
This commit is contained in:
parent
5191eef715
commit
2af8a8b008
2 changed files with 73 additions and 27 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf"
|
|||
help=$(cat <<EOF
|
||||
Options are:
|
||||
-h This message
|
||||
-x "up" Set wifi status (options are "up" or "down")
|
||||
-s "SSID" Set Wi-Fi SSID
|
||||
-p "PSK" Set Wi-Fi PSK (password)
|
||||
-c "COUNTRY" Set Wi-Fi 2-letter country code (such as US, DE)
|
||||
|
|
@ -35,17 +36,24 @@ if [ $# -eq 0 ]; then
|
|||
fi
|
||||
|
||||
# Parse options
|
||||
while getopts ":hs:p:c:ewn:tr" opt; do
|
||||
while getopts ":hx:s:p:c:ewn:tr" opt; do
|
||||
case ${opt} in
|
||||
h) # Option -h (help)
|
||||
echo -e "$help"
|
||||
;;
|
||||
s) # Option -s (ssid)
|
||||
x) # Option -x (set wifi status)
|
||||
if [ $OPTARG = "up" ]; then
|
||||
ip link set wlan0 up
|
||||
elif [ $OPTARG = "down" ]; then
|
||||
ip link set wlan0 down
|
||||
fi
|
||||
;;
|
||||
s) # Option -s (ssid)
|
||||
sed -i "/ssid=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf"
|
||||
echo "Setting SSID to $OPTARG."
|
||||
updated_wifi="true"
|
||||
;;
|
||||
p) # Option -p (psk)
|
||||
p) # Option -p (psk)
|
||||
sed -i "/psk=/s/\".*\"/\"$(echo "$OPTARG" | sed 's/&/\\&/g')\"/" "$wpa_supplicant_conf"
|
||||
echo "Setting PSK to (hidden)."
|
||||
updated_wifi="true"
|
||||
|
|
@ -92,15 +100,15 @@ For more details, enter \`iwconfig\`."
|
|||
total=0
|
||||
# Ping each target 5 times and count successful pings
|
||||
for target in "${targets[@]}"; do
|
||||
count=$(ping -c 5 -W 1 "$target" | grep -c 'bytes from') # Count lines with successful pings
|
||||
count=$(ping -c 5 -W 1 "$target" | grep -c 'time') # Count lines with successful pings
|
||||
successful=$((successful + count))
|
||||
((total+=5))
|
||||
done
|
||||
# Use dialog to display message based on successful pings count
|
||||
if [ "$successful" -eq 0 ]; then
|
||||
echo "No internet connection detected."
|
||||
echo -e "\033[0;31mNo internet connection detected.\033[0m"
|
||||
else
|
||||
echo "Internet connection is up.\n\nPinged $(echo "${targets[*]}" | sed 's/ /, /g').\nReceived $successful/$total responses."
|
||||
echo -e "Internet connection is \033[4m\033[0;32mup\033[0m.\n\nPinged $(echo "${targets[*]}" | sed 's/ /, /g').\nReceived $successful/$total responses."
|
||||
fi
|
||||
;;
|
||||
r) # Option -r (restart Wi-Fi)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue