#!/bin/bash # Script d'initialisation de l'environnement SSH pour ihm_client # Configure automatiquement SSH pour tous les push set -e echo "🚀 Initialisation de l'environnement SSH pour ihm_client..." # Couleurs pour les messages RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Fonction pour afficher les messages colorĂ©s print_status() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # VĂ©rifier si on est dans le bon rĂ©pertoire if [[ ! -f "package.json" ]] || [[ ! -d ".git" ]]; then print_error "Ce script doit ĂȘtre exĂ©cutĂ© depuis le rĂ©pertoire racine de ihm_client" exit 1 fi print_status "Configuration de l'environnement SSH..." # 1. Configuration Git pour SSH print_status "Configuration Git pour utiliser SSH..." git config --global url."git@git.4nkweb.com:".insteadOf "https://git.4nkweb.com/" # 2. VĂ©rifier si une clĂ© SSH existe print_status "VĂ©rification des clĂ©s SSH existantes..." if [[ -f ~/.ssh/id_rsa ]] || [[ -f ~/.ssh/id_ed25519 ]]; then print_success "ClĂ© SSH trouvĂ©e" SSH_KEY_EXISTS=true else print_warning "Aucune clĂ© SSH trouvĂ©e" SSH_KEY_EXISTS=false fi # 3. Tester la connexion SSH print_status "Test de la connexion SSH vers git.4nkweb.com..." if ssh -T git@git.4nkweb.com 2>&1 | grep -q "successfully authenticated"; then print_success "Authentification SSH rĂ©ussie" SSH_WORKING=true else print_error "Échec de l'authentification SSH" SSH_WORKING=false fi # 4. Configuration des alias Git print_status "Configuration des alias Git..." git config --global alias.ssh-push '!f() { git add . && git commit -m "${1:-Auto-commit $(date)}" && git push origin $(git branch --show-current); }; f' git config --global alias.quick-push '!f() { git add . && git commit -m "Update $(date)" && git push origin $(git branch --show-current); }; f' print_success "Alias Git configurĂ©s" # 5. VĂ©rifier les remotes print_status "VĂ©rification des remotes Git..." if git remote -v | grep -q "git@git.4nkweb.com"; then print_success "Remotes configurĂ©s pour SSH" else print_warning "Remotes non configurĂ©s pour SSH" print_status "Mise Ă  jour des remotes..." git remote set-url origin git@git.4nkweb.com:4nk/ihm_client.git print_success "Remotes mis Ă  jour" fi # 6. Rendre les scripts exĂ©cutables print_status "Configuration des permissions des scripts..." chmod +x scripts/auto-ssh-push.sh 2>/dev/null || true chmod +x scripts/setup-ssh-ci.sh 2>/dev/null || true print_success "Scripts rendus exĂ©cutables" # 7. CrĂ©er un fichier de configuration local print_status "CrĂ©ation du fichier de configuration local..." cat > .ssh-config << EOF # Configuration SSH automatique pour ihm_client # GĂ©nĂ©rĂ© le $(date) # Configuration Git git config --global url."git@git.4nkweb.com:".insteadOf "https://git.4nkweb.com/" # Alias Git git config --global alias.ssh-push '!f() { git add . && git commit -m "\${1:-Auto-commit \$(date)}" && git push origin \$(git branch --show-current); }; f' git config --global alias.quick-push '!f() { git add . && git commit -m "Update \$(date)" && git push origin \$(git branch --show-current); }; f' # Test SSH ssh -T git@git.4nkweb.com # Scripts disponibles ./scripts/auto-ssh-push.sh quick ./scripts/auto-ssh-push.sh message "Mon message" git ssh-push "Mon message" git quick-push EOF print_success "Fichier de configuration créé: .ssh-config" # 8. RĂ©sumĂ© de la configuration echo "" print_success "=== Configuration SSH terminĂ©e ===" echo "" echo "✅ Configuration Git pour SSH" echo "✅ Alias Git configurĂ©s" echo "✅ Remotes vĂ©rifiĂ©s" echo "✅ Scripts configurĂ©s" echo "" if [[ "$SSH_WORKING" == "true" ]]; then print_success "SSH fonctionne correctement" echo "" echo "🚀 Vous pouvez maintenant utiliser :" echo " ./scripts/auto-ssh-push.sh quick" echo " ./scripts/auto-ssh-push.sh message \"Mon message\"" echo " git ssh-push \"Mon message\"" echo " git quick-push" echo "" else print_warning "SSH ne fonctionne pas encore" echo "" echo "🔧 Pour configurer SSH :" echo " 1. GĂ©nĂ©rer une clĂ© SSH : ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_4nk" echo " 2. Ajouter Ă  l'agent SSH : ssh-add ~/.ssh/id_ed25519_4nk" echo " 3. Ajouter la clĂ© publique Ă  votre compte Gitea" echo " 4. Relancer ce script : ./scripts/init-ssh-env.sh" echo "" fi # 9. Test final if [[ "$SSH_WORKING" == "true" ]]; then print_status "Test final de push SSH..." echo "💡 Pour tester, utilisez : ./scripts/auto-ssh-push.sh status" fi print_success "Initialisation SSH terminĂ©e !"