added WIP python version

This commit is contained in:
Pranav Jerry 2021-05-21 20:26:00 +05:30
parent a2129e40e5
commit 803dcfbe91

View File

@ -1,35 +1,48 @@
#!/usr/bin/env bash #!/usr/bin/env python3
DATADIR="$(dirname "$0")/../share/naxalnet" """
NETWORKD_DIR=/run/systemd/network Setup a working BATMAN Advanced network
SSID="Hello World" with systemd-networkd and iwd
"""
if [[ $# != 1 ]] # for linking resolv.conf
then from pathlib import Path
echo "Usage: $0 {wireless device}" from dasbus.connection import SystemMessageBus
echo "Example: $0 wlan0"
exit 1
fi
if [[ ! -d "$NETWORKD_DIR" ]] SYSTEMD_RESOLVED_STUB_RESOLVE = "/run/systemd/resolve/stub-resolv.conf"
then RESOLV_CONF = "/etc/resolv.conf"
mkdir "$NETWORKD_DIR"
fi
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" def get_all_devices(proxy):
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf """
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" # Now find out which of them are devices
systemctl reload-or-restart iwd systemd-resolved systemd-networkd 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 return devices
#sleep 5
echo "Configuring iwd"
iwctl device "$1" set-property Mode ad-hoc
iwctl ad-hoc "$1" start_open "$SSID"
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")