From 3953a280adb832c395ffa8af7ffab1bff43fb4b0 Mon Sep 17 00:00:00 2001 From: Hardik Zinzuvadiya <25708027+Z4nzu@users.noreply.github.com> Date: Sun, 15 Mar 2026 16:34:06 +0530 Subject: [PATCH] Fix Docker sudo error, 99 back navigation, and empty input exit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit install.py: - sudo prefix now determined by euid (== 0 means root) not by OS name - Previously used 'sudo ' for all Linux — breaks inside Docker where we run as root but sudo is not installed - Single priv variable computed once at top of install_system_packages() Dockerfile: - Add python3-venv back to apt installs - Was removed as 'unused' but install.py uses 'python3 -m venv' to create the virtualenv in APP_INSTALL_DIR; missing package caused venv failure core.py (HackingTool.show_options + HackingToolsCollection.show_options): - 99 always returns now instead of sys.exit() when parent is None Previously: sub-menus with no parent called sys.exit() — since interact_menu() never passes parent, pressing 99 in any category exited the entire program instead of returning to the main menu - Empty Enter (blank input) now continues the loop instead of defaulting to "99" and triggering exit Previously: Prompt default="99" meant pressing Enter without typing anything was treated as choosing exit - "Exit" label on 99 row changed to "Main Menu" since it now returns --- Dockerfile | 2 +- core.py | 20 ++++++++++---------- install.py | 6 ++++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 42b1c0d..01022be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ LABEL org.opencontainers.image.title="hackingtool" \ # - --no-install-recommends keeps the layer lean RUN apt-get update && \ apt-get install -y --no-install-recommends \ - git python3-pip curl wget php && \ + git python3-pip python3-venv curl wget php && \ rm -rf /var/lib/apt/lists/* WORKDIR /root/hackingtool diff --git a/core.py b/core.py index def583f..fe93b9a 100644 --- a/core.py +++ b/core.py @@ -113,10 +113,12 @@ class HackingTool: if self.PROJECT_URL: table.add_row("98", "Open Project Page") - table.add_row("99", f"Back to {parent.TITLE if parent else 'Exit'}") + table.add_row("99", f"Back to {parent.TITLE if parent else 'Main Menu'}") console.print(table) - raw = Prompt.ask("\n[bold cyan][?] Select an option[/bold cyan]", default="99") + raw = Prompt.ask("\n[bold cyan][?] Select an option[/bold cyan]", default="") + if not raw.strip(): + continue try: choice = int(raw) except ValueError: @@ -125,9 +127,7 @@ class HackingTool: continue if choice == 99: - if parent is None: - sys.exit() - return 99 + return elif choice == 98 and self.PROJECT_URL: self.show_project_page() elif 1 <= choice <= len(self.OPTIONS): @@ -272,10 +272,12 @@ class HackingToolsCollection: if incompatible: console.print(f"[dim]({len(incompatible)} tools hidden — not supported on current OS)[/dim]") - table.add_row("99", f"Back to {parent.TITLE if parent else 'Exit'}") + table.add_row("99", f"Back to {parent.TITLE if parent else 'Main Menu'}") console.print(table) - raw = Prompt.ask("\n[bold cyan][?] Choose a tool[/bold cyan]", default="99") + raw = Prompt.ask("\n[bold cyan][?] Choose a tool[/bold cyan]", default="") + if not raw.strip(): + continue try: choice = int(raw) except ValueError: @@ -283,9 +285,7 @@ class HackingToolsCollection: continue if choice == 99: - if parent is None: - sys.exit() - return 99 + return elif choice == 98 and archived: self._show_archived_tools() elif 0 <= choice < len(active): diff --git a/install.py b/install.py index 775063b..01eb4a0 100755 --- a/install.py +++ b/install.py @@ -107,11 +107,14 @@ def install_system_packages(): console.print("[warning]Skipping system packages — no package manager found.[/warning]") return + # Use sudo only when not already root (uid != 0). + # Inside Docker we run as root and sudo is not installed. + priv = "" if os.geteuid() == 0 else "sudo " + # Update index first (skip for brew — not needed) if mgr != "brew": update_cmd = PACKAGE_UPDATE_CMDS.get(mgr, "") if update_cmd: - priv = "" if CURRENT_OS.system == "macos" else "sudo " console.print(f"[dim]Updating package index ({mgr})...[/dim]") subprocess.run(f"{priv}{update_cmd}", shell=True, check=False) @@ -121,7 +124,6 @@ def install_system_packages(): install_tpl = PACKAGE_INSTALL_CMDS[mgr] cmd = install_tpl.format(packages=" ".join(packages)) - priv = "" if CURRENT_OS.system == "macos" else "sudo " console.print(f"[dim]Installing system dependencies ({mgr})...[/dim]") result = subprocess.run(f"{priv}{cmd}", shell=True, check=False) if result.returncode != 0: