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 f43c5d7..671cc72 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 @@ -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 <> /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 diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/.firstboot b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/.firstboot new file mode 100644 index 0000000..e60fd6a --- /dev/null +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/.firstboot @@ -0,0 +1 @@ +# File to tell rc.local that this is the first boot. Will be deleted automatically. \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/runonce.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/runonce.sh new file mode 100644 index 0000000..bd517de --- /dev/null +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/runonce.sh @@ -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 <> /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 \ No newline at end of file