Skip to content

Commit 8ca297d

Browse files
authored
Refactor install.sh for enhanced installation flow
Updated install script to improve installation process and support for virtual environments.
1 parent 314e0b7 commit 8ca297d

File tree

1 file changed

+119
-67
lines changed

1 file changed

+119
-67
lines changed

install.sh

Lines changed: 119 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ BLUE='\033[0;34m'
1515
PURPLE='\033[0;35m'
1616
CYAN='\033[0;36m'
1717
WHITE='\033[1;37m'
18-
NC='\033[0m' # No Color
18+
NC='\033[0m'
1919

20-
# Version
20+
# Version and URLs
2121
SPYHUNT_VERSION="4.0.3"
22-
REPO_URL="https://github.com/Pymmdrza/SpyHunt"
22+
REPO_URL="https://github.com/Pymmdrza/SpyHunt.git"
2323
INSTALL_DIR="${HOME}/.local/share/spyhunt"
2424
BIN_DIR="${HOME}/.local/bin"
25+
VENV_DIR="${INSTALL_DIR}/venv"
2526

2627
# Banner
2728
print_banner() {
@@ -30,7 +31,7 @@ print_banner() {
3031
_____ _____ __ __ _ _ _ _ _ _ _______
3132
/ ____| __ \ \ \ / /| | | | | | | \ | |__ __|
3233
| (___ | |__) | \ \_/ / | |__| | | | | \| | | |
33-
\___ \| ___/ \ / | __ | | | | . ` | | |
34+
\___ \| ___/ \ / | __ | | | | . ` | | |
3435
____) | | | | | | | | |__| | |\ | | |
3536
|_____/|_| |_| |_| |_|\____/|_| \_| |_|
3637
@@ -110,8 +111,8 @@ check_python() {
110111

111112
if command -v python3 &> /dev/null; then
112113
PYTHON_VERSION=$(python3 --version 2>&1 | awk '{print $2}')
113-
PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d. -f1)
114-
PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d. -f2)
114+
PYTHON_MAJOR=$(echo "$PYTHON_VERSION" | cut -d. -f1)
115+
PYTHON_MINOR=$(echo "$PYTHON_VERSION" | cut -d. -f2)
115116

116117
if [ "$PYTHON_MAJOR" -ge 3 ] && [ "$PYTHON_MINOR" -ge 7 ]; then
117118
log_success "Python ${PYTHON_VERSION} found"
@@ -130,19 +131,19 @@ install_python() {
130131
case $OS in
131132
debian)
132133
$SUDO apt-get update
133-
$SUDO apt-get install -y python3 python3-pip python3-venv
134+
$SUDO apt-get install -y python3 python3-pip python3-venv python3-full
134135
;;
135136
redhat)
136-
$SUDO yum install -y python3 python3-pip
137+
$SUDO yum install -y python3 python3-pip python3-virtualenv
137138
;;
138139
fedora)
139-
$SUDO dnf install -y python3 python3-pip
140+
$SUDO dnf install -y python3 python3-pip python3-virtualenv
140141
;;
141142
arch)
142-
$SUDO pacman -Sy --noconfirm python python-pip
143+
$SUDO pacman -Sy --noconfirm python python-pip python-virtualenv
143144
;;
144145
alpine)
145-
$SUDO apk add --no-cache python3 py3-pip
146+
$SUDO apk add --no-cache python3 py3-pip py3-virtualenv
146147
;;
147148
macos)
148149
if ! command -v brew &> /dev/null; then
@@ -167,7 +168,7 @@ install_dependencies() {
167168
case $OS in
168169
debian)
169170
$SUDO apt-get update
170-
$SUDO apt-get install -y git curl wget nmap libffi-dev libssl-dev build-essential
171+
$SUDO apt-get install -y git curl wget nmap libffi-dev libssl-dev build-essential python3-venv
171172
;;
172173
redhat)
173174
$SUDO yum install -y git curl wget nmap libffi-devel openssl-devel gcc
@@ -210,59 +211,99 @@ clone_repository() {
210211
git pull origin main || git pull origin master
211212
else
212213
cd "$INSTALL_DIR"
213-
git clone --depth 1 "$REPO_URL.git"
214+
git clone --depth 1 "$REPO_URL"
214215
fi
215216

216217
log_success "SpyHunt downloaded successfully"
217218
}
218219

