From 9232700714867b123d6febc725a47d6d70bcb269 Mon Sep 17 00:00:00 2001 From: nagumii Date: Sat, 28 Dec 2024 20:37:17 +0200 Subject: [PATCH 1/9] Create femtofox-config --- .../usr/local/bin/femtofox-config | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config new file mode 100644 index 0000000..12381ec --- /dev/null +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config @@ -0,0 +1,113 @@ +#!/bin/bash + +# Function to handle Wi-Fi settings +wifi_settings() { + local wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" + local wifi_ssid="" + local wifi_psk="" + local wifi_country="" + wifi_ssid=$(dialog --inputbox "Enter Wi-Fi SSID:" 8 40 3>&1 1>&2 2>&3) + wifi_psk=$(dialog --passwordbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3) + wifi_country=$(dialog --inputbox "Enter Country Code (e.g., US, DE):" 8 40 3>&1 1>&2 2>&3) + sed -i "/country=/s/\".*\"/\"$wifi_country\"/" "$wpa_supplicant_conf" + sed -i "/ssid=/s/\".*\"/\"$wifi_ssid\"/" "$wpa_supplicant_conf" + sed -i "/psk=/s/\".*\"/\"$wifi_psk\"/" "$wpa_supplicant_conf" + systemctl restart wpa_supplicant + wpa_cli -i wlan0 reconfigure + echo "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi setting." + timeout 30s dhclient -v + 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." + else + echo "Updated Meshtastic successfully." + fi + dialog --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic wifi setting set to ON" 10 40 +} + +# Function to handle region settings +region_settings() { + local region="" + region=$(dialog --inputbox "Enter Region Code (e.g., US, EU):" 8 40 3>&1 1>&2 2>&3) + + dialog --msgbox "Region set to: $region" 8 40 +} + +# Function to handle timezone settings +timezone_settings() { + local timezone="" + timezone=$(dialog --inputbox "Enter Timezone (e.g., America/Los_Angeles):" 8 40 3>&1 1>&2 2>&3) + + dialog --msgbox "Timezone set to: $timezone" 8 40 +} + +# Function to handle Meshtastic CLI settings +meshtastic_settings() { + local option="" + option=$(dialog --menu "Meshtastic CLI Options" 15 40 4 \ + 1 "Set device name" \ + 2 "Configure channel" \ + 3 "Check node info" \ + 4 "Back to Main Menu" 3>&1 1>&2 2>&3) + + case $option in + 1) + local name="" + name=$(dialog --inputbox "Enter device name:" 8 40 3>&1 1>&2 2>&3) + dialog --msgbox "Device name set to: $name" 8 40 + ;; + 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 +} + + +export NCURSES_NO_UTF8_ACS=1 # prevents weirdness over tty + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root." + echo "Try \`sudo femto-config\`." + exit 1 +fi + + +# Main menu +while true; do + choice=$(dialog --menu "Femtofox Config" 15 40 5 \ + 1 "Wi-Fi" \ + 2 "Meshtasticd" \ + 3 "Misc" \ + 4 "Install third party apps" \ + 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) 3rd_party ;; + 5) luckfox-config ;; + 6) femto_help ;; + 7) break ;; + *) dialog --msgbox "Invalid choice, please try again." 8 40 ;; + esac +done + +clear +echo "Goodbye!" \ No newline at end of file From 4502daa0a80df63859643f51c59fe5d364f07515 Mon Sep 17 00:00:00 2001 From: nagumii Date: Sat, 28 Dec 2024 22:53:59 +0200 Subject: [PATCH 2/9] Update femtofox-config --- .../usr/local/bin/femtofox-config | 62 ++++++++++++------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config index 12381ec..2b5e014 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config @@ -2,27 +2,47 @@ # Function to handle Wi-Fi settings wifi_settings() { - local wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" - local wifi_ssid="" - local wifi_psk="" - local wifi_country="" - wifi_ssid=$(dialog --inputbox "Enter Wi-Fi SSID:" 8 40 3>&1 1>&2 2>&3) - wifi_psk=$(dialog --passwordbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3) - wifi_country=$(dialog --inputbox "Enter Country Code (e.g., US, DE):" 8 40 3>&1 1>&2 2>&3) - sed -i "/country=/s/\".*\"/\"$wifi_country\"/" "$wpa_supplicant_conf" - sed -i "/ssid=/s/\".*\"/\"$wifi_ssid\"/" "$wpa_supplicant_conf" - sed -i "/psk=/s/\".*\"/\"$wifi_psk\"/" "$wpa_supplicant_conf" - systemctl restart wpa_supplicant - wpa_cli -i wlan0 reconfigure - echo "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi setting." - timeout 30s dhclient -v - 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." - else - echo "Updated Meshtastic successfully." - fi - dialog --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic wifi setting set to ON" 10 40 + + local option="" + option=$(dialog --menu "Wifi settings" 15 40 4 \ + 1 "View wifi settings" \ + 2 "Change wifi settings" \ + 3 "Back to Main Menu" 3>&1 1>&2 2>&3) + + case $option in + 1) + local name="" + name=$(dialog --inputbox "Enter device name:" 8 40 3>&1 1>&2 2>&3) + dialog --msgbox "Device name set to: $name" 8 40 + ;; + 2) + local wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" + local wifi_ssid="" + local wifi_psk="" + local wifi_country="" + wifi_ssid=$(dialog --title "Wifi settings" --inputbox "Enter Wi-Fi SSID:" 8 40 3>&1 1>&2 2>&3) + wifi_psk=$(dialog --title "Wifi settings" --passwordbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3) + wifi_country=$(dialog --title "Wifi settings" --inputbox "Enter Country Code (e.g., US, DE):" 8 40 3>&1 1>&2 2>&3) + sed -i "/country=/s/\".*\"/\"$wifi_country\"/" "$wpa_supplicant_conf" + sed -i "/ssid=/s/\".*\"/\"$wifi_ssid\"/" "$wpa_supplicant_conf" + sed -i "/psk=/s/\".*\"/\"$wifi_psk\"/" "$wpa_supplicant_conf" + systemctl restart wpa_supplicant + wpa_cli -i wlan0 reconfigure + echo "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi setting." + timeout 30s dhclient -v + 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." + else + echo "Updated Meshtastic successfully." + fi + dialog --title "Wifi settings" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic wifi setting set to ON" 10 40 + ;; + 3) + return + ;; + esac + } # Function to handle region settings From b708cec6f9f944ed274b793d5812c3277312f898 Mon Sep 17 00:00:00 2001 From: nagumii Date: Sat, 28 Dec 2024 23:29:53 +0200 Subject: [PATCH 3/9] splitting different config sections into separate files for now --- .../usr/local/bin/femto-wifi-config | 61 +++++++++++++++++++ .../{femtofox-config => femtofox-config.sh} | 0 2 files changed, 61 insertions(+) create mode 100644 foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config rename foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/{femtofox-config => femtofox-config.sh} (100%) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config new file mode 100644 index 0000000..7944339 --- /dev/null +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config @@ -0,0 +1,61 @@ +#!/bin/bash +wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" +help="Options are -v (verbose mode), -s (ssid), -p (PSK), -c (country)." + +# Initialize variables +verbose="false" +updated_wifi="false" +ssid="" +psk="" +country="" + +if [ $# -eq 0 ]; then + echo "No arguments provided." + echo "$help" + exit 1 +fi + +# Parse options +while getopts ":s:p:c:" opt; do + case ${opt} in + s) # Option -s (ssid) + sed -i "/ssid=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf" + echo "Set SSID to $OPTARG." + updated_wifi="true" + ;; + p) # Option -p (psk) + sed -i "/psk=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf" + echo "Set PSK to $OPTARG." + updated_wifi="true" + ;; + c) # Option -c (country) + country=$OPTARG + sed -i "/country=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf" + echo "Set country to $OPTARG." + updated_wifi="true" + ;; + \?) # Invalid option + echo "Invalid option: -$OPTARG." + echo "$help" + exit 1 + ;; + :) # Missing argument for option + echo "Option -$OPTARG requires an argument." + echo "$help" + exit 1 + ;; + esac +done + +if [ "$updated_wifi" = true ]; then + systemctl restart wpa_supplicant + wpa_cli -i wlan0 reconfigure + timeout 30s dhclient -v + echo "wpa_supplicant.conf updated and 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." + else + echo "Updated Meshtastic successfully." + fi +fi diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config.sh similarity index 100% rename from foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config rename to foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config.sh From 2952029948f3d14473ba867edee37130f135b85c Mon Sep 17 00:00:00 2001 From: nagumii Date: Sun, 29 Dec 2024 00:22:02 +0200 Subject: [PATCH 4/9] change filename --- .../bin/{femto-wifi-config => femto-wifi-config.sh} | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) rename foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/{femto-wifi-config => femto-wifi-config.sh} (82%) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh similarity index 82% rename from foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config rename to foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh index 7944339..05ab83e 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh @@ -20,18 +20,17 @@ while getopts ":s:p:c:" opt; do case ${opt} in s) # Option -s (ssid) sed -i "/ssid=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf" - echo "Set SSID to $OPTARG." + echo "Setting SSID to $OPTARG." updated_wifi="true" ;; p) # Option -p (psk) sed -i "/psk=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf" - echo "Set PSK to $OPTARG." + echo "Setting PSK to $OPTARG." updated_wifi="true" ;; c) # Option -c (country) - country=$OPTARG - sed -i "/country=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf" - echo "Set country to $OPTARG." + sed -i "/country=/s/=[^ ]*/=$OPTARG/" "/etc/wpa_supplicant/wpa_supplicant.conf" + echo "Setting country to $OPTARG." updated_wifi="true" ;; \?) # Invalid option @@ -49,7 +48,7 @@ done if [ "$updated_wifi" = true ]; then systemctl restart wpa_supplicant - wpa_cli -i wlan0 reconfigure + wpa_cli -i wlan0 reconfigure # <-------- add watch for FAIL response, error out timeout 30s dhclient -v echo "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi setting." updatemeshtastic.sh "--set network.wifi_enabled true" 10 "USB config" #| tee -a /tmp/femtofox-config.log From d9a55bb579551548ac1d945f2e3b408d5ef29706 Mon Sep 17 00:00:00 2001 From: nagumii Date: Sun, 29 Dec 2024 00:38:08 +0200 Subject: [PATCH 5/9] Update femto-wifi-config.sh --- .../usr/local/bin/femto-wifi-config.sh | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh index 05ab83e..022e0d3 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh @@ -1,6 +1,18 @@ #!/bin/bash +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root. Try \`sudo femto-config\`." + exit 1 +fi + wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" -help="Options are -v (verbose mode), -s (ssid), -p (PSK), -c (country)." +help=$(cat < Date: Sun, 29 Dec 2024 13:26:40 +0200 Subject: [PATCH 6/9] update menu system --- .../usr/local/bin/femtofox-config | 163 ++++++++++++++++++ .../usr/local/bin/femtofox-config.sh | 133 -------------- 2 files changed, 163 insertions(+), 133 deletions(-) create mode 100644 foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config delete mode 100644 foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config.sh diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config new file mode 100644 index 0000000..c37b97a --- /dev/null +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config @@ -0,0 +1,163 @@ +#!/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." + echo "Try \`sudo femto-config\`." + exit 1 +fi + + +# Function to handle Wi-Fi settings +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="on" + else + mesh_wifi_status="off" + fi + dialog --title "Wifi settings" --msgbox "SSID: $wifi_ssid\nPassword: $wifi_psk\nCountry: $wifi_country\nMeshtastic wifi setting: $mesh_wifi_status" 10 40 + ;; + 2) + local wifi_ssid="" + local wifi_psk="" + local wifi_country="" + wifi_ssid=$(dialog --title "Wifi settings" --inputbox "Enter Wi-Fi SSID:" 8 40 3>&1 1>&2 2>&3) + wifi_psk=$(dialog --title "Wifi settings" --inputbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3) + wifi_country=$(dialog --title "Wifi settings" --inputbox "Enter Country Code (e.g., US, DE) - optional:" 8 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 + exit + eval $cmd + dialog --title "Wifi settings" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: $wifi_psk\nCountry: $wifi_country\nMeshtastic wifi setting set to ON" 10 40 + ;; + 3) + femto-wifi-config.sh -r + ;; + 4) + return + ;; + esac + done +} + +# Function to handle timezone settings + +# Function to select and set the time zone +set_timezone() { +local selected_timezone +local timezones + +# 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 +local options=() +while IFS= read -r timezone; do + options+=("$timezone" "$timezone") +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 + if timedatectl set-timezone "$selected_timezone"; then + dialog --msgbox "Time zone set to $selected_timezone successfully." 8 40 + else + dialog --msgbox "Failed to set the time zone. Please try again." 8 40 + fi +else + dialog --msgbox "No time zone selected. Returning to menu." 8 40 +fi +} + +# Function to handle Meshtastic CLI settings +misc_settings() { + local option="" + option=$(dialog --menu "Meshtastic CLI Options" 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) + set_timezone + ;; + 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 +} + + +# Main menu +while true; do + choice=$(dialog --menu "Femtofox Config" 15 40 5 \ + 1 "Wi-Fi" \ + 2 "Meshtasticd" \ + 3 "Misc" \ + 4 "Install third party apps" \ + 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) 3rd_party ;; + 5) luckfox-config ;; + 6) femto_help ;; + 7) break ;; + *) dialog --msgbox "Invalid choice, please try again." 8 40 ;; + esac +done + diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config.sh deleted file mode 100644 index 2b5e014..0000000 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config.sh +++ /dev/null @@ -1,133 +0,0 @@ -#!/bin/bash - -# Function to handle Wi-Fi settings -wifi_settings() { - - local option="" - option=$(dialog --menu "Wifi settings" 15 40 4 \ - 1 "View wifi settings" \ - 2 "Change wifi settings" \ - 3 "Back to Main Menu" 3>&1 1>&2 2>&3) - - case $option in - 1) - local name="" - name=$(dialog --inputbox "Enter device name:" 8 40 3>&1 1>&2 2>&3) - dialog --msgbox "Device name set to: $name" 8 40 - ;; - 2) - local wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" - local wifi_ssid="" - local wifi_psk="" - local wifi_country="" - wifi_ssid=$(dialog --title "Wifi settings" --inputbox "Enter Wi-Fi SSID:" 8 40 3>&1 1>&2 2>&3) - wifi_psk=$(dialog --title "Wifi settings" --passwordbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3) - wifi_country=$(dialog --title "Wifi settings" --inputbox "Enter Country Code (e.g., US, DE):" 8 40 3>&1 1>&2 2>&3) - sed -i "/country=/s/\".*\"/\"$wifi_country\"/" "$wpa_supplicant_conf" - sed -i "/ssid=/s/\".*\"/\"$wifi_ssid\"/" "$wpa_supplicant_conf" - sed -i "/psk=/s/\".*\"/\"$wifi_psk\"/" "$wpa_supplicant_conf" - systemctl restart wpa_supplicant - wpa_cli -i wlan0 reconfigure - echo "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi setting." - timeout 30s dhclient -v - 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." - else - echo "Updated Meshtastic successfully." - fi - dialog --title "Wifi settings" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic wifi setting set to ON" 10 40 - ;; - 3) - return - ;; - esac - -} - -# Function to handle region settings -region_settings() { - local region="" - region=$(dialog --inputbox "Enter Region Code (e.g., US, EU):" 8 40 3>&1 1>&2 2>&3) - - dialog --msgbox "Region set to: $region" 8 40 -} - -# Function to handle timezone settings -timezone_settings() { - local timezone="" - timezone=$(dialog --inputbox "Enter Timezone (e.g., America/Los_Angeles):" 8 40 3>&1 1>&2 2>&3) - - dialog --msgbox "Timezone set to: $timezone" 8 40 -} - -# Function to handle Meshtastic CLI settings -meshtastic_settings() { - local option="" - option=$(dialog --menu "Meshtastic CLI Options" 15 40 4 \ - 1 "Set device name" \ - 2 "Configure channel" \ - 3 "Check node info" \ - 4 "Back to Main Menu" 3>&1 1>&2 2>&3) - - case $option in - 1) - local name="" - name=$(dialog --inputbox "Enter device name:" 8 40 3>&1 1>&2 2>&3) - dialog --msgbox "Device name set to: $name" 8 40 - ;; - 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 -} - - -export NCURSES_NO_UTF8_ACS=1 # prevents weirdness over tty - -if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root." - echo "Try \`sudo femto-config\`." - exit 1 -fi - - -# Main menu -while true; do - choice=$(dialog --menu "Femtofox Config" 15 40 5 \ - 1 "Wi-Fi" \ - 2 "Meshtasticd" \ - 3 "Misc" \ - 4 "Install third party apps" \ - 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) 3rd_party ;; - 5) luckfox-config ;; - 6) femto_help ;; - 7) break ;; - *) dialog --msgbox "Invalid choice, please try again." 8 40 ;; - esac -done - -clear -echo "Goodbye!" \ No newline at end of file From 28bee1748016b58bb66ca2d5d4d348b1211e9f40 Mon Sep 17 00:00:00 2001 From: nagumii Date: Sun, 29 Dec 2024 13:58:11 +0200 Subject: [PATCH 7/9] Create femto-set-timezone.sh --- .../usr/local/bin/femto-set-timezone.sh | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-timezone.sh diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-timezone.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-timezone.sh new file mode 100644 index 0000000..25bb6bb --- /dev/null +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-timezone.sh @@ -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-config\`." + exit 1 +fi + +arg_count=$# + +help=$(cat <&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 \ No newline at end of file From 033c6f89fb09b7ae39549fd232c02b11946d85ff Mon Sep 17 00:00:00 2001 From: nagumii Date: Sun, 29 Dec 2024 19:58:43 +0200 Subject: [PATCH 8/9] More femtoconfig stuff --- .../usr/local/bin/femto-set-timezone.sh | 2 +- .../usr/local/bin/femto-wifi-config.sh | 12 +- .../usr/local/bin/femtofox-config | 201 +++++++++++------- 3 files changed, 132 insertions(+), 83 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-timezone.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-timezone.sh index 25bb6bb..c567b0b 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-timezone.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-timezone.sh @@ -2,7 +2,7 @@ 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-config\`." + echo "This script must be run as root. Try \`sudo femto-set-timezone\`." exit 1 fi diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh index 022e0d3..fdb3322 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-wifi-config.sh @@ -1,6 +1,6 @@ #!/bin/bash if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root. Try \`sudo femto-config\`." + echo "This script must be run as root. Try \`sudo femto-wifi-config\`." exit 1 fi @@ -11,6 +11,7 @@ Options are: -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 ) @@ -28,7 +29,7 @@ if [ $# -eq 0 ]; then fi # Parse options -while getopts ":s:p:c:h" opt; do +while getopts ":s:p:c:hr" opt; do case ${opt} in s) # Option -s (ssid) sed -i "/ssid=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf" @@ -48,6 +49,9 @@ while getopts ":s:p:c:h" opt; do h) # Option -h (help) echo -e "$help" ;; + r) # Option -r (restart wifi) + updated_wifi="true" + ;; \?) # Invalid option echo "Invalid option: -$OPTARG" echo -e "$help" @@ -65,11 +69,13 @@ 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 "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi setting." + 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 diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config index c37b97a..abf97a1 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config @@ -1,16 +1,19 @@ #!/bin/bash -export NCURSES_NO_UTF8_ACS=1 # prevents weirdness over tty +# 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 femto-config\`." + 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="" @@ -31,28 +34,45 @@ wifi_settings() { 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="on" + mesh_wifi_status="enabled" else - mesh_wifi_status="off" + mesh_wifi_status="disabled" fi - dialog --title "Wifi settings" --msgbox "SSID: $wifi_ssid\nPassword: $wifi_psk\nCountry: $wifi_country\nMeshtastic wifi setting: $mesh_wifi_status" 10 40 - ;; + 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 "Wifi settings" --inputbox "Enter Wi-Fi SSID:" 8 40 3>&1 1>&2 2>&3) - wifi_psk=$(dialog --title "Wifi settings" --inputbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3) - wifi_country=$(dialog --title "Wifi settings" --inputbox "Enter Country Code (e.g., US, DE) - optional:" 8 40 3>&1 1>&2 2>&3) + 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 - exit + if [ -z "$wifi_ssid" ]; then + dialog --title "$title" --msgbox "\nSSID is required." 8 40 + return + fi eval $cmd - dialog --title "Wifi settings" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: $wifi_psk\nCountry: $wifi_country\nMeshtastic wifi setting set to ON" 10 40 + 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) - femto-wifi-config.sh -r + dialog --title "Wifi restart" --yesno "Wifi will be restarted.\nMeshtastic wifi setting will be set to ON." 7 50 + exitstatus=$? + if [ $exitstatus -eq 0 ]; then + femto-wifi-config.sh -r + fi ;; 4) return @@ -61,84 +81,107 @@ wifi_settings() { done } -# Function to handle timezone settings +# 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) -# Function to select and set the time zone -set_timezone() { -local selected_timezone -local timezones - -# 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 -local options=() -while IFS= read -r timezone; do - options+=("$timezone" "$timezone") -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 - if timedatectl set-timezone "$selected_timezone"; then - dialog --msgbox "Time zone set to $selected_timezone successfully." 8 40 - else - dialog --msgbox "Failed to set the time zone. Please try again." 8 40 + 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 -else - dialog --msgbox "No time zone selected. Returning to menu." 8 40 -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 Meshtastic CLI settings -misc_settings() { - local option="" - option=$(dialog --menu "Meshtastic CLI Options" 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) - set_timezone - ;; - 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 +# 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 --menu "Femtofox Config" 15 40 5 \ + choice=$(dialog --title "$(date)" --menu "Femtofox Config" 15 40 5 \ 1 "Wi-Fi" \ 2 "Meshtasticd" \ 3 "Misc" \ - 4 "Install third party apps" \ + 4 "Software" \ 5 "Run OEM luckfox-config" \ 6 "Help" \ 7 "Exit" 3>&1 1>&2 2>&3) @@ -153,7 +196,7 @@ while true; do 1) wifi_settings ;; 2) meshtasticd_settings ;; 3) misc_settings ;; - 4) 3rd_party ;; + 4) software_settings ;; 5) luckfox-config ;; 6) femto_help ;; 7) break ;; From b0a10685a7f8ac1905f70df04572ae27edb9d353 Mon Sep 17 00:00:00 2001 From: nagumii Date: Sun, 29 Dec 2024 20:43:42 +0200 Subject: [PATCH 9/9] Update femtofox-config --- .../out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config index abf97a1..80f798a 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femtofox-config @@ -68,11 +68,8 @@ For more details, enter \`iwconfig\`. 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" --yesno "Wifi will be restarted.\nMeshtastic wifi setting will be set to ON." 7 50 - exitstatus=$? - if [ $exitstatus -eq 0 ]; then - femto-wifi-config.sh -r - fi + 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