Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions nilrt_snac/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
There is NO WARRANTY, to the extent permitted by law.
"""

WARNING_MESSAGE: str = """\
!! ================================ WARNING ================================= !!
!! Running this tool will irreversibly alter the state of your system. !!
!! If you are accessing your system using WiFi, you will lose connection. !!
!! ========================================================================== !!
"""


def _get_enabled_modules(config_file_path: Path = Path("/etc/snac/snac.conf")) -> Dict[str, bool]:
"""Read the config file and return a dict of module enabled states. Strict validation and error reporting."""
Expand Down Expand Up @@ -58,8 +65,7 @@ def _get_enabled_modules(config_file_path: Path = Path("/etc/snac/snac.conf")) -

def _configure(args: argparse.Namespace) -> int:
"""Configure SNAC mode."""
logger.warning("!! Running this tool will irreversibly alter the state of your system. !!")
logger.warning("!! If you are accessing your system using WiFi, you will lose connection. !!")
sys.stderr.write(WARNING_MESSAGE)

if args.yes:
consent = "y"
Expand Down
23 changes: 0 additions & 23 deletions nilrt_snac/_pre_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,6 @@ def _check_euid_root():
if os.geteuid() != 0:
raise SNACError("This script must be run as root.", Errors.EX_BAD_ENVIRONMENT)


# Check that iptables is available.
# NOTE: The ip_tables kernel module is only loaded once the first call to iptables has
# been made, (inlcuding rule creation).
def _check_iptables():
print("Checking iptables")
if not opkg_helper.is_installed("iptables"):
logger.debug(" Installing iptables")
opkg_helper.install("iptables")

logger.debug(" Ensuring iptables is loaded")
try:
run_with_logging("iptables", "-L", check=False)
except Exception:
raise SNACError("Failed to load iptables.", Errors.EX_CHECK_FAILURE)

logger.debug(" Ensuring iptables is installed")
result = subprocess.run(["lsmod"], stdout=subprocess.PIPE)
if "ip_tables" not in result.stdout.decode():
raise SNACError("Failed to find ip_tables module.", Errors.EX_CHECK_FAILURE)


# Check that the script isn't executing within a safemode context
def _check_runmode():
safe_mode = pathlib.Path("/etc/natinst/safemode")
Expand All @@ -51,6 +29,5 @@ def _check_nilrt():

def verify_prereqs(): # noqa: D103 - Missing docstring in public function (auto-generated noqa)
_check_euid_root()
_check_iptables()
_check_runmode()
_check_nilrt()
6 changes: 0 additions & 6 deletions tests/integration/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ def test_conflicts_ipk():
"""The nilrt-snac-conflicts IPK should be installed to the data path."""
assert (nilrt_snac.SNAC_DATA_DIR / "nilrt-snac-conflicts.ipk").exists()


def test_iptables():
"""This package requires the iptables module."""
nilrt_snac._pre_reqs._check_iptables() # assert no raise


def test_opkg_binary():
"""This package requires the opkg package manager."""
assert shutil.which("opkg")
Expand Down
Loading