sdk_signer/scripts/scripts/setup-ssh-ci.sh

56 lines
1.7 KiB
Bash
Executable File
Raw 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.

#!/usr/bin/env bash
set -euo pipefail
# Script de configuration SSH pour CI/CD (template Linux)
# Utilise automatiquement la clé SSH pour les opérations Git
GITEA_HOST="${GITEA_HOST:-git.4nkweb.com}"
echo "🔑 Configuration automatique de la clé SSH pour CI/CD..."
if [ -n "${CI:-}" ]; then
echo "✅ Environnement CI détecté"
if [ -n "${SSH_PRIVATE_KEY:-}" ]; then
echo "🔐 Configuration de la clé SSH privée..."
mkdir -p ~/.ssh && chmod 700 ~/.ssh
printf "%s" "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
if [ -n "${SSH_PUBLIC_KEY:-}" ]; then
printf "%s" "$SSH_PUBLIC_KEY" > ~/.ssh/id_rsa.pub
chmod 644 ~/.ssh/id_rsa.pub
fi
cat > ~/.ssh/config << EOF
Host ${GITEA_HOST}
HostName ${GITEA_HOST}
User git
IdentityFile ~/.ssh/id_rsa
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOF
chmod 600 ~/.ssh/config
echo "🧪 Test SSH vers ${GITEA_HOST}..."
ssh -T git@"${GITEA_HOST}" 2>&1 || true
git config --global url."git@${GITEA_HOST}:".insteadOf "https://${GITEA_HOST}/"
echo "✅ Configuration SSH terminée"
else
echo "⚠️ SSH_PRIVATE_KEY non défini, bascule HTTPS"
fi
else
echo " Environnement local détecté"
if [ -f ~/.ssh/id_rsa ] || [ -f ~/.ssh/id_ed25519 ]; then
echo "🔑 Clé SSH locale trouvée"
git config --global url."git@${GITEA_HOST}:".insteadOf "https://${GITEA_HOST}/"
echo "✅ Configuration SSH locale terminée"
else
echo "⚠️ Aucune clé SSH trouvée; configuration manuelle requise"
fi
fi
echo "🎯 Configuration SSH CI/CD terminée"