diff --git a/naxalnet b/naxalnet index b0c0d3e..9e318b1 100755 --- a/naxalnet +++ b/naxalnet @@ -30,7 +30,7 @@ NETWORKD_CONFIGS = "/usr/share/naxalnet/networkd" NETWORKD_VOLATILE_DIR = "/run/systemd/network" RESOLVED_STUB_RESOLVE = "/run/systemd/resolve/stub-resolv.conf" RESOLV_CONF = "/etc/resolv.conf" - +ADHOC_SSID = "HelloWorld" # Copy networkd configs to volatile dir. # See man:systemd.networkm(5) @@ -45,8 +45,9 @@ try: # Copy all files in src to dest for i in src.iterdir(): copy(i, dest) -except: - sys.exit("An error occured while copying network files") +except PermissionError as e: + print(e) + sys.exit("Make sure you are root") # Symlink resolvd.conf to systemd's stub-resolvd.conf @@ -60,7 +61,8 @@ try: r.unlink() print("Linking resolv.conf") r.symlink_to(RESOLVED_STUB_RESOLVE) -except: +except PermissionError as e: + print(e) sys.exit("An error occured while linking resolv.conf") @@ -79,8 +81,20 @@ try: # add all devices to the list print("Found device:", obj["net.connman.iwd.Device"]["Name"]) devices.append(name) - # TODO: On first devices, start ad-hoc - # If there is a second device, start AP + + # Start ad-hoc on first device + devpath = devices.pop() + print("Working on first device", devpath) + dev1 = bus.get_proxy("net.connman.iwd", devpath) + if not dev1.Powered: + print("Device is off. Turning on") + dev1.Powered = True + print("Device is in", dev1.Mode) + dev1.Mode = "ad-hoc" + print("Switched to", dev1.Mode) + print("Starting ad-hoc network") + dev1.StartOpen(ADHOC_SSID) + # TODO: If there is a second device, start AP # in it except: sys.exit("An error occured while communicating with iwd")