mirror of
https://github.com/femtofox/femtofox.git
synced 2026-11-19 22:46:38 -05:00
Merged in up to date scripts
This commit is contained in:
parent
9910305ef8
commit
1d585e3f6e
13 changed files with 61 additions and 517 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
Ubuntu 22.04.3 LTS \n \l
|
||||
|
||||
[username:password] root:root femto:fox
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue