2020-08-14 11:11:59 +00:00
|
|
|
import os
|
2023-07-19 16:24:38 +00:00
|
|
|
import sys
|
2026-03-15 08:24:30 +00:00
|
|
|
import subprocess
|
2020-08-14 11:11:59 +00:00
|
|
|
from time import sleep
|
|
|
|
|
|
2026-03-15 08:24:30 +00:00
|
|
|
from rich.prompt import Confirm
|
2025-10-14 06:02:18 +00:00
|
|
|
|
2026-03-15 08:24:30 +00:00
|
|
|
from core import HackingTool, HackingToolsCollection, console
|
|
|
|
|
from constants import APP_INSTALL_DIR, APP_BIN_PATH, USER_CONFIG_DIR, REPO_URL
|
2020-08-14 11:11:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class UpdateTool(HackingTool):
|
|
|
|
|
TITLE = "Update Tool or System"
|
2026-03-15 08:24:30 +00:00
|
|
|
DESCRIPTION = "Update system packages or pull the latest hackingtool code"
|
2020-08-14 11:11:59 +00:00
|
|
|
|
|
|
|
|
def __init__(self):
|
2026-03-15 08:24:30 +00:00
|
|
|
super().__init__([
|
2020-08-14 11:11:59 +00:00
|
|
|
("Update System", self.update_sys),
|
2026-03-15 08:24:30 +00:00
|
|
|
("Update Hackingtool", self.update_ht),
|
2025-10-14 06:02:18 +00:00
|
|
|
], installable=False, runnable=False)
|
2020-08-14 11:11:59 +00:00
|
|
|
|
|
|
|
|
def update_sys(self):
|
2026-03-15 08:24:30 +00:00
|
|
|
from os_detect import CURRENT_OS, PACKAGE_UPDATE_CMDS
|
|
|
|
|
mgr = CURRENT_OS.pkg_manager
|
|
|
|
|
cmd = PACKAGE_UPDATE_CMDS.get(mgr)
|
|
|
|
|
if cmd:
|
2026-03-15 14:25:00 +00:00
|
|
|
priv = "" if (CURRENT_OS.system == "macos" or os.geteuid() == 0) else "sudo "
|
2026-03-15 08:25:05 +00:00
|
|
|
# shell=True needed — cmd contains && chains; strings are hardcoded, not user input
|
|
|
|
|
subprocess.run(f"{priv}{cmd}", shell=True, check=False)
|
2026-03-15 08:24:30 +00:00
|
|
|
else:
|
|
|
|
|
console.print("[warning]Unknown package manager — update manually.[/warning]")
|
2020-08-14 11:11:59 +00:00
|
|
|
|
|
|
|
|
def update_ht(self):
|
2026-03-15 08:24:30 +00:00
|
|
|
if not APP_INSTALL_DIR.exists():
|
|
|
|
|
console.print(f"[error]Install directory not found: {APP_INSTALL_DIR}[/error]")
|
|
|
|
|
console.print("[dim]Run install.py first.[/dim]")
|
|
|
|
|
return
|
|
|
|
|
console.print(f"[bold cyan]Pulling latest code from {REPO_URL}...[/bold cyan]")
|
|
|
|
|
result = subprocess.run(
|
|
|
|
|
["git", "pull", "--rebase"],
|
|
|
|
|
cwd=str(APP_INSTALL_DIR),
|
|
|
|
|
capture_output=True, text=True,
|
|
|
|
|
)
|
|
|
|
|
if result.returncode != 0:
|
|
|
|
|
console.print(f"[error]git pull failed:\n{result.stderr}[/error]")
|
|
|
|
|
return
|
|
|
|
|
pip = str(APP_INSTALL_DIR / "venv" / "bin" / "pip")
|
|
|
|
|
if (APP_INSTALL_DIR / "venv" / "bin" / "pip").exists():
|
|
|
|
|
subprocess.run([pip, "install", "-q", "-r",
|
|
|
|
|
str(APP_INSTALL_DIR / "requirements.txt")])
|
|
|
|
|
console.print("[success]✔ Hackingtool updated.[/success]")
|
2020-08-14 11:11:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class UninstallTool(HackingTool):
|
|
|
|
|
TITLE = "Uninstall HackingTool"
|
2026-03-15 08:24:30 +00:00
|
|
|
DESCRIPTION = "Remove hackingtool from system"
|
2020-08-14 11:11:59 +00:00
|
|
|
|
|
|
|
|
def __init__(self):
|
2026-03-15 08:24:30 +00:00
|
|
|
super().__init__([
|
|
|
|
|
("Uninstall", self.uninstall),
|
2025-10-14 06:02:18 +00:00
|
|
|
], installable=False, runnable=False)
|
2020-08-14 11:11:59 +00:00
|
|
|
|
|
|
|
|
def uninstall(self):
|
2026-03-15 08:24:30 +00:00
|
|
|
import shutil
|
|
|
|
|
console.print("[warning]This will remove hackingtool from your system.[/warning]")
|
|
|
|
|
if not Confirm.ask("Continue?", default=False):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if APP_INSTALL_DIR.exists():
|
|
|
|
|
shutil.rmtree(str(APP_INSTALL_DIR))
|
|
|
|
|
console.print(f"[success]✔ Removed {APP_INSTALL_DIR}[/success]")
|
|
|
|
|
else:
|
|
|
|
|
console.print(f"[dim]{APP_INSTALL_DIR} not found — already removed?[/dim]")
|
|
|
|
|
|
|
|
|
|
if APP_BIN_PATH.exists():
|
|
|
|
|
APP_BIN_PATH.unlink()
|
|
|
|
|
console.print(f"[success]✔ Removed launcher {APP_BIN_PATH}[/success]")
|
|
|
|
|
|
|
|
|
|
if Confirm.ask(f"Also remove user data at {USER_CONFIG_DIR}?", default=False):
|
|
|
|
|
shutil.rmtree(str(USER_CONFIG_DIR), ignore_errors=True)
|
|
|
|
|
console.print(f"[success]✔ Removed {USER_CONFIG_DIR}[/success]")
|
|
|
|
|
|
|
|
|
|
console.print("[bold green]Hackingtool uninstalled. Goodbye.[/bold green]")
|
2020-08-14 11:11:59 +00:00
|
|
|
sleep(1)
|
2026-03-15 08:24:30 +00:00
|
|
|
sys.exit(0)
|
2020-08-14 11:11:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolManager(HackingToolsCollection):
|
|
|
|
|
TITLE = "Update or Uninstall | Hackingtool"
|
|
|
|
|
TOOLS = [
|
|
|
|
|
UpdateTool(),
|
2026-03-15 08:24:30 +00:00
|
|
|
UninstallTool(),
|
2020-08-14 11:11:59 +00:00
|
|
|
]
|
2025-10-14 06:02:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
manager = ToolManager()
|
|
|
|
|
manager.show_options()
|