many changes

Looks like issue #3 is fixed. Added an AUR package
to the README. Fixed another bug related to linking
resolv.conf (I didn't know Path.exsts() checks the destination
if Path was a symlink). Changed how it deals with resolv.conf if
it is a symlink or normal files. Also, added a 'RestartSec=5sec'
to the systemd service.
This commit is contained in:
Pranav Jerry 2021-06-11 10:15:35 +05:30
parent 7e513b8475
commit 1d2d4b2d88
No known key found for this signature in database
GPG Key ID: F1DCDC4FED0A0C5B
3 changed files with 40 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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]