From 803dcfbe91b76bd40e2f7674b9ba4081e46d3de6 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Fri, 21 May 2021 20:26:00 +0530 Subject: [PATCH] added WIP python version --- naxalnet | 67 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/naxalnet b/naxalnet index c333bdd..80977d8 100755 --- a/naxalnet +++ b/naxalnet @@ -1,35 +1,48 @@ -#!/usr/bin/env bash +#!/usr/bin/env python3 -DATADIR="$(dirname "$0")/../share/naxalnet" -NETWORKD_DIR=/run/systemd/network -SSID="Hello World" +""" +Setup a working BATMAN Advanced network +with systemd-networkd and iwd +""" -if [[ $# != 1 ]] -then - echo "Usage: $0 {wireless device}" - echo "Example: $0 wlan0" - exit 1 -fi +# for linking resolv.conf +from pathlib import Path +from dasbus.connection import SystemMessageBus -if [[ ! -d "$NETWORKD_DIR" ]] -then - mkdir "$NETWORKD_DIR" -fi +SYSTEMD_RESOLVED_STUB_RESOLVE = "/run/systemd/resolve/stub-resolv.conf" +RESOLV_CONF = "/etc/resolv.conf" -echo "Copying systemd-networkd config files" -# Copies all files in DATADIR to NETWORKD_DIR -find "$DATADIR" -type f -execdir cp -t "$NETWORKD_DIR" {} + -echo "Linking resolv.conf to systemd-resolved's stub-resolved.conf" -ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf +def get_all_devices(proxy): + """ + Returns d-bus object path of all devices as a list of strings. + proxy: usually what is returned by bus.get_proxy('net.connman.iwd','/') + """ + # Gets all D-Bus objects in the proxy. + objects = proxy.GetManagedObjects() -echo "Starting services" -systemctl reload-or-restart iwd systemd-resolved systemd-networkd + # Now find out which of them are devices + devices = [] + for name, obj in objects.items(): + if "net.connman.iwd.Device" in obj: + # add all devices to the list + devices.append(name) -# wait five seconds for iwd to start -#sleep 5 -echo "Configuring iwd" -iwctl device "$1" set-property Mode ad-hoc -iwctl ad-hoc "$1" start_open "$SSID" + return devices -echo "Done" + +# Copy networkd configs + + +# syslink resolvd +try: + Path(RESOLV_CONF).symlink_to(SYSTEMD_RESOLVED_STUB_RESOLVE) +except FileExistsError: + print("Resolv.conf already exists") + +# connect to the System bus +bus = SystemMessageBus() +# iwd proxy +proxy = bus.get_proxy("net.connman.iwd", "/") + +print("Bye")