Skip to content

Instantly share code, notes, and snippets.

@dinccey
Last active December 20, 2025 11:46
Show Gist options
  • Select an option

  • Save dinccey/d04a3a1aa288444ec1b28e8d8645b146 to your computer and use it in GitHub Desktop.

Select an option

Save dinccey/d04a3a1aa288444ec1b28e8d8645b146 to your computer and use it in GitHub Desktop.
GL.Inet Comet KVM install Netbird

Install Netbird

Working on firmware 1.7.2 NOTE: there might still be issues with some features of Netbird, but this at least gets it up and running and connected.

  1. Download armv6 binary from Netbird github releases, upload it extracted via Comet UI →Virtual media
  2. Copy and run this script (use wget, do not copy into vi) or use the Virtual media UI
  3. The uploaded files are located in /userdata/media/
  4. Access the terminal via Web UI or SSH
#!/bin/sh
# =============================================================================
#  install-netbird-comet.sh — AIO auto-start via inittab wrapper + S99custom hook
#  GL.iNet Comet (GL-RM1) – Buildroot/BusyBox — December 2025
# =============================================================================

set -e

echo "=== Netbird installer for GL.iNet Comet (AIO auto-start via inittab + S99custom) ==="

# 1) Clean old/broken Netbird service/init files (keep binary)
killall netbird 2>/dev/null || true
rm -rf /var/run/netbird* /var/log/netbird.log \
       /etc/init.d/netbird /etc/init.d/S99netbird \
       /etc/rc.d/S99netbird 2>/dev/null || true
sed -i '/netbird-wrapper.sh/d' /etc/inittab 2>/dev/null || true
sed -i '/netbird service run/d' /etc/inittab 2>/dev/null || true
echo "[+] Old service/init files cleaned (binary preserved)"

# 2) Ensure binary exists
if [ -x /usr/bin/netbird ]; then
  echo "[+] Using existing /usr/bin/netbird"
elif ls /userdata/media/netbird* 1>/dev/null 2>&1; then
  cp /userdata/media/netbird* /usr/bin/netbird
  chmod +x /usr/bin/netbird
  echo "[+] Netbird binary installed from /userdata/media"
else
  echo "[!] WARNING: No netbird binary found in /usr/bin or /userdata/media"
fi

# 3) Enable IPv4 forwarding
grep -q "^net.ipv4.ip_forward=1" /etc/sysctl.conf 2>/dev/null || \
  echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p >/dev/null 2>&1 || true
echo "[+] IP forwarding enabled"

# 4) Netbird service script (uses 'service run')
cat > /etc/init.d/netbird <<'EOF'
#!/bin/sh
# Netbird service for GL.iNet Comet — uses 'service run'

PIDFILE=/var/run/netbird.pid
LOG=/var/log/netbird.log
BIN=/usr/bin/netbird

case "$1" in
  start)
    mkdir -p /var/run
    chmod 755 /var/run

    if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
      echo "Netbird already running (pid $(cat "$PIDFILE"))"
      exit 0
    fi

    echo "Starting Netbird management service (service run)..."
    "$BIN" service run --log-file "$LOG" >/dev/null 2>&1 &
    echo $! > "$PIDFILE"

    # Wait up to 20s for management socket
    for i in $(seq 1 20); do
      [ -S /var/run/netbird.sock ] && break
      sleep 1
    done

    if [ -S /var/run/netbird.sock ]; then
      echo "Netbird started: /var/run/netbird.sock ready"
      exit 0
    else
      echo "WARN: netbird.sock missing — check $LOG"
      exit 1
    fi
    ;;
  stop)
    if [ -f "$PIDFILE" ]; then
      kill "$(cat "$PIDFILE")" 2>/dev/null || true
      rm -f "$PIDFILE"
    fi
    rm -f /var/run/netbird.sock
    killall netbird 2>/dev/null || true
    echo "Netbird stopped"
    ;;
  restart)
    $0 stop; sleep 2; $0 start
    ;;
  status)
    if [ -S /var/run/netbird.sock ]; then
      netbird status
    else
      echo "Netbird NOT running (no /var/run/netbird.sock)"
      [ -f "$LOG" ] && tail -n 50 "$LOG"
    fi
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac
EOF
chmod +x /etc/init.d/netbird
echo "[+] Service script installed at /etc/init.d/netbird"

# 5) Create wrapper script for init respawn
cat > /usr/bin/netbird-wrapper.sh <<'EOF'
#!/bin/sh
# Deferred Netbird start via BusyBox init respawn
sleep 30
echo ">>> netbird-wrapper fired at $(date)" > /etc/netbird_boot_marker.log
exec /etc/init.d/netbird start
EOF
chmod +x /usr/bin/netbird-wrapper.sh
echo "[+] Wrapper installed at /usr/bin/netbird-wrapper.sh"

# 6) Add wrapper to inittab
if ! grep -q 'netbird-wrapper.sh' /etc/inittab; then
  printf "%s\n" "::respawn:/usr/bin/netbird-wrapper.sh" >> /etc/inittab
  echo "[+] Added inittab respawn for netbird-wrapper"
else
  echo "[i] inittab already contains netbird-wrapper respawn"
fi

# 7) Boot marker
echo ">>> installer completed at $(date)" >> /etc/netbird_boot_marker.log

# 8) Start now and verify
if /etc/init.d/netbird start; then
  :
else
  echo "[!] Start reported a problem; showing last 100 lines of log:"
  [ -f /var/log/netbird.log ] && tail -n 100 /var/log/netbird.log || echo "(no log yet)"
fi

sleep 2
if [ -S /var/run/netbird.sock ]; then
  echo "[✓] netbird.sock present. 'netbird status' should work."
else
  echo "[x] netbird.sock missing. Try:"
  echo "   1) /usr/bin/netbird service run --log-file /var/log/netbird.log"
  echo "   2) tail -n 200 /var/log/netbird.log"
fi

# 9) Patch S99custom to include Netbird deferred start
if [ -f /etc/init.d/S99custom ]; then
  # Remove any old Netbird deferred start block
  sed -i '/# Netbird deferred start/,+5d' /etc/init.d/S99custom 2>/dev/null || true

  # Insert new block before the final exit line
  sed -i '/^exit\s\?\$?/i\
# Netbird deferred start\n(\
  sleep 30\n\
  echo ">>> S99custom launching Netbird at $(date)" > /etc/netbird_boot_marker.log\n\
  /usr/bin/netbird service run --log-file /var/log/netbird.log &\n\
) &\n' /etc/init.d/S99custom

  echo "[+] Netbird deferred start block added to S99custom"
else
  echo "[!] WARNING: /etc/init.d/S99custom not found — skipping patch"
fi

echo ""
echo "=================================="
echo "INSTALLATION COMPLETE"
echo "=================================="
echo "Next steps:"
echo "  1) If first time: netbird up --setup-key YOUR_PREAPPROVED_KEY"
echo "  2) Check:         /etc/init.d/netbird status"
echo "  3) Logs:          tail -f /var/log/netbird.log"
echo "  4) Reboot — expect /etc/netbird_boot_marker.log to show wrapper marker"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment