mirror of
https://github.com/Z4nzu/hackingtool
synced 2026-05-23 08:58:22 +00:00
Change install with py
This commit is contained in:
parent
1032080167
commit
7cfe200e3d
2 changed files with 191 additions and 160 deletions
191
install.py
Executable file
191
install.py
Executable file
|
|
@ -0,0 +1,191 @@
|
|||
#!/usr/bin/env python3
|
||||
# install_hackingtool.py (rich-based installer UI)
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from rich.console import Console
|
||||
from rich.panel import Panel
|
||||
from rich.prompt import Prompt, Confirm, IntPrompt
|
||||
from rich.table import Table
|
||||
from rich.align import Align
|
||||
from rich.progress import Progress, SpinnerColumn, TextColumn
|
||||
from rich.text import Text
|
||||
from rich import box
|
||||
from random import choice
|
||||
|
||||
console = Console()
|
||||
|
||||
REPO_URL = "https://github.com/Z4nzu/hackingtool.git"
|
||||
INSTALL_DIR = Path("/usr/share/hackingtool")
|
||||
BIN_PATH = Path("/usr/bin/hackingtool")
|
||||
VENV_DIR_NAME = "venv"
|
||||
REQUIREMENTS = "requirements.txt"
|
||||
|
||||
|
||||
def check_root():
|
||||
if os.geteuid() != 0:
|
||||
console.print(Panel("[red]This installer must be run as root. Use: sudo python3 install_hackingtool.py[/red]"))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def run_cmd(cmd, check=True, capture=False, env=None):
|
||||
return subprocess.run(cmd, shell=True, check=check, capture_output=capture, text=True, env=env)
|
||||
|
||||
|
||||
def colorful_logo():
|
||||
logos = ["magenta", "bright_magenta", "cyan", "blue", "green", "yellow"]
|
||||
style = choice(logos)
|
||||
logo_lines = r"""
|
||||
▄█ █▄ ▄████████ ▄████████ ▄█ ▄█▄ ▄█ ███▄▄▄▄ ▄██████▄ ███ ▄██████▄ ▄██████▄ ▄█
|
||||
███ ███ ███ ███ ███ ███ ███ ▄███▀ ███ ███▀▀▀██▄ ███ ███ ▀█████████▄ ███ ███ ███ ███ ███
|
||||
███ ███ ███ ███ ███ █▀ ███▐██▀ ███▌ ███ ███ ███ █▀ ▀███▀▀██ ███ ███ ███ ███ ███
|
||||
▄███▄▄▄▄███▄▄ ███ ███ ███ ▄█████▀ ███▌ ███ ███ ▄███ ███ ▀ ███ ███ ███ ███ ███
|
||||
▀▀███▀▀▀▀███▀ ▀███████████ ███ ▀▀█████▄ ███▌ ███ ███ ▀▀███ ████▄ ███ ███ ███ ███ ███ ███
|
||||
███ ███ ███ ███ ███ █▄ ███▐██▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
|
||||
███ ███ ███ ███ ███ ███ ███ ▀███▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███▌ ▄
|
||||
███ █▀ ███ █▀ ████████▀ ███ ▀█▀ █▀ ▀█ █▀ ████████▀ ▄████▀ ▀██████▀ ▀██████▀ █████▄▄██
|
||||
▀ ▀
|
||||
"""
|
||||
panel = Panel(Text(logo_lines, style=style), box=box.DOUBLE, border_style=style)
|
||||
console.print(panel)
|
||||
console.print(f"[bold {style}]https://github.com/Z4nzu/hackingtool[/bold {style}]\n")
|
||||
|
||||
|
||||
def choose_distro():
|
||||
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"))
|
||||
choice = IntPrompt.ask("Choice", choices=["0", "1", "2"], default=1)
|
||||
return choice
|
||||
|
||||
|
||||
def check_internet():
|
||||
console.print("[yellow]* Checking internet connectivity...[/yellow]")
|
||||
try:
|
||||
run_cmd("curl -sSf --max-time 10 https://www.google.com > /dev/null", check=True)
|
||||
console.print("[green][✔] Internet connection OK[/green]")
|
||||
return True
|
||||
except Exception:
|
||||
try:
|
||||
run_cmd("curl -sSf --max-time 10 https://github.com > /dev/null", check=True)
|
||||
console.print("[green][✔] Internet connection OK[/green]")
|
||||
return True
|
||||
except Exception:
|
||||
console.print("[red][✘] Internet connection not available[/red]")
|
||||
return False
|
||||
|
||||
|
||||
def system_update_and_install(choice):
|
||||
if choice == 1:
|
||||
console.print("[yellow]* Running apt update/upgrade...[/yellow]")
|
||||
run_cmd("apt update -y && apt upgrade -y")
|
||||
console.print("[yellow]* Installing required packages (apt)...[/yellow]")
|
||||
run_cmd("apt-get install -y git python3-pip python3-venv figlet boxes php curl xdotool wget")
|
||||
elif choice == 2:
|
||||
console.print("[yellow]* Running pacman update...[/yellow]")
|
||||
run_cmd("pacman -Syu --noconfirm")
|
||||
console.print("[yellow]* Installing required packages (pacman)...[/yellow]")
|
||||
run_cmd("pacman -S --noconfirm git python-pip")
|
||||
# figlet via pacman or AUR handled later if desired
|
||||
|
||||
|
||||
def prepare_install_dir():
|
||||
if INSTALL_DIR.exists():
|
||||
console.print(f"[red]The directory {INSTALL_DIR} already exists.[/red]")
|
||||
if Confirm.ask("Replace it? This will remove the existing directory", default=False):
|
||||
run_cmd(f"rm -rf {str(INSTALL_DIR)}")
|
||||
else:
|
||||
console.print("[red]Installation aborted by user.[/red]")
|
||||
sys.exit(1)
|
||||
INSTALL_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
def git_clone():
|
||||
console.print("[yellow]* Cloning hackingtool repository...[/yellow]")
|
||||
try:
|
||||
run_cmd(f"git clone {REPO_URL} {str(INSTALL_DIR)}")
|
||||
console.print("[green][✔] Repository cloned[/green]")
|
||||
return True
|
||||
except Exception as e:
|
||||
console.print(f"[red][✘] Failed to clone repository: {e}[/red]")
|
||||
return False
|
||||
|
||||
|
||||
def create_venv_and_install(choice):
|
||||
venv_path = INSTALL_DIR / VENV_DIR_NAME
|
||||
console.print("[yellow]* Creating virtual environment...[/yellow]")
|
||||
run_cmd(f"python3 -m venv {str(venv_path)}")
|
||||
activate = venv_path / "bin" / "activate"
|
||||
pip = str(venv_path / "bin" / "pip")
|
||||
if (INSTALL_DIR / REQUIREMENTS).exists():
|
||||
console.print("[yellow]* Installing Python requirements...[/yellow]")
|
||||
run_cmd(f"{pip} install -r {str(INSTALL_DIR / REQUIREMENTS)}")
|
||||
else:
|
||||
console.print("[yellow]requirements.txt not found, skipping pip install.[/yellow]")
|
||||
if choice == 1:
|
||||
run_cmd("apt install figlet -y")
|
||||
elif choice == 2:
|
||||
# try pacman and fallback to AUR instructions
|
||||
try:
|
||||
run_cmd("pacman -S --noconfirm figlet")
|
||||
except Exception:
|
||||
console.print("[yellow]figlet not available in pacman automatically. Consider installing from AUR.[/yellow]")
|
||||
|
||||
|
||||
def create_launcher():
|
||||
console.print("[yellow]* Creating launcher script...[/yellow]")
|
||||
launcher = INSTALL_DIR / "hackingtool.sh"
|
||||
with open(launcher, "w") as f:
|
||||
f.write("#!/bin/bash\n")
|
||||
f.write(f"source {str(INSTALL_DIR / VENV_DIR_NAME)}/bin/activate\n")
|
||||
f.write(f"python3 {str(INSTALL_DIR / 'hackingtool.py')} \"$@\"\n")
|
||||
os.chmod(launcher, 0o755)
|
||||
# move to /usr/bin/hackingtool
|
||||
if BIN_PATH.exists():
|
||||
BIN_PATH.unlink()
|
||||
shutil.move(str(launcher), str(BIN_PATH))
|
||||
console.print(f"[green][✔] Launcher installed at {str(BIN_PATH)}[/green]")
|
||||
|
||||
|
||||
def final_messages():
|
||||
console.print("\n" + Panel("[bold magenta]Installation complete[/bold magenta]\n\nType [bold cyan]hackingtool[/bold cyan] in terminal to start.", border_style="magenta"))
|
||||
|
||||
|
||||
def main():
|
||||
check_root()
|
||||
console.clear()
|
||||
colorful_logo()
|
||||
choice = choose_distro()
|
||||
if choice == 0:
|
||||
console.print("[red]Exiting...[/red]")
|
||||
sys.exit(0)
|
||||
if not check_internet():
|
||||
sys.exit(1)
|
||||
|
||||
with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}")) as progress:
|
||||
progress.add_task(description="Preparing system...", total=None)
|
||||
system_update_and_install(choice)
|
||||
|
||||
prepare_install_dir()
|
||||
ok = git_clone()
|
||||
if not ok:
|
||||
sys.exit(1)
|
||||
|
||||
with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}")) as progress:
|
||||
progress.add_task(description="Setting up virtualenv & requirements...", total=None)
|
||||
create_venv_and_install(choice)
|
||||
|
||||
create_launcher()
|
||||
final_messages()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
console.print("\n[red]Installation interrupted by user[/red]")
|
||||
sys.exit(1)
|
||||
except subprocess.CalledProcessError as e:
|
||||
console.print(f"[red]Command failed: {e}[/red]")
|
||||
sys.exit(1)
|
||||
160
install.sh
160
install.sh
|
|
@ -1,160 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
clear
|
||||
|
||||
RED='\e[1;31m'
|
||||
GREEN='\e[1;32m'
|
||||
YELLOW='\e[1;33m'
|
||||
BLUE='\e[1;34m'
|
||||
CYAN='\e[1;36m'
|
||||
WHITE='\e[1;37m'
|
||||
ORANGE='\e[1;93m'
|
||||
NC='\e[0m'
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo -e "${RED}This script must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
COLOR_NUM=$((RANDOM % 7))
|
||||
# Assign a color variable based on the random number
|
||||
case $COLOR_NUM in
|
||||
0) COLOR=$RED;;
|
||||
1) COLOR=$GREEN;;
|
||||
2) COLOR=$YELLOW;;
|
||||
3) COLOR=$BLUE;;
|
||||
4) COLOR=$CYAN;;
|
||||
5) COLOR=$ORANGE;;
|
||||
*) COLOR=$WHITE;;
|
||||
esac
|
||||
|
||||
echo -e "${COLOR}"
|
||||
echo ""
|
||||
echo " ▄█ █▄ ▄████████ ▄████████ ▄█ ▄█▄ ▄█ ███▄▄▄▄ ▄██████▄ ███ ▄██████▄ ▄██████▄ ▄█ ";
|
||||
echo " ███ ███ ███ ███ ███ ███ ███ ▄███▀ ███ ███▀▀▀██▄ ███ ███ ▀█████████▄ ███ ███ ███ ███ ███ ";
|
||||
echo " ███ ███ ███ ███ ███ █▀ ███▐██▀ ███▌ ███ ███ ███ █▀ ▀███▀▀██ ███ ███ ███ ███ ███ ";
|
||||
echo " ▄███▄▄▄▄███▄▄ ███ ███ ███ ▄█████▀ ███▌ ███ ███ ▄███ ███ ▀ ███ ███ ███ ███ ███ ";
|
||||
echo "▀▀███▀▀▀▀███▀ ▀███████████ ███ ▀▀█████▄ ███▌ ███ ███ ▀▀███ ████▄ ███ ███ ███ ███ ███ ███ ";
|
||||
echo " ███ ███ ███ ███ ███ █▄ ███▐██▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ";
|
||||
echo " ███ ███ ███ ███ ███ ███ ███ ▀███▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███▌ ▄ ";
|
||||
echo " ███ █▀ ███ █▀ ████████▀ ███ ▀█▀ █▀ ▀█ █▀ ████████▀ ▄████▀ ▀██████▀ ▀██████▀ █████▄▄██ ";
|
||||
echo " ▀ ▀ ";
|
||||
|
||||
echo -e "${BLUE} https://github.com/Z4nzu/hackingtool ${NC}"
|
||||
echo -e "${RED} [!] This Tool Must Run As ROOT [!]${NC}\n"
|
||||
echo -e "${CYAN} Select Best Option : \n"
|
||||
echo -e "${WHITE} [1] Kali Linux / Parrot-Os (apt)"
|
||||
echo -e "${WHITE} [2] Arch Linux (pacman)" # added arch linux support because of feature request #231
|
||||
echo -e "${WHITE} [0] Exit "
|
||||
|
||||
echo -e "${COLOR}┌──($USER㉿$HOST)-[$(pwd)]"
|
||||
choice=$1
|
||||
if [[ ! $choice =~ ^[1-2]+$ ]]; then
|
||||
read -p "└─$>>" choice
|
||||
fi
|
||||
|
||||
# Define installation directories
|
||||
install_dir="/usr/share/hackingtool"
|
||||
bin_dir="/usr/bin"
|
||||
|
||||
# Check if the user chose a valid option and perform the installation steps
|
||||
if [[ $choice =~ ^[1-2]+$ ]]; then
|
||||
echo -e "${YELLOW}[*] Checking Internet Connection ..${NC}"
|
||||
echo "";
|
||||
if curl -s -m 10 https://www.google.com > /dev/null || curl -s -m 10 https://www.github.com > /dev/null; then
|
||||
echo -e "${GREEN}[✔] Internet connection is OK [✔]${NC}"
|
||||
echo "";
|
||||
echo -e "${YELLOW}[*] Updating package list ..."
|
||||
# Perform installation steps based on the user's choice
|
||||
if [[ $choice == 1 ]]; then
|
||||
sudo apt update -y && sudo apt upgrade -y
|
||||
sudo apt-get install -y git python3-pip figlet boxes php curl xdotool wget -y ;
|
||||
elif [[ $choice == 2 ]]; then
|
||||
sudo pacman -Suy -y
|
||||
sudo pacman -S python-pip -y
|
||||
else
|
||||
exit
|
||||
fi
|
||||
echo "";
|
||||
echo -e "${YELLOW}[*] Checking directories...${NC}"
|
||||
if [[ -d "$install_dir" ]]; then
|
||||
echo -e -n "${RED}[!] The directory $install_dir already exists. Do you want to replace it? [y/n]: ${NC}"
|
||||
read input
|
||||
if [[ $input == "y" ]] || [[ $input == "Y" ]]; then
|
||||
echo -e "${YELLOW}[*]Removing existing module.. ${NC}"
|
||||
sudo rm -rf "$install_dir"
|
||||
else
|
||||
echo -e "${RED}[✘]Installation Not Required[✘] ${NC}"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
echo "";
|
||||
echo -e "${YELLOW}[✔] Downloading hackingtool...${NC}"
|
||||
if sudo git clone https://github.com/Z4nzu/hackingtool.git $install_dir; then
|
||||
# Install virtual environment
|
||||
echo -e "${YELLOW}[*] Installing Virtual Environment...${NC}"
|
||||
if [[ $choice == 1 ]]; then
|
||||
sudo apt install python3-venv -y
|
||||
elif [[ $choice == 2 ]]; then
|
||||
echo "Python 3.3+ comes with a module called venv.";
|
||||
fi
|
||||
echo "";
|
||||
# Create a virtual environment for the tool
|
||||
echo -e "${YELLOW}[*] Creating virtual environment..."
|
||||
sudo python3 -m venv $install_dir/venv
|
||||
source $install_dir/venv/bin/activate
|
||||
# Install requirements
|
||||
echo -e "${GREEN}[✔] Virtual Environment successfully [✔]${NC}";
|
||||
echo "";
|
||||
echo -e "${YELLOW}[*] Installing requirements...${NC}"
|
||||
if [[ $choice == 1 ]]; then
|
||||
pip3 install -r $install_dir/requirements.txt
|
||||
sudo apt install figlet -y
|
||||
elif [[ $choice == 2 ]]; then
|
||||
pip3 install -r $install_dir/requirements.txt
|
||||
sudo -u $SUDO_USER git clone https://aur.archlinux.org/boxes.git && cd boxes
|
||||
sudo -u $SUDO_USER makepkg -si
|
||||
sudo pacman -S figlet -y
|
||||
fi
|
||||
# Create a shell script to launch the tool
|
||||
echo -e "${YELLOW}[*] Creating a shell script to launch the tool..."
|
||||
# echo '#!/bin/bash' > hackingtool.sh
|
||||
echo '#!/bin/bash' > $install_dir/hackingtool.sh
|
||||
echo "source $install_dir/venv/bin/activate" >> $install_dir/hackingtool.sh
|
||||
echo "python3 $install_dir/hackingtool.py \$@" >> $install_dir/hackingtool.sh
|
||||
chmod +x $install_dir/hackingtool.sh
|
||||
sudo mv $install_dir/hackingtool.sh $bin_dir/hackingtool
|
||||
echo -e "${GREEN}[✔] Script created successfully [✔]"
|
||||
else
|
||||
echo -e "${RED}[✘] Failed to download Hackingtool [✘]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
else
|
||||
echo -e "${RED}[✘] Internet connection is not available [✘]${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -d $install_dir ]; then
|
||||
echo "";
|
||||
echo -e "${GREEN}[✔] Successfully Installed [✔]";
|
||||
echo "";
|
||||
echo "";
|
||||
echo -e "${ORANGE}[+]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[+]"
|
||||
echo "[+] [+]"
|
||||
echo -e "${ORANGE}[+] ✔✔✔ Now Just Type In Terminal (hackingtool) ✔✔✔ [+]"
|
||||
echo "[+] [+]"
|
||||
echo -e "${ORANGE}[+]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[+]"
|
||||
else
|
||||
echo -e "${RED}[✘] Installation Failed !!! [✘]";
|
||||
exit 1
|
||||
fi
|
||||
|
||||
elif [[ $choice == 0 ]]; then
|
||||
echo -e "${RED}[✘] Exiting tool [✘]"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${RED}[!] Select Valid Option [!]"
|
||||
fi
|
||||
Loading…
Reference in a new issue