61 lines
2.0 KiB
Bash
Executable File
61 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Script d'initialisation de l'environnement SSH (template Linux)
|
|
# Configure automatiquement SSH pour les push via Gitea
|
|
|
|
GITEA_HOST="${GITEA_HOST:-git.4nkweb.com}"
|
|
|
|
echo "🚀 Initialisation de l'environnement SSH (template)..."
|
|
|
|
# Couleurs
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
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"; }
|
|
|
|
print_status "Configuration SSH..."
|
|
|
|
# 1. Configuration Git pour SSH
|
|
print_status "Configuration Git pour utiliser SSH (${GITEA_HOST})..."
|
|
git config --global url."git@${GITEA_HOST}:".insteadOf "https://${GITEA_HOST}/"
|
|
|
|
# 2. Vérification des clés SSH
|
|
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"
|
|
else
|
|
print_warning "Aucune clé SSH trouvée"
|
|
fi
|
|
|
|
# 3. Test de la connexion SSH
|
|
print_status "Test de la connexion SSH vers ${GITEA_HOST}..."
|
|
if ssh -T git@"${GITEA_HOST}" 2>&1 | grep -qi "authenticated\|welcome"; then
|
|
print_success "Authentification SSH réussie"
|
|
else
|
|
print_error "Échec de l'authentification SSH"
|
|
fi
|
|
|
|
# 4. 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. Rendu exécutable des scripts si chemin standard
|
|
print_status "Configuration des permissions des scripts (si présents)..."
|
|
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 (si présents)"
|
|
|
|
# 6. Résumé
|
|
echo ""
|
|
print_success "=== Configuration SSH terminée ==="
|
|
|