netgescon-master/sync-complete-netgescon.sh
Pikappa2 500712a945 🚀 NETGESCON - Git Distribuito e Sistema Distribuzione Implementato
📦 NUOVO SISTEMA COMPLETO:
 Repository Git con branches professionali (master/development/release/hotfix)
 Workflow Git automatizzato con script dedicati
 Sistema packaging: DEB, Docker, VM templates
 Auto-updater per distribuzioni remote
 Plugin system progettato per marketplace
 Licenza A-GPL per protezione IP

🛠️ SCRIPT AUTOMAZIONE:
- git-workflow.sh → Workflow sviluppo/release/hotfix completo
- setup-git-server-master.sh → Setup Gitea su server master
- build-distribution.sh → Build e packaging automatico
- sync aggiornato con supporto Git

🎯 STRATEGIA DISTRIBUZIONE:
- Team distribuito con Git professionale
- Packaging multi-piattaforma automatico
- Sistema aggiornamenti controllati
- Plugin marketplace per estensibilità
- Protezione IP con A-GPL

📅 2025-07-19 16:58:52 - Sistema enterprise pronto!
2025-07-19 16:58:53 +02:00

423 lines
14 KiB
Bash

#!/bin/bash
# =============================================================================
# NETGESCON - SINCRONIZZAZIONE COMPLETA A MASTER
# =============================================================================
# Script per sincronizzare TUTTO il progetto NetGescon verso MASTER
# Mantiene struttura identica tra locale e remoto
#
# Creato: 19/07/2025
# Uso: ./sync-complete-netgescon.sh [opzioni]
# =============================================================================
# Configurazione colori
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Configurazione base
SOURCE_BASE="$HOME/netgescon/"
TARGET_MASTER="netgescon@192.168.0.201:/var/www/netgescon/"
LOG_FILE="$HOME/netgescon/log/sync-complete-$(date +%Y%m%d-%H%M%S).log"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
# Crea directory log se non esiste
mkdir -p "$HOME/netgescon/log"
# Funzione di logging
log() {
local level=$1
shift
local message="$*"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $message" | tee -a "$LOG_FILE"
}
# Funzione di stampa colorata
print_status() {
local color=$1
local message=$2
echo -e "${color}$message${NC}"
log "INFO" "$message"
}
# Funzione di controllo prerequisiti
check_prerequisites() {
print_status "$BLUE" "🔍 Controllo prerequisiti sincronizzazione completa..."
# Verifica rsync
if ! command -v rsync &> /dev/null; then
print_status "$RED" "❌ ERRORE: rsync non installato"
exit 1
fi
# Verifica directory sorgente
if [ ! -d "$SOURCE_BASE" ]; then
print_status "$RED" "❌ ERRORE: Directory NetGescon non trovata: $SOURCE_BASE"
exit 1
fi
# Verifica connettività SSH
local host=$(echo "$TARGET_MASTER" | cut -d':' -f1)
ssh -o ConnectTimeout=5 -o BatchMode=yes "$host" exit 2>/dev/null
if [ $? -ne 0 ]; then
print_status "$RED" "❌ ERRORE: Connessione SSH fallita verso $host"
print_status "$YELLOW" " Verificare connettività e chiavi SSH"
exit 1
fi
print_status "$GREEN" "✅ Tutti i prerequisiti soddisfatti"
}
# Funzione di statistiche pre-sync
show_source_stats() {
print_status "$BLUE" "📊 Statistiche progetto NetGescon locale:"
local total_files=$(find "$SOURCE_BASE" -type f | wc -l)
local total_dirs=$(find "$SOURCE_BASE" -type d | wc -l)
local md_files=$(find "$SOURCE_BASE" -name "*.md" | wc -l)
local php_files=$(find "$SOURCE_BASE" -name "*.php" | wc -l)
local js_files=$(find "$SOURCE_BASE" -name "*.js" | wc -l)
local img_files=$(find "$SOURCE_BASE" -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.gif" | wc -l)
local total_size=$(du -sh "$SOURCE_BASE" | cut -f1)
echo " 📄 File totali: $total_files"
echo " 📁 Directory: $total_dirs"
echo " 📝 Markdown: $md_files"
echo " 🐘 PHP: $php_files"
echo " 📜 JavaScript: $js_files"
echo " 🖼️ Immagini: $img_files"
echo " 💾 Dimensione totale: $total_size"
echo ""
log "STATS" "Files: $total_files, Dirs: $total_dirs, MD: $md_files, PHP: $php_files, Size: $total_size"
}
# Funzione per mostrare struttura che verrà sincronizzata
show_sync_structure() {
print_status "$BLUE" "🗂️ Struttura che verrà sincronizzata:"
echo ""
echo "LOCALE → MASTER:"
echo " ~/netgescon/netgescon-laravel/ → /var/www/netgescon/netgescon-laravel/"
echo " ~/netgescon/docs/ → /var/www/netgescon/docs/"
echo " ~/netgescon/scripts/ → /var/www/netgescon/scripts/"
echo " ~/netgescon/sync-docs-rsync.sh → /var/www/netgescon/sync-docs-rsync.sh"
echo " ~/netgescon/sync-docs-config.env → /var/www/netgescon/sync-docs-config.env"
echo " ~/netgescon/[altri file] → /var/www/netgescon/[altri file]"
echo ""
print_status "$YELLOW" "⚠️ TUTTO il contenuto di ~/netgescon/ sarà sincronizzato"
}
# Funzione di sincronizzazione principale
perform_complete_sync() {
print_status "$YELLOW" "🚀 Avvio sincronizzazione completa NetGescon..."
echo ""
# Conferma dell'utente
if [[ "${FORCE_MODE:-}" != "1" ]]; then
print_status "$YELLOW" "⚠️ ATTENZIONE: Sincronizzazione completa verso MASTER"
print_status "$BLUE" " Sorgente: $SOURCE_BASE"
print_status "$BLUE" " Destinazione: $TARGET_MASTER"
echo ""
read -p "Continuare? (y/N): " confirm
if [[ "$confirm" != [yY] ]]; then
print_status "$YELLOW" "⏹️ Sincronizzazione annullata"
exit 0
fi
fi
# Backup remoto prima della sincronizzazione
print_status "$BLUE" "💾 Backup ambiente remoto..."
local remote_host=$(echo "$TARGET_MASTER" | cut -d':' -f1)
local remote_path=$(echo "$TARGET_MASTER" | cut -d':' -f2)
ssh "$remote_host" "
if [ -d '$remote_path' ]; then
sudo cp -r '$remote_path' '${remote_path}-backup-$(date +%Y%m%d-%H%M%S)'
echo 'Backup remoto completato'
else
sudo mkdir -p '$remote_path'
echo 'Directory remota creata'
fi
"
# Opzioni rsync per sincronizzazione completa
local rsync_opts="-avz --progress --delete"
rsync_opts+=" --exclude='.git'"
rsync_opts+=" --exclude='node_modules'"
rsync_opts+=" --exclude='vendor'"
rsync_opts+=" --exclude='storage/logs/*'"
rsync_opts+=" --exclude='.env'"
rsync_opts+=" --exclude='*.tmp'"
rsync_opts+=" --exclude='*~'"
rsync_opts+=" --exclude='.DS_Store'"
rsync_opts+=" --exclude='Thumbs.db'"
rsync_opts+=" --exclude='__pycache__'"
# Esclusioni specifiche (materiali Windows e backup process)
rsync_opts+=" --exclude='docs/04-materiali-windows/'"
rsync_opts+=" --exclude='docs/05-backup-unificazione/scripts-processo/'"
print_status "$BLUE" "🔄 Sincronizzazione in corso..."
local sync_start=$(date +%s)
if eval rsync $rsync_opts "$SOURCE_BASE" "$TARGET_MASTER" 2>&1 | tee -a "$LOG_FILE"; then
local sync_end=$(date +%s)
local sync_duration=$((sync_end - sync_start))
print_status "$GREEN" "✅ Sincronizzazione completata con successo!"
print_status "$BLUE" " Durata: ${sync_duration}s"
log "SUCCESS" "Sync completa completata in ${sync_duration}s"
return 0
else
print_status "$RED" "❌ ERRORE durante sincronizzazione"
log "ERROR" "Sync completa fallita"
return 1
fi
}
# Funzione di verifica post-sync
verify_sync() {
print_status "$BLUE" "🔍 Verifica post-sincronizzazione..."
local remote_host=$(echo "$TARGET_MASTER" | cut -d':' -f1)
local remote_path=$(echo "$TARGET_MASTER" | cut -d':' -f2)
# Verifica presenza file chiave
local key_files=(
"netgescon-laravel/composer.json"
"docs/00-PIANO-LAVORO-MASTER.md"
"docs/00-COPILOT-HANDOFF-MASTER.md"
"sync-docs-rsync.sh"
)
print_status "$BLUE" " Verifica file chiave sul MASTER:"
local all_ok=true
for file in "${key_files[@]}"; do
if ssh "$remote_host" "[ -f '$remote_path$file' ]"; then
echo "$file"
else
echo "$file [MANCANTE]"
all_ok=false
fi
done
if $all_ok; then
print_status "$GREEN" "✅ Verifica completata - tutti i file chiave presenti"
# Statistiche remote
local remote_files=$(ssh "$remote_host" "find '$remote_path' -type f | wc -l")
local remote_size=$(ssh "$remote_host" "du -sh '$remote_path' | cut -f1")
print_status "$BLUE" "📊 Statistiche MASTER dopo sync:"
echo " 📄 File: $remote_files"
echo " 💾 Dimensione: $remote_size"
return 0
else
print_status "$RED" "❌ Verifica fallita - alcuni file mancanti"
return 1
fi
}
# Funzione di setup post-sync
post_sync_setup() {
print_status "$BLUE" "⚙️ Setup post-sincronizzazione..."
local remote_host=$(echo "$TARGET_MASTER" | cut -d':' -f1)
local remote_path=$(echo "$TARGET_MASTER" | cut -d':' -f2)
# Imposta permessi corretti
ssh "$remote_host" "
cd '$remote_path'
# Permessi script
sudo chmod +x sync-docs-rsync.sh
sudo chmod +x docs/03-scripts-automazione/*.sh
# Permessi Laravel
if [ -d 'netgescon-laravel' ]; then
sudo chown -R www-data:www-data netgescon-laravel/storage
sudo chown -R www-data:www-data netgescon-laravel/bootstrap/cache
sudo chmod -R 775 netgescon-laravel/storage
sudo chmod -R 775 netgescon-laravel/bootstrap/cache
fi
echo 'Permessi impostati correttamente'
"
print_status "$GREEN" "✅ Setup post-sync completato"
}
# === COMMIT AUTOMATICO PRIMA DELLA SINCRONIZZAZIONE ===
git_auto_commit() {
echo -e "${BLUE}📦 Commit automatico modifiche Git...${NC}" | tee -a "$LOG_FILE"
cd "$SOURCE_BASE"
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "🔄 Auto-sync $(date '+%Y-%m-%d %H:%M:%S')
📋 Sincronizzazione automatica prima di push al master
🔄 Modifiche: $(git status --porcelain | wc -l) file
📅 $(date '+%Y-%m-%d %H:%M:%S')"
log "SUCCESS" "Commit automatico creato"
echo -e " ${GREEN}✅ Commit automatico creato${NC}" | tee -a "$LOG_FILE"
else
log "INFO" "Nessuna modifica Git da committare"
echo -e " ${GREEN}✅ Repository Git già aggiornato${NC}" | tee -a "$LOG_FILE"
fi
}
# === SETUP GIT REMOTO DOPO SINCRONIZZAZIONE ===
setup_git_remote() {
echo -e "${BLUE}🔧 Setup Git su server master...${NC}" | tee -a "$LOG_FILE"
ssh netgescon@192.168.0.201 << 'EOF'
cd /var/www/netgescon
# Configura Git se necessario
if ! git config user.name >/dev/null 2>&1; then
git config user.name "NetGescon Master Server"
git config user.email "server@netgescon.local"
echo "Git configurato su master server"
fi
# Reset al commit sincronizzato (soft reset per preservare working directory)
if [ -d ".git" ]; then
git add .
git status
echo "Repository Git sincronizzato su master"
fi
EOF
log "SUCCESS" "Git configurato su server master"
echo -e " ${GREEN}✅ Git configurato su master${NC}" | tee -a "$LOG_FILE"
}
# Funzione di aiuto
show_help() {
cat << EOF
NETGESCON - Sincronizzazione Completa verso MASTER
UTILIZZO:
$0 [opzione]
OPZIONI:
--help, -h Mostra questo aiuto
--stats Mostra solo statistiche senza sincronizzare
--check Controlla solo prerequisiti
--dry-run Simula sincronizzazione senza modificare file
--force Sincronizza senza conferme interattive
DESCRIZIONE:
Sincronizza TUTTO il progetto NetGescon mantenendo struttura identica:
LOCALE: ~/netgescon/
MASTER: /var/www/netgescon/
Include:
- netgescon-laravel/ (applicazione web)
- docs/ (documentazione completa)
- scripts/ (tool e automazione)
- sync-docs-rsync.sh (script sincronizzazione)
- Altri file progetto
Esclude:
- .git (repository Git)
- node_modules (dipendenze JS)
- vendor (dipendenze PHP)
- File temporanei e cache
ESEMPI:
$0 # Sincronizzazione normale con conferme
$0 --stats # Solo statistiche
$0 --dry-run # Test senza modifiche
$0 --force # Sincronizzazione automatica
LOG:
I log vengono salvati in: $HOME/netgescon/log/
EOF
}
# Main - Parsing argomenti e esecuzione
main() {
case "${1:-}" in
--help|-h)
show_help
exit 0
;;
--stats)
check_prerequisites
show_source_stats
show_sync_structure
exit 0
;;
--check)
check_prerequisites
print_status "$GREEN" "✅ Sistema pronto per sincronizzazione completa"
exit 0
;;
--dry-run)
print_status "$YELLOW" "🔍 MODALITÀ DRY-RUN (nessuna modifica effettiva)"
export DRY_RUN_MODE=1
check_prerequisites
show_source_stats
show_sync_structure
print_status "$BLUE" "In modalità dry-run - per test effettivo aggiungere --dry-run a rsync"
exit 0
;;
--force)
print_status "$YELLOW" "⚡ MODALITÀ FORCE (senza conferme)"
export FORCE_MODE=1
;;
"")
# Modalità normale
;;
*)
echo "Opzione non riconosciuta: $1"
echo "Usare --help per vedere le opzioni disponibili"
exit 1
;;
esac
# Esecuzione normale
print_status "$BLUE" "🏁 AVVIO SINCRONIZZAZIONE COMPLETA NETGESCON"
echo "=================================================================="
check_prerequisites
show_source_stats
show_sync_structure
git_auto_commit
if perform_complete_sync; then
verify_sync
post_sync_setup
setup_git_remote
print_status "$GREEN" "🎉 SINCRONIZZAZIONE COMPLETA RIUSCITA!"
print_status "$BLUE" "📋 RIEPILOGO:"
echo " 🎯 Progetto NetGescon completamente sincronizzato"
echo " 📁 Struttura identica locale ↔ MASTER"
echo " 🤖 AI remoto ha accesso completo a documentazione"
echo " ⚙️ Script e tool disponibili su MASTER"
echo " 📝 Log completo: $LOG_FILE"
else
print_status "$RED" "❌ Sincronizzazione fallita"
exit 1
fi
print_status "$BLUE" "🏁 Sincronizzazione terminata"
}
# Esegui se chiamato direttamente
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi