diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..1041071
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,4 @@
+include LICENSE
+include README.md
+include naxalnet.service
+include systemd-networkd/*
diff --git a/Makefile b/Makefile
index b8dfece..f81213a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,8 @@
-PREFIX := /usr
+# This makefile uses setup.py under the hood
+all: build
-install: naxalnet
- install -d $(DESTDIR)$(PREFIX)/bin
- install -d $(DESTDIR)$(PREFIX)/lib/systemd/system/
- install -m644 naxalnet.service $(DESTDIR)$(PREFIX)/lib/systemd/system/
- install naxalnet $(DESTDIR)$(PREFIX)/bin/
- install -d $(DESTDIR)$(PREFIX)/share/naxalnet/networkd
- install -m644 systemd-networkd/* $(DESTDIR)$(PREFIX)/share/naxalnet/networkd
+build:
+ python setup.py build
-testdeps:
- @for i in networkctl systemctl python3; do \
- echo "Checking for $$i"; \
- which $$i > /dev/null && echo " $$i found" || \
- (echo " $$i not found"; exit 1); \
- done
+install: build
+ python setup.py install --root="$(DESTDIR)/" --optimize=1 --skip-build
diff --git a/naxalnet/__init__.py b/naxalnet/__init__.py
new file mode 100644
index 0000000..c2fbd44
--- /dev/null
+++ b/naxalnet/__init__.py
@@ -0,0 +1,3 @@
+#!/usr/bin/env python3
+
+__version__ = "0.1.0a"
diff --git a/naxalnet/__main__.py b/naxalnet/__main__.py
new file mode 100644
index 0000000..4d9d341
--- /dev/null
+++ b/naxalnet/__main__.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python3
+
+from naxalnet.scripts import here_be_dragons
+
+if __name__ == "__main__":
+ here_be_dragons()
diff --git a/naxalnet/naxalnet.py b/naxalnet/naxalnet.py
deleted file mode 100755
index fbd2b7f..0000000
--- a/naxalnet/naxalnet.py
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright (C) 2021 The naxalnet Authors
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-"""
-Setup a working BATMAN Advanced network
-with systemd-networkd and iwd
-"""
-
-import sys
-from pathlib import Path
-from shutil import copy
-
-# from dasbus.connection import SystemMessageBus
-from dasbus.error import DBusError
-from iwd import IWD, Device, Adapter
-
-NETWORKD_CONFIGS = "/usr/share/naxalnet/networkd"
-NETWORKD_VOLATILE_DIR = "/run/systemd/network"
-ADHOC_SSID = "HelloWorld"
-AP_SSID = "NaxalNet"
-AP_PASSWD = "naxalnet256"
-# Copy networkd configs to volatile dir.
-# The D-Bus API does not support creating new interfaces
-# or linking to bridges. So we use config files.
-# See man:systemd.network(5)
-
-try:
- print("Copying network config files")
- dest = Path(NETWORKD_VOLATILE_DIR)
- src = Path(NETWORKD_CONFIGS)
-
- # Create the volatile directory if it doesn't exist
- dest.mkdir(parents=True, exist_ok=True)
-
- # Copy all files in src to dest
- for i in src.iterdir():
- copy(i, dest)
-except PermissionError as error:
- print(error)
- sys.exit("Make sure you are root")
-
-# Now, the iwd part
-try:
- iwd = IWD()
- devices = iwd.get_devices()
- adhoc_devices = []
- ap_devices = []
-
- for i in devices:
- d = Device(i)
- a = Adapter(d.adapter)
- if a.supports_mode("ad-hoc"):
- adhoc_devices.append(i)
- if a.supports_mode("ap"):
- ap_devices.append(i)
-
- if len(adhoc_devices) != 0:
- # Start ad-hoc on first device supporting ad-hoc
- adhoc_device = Device(adhoc_devices.pop())
- # The same device is likely to have ap support too.
- # But we can't start ad-hoc and ap on the same interface.
- # Remove dev1 from ap_devices if it exists there
- if adhoc_device.name in ap_devices:
- ap_devices.remove(adhoc_device.name)
- print("Working on ad-hoc")
- adhoc_device.start_adhoc_open(ADHOC_SSID)
- # Start Access point if ap_device is not empty,
- # ie, we have more devices
- if len(ap_devices) != 0:
- print("Working on AP")
- ap_device = Device(ap_devices.pop())
- # _TODO: start ap after implementing in in iwd.py
- ap_device.start_ap(AP_SSID, AP_PASSWD)
-except DBusError as error:
- print(error)
- sys.exit("An error occured while communicating with iwd")
-
-print("Bye")
diff --git a/naxalnet/scripts.py b/naxalnet/scripts.py
new file mode 100644
index 0000000..fde65f4
--- /dev/null
+++ b/naxalnet/scripts.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2021 The naxalnet Authors
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+"""
+Setup a working BATMAN Advanced network
+with systemd-networkd and iwd
+"""
+
+import sys
+from pathlib import Path
+from shutil import copy
+
+# from dasbus.connection import SystemMessageBus
+from dasbus.error import DBusError
+from naxalnet.iwd import IWD, Device, Adapter
+
+NETWORKD_CONFIGS = "/usr/share/naxalnet/networkd"
+NETWORKD_VOLATILE_DIR = "/run/systemd/network"
+ADHOC_SSID = "HelloWorld"
+AP_SSID = "NaxalNet"
+AP_PASSWD = "naxalnet256"
+
+
+def here_be_dragons():
+ # Copy networkd configs to volatile dir.
+ # The D-Bus API does not support creating new interfaces
+ # or linking to bridges. So we use config files.
+ # See man:systemd.network(5)
+
+ try:
+ print("Copying network config files")
+ dest = Path(NETWORKD_VOLATILE_DIR)
+ src = Path(NETWORKD_CONFIGS)
+
+ # Create the volatile directory if it doesn't exist
+ dest.mkdir(parents=True, exist_ok=True)
+
+ # Copy all files in src to dest
+ for i in src.iterdir():
+ copy(i, dest)
+ except PermissionError as error:
+ print(error)
+ sys.exit("Make sure you are root")
+
+ # Now, the iwd part
+ try:
+ iwd = IWD()
+ devices = iwd.get_devices()
+ adhoc_devices = []
+ ap_devices = []
+
+ for i in devices:
+ d = Device(i)
+ a = Adapter(d.adapter)
+ if a.supports_mode("ad-hoc"):
+ adhoc_devices.append(i)
+ if a.supports_mode("ap"):
+ ap_devices.append(i)
+
+ if len(adhoc_devices) != 0:
+ # Start ad-hoc on first device supporting ad-hoc
+ adhoc_device = Device(adhoc_devices.pop())
+ # The same device is likely to have ap support too.
+ # But we can't start ad-hoc and ap on the same interface.
+ # Remove dev1 from ap_devices if it exists there
+ if adhoc_device.name in ap_devices:
+ ap_devices.remove(adhoc_device.name)
+ print("Working on ad-hoc")
+ adhoc_device.start_adhoc_open(ADHOC_SSID)
+ # Start Access point if ap_device is not empty,
+ # ie, we have more devices
+ if len(ap_devices) != 0:
+ print("Working on AP")
+ ap_device = Device(ap_devices.pop())
+ ap_device.start_ap(AP_SSID, AP_PASSWD)
+ except DBusError as error:
+ print(error)
+ sys.exit("An error occured while communicating with iwd")
+
+ print("Bye")
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..4ab3cc1
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,36 @@
+[metadata]
+name = naxalnet
+version = attr: naxalnet.__version__
+description = create mesh networks with batman-adv and systemd
+long_description = file: README.md, LICENSE
+url = https://git.disroot.org/pranav/naxalnet
+author = Pranav Jerry
+author_email = libreinator@disroot.org
+license = GPLv3
+classifiers =
+ License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
+ Operating System :: POSIX :: Linux
+ Programming Language :: Python :: 3 :: Only
+
+[options]
+include_package_data = true
+packages = find:
+python_requires = >=3.6
+install_requires =
+ dasbus
+
+[options.entry_points]
+console_scripts =
+ naxalnet = naxalnet.scripts:here_be_dragons
+
+[options.data_files]
+/usr/lib/systemd/system =
+ naxalnet.service
+/usr/share/naxalnet/networkd =
+ systemd-networkd/01-batman.netdev
+ systemd-networkd/02-bridge.netdev
+ systemd-networkd/03-wireless-ad-hoc.network
+ systemd-networkd/04-batman.network
+ systemd-networkd/05-wireless-ap.network
+ systemd-networkd/06-eth.network
+ systemd-networkd/07-bridge.network
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..229b2eb
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,5 @@
+#!/usr/bin/env python3
+
+from setuptools import setup
+
+setup()