Merge pull request #91 from noon92/femto-config

Femto config. Do not merge - WIP
This commit is contained in:
noon92 2024-12-29 21:37:42 +02:00 • committed by GitHub
commit 2f4c4ae4a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 355 additions and 0 deletions

View file

@ -0,0 +1,71 @@
#!/bin/bash
export NCURSES_NO_UTF8_ACS=1 # prevents weirdness over tty
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Try \`sudo femto-set-timezone\`."
exit 1
fi
arg_count=$#
help=$(cat <<EOF
If no argument is specified, a menu system will be used. Options are:
-h This message
-t "TIMEZONE" Set timezone
EOF
)
set_timezone() {
if timedatectl set-timezone "$1"; then
msg="Time zone set to $1 successfully."
status=0
else
msg="Failed to set the time zone to $1. Please try again." 8 40
status=1
fi
if [ $arg_count -eq 0 ]; then
dialog --msgbox "$msg" 8 40
else
echo $msg
logger $msg
fi
exit $status
}
while getopts ":t:h" opt; do
case ${opt} in
t) # Option -t (timezone)
set_timezone "$OPTARG"
;;
h) # Option -h (help)
echo -e "$help"
;;
esac
done
# Fetch available time zones
timezones=$(timedatectl list-timezones)
if [[ -z "$timezones" ]]; then
dialog --msgbox "Failed to retrieve time zones. Ensure 'timedatectl' is installed and functional." 8 50
return
fi
# Build options for dialog menu
while IFS= read -r timezone; do
options+=("$timezone" "x")
done <<< "$timezones"
# Convert options array to string
options_str=$(printf '%s\n' "${options[@]}")
# Show timezone selection menu
selected_timezone=$(dialog --title "Select Time Zone" --menu "Choose a time zone:" 20 60 10 $(printf "%s " "${options[@]}") 3>&1 1>&2 2>&3)
exit_status=$?
if [[ $exit_status -eq 0 && -n "$selected_timezone" ]]; then
# Set the selected time zone
set_timezone $selected_timezone
else
dialog --msgbox "No time zone selected. Returning to menu." 8 40
fi

View file

@ -0,0 +1,81 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Try \`sudo femto-wifi-config\`."
exit 1
fi
wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf"
help=$(cat <<EOF
Options are:
-h This message
-s "SSID" Set wifi SSID
-p "PSK" Set wifi PSK (password)
-c "COUNTRY" Set wifi 2-letter country code (such as US, DE)
-r Restart wifi
EOF
)
# Initialize variables
verbose="false"
updated_wifi="false"
ssid=""
psk=""
country=""
if [ $# -eq 0 ]; then
echo "No arguments provided."
echo -e "$help"
exit 1
fi
# Parse options
while getopts ":s:p:c:hr" opt; do
case ${opt} in
s) # Option -s (ssid)
sed -i "/ssid=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf"
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."
updated_wifi="true"
;;
c) # Option -c (country)
sed -i "/country=/s/=[^ ]*/=$OPTARG/" "/etc/wpa_supplicant/wpa_supplicant.conf"
echo "Setting country to $OPTARG."
updated_wifi="true"
;;
h) # Option -h (help)
echo -e "$help"
;;
r) # Option -r (restart wifi)
updated_wifi="true"
;;
\?) # Invalid option
echo "Invalid option: -$OPTARG"
echo -e "$help"
exit 1
;;
:) # Missing argument for option
echo "Option -$OPTARG requires a setting."
echo -e "$help"
exit 1
;;
esac
done
if [ "$updated_wifi" = true ]; then
systemctl restart wpa_supplicant
wpa_cli -i wlan0 reconfigure # <-------- add watch for FAIL response, error out
timeout 30s dhclient -v
echo " Wifi restarted. Enabling Meshtastic wifi setting."
updatemeshtastic.sh "--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
fi

View file

@ -0,0 +1,203 @@
#!/bin/bash
# prevents weirdness over tty
export NCURSES_NO_UTF8_ACS=1
export TERM=xterm-256color
export LANG=C.UTF-8
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
echo "Try \`sudo femtofox-config\`."
exit 1
fi
# Function to handle Wi-Fi settings
wifi_settings() {
title="Wifi settings"
wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf"
while true; do
local option=""
option=$(dialog --menu "Wifi settings" 15 40 4 \
1 "View wifi settings" \
2 "Change wifi settings" \
3 "Restart wifi" \
4 "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
break
fi
case $option in
1)
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"
else
mesh_wifi_status="disabled"
fi
dialog --title "$title" --msgbox "\
SSID: $wifi_ssid\n\
Password: $wifi_psk\n\
Country: $wifi_country\n\
Meshtastic wifi: $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\
Current IP: $(hostname -I | awk '{print $1}')\n\
For more details, enter \`iwconfig\`.
" 0 0
;;
2)
local wifi_ssid=""
local wifi_psk=""
local wifi_country=""
wifi_ssid=$(dialog --title "$title" --inputbox "Enter Wi-Fi SSID:" 8 40 3>&1 1>&2 2>&3)
wifi_psk=$(dialog --title "$title" --inputbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3)
wifi_country=$(dialog --title "$title" --inputbox "Enter Country Code (e.g., US, DE) - optional:" 9 40 3>&1 1>&2 2>&3)
cmd="femto-wifi-config.sh -s \"$wifi_ssid\" -p \"$wifi_psk\""
[ -n "$wifi_country" ] && cmd="$cmd -c \"$wifi_country\""
echo $cmd
if [ -z "$wifi_ssid" ]; then
dialog --title "$title" --msgbox "\nSSID is required." 8 40
return
fi
eval $cmd
dialog --title "$title" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: $wifi_psk\nCountry: $wifi_country\nMeshtastic wifi setting set to ON" 10 40
;;
3)
dialog --title "Wifi restart" --msgbox "Wifi will be restarted.\nMeshtastic wifi setting will be set to ON." 7 50
femto-wifi-config.sh -r
;;
4)
return
;;
esac
done
}
# Function to handle misc settings
misc_settings() {
while true; do
local option=""
option=$(dialog --menu "Misc Settings" 15 40 4 \
1 "Set system timezone" \
2 "blah" \
3 "blah" \
4 "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
break
fi
case $option in
1)
femto-set-timezone.sh
;;
2)
local channel=""
channel=$(dialog --inputbox "Enter channel ID:" 8 40 3>&1 1>&2 2>&3)
dialog --msgbox "Channel ID set to: $channel" 8 40
;;
3)
dialog --msgbox "Node info retrieved successfully!" 8 40
;;
4)
return
;;
esac
done
}
# Function to handle Meshtasticd settings
meshtasticd_settings() {
while true; do
local option=""
option=$(dialog --menu "Meshtasticd Settings" 15 40 4 \
1 "Configuration URL (QR code)" \
2 "LoRa radio" \
3 "Admin key" \
4 "Legacy admin channel" \
5 "Upgrade Meshtasticd" \
6 "Uninstall Meshtasticd" \
7 "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
break
fi
case $option in
1)
echo "Getting current Meshtastic QR code and URL..."
url=$(meshtastic --host --qr-all | grep -oP '(?<=Complete URL \(includes all channels\): )https://[^ ]+')
echo "$url" | qrencode -o - -t UTF8 -s 1
echo "Meshtastic configuration URL:"
echo $url
echo "Press any key to continue..."
read -n 1 -s -r
newurl=$(dialog --title "Meshtastic URL" --inputbox "New Meshtasticd URL (SHIFT+INS to paste):" 8 50 3>&1 1>&2 2>&3)
if [ -n "$newurl" ]; then
dialog --title "Meshtastic URL" --yesno "New Meshtasticd URL:\n$url\n\nConfirm?" 15 60
if [ $? -eq 0 ]; then
echo "Submitting to Meshtastic..."
updatemeshtastic.sh "--seturl $newurl" 10 "Set URL"
fi
fi
;;
2)
;;
3)
;;
4)
;;
5)
;;
6)
;;
7)
return
;;
esac
done
}
# Main menu
while true; do
choice=$(dialog --title "$(date)" --menu "Femtofox Config" 15 40 5 \
1 "Wi-Fi" \
2 "Meshtasticd" \
3 "Misc" \
4 "Software" \
5 "Run OEM luckfox-config" \
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 -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $choice in
1) wifi_settings ;;
2) meshtasticd_settings ;;
3) misc_settings ;;
4) software_settings ;;
5) luckfox-config ;;
6) femto_help ;;
7) break ;;
*) dialog --msgbox "Invalid choice, please try again." 8 40 ;;
esac
done