diff --git a/README.md b/README.md index 5dcae14..2b2dbe6 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,14 @@ advocating the constitutional rights). ## Installing +### Arch Linux + +Install [naxalnet-git][] from the AUR: + +```sh +yay -S naxalnet-git +``` + ### Manually Clone the repo and cd into it. @@ -116,3 +124,4 @@ This project is in alpha stage. Documentation is incomplete. [jami]: https://jami.net [ssb]: https://scuttlebutt.nz [python-dasbus]: https://github.com/rhinstaller/dasbus +[naxalnet-git]: https://aur.archlinux.org/packages/naxalnet-git diff --git a/naxalnet b/naxalnet index 9e318b1..124a1bc 100755 --- a/naxalnet +++ b/naxalnet @@ -22,9 +22,11 @@ with systemd-networkd and iwd import sys +import time from pathlib import Path from shutil import copy from dasbus.connection import SystemMessageBus +from dasbus.error import DBusError NETWORKD_CONFIGS = "/usr/share/naxalnet/networkd" NETWORKD_VOLATILE_DIR = "/run/systemd/network" @@ -45,8 +47,8 @@ try: # Copy all files in src to dest for i in src.iterdir(): copy(i, dest) -except PermissionError as e: - print(e) +except PermissionError as error: + print(error) sys.exit("Make sure you are root") @@ -56,13 +58,26 @@ except PermissionError as e: try: print("Checking resolv.conf") r = Path(RESOLV_CONF) - if r.exists(): - print(r, "already exists. Removing it") - r.unlink() + if r.is_symlink(): + # Naxalnet will be started before resolved, so the destination + # is unlikely to exist at the time + # If r is linked to resolved's resolv.conf, dont change it + if r.samefile(RESOLVED_STUB_RESOLVE): + print(r, "is already linked to stub-resolv.conf. Not changing") + # Else if the destination exists + elif r.exists(): + print(r, "is a symlink that exists. Not removing") + else: + print(r, "is a symlink to a destination that doesn't exist. Removing") + r.unlink() + elif r.exists(): + print(r, "is not a symlink") + x = r.rename(RESOLV_CONF + ".naxalnet-bkp") + print(r, "was moved to", x) print("Linking resolv.conf") - r.symlink_to(RESOLVED_STUB_RESOLVE) -except PermissionError as e: - print(e) + r.symlink_to(RESOLVED_STUB_RESOLVE) +except PermissionError as error: + print(error) sys.exit("An error occured while linking resolv.conf") @@ -89,14 +104,17 @@ try: 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) + if dev1.Mode != "ad-hoc": + print("Device is in", dev1.Mode) + print("Switching to ad-hoc") + dev1.Mode = "ad-hoc" + # Changing Mode requires connecting to the proxy again + dev1 = bus.get_proxy("net.connman.iwd", devpath) print("Starting ad-hoc network") dev1.StartOpen(ADHOC_SSID) # TODO: If there is a second device, start AP # in it -except: +except DBusError: sys.exit("An error occured while communicating with iwd") # Sleep my little baby-oh diff --git a/naxalnet.service b/naxalnet.service index 7e08156..19a6182 100644 --- a/naxalnet.service +++ b/naxalnet.service @@ -17,6 +17,7 @@ Type=oneshot RemainAfterExit=yes # Temporary (maybe permanent) fix to aborting after changing to ad-hoc Restart=on-failure +RestartSec=5sec ExecStart=/usr/bin/naxalnet [Install]