Hi team, I made this script with the help of AI for my mudi 7. Maybe you can use it or give some feedback?
The goal was to make it power efficient as it is powered on battery (event driven). I have been used it for a bit and it is working for me. The setup key I use is reusable and ephemeral, otherwise it seems to work only a single time and it removes the duplicates every 10 mins. On the user interface wi-fi> 5Ghz/6Ghz there is a toggle that enable/disable wifi. This I linked to reconnect, in case you are not connected. So far the user interface does not allow to trigger a script that is why I linked it like this. Keep in mind that you will need to recreate this after a firmware upgrade as the package and scripts are missing after.
OpenWrt — NetBird Headless Setup (v2 FINAL)
======================================================
PURPOSE
NetBird runs headless on GL.iNet OpenWrt router
Auto-connect triggers:
Boot
LTE up (modem_cpu)
WiFi 5GHz up (wlan1)
hostapd restart
Event-driven (no polling)
======================================================
FULL RESTORE (AFTER FIRMWARE RESET)
Remove old version
opkg remove netbird
Clean leftovers
rm -rf /etc/netbird /var/lib/netbird /etc/init.d/netbird
Install latest (IMPORTANT)
curl -fsSL https://pkgs.netbird.io/install.sh | sh
!!! WARNING !!!
Do NOT use opkg version (too old)
Verify version
netbird version
Expected: 0.7x.x
Initial login
netbird service start
sleep 3
netbird up --setup-key XXX
netbird status
Expected:
Management: Connected
Signal: Connected
======================================================
INTERFACE CHECK (CRITICAL)
ip route
Expected:
default via ... dev rmnet_data0
If not → update scripts accordingly.
======================================================
CREATE REQUIRED DIRECTORIES
mkdir -p /etc/hotplug.d/iface
mkdir -p /etc/hotplug.d/hostapd
======================================================
CREATE FILES (IMPORTANT STEP)
NOTE:
You MUST create these files manually using cat << EOF
FILE 1: /etc/rc.local (BOOT CONNECT SCRIPT)
#!/bin/sh
mkdir -p /var/log/netbird
touch /var/log/netbird/netbird.log /var/log/netbird/netbird.err
netbird service start 2>/dev/null || true
(
i=0
while [ ! -S /var/run/netbird.sock ] && [ $i -lt 60 ]; do
sleep 1; i=$((i+1))
done
j=0
while ! ip route | grep -q '^default .*rmnet_data0' && [ $j -lt 60 ]; do
sleep 1; j=$((j+1))
done
netbird up --setup-key XXX
>/tmp/netbird-up-boot.log 2>&1
) &
exit 0
FILE 2: /etc/hotplug.d/iface/90-netbird-reconnect
(LTE + WIFI RECONNECT HANDLER)
#!/bin/sh
[ "$ACTION" = "ifup" ] || exit 0
KEY="XXX"
LTE_IF="modem_cpu"
WIFI_IFS="wlan1"
is_wifi_if=false
for ifn in $WIFI_IFS; do
[ "$INTERFACE" = "$ifn" ] && is_wifi_if=true && break
done
case "$INTERFACE" in
$LTE_IF) trigger=true ;;
*) [ "$is_wifi_if" = "true" ] && trigger=true || trigger=false ;;
esac
[ "$trigger" = "true" ] || exit 0
if ! netbird status 2>/dev/null | grep -q "Management: Connected"; then
netbird service restart 2>/dev/null || true
(
i=0
while [ ! -S /var/run/netbird.sock ] && [ $i -lt 30 ]; do sleep 1; i=$((i+1)); done
j=0
while ! ip route | grep -q '^default .*rmnet_data0' && [ $j -lt 30 ]; do sleep 1; j=$((j+1)); done
netbird up --setup-key "$KEY" >/tmp/netbird-up-ifup.log 2>&1
) &
fi
FILE 3: /etc/hotplug.d/hostapd/90-netbird-hostapd-hook
(HOSTAPD FALLBACK TRIGGER)
#!/bin/sh
[ -z "$1" ] && exit 0
if [ "$1" = "wlan1" ]; then
INTERFACE="$1" ACTION=ifup /etc/hotplug.d/iface/90-netbird-reconnect >/tmp/netbird-hostapd.log 2>&1 || true
fi
======================================================
SET PERMISSIONS
chmod +x /etc/rc.local
chmod +x /etc/hotplug.d/iface/90-netbird-reconnect
chmod +x /etc/hotplug.d/hostapd/90-netbird-hostapd-hook
======================================================
EXPECTED BEHAVIOR
netbird status →
Management: Connected
Signal: Connected
NOTES:
Log files may NOT exist → normal
Scripts are silent when healthy
======================================================
NORMAL BOOT LOGS (NOT ERRORS)
Possible logs:
netbird.sock not found
retrying login
This is NORMAL.
Only final state matters: Connected
======================================================
TESTING
Simulate reconnect:
INTERFACE=wlan1 ACTION=ifup /etc/hotplug.d/iface/90-netbird-reconnect
======================================================
QUICK RECOVERY
netbird service restart
sleep 3
netbird up --setup-key XXX
======================================================
DEBUGGING / USEFUL COMMANDS
netbird status -d
ip addr show wt0
uci show network.netbird
service netbird info
Log files:
cat /tmp/netbird-up-boot.log
cat /tmp/netbird-up-ifup.log
cat /tmp/netbird-hostapd.log
System log:
logread | grep netbird | tail -50
======================================================
NETBIRD CLI REFERENCE (SHORT)
Common commands:
netbird status
netbird up
netbird down
netbird service start
netbird service restart
netbird version
netbird debug
======================================================
COMMON ISSUES
Not connecting after reboot:
→ LTE slow → increase wait time
Reconnect not triggered:
→ interface changed → check ip route
No logs:
→ already connected → normal
Everything in a single command> replace with your own key.
#!/bin/sh
echo "=== NetBird full bootstrap starting ==="
KEY="<YOUR_SETUP_KEY>"
echo "[1/7] Removing old NetBird..."
opkg remove netbird 2>/dev/null
echo "[2/7] Cleaning old config..."
rm -rf /etc/netbird /var/lib/netbird /etc/init.d/netbird
echo "[3/7] Installing latest NetBird..."
curl -fsSL https://pkgs.netbird.io/install.sh | sh
sleep 3
echo "[4/7] Starting service..."
netbird service start
sleep 3
echo "[5/7] Initial login..."
netbird up --setup-key "$KEY"
echo "[6/7] Creating hotplug directories..."
mkdir -p /etc/hotplug.d/iface
mkdir -p /etc/hotplug.d/hostapd
echo "[7/7] Creating config files..."
cat << 'EOF' > /etc/rc.local
#!/bin/sh
mkdir -p /var/log/netbird
touch /var/log/netbird/netbird.log /var/log/netbird/netbird.err
netbird service start 2>/dev/null || true
(
i=0
while [ ! -S /var/run/netbird.sock ] && [ $i -lt 60 ]; do
sleep 1; i=$((i+1))
done
j=0
while ! ip route | grep -q '^default .*rmnet_data0' && [ $j -lt 60 ]; do
sleep 1; j=$((j+1))
done
netbird up --setup-key <YOUR_SETUP_KEY>
/tmp/netbird-up-boot.log 2>&1
) &
exit 0
EOF
cat << 'EOF' > /etc/hotplug.d/iface/90-netbird-reconnect
#!/bin/sh
[ "$ACTION" = "ifup" ] || exit 0
KEY="<YOUR_SETUP_KEY>"
LTE_IF="modem_cpu"
WIFI_IFS="wlan1"
is_wifi_if=false
for ifn in $WIFI_IFS; do
[ "$INTERFACE" = "$ifn" ] && is_wifi_if=true && break
done
case "$INTERFACE" in
$LTE_IF) trigger=true ;;
*) [ "$is_wifi_if" = "true" ] && trigger=true || trigger=false ;;
esac
[ "$trigger" = "true" ] || exit 0
if ! netbird status 2>/dev/null | grep -q "Management: Connected"; then
netbird service restart 2>/dev/null || true
(
i=0
while [ ! -S /var/run/netbird.sock ] && [ $i -lt 30 ]; do sleep 1; i=$((i+1)); done
j=0
while ! ip route | grep -q '^default .*rmnet_data0' && [ $j -lt 30 ]; do sleep 1; j=$((j+1)); done
netbird up --setup-key "$KEY" >/tmp/netbird-up-ifup.log 2>&1
) &
fi
EOF
cat << 'EOF' > /etc/hotplug.d/hostapd/90-netbird-hostapd-hook
#!/bin/sh
[ -z "$1" ] && exit 0
if [ "$1" = "wlan1" ]; then
INTERFACE="$1" ACTION=ifup /etc/hotplug.d/iface/90-netbird-reconnect >/tmp/netbird-hostapd.log 2>&1 || true
fi
EOF
echo "Setting permissions..."
chmod +x /etc/rc.local
chmod +x /etc/hotplug.d/iface/90-netbird-reconnect
chmod +x /etc/hotplug.d/hostapd/90-netbird-hostapd-hook
echo "=== Bootstrap complete ==="
echo "Checking status..."
sleep 3
netbird status