mirror of
https://github.com/femtofox/femtofox.git
synced 2026-11-29 19:37:20 -05:00
Merge pull request #119 from noon92/femto-config
Migrate usb-config script to use the new architecture
This commit is contained in:
commit
9bdeeefd9e
8 changed files with 186 additions and 103 deletions
|
|
@ -7,7 +7,7 @@ luckfox-config load
|
|||
|
||||
#run only on first boot
|
||||
if [ -e "/usr/local/bin/.firstboot" ]; then
|
||||
/usr/local/bin/runonce.sh
|
||||
/usr/local/bin/femto_runonce.sh
|
||||
fi
|
||||
|
||||
# try enable RTC
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ evtest --grab /dev/input/event0 | while read line; do
|
|||
else
|
||||
logger "$duration second button press detected. Rebooting."
|
||||
echo 1 > /sys/class/gpio/gpio34/value;
|
||||
sudo reboot
|
||||
reboot
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ set_lora_radio() {
|
|||
;;
|
||||
esac
|
||||
if [ -n "$radio" ]; then #if a radio was selected
|
||||
femto-meshtasticd-config.sh -l "$radio"
|
||||
femto-meshtasticd-config.sh -l "$radio" -s # set the radio, then restart.
|
||||
return
|
||||
fi
|
||||
done
|
||||
|
|
@ -261,7 +261,7 @@ meshtasticd_settings() {
|
|||
local title="Meshtasticd Settings"
|
||||
while true; do
|
||||
local option=""
|
||||
option=$(dialog --menu "$title" 19 50 4 \
|
||||
option=$(dialog --menu "$title" 22 50 4 \
|
||||
1 "View current configuration URL & QR code" \
|
||||
2 "Set new configuration URL" \
|
||||
3 "View current lora radio selection" \
|
||||
|
|
@ -271,9 +271,12 @@ meshtasticd_settings() {
|
|||
7 "Clear admin keys" \
|
||||
8 "Enable legacy admin channel" \
|
||||
9 "Disable legacy admin channel" \
|
||||
10 "Upgrade/install Meshtasticd" \
|
||||
11 "Uninstall Meshtasticd" \
|
||||
12 "Back to Main Menu" 3>&1 1>&2 2>&3)
|
||||
10 "Meshtasticd service status" \
|
||||
11 "Start/restart Meshtasticd service" \
|
||||
12 "Stop Meshtasticd service" \
|
||||
13 "Upgrade/install Meshtasticd" \
|
||||
14 "Uninstall Meshtasticd" \
|
||||
15 "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
|
||||
|
|
@ -333,21 +336,38 @@ meshtasticd_settings() {
|
|||
pause
|
||||
fi
|
||||
;;
|
||||
10) #Upgrade meshtasticd)
|
||||
10) #check meshtasticd service status)
|
||||
dialog --msgbox "$(systemctl status meshtasticd)" 0 0
|
||||
;;
|
||||
11) #start/restart meshtasticd)
|
||||
dialog --title "$title" --yesno "Start/restart Meshtasticd service?" 0 0
|
||||
if [ $? -eq 0 ]; then #unless cancel/no
|
||||
femto-meshtasticd-config.sh -s
|
||||
dialog --msgbox "Meshtasticd service started/restarted." 0 0
|
||||
fi
|
||||
;;
|
||||
12) #stop meshtasticd)
|
||||
dialog --title "$title" --yesno "Stop Meshtasticd service?" 0 0
|
||||
if [ $? -eq 0 ]; then #unless cancel/no
|
||||
femto-meshtasticd-config.sh -t
|
||||
dialog --msgbox "Meshtasticd service stopped." 0 0
|
||||
fi
|
||||
;;
|
||||
13) #Upgrade meshtasticd)
|
||||
dialog --title "$title" --yesno "Upgrade Meshtasticd?\nRequires internet connection." 0 0
|
||||
if [ $? -eq 0 ]; then #unless cancel/no
|
||||
femto-meshtasticd-config.sh -u
|
||||
pause
|
||||
fi
|
||||
;;
|
||||
11)
|
||||
14) #uninstall meshtasticd)
|
||||
dialog --title "$title" --yesno "Uninstall Meshtasticd?\n\nFoxbuntu was designed with Meshtasticd integration in mind, and may behave unexpectedly if Meshtasticd is removed." 0 0
|
||||
if [ $? -eq 0 ]; then
|
||||
femto-meshtasticd-config.sh -r
|
||||
femto-meshtasticd-config.sh -x
|
||||
dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run \`sudo runonce.sh\`." 8 40
|
||||
fi
|
||||
;;
|
||||
12)
|
||||
15)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
|
|
|||
|
|
@ -16,8 +16,11 @@ Options are:
|
|||
-c Clear admin keys
|
||||
-e Enable legacy admin channel
|
||||
-d Disable legacy admin channel
|
||||
-o "true" Set legacy admin channel state (true/false), case sensitive
|
||||
-s Start/restart Meshtasticd Service
|
||||
-t Stop Meshtasticd Service
|
||||
-u Upgrade Meshtasticd
|
||||
-r Uninstall Meshtasticd
|
||||
-x Uninstall Meshtasticd
|
||||
-m Meshtastic update tool. Syntax: \`femto-meshtasticd-config.sh -m \"--set security.admin_channel_enabled false\" 10 \"Disable legacy admin\"\`
|
||||
Will retry the \`--set security.admin_channel_enabled false\` command until successful or up to 10 times, and tag status reports with \`Disable legacy admin\` via echo and to system log.
|
||||
EOF
|
||||
|
|
@ -40,23 +43,24 @@ meshtastic_update() {
|
|||
logger $output
|
||||
if echo "$output" | grep -qiE "Abort|invalid|Error|refused|Errno"; then
|
||||
if [ "$retries" -lt $attempts ]; then
|
||||
local msg="${ref:+$ref }Meshtastic update failed, retrying ($(($retries + 1))/$attempts)..."
|
||||
local msg="${ref:+$ref}Meshtastic update failed, retrying ($(($retries + 1))/$attempts)..."
|
||||
echo "$msg"
|
||||
logger "$msg"
|
||||
sleep 2 # Add a small delay before retrying
|
||||
fi
|
||||
else
|
||||
local success="true"
|
||||
msg="${ref:+$ref }Meshtastic update successful!"
|
||||
msg="${ref:+$ref}Meshtastic update successful!"
|
||||
echo "$msg"
|
||||
logger "$msg"
|
||||
if [ -n "$external" ]; then
|
||||
exit 0
|
||||
fi
|
||||
return
|
||||
fi
|
||||
done
|
||||
if [ -z "$success" ]; then
|
||||
msg="${ref:+$ref }Meshtastic update failed."
|
||||
msg="${ref:+$ref}Meshtastic update FAILED."
|
||||
echo "$msg"
|
||||
logger "$msg"
|
||||
if [ -n "$external" ]; then
|
||||
|
|
@ -66,7 +70,7 @@ meshtastic_update() {
|
|||
}
|
||||
|
||||
# Parse options
|
||||
while getopts ":hgkl:q:va:cedurm" opt; do
|
||||
while getopts ":hgkl:q:va:cedo:struxm" opt; do
|
||||
case ${opt} in
|
||||
h) # Option -h (help)
|
||||
echo -e "$help"
|
||||
|
|
@ -118,11 +122,22 @@ while getopts ":hgkl:q:va:cedurm" opt; do
|
|||
d) # Option -d (disable legacy admin)
|
||||
meshtastic_update "--set security.admin_channel_enabled false" 10 "Disable legacy admin"
|
||||
;;
|
||||
o) # Option -o (set legacy admin true/false)
|
||||
meshtastic_update "--set security.admin_channel_enabled $OPTARG" 10 "Disable legacy admin"
|
||||
;;
|
||||
s) # Option -s (start/restart Meshtasticd service)
|
||||
systemctl restart meshtasticd
|
||||
echo "Meshtasticd service started/restarted."
|
||||
;;
|
||||
t) # Option -t (stop Meshtasticd service)
|
||||
systemctl stop meshtasticd
|
||||
echo "Meshtasticd service stopped."
|
||||
;;
|
||||
u) # Option -u (upgrade meshtasticd)
|
||||
apt update
|
||||
apt install --only-upgrade meshtasticd
|
||||
;;
|
||||
r) # Option -r (uninstall meshtasticd)
|
||||
x) # Option -x (uninstall meshtasticd)
|
||||
apt remove meshtasticd
|
||||
;;
|
||||
m)
|
||||
|
|
|
|||
|
|
@ -121,11 +121,11 @@ if [ "$updated_wifi" = true ]; then
|
|||
timeout 30s dhclient -v
|
||||
echo " Wifi restarted. Enabling Meshtastic wifi setting."
|
||||
femto-meshtasticd-config.sh -m "--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
|
||||
# if [ $? -eq 1 ]; then
|
||||
# echo "Update of Meshtastic FAILED."
|
||||
# exit 1
|
||||
# else
|
||||
# echo "Updated Meshtastic successfully."
|
||||
# exit 0
|
||||
# fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
#!/bin/bash
|
||||
mount_point="/mnt/usb" # Set the mount point
|
||||
|
||||
# Set the mount point
|
||||
mount_point="/mnt/usb"
|
||||
|
||||
# Function to log both to the screen and syslog
|
||||
# Function to log to screen, syslog and logfile to be saved to usb drive
|
||||
log_message() {
|
||||
echo "USB config: $1" # Echo to the screen
|
||||
logger "USB config: $1" # Log to the system log
|
||||
echo "$(date +"%Y-%m-%d %H:%M:%S") $1" >> /tmp/femtofox-config.log # Log to file
|
||||
echo "USB config: $1"
|
||||
logger "USB config: $1"
|
||||
echo "$(date +"%Y-%m-%d %H:%M:%S") $1" >> /tmp/femtofox-config.log
|
||||
}
|
||||
|
||||
exit_script() {
|
||||
|
|
@ -39,11 +37,6 @@ escape_sed() {
|
|||
usb_path=$(lsblk -o NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT | grep -E "vfat|ext4|ntfs|exfat" | grep -E "sd[a-z]([0-9]*)" | awk '{print $1}' | sed 's/[^a-zA-Z0-9]//g' | head -n 1)
|
||||
full_device_path="/dev/$usb_path" # Construct the full device path
|
||||
|
||||
#if [ -d "$mount_point" ]; then
|
||||
# rmdir "$mount_point"
|
||||
# log_message "/mnt/usb deleted."
|
||||
#fi
|
||||
|
||||
# If no USB device is found, exit
|
||||
if [ -z "$usb_path" ]; then
|
||||
message="No USB drive found."
|
||||
|
|
@ -92,8 +85,8 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
meshtastic_lora_radio=""
|
||||
found_config="false"
|
||||
update_wifi="false"
|
||||
update_meshtastic_url=""
|
||||
update_meshtastic_security=""
|
||||
wifi_command="femto-network-config.sh"
|
||||
meshtastic_security_command="femto-meshtasticd-config.sh"
|
||||
|
||||
# Escape and read the fields from the USB config file if they exist
|
||||
while IFS='=' read -r key value; do
|
||||
|
|
@ -113,30 +106,25 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
|
||||
# Update wpa_supplicant.conf with the new values, if specified
|
||||
if [[ -n "$wifi_country" ]]; then
|
||||
# Update or add the country field
|
||||
if grep -q "^country=" "$wpa_supplicant_conf"; then
|
||||
sed -i "s/^country=.*/country=$wifi_country/" "$wpa_supplicant_conf"
|
||||
log_message "Updated Wi-Fi country in wpa_supplicant.conf to $wifi_country."
|
||||
else
|
||||
echo "country=$wifi_country" >> "$wpa_supplicant_conf"
|
||||
log_message "Added Wi-Fi country to wpa_supplicant.conf as $wifi_country."
|
||||
fi
|
||||
# Update country field
|
||||
wifi_command="$wifi_command -c \"$wifi_country\""
|
||||
log_message "Updating Wi-Fi country in wpa_supplicant.conf to $wifi_country."
|
||||
found_config="true"
|
||||
update_wifi="true"
|
||||
fi
|
||||
|
||||
if [[ -n "$wifi_ssid" ]]; then
|
||||
# Update the ssid in the network block
|
||||
sed -i "/ssid=/s/\".*\"/\"$wifi_ssid\"/" "$wpa_supplicant_conf"
|
||||
log_message "Updated Wi-Fi SSID in wpa_supplicant.conf to $wifi_ssid."
|
||||
wifi_command="$wifi_command -s \"$wifi_ssid\""
|
||||
log_message "Updating Wi-Fi SSID in wpa_supplicant.conf to \`$wifi_ssid\`."
|
||||
found_config="true"
|
||||
update_wifi="true"
|
||||
fi
|
||||
|
||||
if [[ -n "$wifi_psk" ]]; then
|
||||
# Update the psk in the network block
|
||||
sed -i "/psk=/s/\".*\"/\"$wifi_psk\"/" "$wpa_supplicant_conf"
|
||||
log_message "Updated Wi-Fi PSK in wpa_supplicant.conf."
|
||||
wifi_command="$wifi_command -p \"$wifi_psk\""
|
||||
log_message "Updating Wi-Fi PSK in wpa_supplicant.conf to \`$wifi_psk\`."
|
||||
found_config="true"
|
||||
update_wifi="true"
|
||||
fi
|
||||
|
|
@ -149,120 +137,99 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
meshtastic_lora_radio=$(echo "$meshtastic_lora_radio" | tr '[:upper:]' '[:lower:]')
|
||||
case "$meshtastic_lora_radio" in
|
||||
'ebyte-e22-900m30s')
|
||||
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
|
||||
radio="sx1262_tcxo"
|
||||
;;
|
||||
'ebyte-e22-900m22s')
|
||||
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
|
||||
radio="sx1262_tcxo"
|
||||
;;
|
||||
'heltec-ht-ra62')
|
||||
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
|
||||
radio="sx1262_tcxo"
|
||||
;;
|
||||
'seeed-wio-sx1262')
|
||||
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
|
||||
radio="sx1262_tcxo"
|
||||
;;
|
||||
'waveshare-sx126x-xxxm')
|
||||
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_XTAL.yaml /etc/meshtasticd/config.d
|
||||
radio="sx1262_xtal"
|
||||
;;
|
||||
'ai-thinker-ra-01sh')
|
||||
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_XTAL.yaml /etc/meshtasticd/config.d
|
||||
radio="sx1262_xtal"
|
||||
;;
|
||||
'ebyte-e80-900m22s')
|
||||
#not yet implemented
|
||||
cp /etc/meshtasticd/available.d/femtofox/femtofox_LR1121_TCXO.yaml /etc/meshtasticd/config.d
|
||||
radio="lr1121_tcxo" # not yet implemented
|
||||
;;
|
||||
'sx1262_tcxo')
|
||||
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
|
||||
radio="sx1262_tcxo"
|
||||
;;
|
||||
'sx1262_xtal')
|
||||
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_XTAL.yaml /etc/meshtasticd/config.d
|
||||
radio="sx1262_xtal"
|
||||
;;
|
||||
'lr1121_tcxo')
|
||||
#not yet implemented
|
||||
cp /etc/meshtasticd/available.d/femtofox/femtofox_LR1121_TCXO.yaml /etc/meshtasticd/config.d
|
||||
radio="lr1121_tcxo" # not yet implemented
|
||||
;;
|
||||
'none')
|
||||
radio="none"
|
||||
;;
|
||||
*)
|
||||
log_message "Invalid LoRa radio name: $meshtastic_lora_radio, ignoring."
|
||||
found_config="false"
|
||||
;;
|
||||
esac
|
||||
if [ "$found_config" = "true" ]; then
|
||||
systemctl restart meshtasticd
|
||||
if [[ -n "$radio" ]]; then # if a radio was found
|
||||
femto-meshtasticd-config.sh -l "$radio" -s 2>&1 | tee -a /tmp/femtofox-config.log # set the radio and restart the service
|
||||
log_message "Set LoRa radio to $meshtastic_lora_radio, restarting Meshtasticd."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "$timezone" ]]; then
|
||||
#sed -i "/timezone=/s/\".*\"/\"$timezone\"/" "$wpa_supplicant_conf"
|
||||
if [[ -n "$timezone" ]]; then # set timezone
|
||||
timezone=$(echo "$timezone" | sed 's/\\//g')
|
||||
log_message "Updating system timezone to $timezone."
|
||||
rm /etc/localtime
|
||||
ln -sf /usr/share/zoneinfo/$timezone /etc/localtime >> /tmp/femtofox-config.log 2>&1
|
||||
femto-set-timezone.sh -t "$timezone"
|
||||
found_config="true"
|
||||
fi
|
||||
|
||||
if [[ -n "$meshtastic_url" ]]; then
|
||||
meshtastic_url=$(echo "$meshtastic_url" | sed 's/\\//g')
|
||||
if [[ -n "$meshtastic_url" ]]; then # set meshtastic URL
|
||||
meshtastic_url=$(echo "$meshtastic_url" | sed 's/\\//g') # remove weirdo windows characters
|
||||
log_message "Updating Meshtastic URL."
|
||||
found_config="true"
|
||||
update_meshtastic_url="--seturl $meshtastic_url"
|
||||
fi
|
||||
|
||||
if [[ -n "$meshtastic_admin_key" ]]; then
|
||||
meshtastic_admin_key=$(echo "$meshtastic_admin_key" | sed 's/\\//g')
|
||||
meshtastic_admin_key=$(echo "$meshtastic_admin_key" | sed 's/\\//g') # remove weirdo windows characters
|
||||
if [ "$meshtastic_admin_key" = "clear" ]; then
|
||||
log_message "Clearing Meshtastic admin key list."
|
||||
meshtastic_admin_key="0"
|
||||
else
|
||||
meshtastic_admin_key="base64:$meshtastic_admin_key"
|
||||
meshtastic_admin_key="$meshtastic_admin_key"
|
||||
log_message "Updating Meshtastic admin key."
|
||||
fi
|
||||
found_config="true"
|
||||
update_meshtastic_security+=" --set security.admin_key $meshtastic_admin_key"
|
||||
meshtastic_security_command+=" -a \"$meshtastic_admin_key\"" # add to the command list
|
||||
fi
|
||||
|
||||
if [[ -n "$meshtastic_legacy_admin" ]]; then
|
||||
meshtastic_legacy_admin=$(echo "$meshtastic_legacy_admin" | sed 's/\\//g')
|
||||
meshtastic_legacy_admin=$(echo "$meshtastic_legacy_admin" | sed 's/\\//g') # remove weirdo windows characters
|
||||
log_message "Updating Meshtastic legacy admin."
|
||||
found_config="true"
|
||||
update_meshtastic_security+=" --set security.admin_channel_enabled $meshtastic_legacy_admin"
|
||||
meshtastic_security_command+=" -o \"$meshtastic_legacy_admin\"" # add to the command list
|
||||
fi
|
||||
|
||||
if [ "$found_config" = true ]; then #if we found a config file containing valid data
|
||||
|
||||
if [ "$update_wifi" = true ]; then #if wifi config found, restart wifi
|
||||
systemctl restart wpa_supplicant 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
wpa_cli -i wlan0 reconfigure 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
log_message "Making changes to wifi settings and restarting wifi."
|
||||
wifi_command="$wifi_command -r"
|
||||
eval $wifi_command 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
log_message "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi setting."
|
||||
timeout 30s dhclient -v 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
|
||||
femto-meshtasticd-config.sh -m "--set network.wifi_enabled true" 10 "USB config" #| tee -a /tmp/femtofox-config.log
|
||||
if [ $? -eq 1 ]; then
|
||||
log_message "Update of Meshtastic FAILED."
|
||||
else
|
||||
log_message "Updated Meshtastic successfully."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$update_meshtastic_url" != "" ]; then
|
||||
log_message "Connecting to Meshtastic radio and submitting $update_meshtastic_url"
|
||||
femto-meshtasticd-config.sh -m "$update_meshtastic_url" 10 "USB config" #| tee -a /tmp/femtofox-config.log
|
||||
if [ $? -eq 1 ]; then
|
||||
log_message "Update of Meshtastic FAILED."
|
||||
else
|
||||
log_message "Updated Meshtastic successfully."
|
||||
fi
|
||||
if [ "$meshtastic_url" != "" ]; then
|
||||
log_message "Connecting to Meshtastic radio and submitting $meshtastic_url"
|
||||
femto-meshtasticd-config.sh -q "$meshtastic_url" 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
fi
|
||||
|
||||
if [ "$update_meshtastic_security" != "" ]; then
|
||||
log_message "Connecting to Meshtastic radio and submitting $update_meshtastic_security"
|
||||
femto-meshtasticd-config.sh -m "$update_meshtastic_security" 10 "USB config" #| tee -a /tmp/femtofox-config.log
|
||||
if [ $? -eq 1 ]; then
|
||||
log_message "Update of Meshtastic FAILED."
|
||||
else
|
||||
log_message "Updated Meshtastic successfully."
|
||||
fi
|
||||
if [ "$meshtastic_security_command" != "" ]; then
|
||||
log_message "Connecting to Meshtastic radio and submitting $meshtastic_security_command
|
||||
"
|
||||
eval "$meshtastic_security_command" 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
fi
|
||||
|
||||
for _ in {1..10}; do #do our successful config boot code
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue