From f73673dc5e24ff90603bf2d5de0aaed543e1be03 Mon Sep 17 00:00:00 2001 From: nagumii Date: Sun, 29 Dec 2024 13:26:40 +0200 Subject: [PATCH] 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