Improve: auto copy SSH key

and fetch .env from local server
main
boban 2026-04-18 23:23:36 +02:00
parent f87b464af0
commit 5bcc381c87
1 changed files with 16 additions and 11 deletions

View File

@ -122,6 +122,9 @@ if [ ! -f "$ENV_FILE" ]; then
echo ""
read -p "Lokale Server IP: " LOCAL_IP
read -p "Lokaler User (z.B. nexxo): " LOCAL_USER
read -sp "Passwort von $LOCAL_USER@$LOCAL_IP: " \
LOCAL_PASS
echo ""
if [ "$MODE" = "staging" ]; then
SRC_ENV=".env.staging"
@ -131,6 +134,9 @@ if [ ! -f "$ENV_FILE" ]; then
SRC_ENV=".env.production"
fi
# sshpass installieren:
apt install -y sshpass -q
# SSH Key erstellen falls nicht vorhanden:
if [ ! -f "/home/$USER/.ssh/id_ed25519" ]; then
echo "→ SSH Key wird erstellt..."
@ -139,20 +145,17 @@ if [ ! -f "$ENV_FILE" ]; then
-N "" -C "$MODE@aziros"
fi
echo ""
echo "╔══════════════════════════════════════╗"
echo "║ SSH Key auf lokalem Server eintragen ║"
echo "╚══════════════════════════════════════╝"
echo ""
echo "Führe auf dem lokalen Server aus:"
echo ""
echo " echo \"$(cat /home/$USER/.ssh/id_ed25519.pub)\" \\"
echo " >> ~/.ssh/authorized_keys"
echo ""
read -p "Drücke ENTER wenn Key hinzugefügt wurde..."
# Key auf lokalem Server eintragen:
echo "→ SSH Key wird eingetragen..."
sshpass -p "$LOCAL_PASS" ssh-copy-id \
-i /home/$USER/.ssh/id_ed25519.pub \
-o StrictHostKeyChecking=no \
$LOCAL_USER@$LOCAL_IP
# .env holen:
echo "→ .env wird kopiert..."
sudo -u $USER scp \
-o StrictHostKeyChecking=no \
$LOCAL_USER@$LOCAL_IP:~/aziros/src/$SRC_ENV \
$ENV_FILE
@ -160,6 +163,8 @@ if [ ! -f "$ENV_FILE" ]; then
echo "❌ .env konnte nicht geholt werden"
exit 1
fi
echo "✅ .env kopiert"
fi
echo "✅ .env vorhanden"