chore: riorganizzati gli script di deploy e aggiunto deploy_www.sh

- Rinomato deploy.sh in deploy_ionic.sh (per deploy su sottodirectory /ionic).
- Rinomato deploy_pwa.sh in deploy_localpwa.sh (per test locale).
- Creato deploy_www.sh per installare e fare la build della PWA direttamente sulla root del dominio (www.canticristiani.it) con base-href=/.
This commit is contained in:
David Frassi
2026-05-20 12:33:08 +02:00
parent 92325df48b
commit a4cd56d406
3 changed files with 103 additions and 0 deletions
View File
Executable
+103
View File
@@ -0,0 +1,103 @@
#!/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"