#!/bin/bash # --- Caricamento variabili d'ambiente --- if [ -f .env ]; then export $(grep -v '^#' .env | xargs) else echo "โŒ Errore: File .env non trovato." exit 1 fi # --- Configurazione Parallelismo --- THREADS=${1:-${FTP_THREADS:-30}} # --- Configurazione FTP per ROOT www.canticristiani.it --- FTP_HOST="ftp.canticristiani.it" FTP_USER="canticristiani.it" FTP_PASS="$FTP_PASSWORD" REMOTE_DIR="" # Carica nella root della cartella FTP if [ -z "$FTP_PASS" ]; then echo "โŒ Errore: FTP_PASSWORD non definita nel file .env" exit 1 fi # --- Aggiornamento Versione --- VERSION=$(date +'%Y.%m.%d.%H%M') echo "export const VERSION = '$VERSION';" > src/app/version.ts echo "๐Ÿท๏ธ Versione aggiornata a: $VERSION" # --- Build della PWA (base-href=/ per installare nella root) --- echo "๐Ÿ“ฆ 1/2 Build della PWA (Production) per ROOT (www.canticristiani.it) in corso..." npm run build -- --configuration=production --base-href=/ || { echo "โŒ Errore nella build"; exit 1; } if [ ! -d "www" ]; then echo "โŒ Errore: Cartella 'www' non trovata." exit 1 fi # --- Upload via FTP --- echo "๐Ÿš€ 2/2 Caricamento parallelo ($THREADS connessioni) su $FTP_HOST nella ROOT..." cd www TOTAL_FILES=$(find . -type f | wc -l | xargs) PROGRESS_LOG=$(mktemp) ERROR_LOG=$(mktemp) show_progress() { local current=0 while [ "$current" -lt "$TOTAL_FILES" ]; do current=$(wc -l < "$PROGRESS_LOG" | xargs) local percent=$((current * 100 / TOTAL_FILES)) local bar_size=20 local num_hash=$((percent * bar_size / 100)) local bar=$(printf "%${num_hash}s" | tr ' ' '#' 2>/dev/null) local spaces=$(printf "%$((bar_size - num_hash))s" | tr ' ' '-') printf "\r[%-20s] %d%% (%d/%d) caricati..." "$bar$spaces" "$percent" "$current" "$TOTAL_FILES" sleep 0.2 done } show_progress & BAR_PID=$! # Lancio dei job paralleli find . -type f | while read -r file; do REMOTE_FILE_PATH=${file#./} # Eseguiamo curl e segniamo SEMPRE il progresso (anche se fallisce) ( # Usiamo --retry per gestire errori temporanei di connessione if ! curl -s --retry 3 --retry-delay 1 --connect-timeout 10 -u "$FTP_USER:$FTP_PASS" --ftp-pasv --ftp-create-dirs -T "$file" "ftp://$FTP_HOST/$REMOTE_FILE_PATH"; then echo "$REMOTE_FILE_PATH" >> "$ERROR_LOG" fi echo 1 >> "$PROGRESS_LOG" ) & # Gestione THREADS while [ $(jobs -r | wc -l) -ge "$THREADS" ]; do sleep 0.05 done done # Attendi fine caricamenti wait # Stop barra sleep 0.5 kill $BAR_PID 2>/dev/null echo "" # Controllo errori ERRORS=$(wc -l < "$ERROR_LOG" | xargs) if [ "$ERRORS" -gt 0 ]; then echo "โš ๏ธ Deploy completato con $ERRORS errori." echo "I seguenti file non sono stati caricati:" cat "$ERROR_LOG" else echo "โœ… Deploy completato con successo nella ROOT senza errori!" fi # Cleanup rm "$PROGRESS_LOG" "$ERROR_LOG" printf "L'app รจ disponibile su https://www.canticristiani.it/\n"