220+
# Create and setup virtual environment
221+
setup_venv() {
222+
log_info "Creating virtual environment..."
223+
224+
# Remove old venv if exists
225+
if [ -d "$VENV_DIR" ]; then
226+
rm -rf "$VENV_DIR"
227+
fi
228+
229+
# Create new virtual environment
230+
$PYTHON_CMD -m venv "$VENV_DIR"
231+
232+
# Activate venv
233+
source "$VENV_DIR/bin/activate"
234+
235+
log_success "Virtual environment created at $VENV_DIR"
236+
}
237+
219238
# Install Python dependencies
220239
install_python_deps() {
221240
log_info "Installing Python dependencies..."
222241

223242
cd "$INSTALL_DIR/SpyHunt"
224243

225-
# Create virtual environment (optional but recommended)
226-
if [ "$USE_VENV" = true ]; then
227-
log_info "Creating virtual environment..."
228-
$PYTHON_CMD -m venv venv
229-
source venv/bin/activate
230-
PIP_CMD="venv/bin/pip"
231-
else
232-
PIP_CMD="$PYTHON_CMD -m pip"
233-
fi
244+
# Always use virtual environment (required for Python 3.12+)
245+
setup_venv
234246

235-
# Upgrade pip
236-
$PIP_CMD install --upgrade pip
247+
# Upgrade pip in venv
248+
"$VENV_DIR/bin/pip" install --upgrade pip setuptools wheel
237249

238250
# Install package
239-
$PIP_CMD install -e .
251+
"$VENV_DIR/bin/pip" install -e .
240252

241253
log_success "Python dependencies installed"
242254
}
243255

244-
# Install via pip (alternative method)
245-
install_via_pip() {
246-
log_info "Installing SpyHunt via pip..."
247-
$PYTHON_CMD -m pip install --upgrade pip
248-
$PYTHON_CMD -m pip install spyhunt
249-
log_success "SpyHunt installed via pip"
256+
# Install via pipx (alternative method for modern systems)
257+
install_via_pipx() {
258+
log_info "Installing SpyHunt via pipx..."
259+
260+
# Install pipx if not available
261+
if ! command -v pipx &> /dev/null; then
262+
log_info "Installing pipx..."
263+
case $OS in
264+
debian)
265+
$SUDO apt-get update
266+
$SUDO apt-get install -y pipx
267+
pipx ensurepath
268+
;;
269+
macos)
270+
brew install pipx
271+
pipx ensurepath
272+
;;
273+
*)
274+
$PYTHON_CMD -m pip install --user pipx
275+
$PYTHON_CMD -m pipx ensurepath
276+
;;
277+
esac
278+
fi
279+
280+
# Install spyhunt via pipx
281+
pipx install spyhunt || pipx upgrade spyhunt
282+
283+
log_success "SpyHunt installed via pipx"
250284
}
251285

