Files
canti/allineacanti.sh
T
2026-05-16 17:24:59 +02:00

55 lines
1.5 KiB
Bash
Executable File

#!/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 FTP ---
FTP_HOST="ftp.canticristiani.it"
FTP_USER="canticristiani.it"
FTP_PASS="$FTP_PASSWORD"
SOURCE_URL="https://libretto.mmcinet.eu/canti/api/get_all_app_tables"
REMOTE_PATH="api/canti.json"
if [ -z "$FTP_PASS" ]; then
echo "❌ Errore: FTP_PASSWORD non definita nel file .env"
exit 1
fi
# --- Download del file ---
echo "⬇️ Scaricamento dati da $SOURCE_URL..."
TEMP_FILE=$(mktemp)
if ! curl -s -L "$SOURCE_URL" -o "$TEMP_FILE"; then
echo "❌ Errore nel download dei dati."
rm "$TEMP_FILE"
exit 1
fi
# --- Rotazione file su FTP ---
echo "🔄 Rotazione file su FTP (canti.json -> canti_ex.json)..."
# Rinominiamo canti.json in canti_ex.json.
# Usiamo i percorsi assoluti per sicurezza.
curl -s -u "$FTP_USER:$FTP_PASS" \
--ftp-pasv \
-Q "*DELE /htdocs/api/canti_ex.json" \
-Q "*RNFR /htdocs/api/canti.json" \
-Q "*RNTO /htdocs/api/canti_ex.json" \
"ftp://$FTP_HOST/" > /dev/null
# --- Upload via FTP ---
echo "🚀 Caricamento nuovo file su $FTP_HOST/$REMOTE_PATH..."
if curl -s -u "$FTP_USER:$FTP_PASS" --ftp-pasv --ftp-create-dirs -T "$TEMP_FILE" "ftp://$FTP_HOST/$REMOTE_PATH"; then
echo "✅ Allineamento completato con successo!"
else
echo "❌ Errore durante il caricamento FTP."
rm "$TEMP_FILE"
exit 1
fi
# Cleanup
rm "$TEMP_FILE"