bugfix: wifi defaults to off if configured via command line instead of usbconfig tool

Also moved first boot stuff to separate script
This commit is contained in:
nagumii 2024-12-14 17:53:28 +02:00
parent 5506758975
commit 3dcd60bd06
3 changed files with 53 additions and 21 deletions

View file

@ -8,27 +8,11 @@
luckfox-config load
#run once to set meshtastic nodeid to derivative of CPU serial number (unique to this board). Check at boot in case of upgrade overwriting this.
if ! grep -q "^ExecStart=.*-h" /usr/lib/systemd/system/meshtasticd.service; then
seed=$(printf "%d\n" 0x$(awk '/Serial/ {print $3}' /proc/cpuinfo) | tail -c 9)
#seed=$((0x$(awk '/Serial/ {print $3}' /proc/cpuinfo) & 0x3B9AC9FF))
sed -i "/^ExecStart=/ s:$: -h $seed:" /usr/lib/systemd/system/meshtasticd.service
echo "Using Luckfox CPU S/N to generate nodeid for Meshtastic."
systemctl daemon-reload
systemctl enable meshtasticd
fi
# 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
echo "Setting eth0 MAC address to derivative of CPU s/n."
cat <<EOF >> /etc/network/interfaces
# static mac address for onboard ethernet (castellated pins)
allow-hotplug eth0
iface eth0 inet dhcp
hwaddress ether $(awk '/Serial/ {print $3}' /proc/cpuinfo | tail -c 11 | sed 's/^\(.*\)/a2\1/' | sed 's/\(..\)/\1:/g;s/:$//')
EOF
echo "Rebooting..."
reboot
#run only on first boot
if [ -e "/usr/local/bin/.firstboot" ]; then
/usr/local/bin/runonce.sh
# Wait for runonce.sh to complete
wait $!
fi
# try enable RTC

View file

@ -0,0 +1 @@
# File to tell rc.local that this is the first boot. Will be deleted automatically.

View file

@ -0,0 +1,47 @@
#!/bin/bash
# prevent randomized mac address for eth0
msg="First boot: Setting eth0 MAC address to derivative of CPU s/n."
echo "$msg"
logger "$msg"
cat <<EOF >> /etc/network/interfaces
# static mac address for onboard ethernet (castellated pins)
allow-hotplug eth0
iface eth0 inet dhcp
hwaddress ether $(awk '/Serial/ {print $3}' /proc/cpuinfo | tail -c 11 | sed 's/^\(.*\)/a2\1/' | sed 's/\(..\)/\1:/g;s/:$//')
EOF
# set meshtastic nodeid to derivative of CPU serial number (unique to this board). Check at boot in case of upgrade overwriting this.
seed=$(printf "%d\n" 0x$(awk '/Serial/ {print $3}' /proc/cpuinfo) | tail -c 9)
#seed=$((0x$(awk '/Serial/ {print $3}' /proc/cpuinfo) & 0x3B9AC9FF))
sed -i "/^ExecStart=/ s:$: -h $seed:" /usr/lib/systemd/system/meshtasticd.service
msg="First boot: Using Luckfox CPU S/N to generate nodeid for Meshtastic."
echo "$msg"
logger "$msg"
systemctl daemon-reload
systemctl enable meshtasticd
# enable wifi in meshtastic settings. Because this is very important, we'll try 5 times.
msg="First boot: Enabling wifi setting in Meshtasticd."
echo "$msg"
logger "$msg"
for retries in $(seq 1 5); do
output=$(meshtastic --host --set network.wifi_enabled true 2>&1)
echo "$output"
if echo "$output" | grep -qiE "Abort|invalid|Error"; then
if [ "$retries" -lt 3 ]; then
msg="First boot: Meshtastic update failed, retrying ($(($retries + 1))/5)..."
echo "$msg"
logger "$msg"
sleep 2 # Add a small delay before retrying
fi
else
break
fi
done
rm /usr/local/bin/.firstboot
msg="First boot: Removing first boot flag and rebooting..."
echo "$msg"
logger "$msg"
reboot