Files
AdsPreview/deployment/scripts/upload.sh
Johannes a6ae81f5b5 feat: Add SSH-Key support for secure deployment authentication
- upload.sh: Conditional SSH-Key vs. password authentication
- Automatic detection of SSH-Keys via FTP_SSH_KEY variable
- CloudPanel-compatible SSH-Key integration
- .env.upload.example: Added SSH-Key documentation
- Secure SFTP uploads without passwords in code
2025-09-07 15:46:11 +02:00

122 lines
3.3 KiB
Bash
Executable File

#!/bin/sh
# Upload-Skript für Webspace Deployment
echo "📤 Webspace Upload Skript"
echo ""
# Konfiguration aus .env.upload Datei laden
ENV_FILE="$(dirname "$0")/.env.upload"
if [ ! -f "$ENV_FILE" ]; then
echo "❌ Konfigurationsdatei nicht gefunden: $ENV_FILE"
echo ""
echo "📋 ERSTELLE EINE .env.upload DATEI:"
echo " 1. Kopiere .env.upload.example zu .env.upload"
echo " 2. Trage deine FTP-Zugangsdaten ein"
echo ""
echo " Beispiel:"
echo " FTP_HOST=\"dein-server.de\""
echo " FTP_USER=\"dein-username\""
echo " FTP_PASS=\"dein-passwort\""
echo " FTP_PATH=\"/htdocs\""
exit 1
fi
# Environment-Variablen aus .env.upload laden
set -a # Export aller Variablen
source "$ENV_FILE"
set +a
# Standard-Port falls nicht gesetzt
FTP_PORT=${FTP_PORT:-22}
echo "🔧 KONFIGURATION:"
echo " Host: $FTP_HOST"
echo " User: $FTP_USER"
echo " Port: $FTP_PORT"
echo " Path: $FTP_PATH"
# SSH-Key Authentifizierung prüfen
if [ -n "$FTP_SSH_KEY" ] && [ -f "$FTP_SSH_KEY" ]; then
echo " Auth: SSH-Key ($FTP_SSH_KEY)"
USE_SSH_KEY=1
else
echo " Auth: Passwort"
USE_SSH_KEY=0
fi
echo ""
# Prüfe ob wir im deployment/scripts/ Ordner sind und wechsle zur Projekt-Root
if [ "$(basename "$PWD")" = "scripts" ]; then
cd ../..
elif [ "$(basename "$PWD")" = "deployment" ]; then
cd ..
fi
# Überprüfe ob deployment/build Ordner existiert
if [ ! -d "deployment/build" ]; then
echo "❌ deployment/build/ Ordner nicht gefunden."
echo " Führe zuerst das deploy.sh Skript aus!"
exit 1
fi
# Überprüfe ob lftp installiert ist
if ! command -v lftp &> /dev/null; then
echo "❌ lftp ist nicht installiert."
echo " Installation: brew install lftp"
echo ""
echo "📋 MANUELLE UPLOAD-ANLEITUNG:"
echo " 1. Öffne deinen FTP Client (FileZilla, etc.)"
echo " 2. Verbinde zu deinem Webspace"
echo " 3. Navigiere zu htdocs/ oder public_html/"
echo " 4. Uploade alle Dateien aus: deployment/build/"
echo ""
exit 1
fi
echo "⚠️ ACHTUNG: Dies überschreibt alle Dateien auf dem Webspace!"
echo " Fortfahren? (y/N)"
read -r response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
echo "Abgebrochen."
exit 0
fi
echo "📤 Uploade via SFTP..."
if [ $USE_SSH_KEY -eq 1 ]; then
# SSH-Key Authentifizierung
lftp -c "
set sftp:auto-confirm yes;
set ssl:verify-certificate no;
set sftp:connect-program 'ssh -i $FTP_SSH_KEY -p $FTP_PORT -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null';
open sftp://$FTP_USER@$FTP_HOST;
cd $FTP_PATH;
lcd deployment/build;
mirror --reverse --delete --verbose --exclude-glob=node_modules/ --exclude-glob=.git/ --exclude-glob=.* --exclude area/ ./ ./;
bye
"
else
# Passwort Authentifizierung
lftp -c "
set sftp:auto-confirm yes;
set ssl:verify-certificate no;
open sftp://$FTP_USER:$FTP_PASS@$FTP_HOST:$FTP_PORT;
cd $FTP_PATH;
lcd deployment/build;
mirror --reverse --delete --verbose --exclude-glob=node_modules/ --exclude-glob=.git/ --exclude-glob=.* --exclude area/ ./ ./;
bye
"
fi
if [ $? -eq 0 ]; then
echo "✅ Upload erfolgreich!"
echo "🌐 Deine App sollte jetzt live sein!"
else
echo "❌ Upload fehlgeschlagen. Prüfe deine FTP-Zugangsdaten."
fi