Last active
June 8, 2025 15:43
-
-
Save jokroese/7d9a4aad6bc9694a75f08c2733058873 to your computer and use it in GitHub Desktop.
Set up a mesh network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [ -z "$1" ]; then | |
echo "Usage: sudo ./setup-mesh.sh 192.168.77.X" | |
exit 1 | |
fi | |
MESH_IP="$1" | |
SERVICE_PATH="/etc/systemd/system/mesh-startup.service" | |
echo "[INFO] Setting up mesh with IP $MESH_IP" | |
sleep 5 | |
# Bring wlan0 down and into IBSS mode | |
echo "[INFO] Configuring wlan0 for mesh" | |
ip link set wlan0 down || true | |
iw wlan0 set type ibss | |
ip link set wlan0 up | |
iw wlan0 ibss join mesh-net 2412 | |
# Load BATMAN module and attach | |
echo "[INFO] Loading BATMAN-adv" | |
modprobe batman-adv | |
batctl if add wlan0 || true | |
ip link set up dev bat0 | |
# Assign IP | |
echo "[INFO] Assigning $MESH_IP to bat0" | |
ip addr add "$MESH_IP"/24 dev bat0 || true | |
# Disable conflicting services | |
echo "[INFO] Disabling conflicting services" | |
systemctl disable --now wpa_supplicant.service || true | |
systemctl disable --now NetworkManager.service || true | |
# Write systemd service with correct IP | |
echo "[INFO] Creating systemd mesh-startup.service" | |
cat <<EOF > "$SERVICE_PATH" | |
[Unit] | |
Description=Start mesh networking on boot | |
After=network.target | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/local/bin/setup-mesh.sh $MESH_IP | |
RemainAfterExit=true | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
chmod 644 "$SERVICE_PATH" | |
systemctl daemon-reexec | |
systemctl enable mesh-startup.service | |
echo "[INFO] Setup complete. Mesh will start automatically on boot." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment