2021-05-21 20:26:00 +05:30
|
|
|
#!/usr/bin/env python3
|
2021-05-10 15:15:42 +05:30
|
|
|
|
2021-05-21 20:26:00 +05:30
|
|
|
"""
|
|
|
|
Setup a working BATMAN Advanced network
|
|
|
|
with systemd-networkd and iwd
|
|
|
|
"""
|
2021-05-10 15:15:42 +05:30
|
|
|
|
2021-05-21 20:26:00 +05:30
|
|
|
# for linking resolv.conf
|
|
|
|
from pathlib import Path
|
|
|
|
from dasbus.connection import SystemMessageBus
|
2021-05-10 15:15:42 +05:30
|
|
|
|
2021-05-21 20:26:00 +05:30
|
|
|
SYSTEMD_RESOLVED_STUB_RESOLVE = "/run/systemd/resolve/stub-resolv.conf"
|
|
|
|
RESOLV_CONF = "/etc/resolv.conf"
|
2021-05-10 15:15:42 +05:30
|
|
|
|
|
|
|
|
2021-05-21 20:26:00 +05:30
|
|
|
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()
|
2021-05-10 15:15:42 +05:30
|
|
|
|
2021-05-21 20:26:00 +05:30
|
|
|
# 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)
|
2021-05-10 15:15:42 +05:30
|
|
|
|
2021-05-21 20:26:00 +05:30
|
|
|
return devices
|
2021-05-10 15:15:42 +05:30
|
|
|
|
2021-05-21 20:26:00 +05:30
|
|
|
|
|
|
|
# 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")
|