mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2024-11-10 07:21:59 +05:30
added WIP python version
This commit is contained in:
parent
a2129e40e5
commit
803dcfbe91
67
naxalnet
67
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")
|
||||
|
Loading…
Reference in New Issue
Block a user