Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Z4nzu
GitHub Repository: Z4nzu/hackingtool
Path: blob/master/install.py
1581 views
1
#!/usr/bin/env python3
2
# install_hackingtool.py (rich-based installer UI)
3
import os
4
import sys
5
import shutil
6
import subprocess
7
from pathlib import Path
8
9
from rich.console import Console
10
from rich.panel import Panel
11
from rich.prompt import Prompt, Confirm, IntPrompt
12
from rich.table import Table
13
from rich.align import Align
14
from rich.progress import Progress, SpinnerColumn, TextColumn
15
from rich.text import Text
16
from rich import box
17
from random import choice
18
19
console = Console()
20
21
REPO_URL = "https://github.com/Z4nzu/hackingtool.git"
22
INSTALL_DIR = Path("/usr/share/hackingtool")
23
BIN_PATH = Path("/usr/bin/hackingtool")
24
VENV_DIR_NAME = "venv"
25
REQUIREMENTS = "requirements.txt"
26
27
28
def check_root():
29
if os.geteuid() != 0:
30
console.print(Panel("[red]This installer must be run as root. Use: sudo python3 install_hackingtool.py[/red]"))
31
sys.exit(1)
32
33
34
def run_cmd(cmd, check=True, capture=False, env=None):
35
return subprocess.run(cmd, shell=True, check=check, capture_output=capture, text=True, env=env)
36
37
38
def colorful_logo():
39
logos = ["magenta", "bright_magenta", "cyan", "blue", "green", "yellow"]
40
style = choice(logos)
41
logo_lines = r"""
42
▄█ █▄ ▄████████ ▄████████ ▄█ ▄█▄ ▄█ ███▄▄▄▄ ▄██████▄ ███ ▄██████▄ ▄██████▄ ▄█
43
███ ███ ███ ███ ███ ███ ███ ▄███▀ ███ ███▀▀▀██▄ ███ ███ ▀█████████▄ ███ ███ ███ ███ ███
44
███ ███ ███ ███ ███ █▀ ███▐██▀ ███▌ ███ ███ ███ █▀ ▀███▀▀██ ███ ███ ███ ███ ███
45
▄███▄▄▄▄███▄▄ ███ ███ ███ ▄█████▀ ███▌ ███ ███ ▄███ ███ ▀ ███ ███ ███ ███ ███
46
▀▀███▀▀▀▀███▀ ▀███████████ ███ ▀▀█████▄ ███▌ ███ ███ ▀▀███ ████▄ ███ ███ ███ ███ ███ ███
47
███ ███ ███ ███ ███ █▄ ███▐██▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
48
███ ███ ███ ███ ███ ███ ███ ▀███▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███▌ ▄
49
███ █▀ ███ █▀ ████████▀ ███ ▀█▀ █▀ ▀█ █▀ ████████▀ ▄████▀ ▀██████▀ ▀██████▀ █████▄▄██
50
▀ ▀
51
"""
52
panel = Panel(Text(logo_lines, style=style), box=box.DOUBLE, border_style=style)
53
console.print(panel)
54
console.print(f"[bold {style}]https://github.com/Z4nzu/hackingtool[/bold {style}]\n")
55
56
57
def choose_distro():
58
console.print(Panel("[bold magenta]Select installation target[/bold magenta]\n\n[1] Kali / Parrot (apt)\n[2] Arch (pacman)\n[0] Exit", border_style="bright_magenta"))
59
choice = IntPrompt.ask("Choice", choices=["0", "1", "2"], default=1)
60
return choice
61
62
63
def check_internet():
64
console.print("[yellow]* Checking internet connectivity...[/yellow]")
65
try:
66
run_cmd("curl -sSf --max-time 10 https://www.google.com > /dev/null", check=True)
67
console.print("[green][✔] Internet connection OK[/green]")
68
return True
69
except Exception:
70
try:
71
run_cmd("curl -sSf --max-time 10 https://github.com > /dev/null", check=True)
72
console.print("[green][✔] Internet connection OK[/green]")
73
return True
74
except Exception:
75
console.print("[red][✘] Internet connection not available[/red]")
76
return False
77
78
79
def system_update_and_install(choice):
80
if choice == 1:
81
console.print("[yellow]* Running apt update/upgrade...[/yellow]")
82
try:
83
run_cmd("apt update -y && apt upgrade -y")
84
except subprocess.CalledProcessError as e:
85
console.print(f"[red][!][/red] apt update/upgrade failed (non-fatal). Continuing installation. Error: {e}")
86
console.print("[yellow]* Installing required packages (apt)...[/yellow]")
87
try:
88
run_cmd("apt-get install -y git python3-pip python3-venv figlet boxes php curl xdotool wget")
89
except subprocess.CalledProcessError as e:
90
console.print(f"[red][!][/red] apt-get install failed (non-fatal). You may need to install some packages manually. Error: {e}")
91
elif choice == 2:
92
console.print("[yellow]* Running pacman update...[/yellow]")
93
try:
94
run_cmd("pacman -Syu --noconfirm")
95
except subprocess.CalledProcessError as e:
96
console.print(f"[red][!][/red] pacman update failed (non-fatal). Continuing installation. Error: {e}")
97
console.print("[yellow]* Installing required packages (pacman)...[/yellow]")
98
try:
99
run_cmd("pacman -S --noconfirm git python-pip")
100
except subprocess.CalledProcessError as e:
101
console.print(f"[red][!][/red] pacman install failed (non-fatal). You may need to install some packages manually. Error: {e}")
102
else:
103
console.print("[red]Invalid package manager choice[/red]")
104
105
106
def prepare_install_dir():
107
if INSTALL_DIR.exists():
108
console.print(f"[red]The directory {INSTALL_DIR} already exists.[/red]")
109
if Confirm.ask("Replace it? This will remove the existing directory", default=False):
110
run_cmd(f"rm -rf {str(INSTALL_DIR)}")
111
else:
112
console.print("[red]Installation aborted by user.[/red]")
113
sys.exit(1)
114
INSTALL_DIR.mkdir(parents=True, exist_ok=True)
115
116
117
def git_clone():
118
console.print("[yellow]* Cloning hackingtool repository...[/yellow]")
119
try:
120
run_cmd(f"git clone {REPO_URL} {str(INSTALL_DIR)}")
121
console.print("[green][✔] Repository cloned[/green]")
122
return True
123
except Exception as e:
124
console.print(f"[red][✘] Failed to clone repository: {e}[/red]")
125
return False
126
127
128
def create_venv_and_install(choice):
129
venv_path = INSTALL_DIR / VENV_DIR_NAME
130
console.print("[yellow]* Creating virtual environment...[/yellow]")
131
run_cmd(f"python3 -m venv {str(venv_path)}")
132
activate = venv_path / "bin" / "activate"
133
pip = str(venv_path / "bin" / "pip")
134
if (INSTALL_DIR / REQUIREMENTS).exists():
135
console.print("[yellow]* Installing Python requirements...[/yellow]")
136
run_cmd(f"{pip} install -r {str(INSTALL_DIR / REQUIREMENTS)}")
137
else:
138
console.print("[yellow]requirements.txt not found, skipping pip install.[/yellow]")
139
if choice == 1:
140
run_cmd("apt install figlet -y")
141
elif choice == 2:
142
# try pacman and fallback to AUR instructions
143
try:
144
run_cmd("pacman -S --noconfirm figlet")
145
except Exception:
146
console.print("[yellow]figlet not available in pacman automatically. Consider installing from AUR.[/yellow]")
147
148
149
def create_launcher():
150
console.print("[yellow]* Creating launcher script...[/yellow]")
151
launcher = INSTALL_DIR / "hackingtool.sh"
152
with open(launcher, "w") as f:
153
f.write("#!/bin/bash\n")
154
f.write(f"source {str(INSTALL_DIR / VENV_DIR_NAME)}/bin/activate\n")
155
f.write(f"python3 {str(INSTALL_DIR / 'hackingtool.py')} \"$@\"\n")
156
os.chmod(launcher, 0o755)
157
# move to /usr/bin/hackingtool
158
if BIN_PATH.exists():
159
BIN_PATH.unlink()
160
shutil.move(str(launcher), str(BIN_PATH))
161
console.print(f"[green][✔] Launcher installed at {str(BIN_PATH)}[/green]")
162
163
164
def final_messages():
165
panel = Panel(
166
"[bold magenta]Installation complete[/bold magenta]\n\nType [bold cyan]hackingtool[/bold cyan] in terminal to start.",
167
border_style="magenta",
168
)
169
console.print(panel)
170
171
def main():
172
check_root()
173
console.clear()
174
colorful_logo()
175
choice = choose_distro()
176
if choice == 0:
177
console.print("[red]Exiting...[/red]")
178
sys.exit(0)
179
if not check_internet():
180
sys.exit(1)
181
182
with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}")) as progress:
183
progress.add_task(description="Preparing system...", total=None)
184
system_update_and_install(choice)
185
186
prepare_install_dir()
187
ok = git_clone()
188
if not ok:
189
sys.exit(1)
190
191
with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}")) as progress:
192
progress.add_task(description="Setting up virtualenv & requirements...", total=None)
193
create_venv_and_install(choice)
194
195
create_launcher()
196
final_messages()
197
198
199
if __name__ == "__main__":
200
try:
201
main()
202
except KeyboardInterrupt:
203
console.print("\n[red]Installation interrupted by user[/red]")
204
sys.exit(1)
205
except subprocess.CalledProcessError as e:
206
console.print(f"[red]Command failed: {e}[/red]")
207
sys.exit(1)
208
209