Improve system update script with ownership fixes and better output

Update deployment script to automatically fix Git ownership issues, add backup for git.env, implement stash for local changes, and enhance output formatting for a clearer user experience.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: abc30983-39f6-45cf-b89b-5b3507bb3c27
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/c9ITWqD
This commit is contained in:
marco370 2025-11-17 16:03:32 +00:00
parent a89ee20a2b
commit cbeb5e666e
3 changed files with 128 additions and 18 deletions

View File

@ -14,6 +14,10 @@ run = ["npm", "run", "start"]
localPort = 5000 localPort = 5000
externalPort = 80 externalPort = 80
[[ports]]
localPort = 34465
externalPort = 3000
[env] [env]
PORT = "5000" PORT = "5000"

34
deployment/fix_git_ownership.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# =============================================================================
# IDS - Fix Git Ownership Error
# =============================================================================
# Risolve: "fatal: detected dubious ownership in repository"
# =============================================================================
set -e
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════╗"
echo "║ Git Ownership Fix ║"
echo "╚═══════════════════════════════════════════════╝"
echo -e "${NC}"
# Aggiungi /opt/ids come safe directory per root
echo -e "${BLUE}🔧 Configuro /opt/ids come safe directory...${NC}"
git config --global --add safe.directory /opt/ids
# Configura anche per utente ids
sudo -u ids git config --global --add safe.directory /opt/ids
echo -e "${GREEN}✅ Configurazione completata${NC}"
echo ""
echo "Repository configurati come safe:"
git config --global --get-all safe.directory
echo ""
exit 0

106
deployment/update_from_git.sh Normal file → Executable file
View File

