#!/bin/bash
# ============================================================
# CRUCiBLE Security Scanner — Linux Installer
# https://cruciblesecurity.com — 100% Free
# ============================================================

set -e

echo ""
echo "  ╔══════════════════════════════════════════════════╗"
echo "  ║   CRUCiBLE SECURiTY — Desktop Scanner Install   ║"
echo "  ║   100% Free — No credit card, no limits          ║"
echo "  ╚══════════════════════════════════════════════════╝"
echo ""

# Check Python 3.8+
if ! command -v python3 &> /dev/null; then
    echo "Python 3 not found. Install with:"
    echo "  Ubuntu/Debian: sudo apt install python3 python3-pip"
    echo "  Fedora/RHEL:   sudo dnf install python3 python3-pip"
    exit 1
fi

PY_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
PY_MAJOR=$(echo "$PY_VERSION" | cut -d. -f1)
PY_MINOR=$(echo "$PY_VERSION" | cut -d. -f2)

if [ "$PY_MAJOR" -lt 3 ] || ([ "$PY_MAJOR" -eq 3 ] && [ "$PY_MINOR" -lt 8 ]); then
    echo "Python 3.8+ required (found $PY_VERSION)"
    exit 1
fi

echo "Python $PY_VERSION detected"
echo ""

# Install dependencies
echo "Installing dependencies..."
pip3 install --quiet psutil flask requests dnspython 2>/dev/null || pip3 install --user --quiet psutil flask requests dnspython

echo "Dependencies installed"
echo ""

# Download the scanner
echo "Downloading CRUCiBLE Security Scanner..."
curl -sL -o ~/crucible-scanner.py https://raw.githubusercontent.com/wes205/crucible-security/main/crucible_scanner_app.py

echo "Scanner saved to ~/crucible-scanner.py"
echo ""

# Launch
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "  Launching CRUCiBLE Security Scanner..."
echo "  Open http://localhost:7777 in your browser"
echo "  Press Ctrl+C to stop the scanner"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

python3 ~/crucible-scanner.py
