From 1d585e3f6e29c6c53ea2a1e600fa6115aee69ef1 Mon Sep 17 00:00:00 2001 From: nagumii Date: Tue, 3 Dec 2024 09:09:24 +0200 Subject: [PATCH] Merged in up to date scripts --- .../overlay-luckfox-ubuntu/etc/rc.local | 66 ++--- .../lib/systemd/system/button.service | 2 +- .../usr/local/bin/usbconfig.sh | 5 +- .../usr/local/bin/wifi-mesh-control.sh | 42 ++- scripts/00-header | 41 --- scripts/button.service | 11 - scripts/buttonservice.sh | 10 - scripts/issue | 4 - scripts/luckfox.cfg | 9 - scripts/rc.local | 87 ------- scripts/usbconfig.sh | 246 ------------------ scripts/wifi-mesh-control.service | 11 - scripts/wifi-mesh-control.sh | 44 ---- 13 files changed, 61 insertions(+), 517 deletions(-) delete mode 100644 scripts/00-header delete mode 100644 scripts/button.service delete mode 100644 scripts/buttonservice.sh delete mode 100644 scripts/issue delete mode 100644 scripts/luckfox.cfg delete mode 100644 scripts/rc.local delete mode 100644 scripts/usbconfig.sh delete mode 100644 scripts/wifi-mesh-control.service delete mode 100644 scripts/wifi-mesh-control.sh diff --git a/foxbuntu/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-ubuntu/etc/rc.local b/foxbuntu/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-ubuntu/etc/rc.local index b81b99b..b6843ad 100755 --- a/foxbuntu/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-ubuntu/etc/rc.local +++ b/foxbuntu/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-ubuntu/etc/rc.local @@ -1,47 +1,53 @@ #!/bin/bash -#not really needed after first boot +# not really needed after first boot /usr/bin/filesystem_resize.sh -#supposedly needed for usb storage, but works anyway +# supposedly needed for usb storage, but works anyway #/etc/init.d/S50usbdevice start luckfox-config load -#try enable RTC +# run once to prevent randomized mac address for eth0 +if ! grep -A 1 "iface eth0 inet dhcp" /etc/network/interfaces | grep -q "hwaddress ether"; then + sed -i "/iface eth0 inet dhcp/a\hwaddress ether $(cat /sys/class/net/eth0/address)" /etc/network/interfaces + echo "Making current eth0 MAC address permanent." +fi + +# try enable RTC echo 'ds1307 0x68' | sudo tee /sys/class/i2c-adapter/i2c-3/new_device > /dev/null 2>&1 # activating USER LED echo 34 > /sys/class/gpio/export && echo out > /sys/class/gpio/gpio34/direction & - ( - if ip addr show wlan0 | grep -q 'inet '; then - echo "Wifi (wlan0) is online"; - else - echo "Wifi (wlan0) is offline"; - fi - if ip addr show eth0 | grep -q 'inet '; then - echo "Built-in ethernet (eth0) is online"; - else - echo "Built-in ethernet (eth0) is offline"; - fi - ) & +( + if ip addr show wlan0 | grep -q 'inet '; then + echo "Wifi (wlan0) is online."; + else + echo "Wifi (wlan0) is offline."; + fi + if ip addr show eth0 | grep -q 'inet '; then + echo "Onboard ethernet (eth0) is online."; + else + echo "Onboard ethernet (eth0) is offline."; + fi + ) & -#if RTC recognized +# if RTC recognized if ls /dev/rtc* 1> /dev/null 2>&1; then - rtc="true" - if sudo hwclock -s 2>&1 | grep -a failed > /dev/null 2>&1; then - echo "RTC device found but failed to get time." - else - hwclock -s > /dev/null 2>&1 & - echo "RTC device found! $(date +"%Y-%m-%d %H:%M:%S %Z")." - fi + rtc="true" + if sudo hwclock -s 2>&1 | grep -a failed > /dev/null 2>&1; then + echo "RTC device found but failed to get time." + else + hwclock -s > /dev/null 2>&1 & + echo "RTC device found! $(date +"%Y-%m-%d %H:%M:%S %Z")." + fi else - echo "RTC not found." - sudo date -s "1 JAN 2024 00:00:00" > /dev/null 2>&1 & + echo "RTC not found." + sudo date -s "1 JAN 2024 00:00:00" > /dev/null 2>&1 & fi -#try get network time +# try get network time date_str=$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g') if [ -n "$date_str" ]; then sudo date -s "$date_str" > /dev/null 2>&1 @@ -55,19 +61,21 @@ else fi # necessary for internet over usb in otg mode (see https://web.archive.org/web/20241006173648/https://wiki.luckfox.com/Luckfox-Pico/Luckfox-Pico-Network-Sharing-1/) -# sleep 5 && route add default gw 172.32.0.100 && echo "nameserver 8.8.8.8" >> /etc/resolv.conf +#sleep 5 && route add default gw 172.32.0.100 && echo "nameserver 8.8.8.8" >> /etc/resolv.conf -#does not appear to lower power consumption, but needs more testing +# does not appear to lower power consumption, but needs more testing #(sleep 5 && cpufreq-set -u 408000 && echo "Boot complete, setting CPU frequency to 408mhz.") & # run USB automount and config tool /usr/local/bin/usbconfig.sh -#boot complete +# boot complete ( echo "Disabling ACT LED..." echo "none" > /sys/class/leds/work/trigger & sleep 1 + + # blink successful boot code for i in $(seq 1 5); do echo 1 > /sys/class/gpio/gpio34/value; sleep 0.5; diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/lib/systemd/system/button.service b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/lib/systemd/system/button.service index 6fc732f..4f91a0c 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/lib/systemd/system/button.service +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/lib/systemd/system/button.service @@ -5,7 +5,7 @@ After=multi-user.target [Service] ExecStart=/usr/local/bin/buttonservice.sh Restart=always -User=root +User=femto [Install] WantedBy=multi-user.target diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/usbconfig.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/usbconfig.sh index 0e67222..bdb740b 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/usbconfig.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/usbconfig.sh @@ -211,7 +211,10 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then if [ "$update_wifi" = true ]; then #if wifi config found, restart wifi sudo systemctl restart wpa_supplicant sudo wpa_cli -i wlan0 reconfigure - log_message "wpa_supplicant.conf updated and wifi restarted, proceeding." + log_message "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi." + sudo dhclient -r + sudo dhclient + meshtastic --host --set network.wifi_enabled true fi if [ "$update_meshtastic" != "" ]; then diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/wifi-mesh-control.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/wifi-mesh-control.sh index ed3ead3..afa9700 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/wifi-mesh-control.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/wifi-mesh-control.sh @@ -1,33 +1,29 @@ #!/bin/bash - -# Wait 60 seconds for networking to be available during boot -sleep 60 - -# Initial value for comparison (set to up by default) -previous_value="1" - -# Ensure Wi-Fi interface is up by default on boot ip link set wlan0 up +sleep 60 #wait 60 seconds so networking will be available during boot + +# Initial value for comparison (start with an impossible value so it'll always implement the current value after boot) +previous_value=2 while true; do - # Fetch the current value + # Run the command to fetch the value current_value=$(cat /root/.portduino/default/prefs/config.proto | protoc --decode_raw | awk '/4 {/, /}/ {if ($1 == "1:") print $2}') # Check if the value has changed if [ "$current_value" != "$previous_value" ]; then - # Log the previous state - case "$previous_value" in - 1) prev_text="Wifi on" ;; - 2) prev_text="Startup" ;; - *) prev_text="Wifi off" ;; - esac - # Log the current state - if [ "$current_value" -eq 1 ]; then - cur_text="Wifi on" - else - cur_text="Wifi off" - fi + if [ "$previous_value" -eq 1 ]; then + prev_text="Wifi on" + elif [ "$previous_value" -eq 2 ]; then + prev_text="Startup" + else + prev_text="Wifi off" + fi + if [ "$current_value" -eq 1 ]; then + cur_text="Wifi on" + else + cur_text="Wifi off" + fi # Log the change logger "Wifi mesh control: wifi setting changed: $prev_text -> $cur_text" @@ -36,10 +32,10 @@ while true; do previous_value="$current_value" fi - # Take action based on the current value + # Take action based on the new value if [ "$current_value" == "1" ]; then ip link set wlan0 up - elif [ "$current_value" == "0" ]; then + else ip link set wlan0 down fi diff --git a/scripts/00-header b/scripts/00-header deleted file mode 100644 index 7c0ff2e..0000000 --- a/scripts/00-header +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh -# - -[ -r /etc/lsb-release ] && . /etc/lsb-release - -#printf "\n" -echo "\e[92m @+ .** - -@@@@@ @@@@@# - #@@@@@ @@@@@@@@ - @@@@@* =@@@@@@@@@@: - .@@@@@. %@@@@@ @@@@@# - *@@@@@ @@@@@@ %@@@@@ - @@@@@% :@@@@@- -@@@@@ - @@@@@- #@@@@@ @@@@@+ - =@@@@@ @@@@@@ @@@@@@ - @@@@@@ .@@@@@= *@@@@@ - @@@@@+ +@@@@@ .@@@@@+ - :@@@@@ @@@@@@ @@@@@@ - #@@@@@ @@@@@* POWERED #@@@@@ - @@@@@# -@@@@@: :@@@@@- - .@@@@@. %@@@@@ @@@@@% - %@@ @@% @@@ -\033[0m" - - -if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then - # Fall back to using the very slow lsb_release utility - DISTRIB_DESCRIPTION=$(lsb_release -s -d) -fi - -[ -r /etc/lsb-release ] && . /etc/lsb-release - -#printf "\n" -printf " %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" "$(uname -r)" "$(uname -m)" -printf " Meshtastic is a registered trademark of Meshtastic LLC.\n" -printf " Meshtastic software components are released under various licenses,\n" -printf " see GitHub for details. No warranty is provided - use at your own risk.\n" -printf " Luckfox: wiki.luckfox.com This image built by github.com/noon92/femtofox\n" -printf " This system has been minimized. To restore content, run 'unminimize'.\n\n" - -printf "IP address: $(hostname -I | sed 's/ / /g') Uptime:$(uptime -p | awk '{$1=""; print $0}' | sed -e 's/ day\b/d/g' -e 's/ hour\b/h/g' -e 's/ hours\b/h/g' -e 's/ minute\b/m/g' -e 's/ minutes\b/m/g' | sed 's/,//g')\n" \ No newline at end of file diff --git a/scripts/button.service b/scripts/button.service deleted file mode 100644 index 4f91a0c..0000000 --- a/scripts/button.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Button Reboot Service -After=multi-user.target - -[Service] -ExecStart=/usr/local/bin/buttonservice.sh -Restart=always -User=femto - -[Install] -WantedBy=multi-user.target diff --git a/scripts/buttonservice.sh b/scripts/buttonservice.sh deleted file mode 100644 index d0d5d81..0000000 --- a/scripts/buttonservice.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -logger "$(date): Listening for button press on $DEVICE..." - -evtest --grab /dev/input/event0 | while read line; do - if echo $line | grep -q "EV_KEY.*value 1"; then - logger "Button pressed, triggering reboot..." - sudo reboot - fi -done diff --git a/scripts/issue b/scripts/issue deleted file mode 100644 index 2b85869..0000000 --- a/scripts/issue +++ /dev/null @@ -1,4 +0,0 @@ -Ubuntu 22.04.3 LTS \n \l - -[username:password] root:root femto:fox - diff --git a/scripts/luckfox.cfg b/scripts/luckfox.cfg deleted file mode 100644 index 1d622a3..0000000 --- a/scripts/luckfox.cfg +++ /dev/null @@ -1,9 +0,0 @@ -SPI0_M0_CS_ENABLE=1 -SPI0_M0_MODE=1 -UART4_M1_STATUS=1 -UART3_M1_STATUS=1 -I2C3_M1_STATUS=1 -I2C3_M1_SPEED=100000 -SPI0_M0_STATUS=1 -SPI0_M0_MISO_ENABLE=1 -SPI0_M0_SPEED=2000000 diff --git a/scripts/rc.local b/scripts/rc.local deleted file mode 100644 index b6843ad..0000000 --- a/scripts/rc.local +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash - -# not really needed after first boot -/usr/bin/filesystem_resize.sh - -# supposedly needed for usb storage, but works anyway -#/etc/init.d/S50usbdevice start - -luckfox-config load - -# run once to prevent randomized mac address for eth0 -if ! grep -A 1 "iface eth0 inet dhcp" /etc/network/interfaces | grep -q "hwaddress ether"; then - sed -i "/iface eth0 inet dhcp/a\hwaddress ether $(cat /sys/class/net/eth0/address)" /etc/network/interfaces - echo "Making current eth0 MAC address permanent." -fi - -# try enable RTC -echo 'ds1307 0x68' | sudo tee /sys/class/i2c-adapter/i2c-3/new_device > /dev/null 2>&1 - -# activating USER LED -echo 34 > /sys/class/gpio/export && echo out > /sys/class/gpio/gpio34/direction & - -( - if ip addr show wlan0 | grep -q 'inet '; then - echo "Wifi (wlan0) is online."; - else - echo "Wifi (wlan0) is offline."; - fi - if ip addr show eth0 | grep -q 'inet '; then - echo "Onboard ethernet (eth0) is online."; - else - echo "Onboard ethernet (eth0) is offline."; - fi - ) & - -# if RTC recognized -if ls /dev/rtc* 1> /dev/null 2>&1; then - rtc="true" - if sudo hwclock -s 2>&1 | grep -a failed > /dev/null 2>&1; then - echo "RTC device found but failed to get time." - else - hwclock -s > /dev/null 2>&1 & - echo "RTC device found! $(date +"%Y-%m-%d %H:%M:%S %Z")." - fi -else - echo "RTC not found." - sudo date -s "1 JAN 2024 00:00:00" > /dev/null 2>&1 & -fi - -# try get network time -date_str=$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g') -if [ -n "$date_str" ]; then - sudo date -s "$date_str" > /dev/null 2>&1 - sudo echo "Got network time: $(date +"%Y-%m-%d %H:%M:%S %Z")." - if [ "$rtc" = "true" ]; then - echo "Setting RTC to network time." - sudo hwclock -w & - fi -else - echo "Failed to fetch network time, using $(date +"%Y-%m-%d %H:%M:%S %Z") instead." -fi - -# necessary for internet over usb in otg mode (see https://web.archive.org/web/20241006173648/https://wiki.luckfox.com/Luckfox-Pico/Luckfox-Pico-Network-Sharing-1/) -#sleep 5 && route add default gw 172.32.0.100 && echo "nameserver 8.8.8.8" >> /etc/resolv.conf - -# does not appear to lower power consumption, but needs more testing -#(sleep 5 && cpufreq-set -u 408000 && echo "Boot complete, setting CPU frequency to 408mhz.") & - -# run USB automount and config tool -/usr/local/bin/usbconfig.sh - -# boot complete -( - echo "Disabling ACT LED..." - echo "none" > /sys/class/leds/work/trigger & - sleep 1 - - # blink successful boot code - for i in $(seq 1 5); do - echo 1 > /sys/class/gpio/gpio34/value; - sleep 0.5; - echo 0 > /sys/class/gpio/gpio34/value; - sleep 0.5; - done -) & - -exit 0 diff --git a/scripts/usbconfig.sh b/scripts/usbconfig.sh deleted file mode 100644 index bdb740b..0000000 --- a/scripts/usbconfig.sh +++ /dev/null @@ -1,246 +0,0 @@ -#!/bin/bash - -# Set the mount point -mount_point="/mnt/usb" - -# Function to log both to the screen and syslog -log_message() { - local msg="USB config: $1" - echo "$msg" # Echo to the screen - logger "USB config: $msg" # Log to the system log -} - -#Blink -blink() { - echo 1 > /sys/class/gpio/gpio34/value; - sleep "$1"; - echo 0 > /sys/class/gpio/gpio34/value; -} - -escape_sed() { - echo "$1" | sed -e 's/[]\/$*.^[]/\\&/g' -} - -# Check if the mount point exists and if a USB drive is plugged in -usb_device=$(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) - -if [ -d "$mount_point" ]; then - sudo rmdir "$mount_point" - log_message "/mnt/usb deleted." -fi - -# If no USB device is found, exit -if [ -z "$usb_device" ]; then - log_message "No USB drive found." - exit 0 -fi - -# Create the mount point if it doesn't exist -if [ ! -d "$mount_point" ]; then - sudo mkdir -p "$mount_point" -fi - -# Construct the full device path -usb_device="/dev/$usb_device" - - -# Debugging: Log and echo the extracted device name -log_message "Extracted device name: $usb_device" - -# Check if the USB drive is already mounted -if mount | grep "$usb_device" > /dev/null; then - log_message "USB drive is already mounted." -else - # Mount the USB drive to the specified mount point - sudo mount "$usb_device" "$mount_point" - if [ $? -eq 0 ]; then - log_message "USB drive mounted successfully at $mount_point." - else - log_message "Failed to mount USB drive." - blink "4" && sleep "0.5" - exit 1 - fi -fi - - wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" - usb_config="/tmp/femtofox-config.txt" - -# Check if the mounted USB drive contains a file femtofox-config.txt -if [ -f "$mount_point/femtofox-config.txt" ]; then - log_message "femtofox-config.txt found on USB drive." - - # Remove Windows-style carriage returns and save a temporary copy of femtofox-config.txt - tr -d '\r' < "$mount_point/femtofox-config.txt" > $usb_config - - # Initialize variables - wifi_ssid="" - wifi_psk="" - wifi_country="" - meshtastic_lora_radio="" - found_config="false" - update_wifi="false" - update_meshtastic="" - - # Escape and read the fields from the USB config file if they exist - while IFS='=' read -r key value; do - value=$(echo "$value" | tr -d '"') - case "$key" in - wifi_ssid) wifi_ssid=$(escape_sed "$value") ;; - wifi_psk) wifi_psk=$(escape_sed "$value") ;; - wifi_country) wifi_country=$(escape_sed "$value") ;; - meshtastic_lora_radio) meshtastic_lora_radio=$(escape_sed "$value") ;; - timezone) timezone=$(escape_sed "$value") ;; - meshtastic_url) meshtastic_url=$(escape_sed "$value") ;; - meshtastic_legacy_admin) meshtastic_legacy_admin=$(escape_sed "$value") ;; - meshtastic_admin_key) meshtastic_admin_key=$(escape_sed "$value") ;; - esac - done < <(grep -E '^(wifi_ssid|wifi_psk|wifi_country|meshtastic_lora_radio|timezone|meshtastic_url|meshtastic_legacy_admin|meshtastic_admin_key)=' "$usb_config") - - - # 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 - 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." - 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." - found_config="true" - update_wifi="true" - fi - - - #get meshtastic_lora_radio model, if specified, and copy appropriate yaml to /etc/meshtasticd/config.d/ - if [[ -n "$meshtastic_lora_radio" ]]; then - rm -f /etc/meshtasticd/config.d/femtofox* - found_config="true" - meshtastic_lora_radio=$(echo "$meshtastic_lora_radio" | tr '[:upper:]' '[:lower:]') - case "$meshtastic_lora_radio" in - 'ebyte-e22-900m30s') - cp /etc/meshtasticd/available.d/femtofox_EByte-E22-900M30S_Ebyte-E22-900M22S.yaml /etc/meshtasticd/config.d - ;; - 'ebyte-e22-900m22s') - cp /etc/meshtasticd/available.d/femtofox_EByte-E22-900M30S_Ebyte-E22-900M22S.yaml /etc/meshtasticd/config.d - ;; - 'e22-900mm22s') - cp /etc/meshtasticd/available.d/femtofox_EByte-E22-900MM22S.yaml /etc/meshtasticd/config.d - ;; - 'heltec-ht-ra62') - cp /etc/meshtasticd/available.d/femtofox_Heltec-HT-RA62_Seeed-WIO-SX1262.yaml /etc/meshtasticd/config.d - ;; - 'seeed-wio-sx1262') - cp /etc/meshtasticd/available.d/femtofox_Heltec-HT-RA62_Seeed-WIO-SX1262.yaml /etc/meshtasticd/config.d - ;; - 'waveshare-sx126x-xxxm') - cp /etc/meshtasticd/available.d/femtofox_Waveshare-SX126X-XXXM_AI-Thinker-RA-01SH.yaml /etc/meshtasticd/config.d - ;; - 'ai-thinker-ra-01sh') - cp /etc/meshtasticd/available.d/femtofox_Waveshare-SX126X-XXXM_AI-Thinker-RA-01SH.yaml /etc/meshtasticd/config.d - ;; - 'none') - ;; - *) - log_message "Invalid LoRa radio name: $meshtastic_lora_radio, ignoring." - found_config="false" - ;; - esac - if [ "$found_config" = "true" ]; then - systemctl restart meshtasticd - log_message "Set LoRa radio to $meshtastic_lora_radio, restarting Meshtasticd and proceeding." - fi - fi - - if [[ -n "$timezone" ]]; then - #sed -i "/timezone=/s/\".*\"/\"$timezone\"/" "$wpa_supplicant_conf" - timezone=$(echo "$timezone" | sed 's/\\//g') - log_message "Updating system timezone to $timezone." - rm /etc/localtime - ln -sf /usr/share/zoneinfo/$timezone /etc/localtime - found_config="true" - fi - - if [[ -n "$meshtastic_url" ]]; then - meshtastic_url=$(echo "$meshtastic_url" | sed 's/\\//g') - log_message "Updating Meshtastic URL to $meshtastic_url." - found_config="true" - update_meshtastic="--seturl $meshtastic_url" - fi - - if [[ -n "$meshtastic_admin_key" ]]; then - if [ "$update_meshtastic" = "" ]; then - meshtastic_admin_key=$(echo "$meshtastic_admin_key" | sed 's/\\//g') - log_message "Updating Meshtastic admin key to $meshtastic_admin_key." - found_config="true" - update_meshtastic=" --set security.admin_key $meshtastic_admin_key" - else - log_message "meshtastic_admin_key: Cannot update Meshtastic URL and security settings in single operation. Remove Meshtastic URL from femtofox-config.txt to make changes to security settings. Ignoring..." - fi - fi - - if [[ -n "$meshtastic_legacy_admin" ]]; then - if [ "$update_meshtastic" = "" ] || [[ "$update_meshtastic" == *security* ]]; then - meshtastic_legacy_admin=$(echo "$meshtastic_legacy_admin" | sed 's/\\//g') - log_message "Updating Meshtastic legacy admin to $meshtastic_legacy_admin." - found_config="true" - update_meshtastic+=" --set security.admin_channel_enabled $meshtastic_legacy_admin" - else - log_message "meshtastic_legacy_admin: Cannot update Meshtastic URL and security settings in single operation. Remove Meshtastic URL from femtofox-config.txt to make changes to security settings. Ignoring..." - fi - 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 - sudo systemctl restart wpa_supplicant - sudo wpa_cli -i wlan0 reconfigure - log_message "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi." - sudo dhclient -r - sudo dhclient - meshtastic --host --set network.wifi_enabled true - fi - - if [ "$update_meshtastic" != "" ]; then - log_message "Connecting to Meshtastic radio and submitting $update_meshtastic" - meshtastic --host $update_meshtastic - fi - - for _ in {1..10}; do #do our successful config boot code - blink "0.125" && sleep 0.125 - done - - else #if no valid data in config file - log_message "femtofox-config.txt does not contain valid configuration info, ignoring." - for _ in {1..5}; do - blink "1.5" && sleep 0.5 - done - exit 1 - fi - -else - log_message "USB drive mounted but femtofox-config.txt not found, ignoring." - for _ in {1..3}; do - blink "1.5" && sleep 0.5 - done - exit 1 -fi - - rm $usb_config #remove temporary copy of femtofox-config.txt - exit 0 \ No newline at end of file diff --git a/scripts/wifi-mesh-control.service b/scripts/wifi-mesh-control.service deleted file mode 100644 index babb847..0000000 --- a/scripts/wifi-mesh-control.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Automatically change wifi status to match config.proto -After=network.target - -[Service] -ExecStart=/usr/local/bin/wifi-mesh-control.sh -Restart=always -User=root - -[Install] -WantedBy=multi-user.target diff --git a/scripts/wifi-mesh-control.sh b/scripts/wifi-mesh-control.sh deleted file mode 100644 index afa9700..0000000 --- a/scripts/wifi-mesh-control.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -ip link set wlan0 up -sleep 60 #wait 60 seconds so networking will be available during boot - -# Initial value for comparison (start with an impossible value so it'll always implement the current value after boot) -previous_value=2 - -while true; do - # Run the command to fetch the value - current_value=$(cat /root/.portduino/default/prefs/config.proto | protoc --decode_raw | awk '/4 {/, /}/ {if ($1 == "1:") print $2}') - - # Check if the value has changed - if [ "$current_value" != "$previous_value" ]; then - - if [ "$previous_value" -eq 1 ]; then - prev_text="Wifi on" - elif [ "$previous_value" -eq 2 ]; then - prev_text="Startup" - else - prev_text="Wifi off" - fi - if [ "$current_value" -eq 1 ]; then - cur_text="Wifi on" - else - cur_text="Wifi off" - fi - - # Log the change - logger "Wifi mesh control: wifi setting changed: $prev_text -> $cur_text" - - # Update the previous value for next comparison - previous_value="$current_value" - fi - - # Take action based on the new value - if [ "$current_value" == "1" ]; then - ip link set wlan0 up - else - ip link set wlan0 down - fi - - # Wait for 30 seconds before checking again - sleep 30 -done