252286
# Create wrapper script
253287
create_wrapper() {
254288
log_info "Creating executable wrapper..."
255289

256-
cat > "$BIN_DIR/spyhunt" << 'WRAPPER'
290+
cat > "$BIN_DIR/spyhunt" << EOF
257291
#!/bin/bash
258-
INSTALL_DIR="${HOME}/.local/share/spyhunt/SpyHunt"
292+
# SpyHunt wrapper script
293+
# Automatically activates virtual environment and runs spyhunt
259294
260-
if [ -d "$INSTALL_DIR/venv" ]; then
261-
source "$INSTALL_DIR/venv/bin/activate"
262-
fi
295+
VENV_DIR="$VENV_DIR"
296+
INSTALL_DIR="$INSTALL_DIR/SpyHunt"
263297
264-
python3 -m spyhunt "$@"
265-
WRAPPER
298+
if [ -f "\$VENV_DIR/bin/activate" ]; then
299+
source "\$VENV_DIR/bin/activate"
300+
python -m spyhunt "\$@"
301+
else
302+
echo "Error: Virtual environment not found at \$VENV_DIR"
303+
echo "Please reinstall SpyHunt: curl -sSL https://raw.githubusercontent.com/Pymmdrza/SpyHunt/main/install.sh | bash"
304+
exit 1
305+
fi
306+
EOF
266307

267308
chmod +x "$BIN_DIR/spyhunt"
268309
log_success "Wrapper script created at $BIN_DIR/spyhunt"
@@ -272,7 +313,6 @@ WRAPPER
272313
configure_path() {
273314
log_info "Configuring PATH..."
274315

275-
# Detect shell
276316
SHELL_NAME=$(basename "$SHELL")
277317

278318
case $SHELL_NAME in
@@ -290,11 +330,14 @@ configure_path() {
290330
;;
291331
esac
292332

293-
# Add to PATH if not already present
294-
if ! grep -q "$BIN_DIR" "$SHELL_RC" 2>/dev/null; then
333+
if ! grep -q "$BIN_DIR" "$SHELL_RC" 2>/dev/null; then
295334
echo "" >> "$SHELL_RC"
296335
echo "# SpyHunt" >> "$SHELL_RC"
297-
echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$SHELL_RC"
336+
if [ "$SHELL_NAME" = "fish" ]; then
337+
echo "set -gx PATH \$PATH $BIN_DIR" >> "$SHELL_RC"
338+
else
339+
echo "export PATH=\"\$PATH: $BIN_DIR\"" >> "$SHELL_RC"
340+
fi
298341
log_success "Added $BIN_DIR to PATH in $SHELL_RC"
299342
else
300343
log_info "PATH already configured"
@@ -307,13 +350,24 @@ verify_installation() {
307350

308351
export PATH="$PATH:$BIN_DIR"
309352

310-
if command -v spyhunt &> /dev/null || [ -f "$BIN_DIR/spyhunt" ]; then
311-
log_success "SpyHunt installed successfully!"
353+
if [ -f "$BIN_DIR/spyhunt" ]; then
354+
# Test if spyhunt works
355+
if "$BIN_DIR/spyhunt" --help &> /dev/null; then
356+
log_success "SpyHunt installed and working!"
357+
else
358+
log_success "SpyHunt installed successfully!"
359+
fi
360+
312361
echo ""
313362
echo -e "${GREEN}╔════════════════════════════════════════════════════════════════╗${NC}"
314363
echo -e "${GREEN}║ Installation Complete! ║${NC}"
315364
echo -e "${GREEN}╚════════════════════════════════════════════════════════════════╝${NC}"
316365
echo ""
366+
echo -e "${WHITE}Installation Details:${NC}"
367+
echo -e " ${CYAN}Install Directory: ${NC} $INSTALL_DIR/SpyHunt"
368+
echo -e " ${CYAN}Virtual Environment:${NC} $VENV_DIR"
369+
echo -e " ${CYAN}Executable:${NC} $BIN_DIR/spyhunt"
370+
echo ""
317371
echo -e "${WHITE}Usage:${NC}"
318372
echo -e " ${CYAN}spyhunt --help${NC} Show help message"
319373
echo -e " ${CYAN}spyhunt -u example.com${NC} Scan a target"
@@ -331,13 +385,21 @@ uninstall() {
331385
log_info "Uninstalling SpyHunt..."
332386

333387
# Remove installation directory
334-
rm -rf "$INSTALL_DIR/SpyHunt"
388+
if [ -d "$INSTALL_DIR" ]; then
389+
rm -rf "$INSTALL_DIR"
390+
log_success "Removed $INSTALL_DIR"
391+
fi
335392

336393
# Remove wrapper
337-
rm -f "$BIN_DIR/spyhunt"
394+
if [ -f "$BIN_DIR/spyhunt" ]; then
395+
rm -f "$BIN_DIR/spyhunt"
396+
log_success "Removed $BIN_DIR/spyhunt"
397+
fi
338398

339-
# Remove pip package
340-
$PYTHON_CMD -m pip uninstall spyhunt -y 2>/dev/null || true
399+
# Try to uninstall via pipx
400+
if command -v pipx &> /dev/null; then
401+
pipx uninstall spyhunt 2>/dev/null || true
402+
fi
341403

342404
log_success "SpyHunt uninstalled successfully"
343405
}
@@ -348,42 +410,34 @@ show_help() {
348410
echo "Usage: ./install.sh [OPTIONS]"
349411
echo ""
350412
echo "Options:"
351-
echo " --pip Install via pip (simpler method)"
352-
echo " --venv Use virtual environment"
413+
echo " --pipx Install via pipx (recommended for system-wide use)"
353414
echo " --uninstall Remove SpyHunt"
354415
echo " --help Show this help message"
355416
echo ""
356417
echo "Examples:"
357418
echo " curl -sSL https://raw.githubusercontent.com/Pymmdrza/SpyHunt/main/install.sh | bash"
358-
echo " ./install.sh --pip"
359-
echo " ./install.sh --venv"
419+
echo " ./install.sh --pipx"
420+
echo " ./install.sh --uninstall"
360421
echo ""
361422
}
362423

363424
# Main installation function
364425
main() {
365426
print_banner
366427

367-
# Parse arguments
368-
USE_VENV=false
369-
USE_PIP=false
428+
USE_PIPX=false
370429

371430
for arg in "$@"; do
372431
case $arg in
373432
--help|-h)
374433
show_help
375434
exit 0
376435
;;
377-
--pip)
378-
USE_PIP=true
379-
;;
380-
--venv)
381-
USE_VENV=true
436+
--pipx)
437+
USE_PIPX=true
382438
;;
383439
--uninstall)
384440
detect_os
385-
check_root
386-
check_python
387441
uninstall
388442
exit 0
389443
;;
@@ -398,18 +452,16 @@ main() {
398452
check_python
399453
install_dependencies
400454

401-
if [ "$USE_PIP" = true ]; then
402-
install_via_pip
455+
if [ "$USE_PIPX" = true ]; then
456+
install_via_pipx
403457
else
404458
create_directories
405459
clone_repository
406460
install_python_deps
407461
create_wrapper
408462
configure_path
463+
verify_installation
409464
fi
410-
411-
verify_installation
412465
}
413466

414-
# Run main
415467
main "$@"

0 commit comments

Comments
 (0)