56 lines
1.6 KiB
Bash
Executable File
56 lines
1.6 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://api.canticristiani.it/cantiletture.json"
|
|
REMOTE_PATH="api/cantiletture.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 -u "$API_AUTH_USER:$API_AUTH_PASS" -L "$SOURCE_URL" -o "$TEMP_FILE"; then
|
|
echo "❌ Errore nel download dei dati."
|
|
rm "$TEMP_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
# --- Caricamento file (FTP o VPS) ---
|
|
if [ -n "$VPS_HOST" ]; then
|
|
echo "🚀 Caricamento nuovo file su VPS ($VPS_HOST) via SCP..."
|
|
ssh "$VPS_USER@$VPS_HOST" "mkdir -p $VPS_PATH/api"
|
|
if scp "$TEMP_FILE" "$VPS_USER@$VPS_HOST:$VPS_PATH/$REMOTE_PATH" && ssh "$VPS_USER@$VPS_HOST" "chmod 644 $VPS_PATH/$REMOTE_PATH"; then
|
|
echo "✅ Allineamento su VPS completato con successo!"
|
|
else
|
|
echo "❌ Errore durante il caricamento via SCP su VPS."
|
|
rm "$TEMP_FILE"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "🚀 Caricamento nuovo file su FTP ($FTP_HOST) via FTP..."
|
|
if curl -s -u "$FTP_USER:$FTP_PASS" --ftp-pasv --ftp-create-dirs -T "$TEMP_FILE" "ftp://$FTP_HOST/$REMOTE_PATH"; then
|
|
echo "✅ Allineamento su FTP completato con successo!"
|
|
else
|
|
echo "❌ Errore durante il caricamento FTP."
|
|
rm "$TEMP_FILE"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Cleanup
|
|
rm "$TEMP_FILE"
|