#!/bin/bash # Script per aggiornare il sistema IDS da git.alfacom.it # Eseguire con: sudo -u ids ./update_from_git.sh # Colori per output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' echo -e "${BLUE}🔄 AGGIORNAMENTO SISTEMA IDS DA GIT${NC}" echo "====================================" IDS_DIR="/opt/ids" cd "$IDS_DIR" || exit 1 # Backup configurazione locale echo -e "\n${BLUE}💾 Backup configurazione locale...${NC}" if [ -f ".env" ]; then cp .env .env.backup echo -e "${GREEN}✅ .env salvato in .env.backup${NC}" fi # Verifica modifiche locali echo -e "\n${BLUE}🔍 Verifica modifiche locali...${NC}" if ! git diff-index --quiet HEAD --; then echo -e "${YELLOW}⚠️ Ci sono modifiche locali non committate${NC}" echo -e "${YELLOW} Esegui 'git status' per vedere i dettagli${NC}" read -p "Vuoi procedere comunque? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi fi # Pull da git echo -e "\n${BLUE}📥 Download aggiornamenti da git.alfacom.it...${NC}" git fetch origin git pull origin main if [ $? -eq 0 ]; then echo -e "${GREEN}✅ Aggiornamenti scaricati con successo${NC}" else echo -e "${RED}❌ Errore durante il download${NC}" exit 1 fi # Ripristina configurazione locale if [ -f ".env.backup" ]; then cp .env.backup .env echo -e "${GREEN}✅ Configurazione locale ripristinata${NC}" fi # Aggiorna dipendenze Node.js echo -e "\n${BLUE}📦 Aggiornamento dipendenze Node.js...${NC}" npm install # Aggiorna dipendenze Python echo -e "\n${BLUE}📦 Aggiornamento dipendenze Python...${NC}" cd python_ml /usr/bin/python3.11 -m pip install -r requirements.txt cd .. # Aggiorna schema database echo -e "\n${BLUE}🗄️ Aggiornamento schema database...${NC}" npm run db:push # Restart servizi echo -e "\n${BLUE}🔄 Restart servizi...${NC}" ./deployment/restart_all.sh echo -e "\n${GREEN}✅ AGGIORNAMENTO COMPLETATO!${NC}" echo "" echo -e "${YELLOW}📋 VERIFICA:${NC}" echo -e " • Controlla log backend: ${BLUE}tail -f /var/log/ids/backend.log${NC}" echo -e " • Controlla log frontend: ${BLUE}tail -f /var/log/ids/frontend.log${NC}" echo -e " • Testa API backend: ${BLUE}curl http://localhost:8000/health${NC}" echo -e " • Testa frontend: ${BLUE}curl http://localhost:5000${NC}"