ids.alfacom.it/deployment/install_python_deps.sh
marco370 0bf61dc69d Improve model training and file saving capabilities
Fixes permission errors for model saving and enhances training logging, ensuring proper storage of ML models and historical data.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 2afb7ddf-484b-4d07-8d99-8c1ca39c0be5
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/VDRknFA
2025-11-22 10:27:30 +00:00

94 lines
3.3 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
pip install httpx==0.25.1
pip install joblib==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"
# Crea directory models per salvataggio modelli ML
echo -e "${BLUE}📁 Creazione directory models...${NC}"
mkdir -p "${IDS_DIR}/python_ml/models"
chown -R ids:ids "${IDS_DIR}/python_ml/models"
chmod 755 "${IDS_DIR}/python_ml/models"
echo -e "${GREEN}✅ Directory models configurata${NC}"
# 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__}')"
python3 -c "import httpx; print(f'✅ HTTPX: {httpx.__version__}')"
python3 -c "import joblib; print(f'✅ Joblib: {joblib.__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 ""