sdk_client/scripts/setup-ssh-ci.sh

80 lines
2.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Script de configuration SSH pour CI/CD ihm_client
# Utilise automatiquement la clé SSH pour les opérations Git
set -e
echo "🔑 Configuration automatique de la clé SSH pour ihm_client CI/CD..."
# Vérifier si on est dans un environnement CI
if [ -n "$CI" ]; then
echo "✅ Environnement CI détecté"
# Configuration SSH pour Gitea Actions
if [ -n "$SSH_PRIVATE_KEY" ]; then
echo "🔐 Configuration de la clé SSH privée..."
# Créer le répertoire SSH
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Écrire la clé privée
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
# Ajouter la clé publique correspondante (si disponible)
if [ -n "$SSH_PUBLIC_KEY" ]; then
echo "$SSH_PUBLIC_KEY" > ~/.ssh/id_rsa.pub
chmod 644 ~/.ssh/id_rsa.pub
fi
# Configuration SSH pour git.4nkweb.com
cat > ~/.ssh/config << EOF
Host git.4nkweb.com
HostName git.4nkweb.com
User git
IdentityFile ~/.ssh/id_rsa
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOF
chmod 600 ~/.ssh/config
# Tester la connexion SSH
echo "🧪 Test de connexion SSH vers git.4nkweb.com..."
if ssh -T git@git.4nkweb.com 2>&1 | grep -q "Welcome"; then
echo "✅ Connexion SSH réussie"
else
echo "⚠️ Connexion SSH établie (message de bienvenue non détecté)"
fi
# Configurer Git pour utiliser SSH
git config --global url."git@git.4nkweb.com:".insteadOf "https://git.4nkweb.com/"
echo "✅ Configuration SSH terminée"
else
echo "⚠️ Variable SSH_PRIVATE_KEY non définie, utilisation de HTTPS"
fi
else
echo " Environnement local détecté"
# Vérifier si une clé SSH existe
if [ -f ~/.ssh/id_rsa ]; then
echo "🔑 Clé SSH locale trouvée"
# Configurer Git pour utiliser SSH localement
git config --global url."git@git.4nkweb.com:".insteadOf "https://git.4nkweb.com/"
echo "✅ Configuration SSH locale terminée"
else
echo "⚠️ Aucune clé SSH trouvée, configuration manuelle requise"
echo "💡 Pour configurer SSH manuellement :"
echo " 1. Générer une clé SSH : ssh-keygen -t rsa -b 4096"
echo " 2. Ajouter la clé publique à votre compte Gitea"
echo " 3. Tester : ssh -T git@git.4nkweb.com"
fi
fi
echo "🎯 Configuration SSH terminée pour ihm_client"