ids.alfacom.it/deployment/install_python_deps.sh
marco370 5b350ff95f Add Python dependency installation and virtual environment support
Introduce a new script to install Python dependencies in a virtual environment, update systemd services to utilize this environment, and modify the setup script to automate dependency checks and installation.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: ea2a08f4-46e1-463d-9c58-16219914ad23
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/n4Q2eeE
2025-11-22 09:40:57 +00:00

83 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# =========================================================
# INSTALL PYTHON DEPENDENCIES - IDS System
# =========================================================
# Installa tutte le dipendenze Python necessarie per IDS
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
IDS_DIR="/opt/ids"
VENV_DIR="${IDS_DIR}/python_ml/venv"
echo -e "${BLUE}🐍 Installazione Dipendenze Python per IDS${NC}\n"
# Check se script è eseguito da root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}❌ Questo script deve essere eseguito come root (usa sudo)${NC}"
exit 1
fi
# Installa python3-venv se non presente
echo -e "${BLUE}📦 Verifica python3-venv...${NC}"
if ! rpm -q python3.11-pip &>/dev/null; then
echo -e "${YELLOW}⚙️ Installazione python3.11-pip...${NC}"
dnf install -y python3.11-pip
fi
# Crea virtual environment
echo -e "${BLUE}🔧 Creazione virtual environment...${NC}"
if [ -d "$VENV_DIR" ]; then
echo -e "${YELLOW}♻️ Virtual environment già esistente, rimuovo...${NC}"
rm -rf "$VENV_DIR"
fi
python3.11 -m venv "$VENV_DIR"
echo -e "${GREEN}✅ Virtual environment creato in ${VENV_DIR}${NC}"
# Attiva virtual environment e installa dipendenze
echo -e "${BLUE}📥 Installazione dipendenze Python...${NC}"
source "${VENV_DIR}/bin/activate"
# Upgrade pip
pip install --upgrade pip
# Installa dipendenze principali
pip install fastapi==0.104.1
pip install uvicorn[standard]==0.24.0
pip install pydantic==2.5.0
pip install python-dotenv==1.0.0
pip install psycopg2-binary==2.9.9
pip install pandas==2.1.3
pip install numpy==1.26.2
pip install scikit-learn==1.3.2
echo -e "${GREEN}✅ Dipendenze Python installate${NC}"
# Cambia ownership a utente ids
echo -e "${BLUE}🔐 Impostazione permessi...${NC}"
chown -R ids:ids "$VENV_DIR"
# Verifica installazione
echo -e "\n${BLUE}🔍 Verifica installazione:${NC}"
source "${VENV_DIR}/bin/activate"
python3 -c "import fastapi; print(f'FastAPI: {fastapi.__version__}')"
python3 -c "import uvicorn; print(f'Uvicorn: {uvicorn.__version__}')"
python3 -c "import sklearn; print(f'Scikit-learn: {sklearn.__version__}')"
python3 -c "import pandas; print(f'Pandas: {pandas.__version__}')"
echo -e "\n${GREEN}╔═══════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ ✅ DIPENDENZE PYTHON INSTALLATE ║${NC}"
echo -e "${GREEN}╚═══════════════════════════════════════════════╝${NC}"
echo -e "\n${BLUE}📝 NOTA:${NC}"
echo -e " Il virtual environment è in: ${YELLOW}${VENV_DIR}${NC}"
echo -e " I systemd services useranno automaticamente questo venv"
echo ""