@ -1,7 +1,13 @@
#!/bin/bash #!/bin/bash
# Script per aggiornare il sistema IDS da git.alfacom.it # =============================================================================
# Eseguire con: sudo -u ids ./update_from_git.sh # IDS - Aggiornamento Sistema da git.alfacom.it
# =============================================================================
# Eseguire come ROOT: ./update_from_git.sh
# Lo script esegue i comandi git come utente 'ids' automaticamente
# =============================================================================
set -e
# Colori per output # Colori per output
RED='\033[0;31m' RED='\033[0;31m'
@ -10,12 +16,32 @@ YELLOW='\033[1;33m'
BLUE='\033[0;34m' BLUE='\033[0;34m'
NC='\033[0m' NC='\033[0m'
echo -e "${BLUE}🔄 AGGIORNAMENTO SISTEMA IDS DA GIT${NC}" echo -e "${BLUE}"
echo "====================================" echo "╔═══════════════════════════════════════════════╗"
echo "║ 🔄 AGGIORNAMENTO SISTEMA IDS DA GIT ║"
echo "╚═══════════════════════════════════════════════╝"
echo -e "${NC}"
IDS_DIR="/opt/ids" IDS_DIR="/opt/ids"
IDS_USER="ids"
# Verifica di essere root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}❌ Questo script deve essere eseguito come root${NC}"
echo -e "${YELLOW} Esegui: sudo ./update_from_git.sh${NC}"
exit 1
fi
cd "$IDS_DIR" || exit 1 cd "$IDS_DIR" || exit 1
# Fix git ownership se necessario
echo -e "${BLUE}🔧 Verifica configurazione git...${NC}"
if ! sudo -u $IDS_USER git config --global --get-all safe.directory | grep -q "^/opt/ids$"; then
echo -e "${YELLOW} Configuro safe directory...${NC}"
sudo -u $IDS_USER git config --global --add safe.directory /opt/ids
echo -e "${GREEN} ✅ Configurato${NC}"
fi
# Backup configurazione locale # Backup configurazione locale
echo -e "\n${BLUE}💾 Backup configurazione locale...${NC}" echo -e "\n${BLUE}💾 Backup configurazione locale...${NC}"
if [ -f ".env" ]; then if [ -f ".env" ]; then
@ -23,9 +49,14 @@ if [ -f ".env" ]; then
echo -e "${GREEN}✅ .env salvato in .env.backup${NC}" echo -e "${GREEN}✅ .env salvato in .env.backup${NC}"
fi fi
if [ -f "git.env" ]; then
cp git.env git.env.backup
echo -e "${GREEN}✅ git.env salvato in git.env.backup${NC}"
fi
# Verifica modifiche locali # Verifica modifiche locali
echo -e "\n${BLUE}🔍 Verifica modifiche locali...${NC}" echo -e "\n${BLUE}🔍 Verifica modifiche locali...${NC}"
if ! git diff-index --quiet HEAD --; then if ! sudo -u $IDS_USER git diff-index --quiet HEAD -- 2>/dev/null; then
echo -e "${YELLOW}⚠️ Ci sono modifiche locali non committate${NC}" echo -e "${YELLOW}⚠️ Ci sono modifiche locali non committate${NC}"
echo -e "${YELLOW} Esegui 'git status' per vedere i dettagli${NC}" echo -e "${YELLOW} Esegui 'git status' per vedere i dettagli${NC}"
read -p "Vuoi procedere comunque? (y/n) " -n 1 -r read -p "Vuoi procedere comunque? (y/n) " -n 1 -r
@ -33,12 +64,15 @@ if ! git diff-index --quiet HEAD --; then
if [[ ! $REPLY =~ ^[Yy]$ ]]; then if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1 exit 1
fi fi
# Stash modifiche locali
echo -e "${BLUE} Salvo modifiche locali temporaneamente...${NC}"
sudo -u $IDS_USER git stash
fi fi
# Pull da git # Pull da git
echo -e "\n${BLUE}📥 Download aggiornamenti da git.alfacom.it...${NC}" echo -e "\n${BLUE}📥 Download aggiornamenti da git.alfacom.it...${NC}"
git fetch origin sudo -u $IDS_USER git fetch origin
git pull origin main sudo -u $IDS_USER git pull origin main
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Aggiornamenti scaricati con successo${NC}" echo -e "${GREEN}✅ Aggiornamenti scaricati con successo${NC}"
@ -48,33 +82,71 @@ else
fi fi
# Ripristina configurazione locale # Ripristina configurazione locale
echo -e "\n${BLUE}🔄 Ripristino configurazione locale...${NC}"
if [ -f ".env.backup" ]; then if [ -f ".env.backup" ]; then
cp .env.backup .env cp .env.backup .env
echo -e "${GREEN}✅ Configurazione locale ripristinata${NC}" chown $IDS_USER:$IDS_USER .env
echo -e "${GREEN}✅ .env ripristinato${NC}"
fi
if [ -f "git.env.backup" ]; then
cp git.env.backup git.env
chown $IDS_USER:$IDS_USER git.env
echo -e "${GREEN}✅ git.env ripristinato${NC}"
fi fi
# Aggiorna dipendenze Node.js # Aggiorna dipendenze Node.js
echo -e "\n${BLUE}📦 Aggiornamento dipendenze Node.js...${NC}" echo -e "\n${BLUE}📦 Aggiornamento dipendenze Node.js...${NC}"
npm install sudo -u $IDS_USER npm install
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Dipendenze Node.js aggiornate${NC}"
else
echo -e "${YELLOW}⚠️ Possibili warning npm (spesso ignorabili)${NC}"
fi
# Aggiorna dipendenze Python # Aggiorna dipendenze Python
echo -e "\n${BLUE}📦 Aggiornamento dipendenze Python...${NC}" echo -e "\n${BLUE}📦 Aggiornamento dipendenze Python...${NC}"
cd python_ml cd python_ml
/usr/bin/python3.11 -m pip install -r requirements.txt sudo -u $IDS_USER /usr/bin/python3.11 -m pip install --upgrade -r requirements.txt
cd .. cd ..
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Dipendenze Python aggiornate${NC}"
fi
# Aggiorna schema database # Aggiorna schema database
echo -e "\n${BLUE}🗄️ Aggiornamento schema database...${NC}" echo -e "\n${BLUE}🗄️ Aggiornamento schema database...${NC}"
npm run db:push sudo -u $IDS_USER npm run db:push
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Schema database sincronizzato${NC}"
fi
# Restart servizi # Restart servizi
echo -e "\n${BLUE}🔄 Restart servizi...${NC}" echo -e "\n${BLUE}🔄 Restart servizi...${NC}"
if [ -f "./deployment/restart_all.sh" ]; then
chmod +x ./deployment/restart_all.sh
./deployment/restart_all.sh ./deployment/restart_all.sh
echo -e "${GREEN}✅ Servizi riavviati${NC}"
else
echo -e "${YELLOW}⚠️ Script restart_all.sh non trovato${NC}"
echo -e "${YELLOW} Riavvia manualmente i servizi se necessario${NC}"
fi
echo -e "\n${GREEN}✅ AGGIORNAMENTO COMPLETATO!${NC}"
echo "" echo ""
echo -e "${YELLOW}📋 VERIFICA:${NC}" echo -e "${GREEN}╔═══════════════════════════════════════════════╗${NC}"
echo -e " • Controlla log backend: ${BLUE}tail -f /var/log/ids/backend.log${NC}" echo -e "${GREEN}║ ✅ AGGIORNAMENTO COMPLETATO ║${NC}"
echo -e " • Controlla log frontend: ${BLUE}tail -f /var/log/ids/frontend.log${NC}" echo -e "${GREEN}╚═══════════════════════════════════════════════╝${NC}"
echo -e " • Testa API backend: ${BLUE}curl http://localhost:8000/health${NC}" echo ""
echo -e " • Testa frontend: ${BLUE}curl http://localhost:5000${NC}" echo -e "${BLUE}📋 VERIFICA SISTEMA:${NC}"
echo -e " • Log backend: ${YELLOW}tail -f /var/log/ids/backend.log${NC}"
echo -e " • Log frontend: ${YELLOW}tail -f /var/log/ids/frontend.log${NC}"
echo -e " • API backend: ${YELLOW}curl http://localhost:8000/health${NC}"
echo -e " • Frontend: ${YELLOW}curl http://localhost:5000${NC}"
echo ""
echo -e "${BLUE}📊 STATO SERVIZI:${NC}"
ps aux | grep -E 'python.*main|npm.*dev|syslog_parser' | grep -v grep
echo ""
exit 0