-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_config.sh
More file actions
executable file
·58 lines (52 loc) · 1.58 KB
/
Copy pathgit_config.sh
File metadata and controls
executable file
·58 lines (52 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Prérequis : git doit être installé sur votre système, et ce script doit être
# exécuté en tant que root !
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
PURPLE='\033[0;35m'
RED='\033[0;31m'
NC='\033[0m'
ME=$(who | grep ":0" | awk '{print $1}' | tr -s ' ')
check_cmd() {
if [[ $? -eq 0 ]] || [[ $? -eq 1 ]]; then
if [ -z "$1" ]; then
echo -e "${GREEN}OK.${NC}"
else
echo -e "${GREEN}OK pour $1.${NC}"
fi
else
if [[ -z "$1" ]]; then
echo -e "${RED}ERREUR !${NC}"
else
echo -e "${RED}ERREUR pour $1.${NC}"
fi
fi
}
install_app() {
if ! command -v "$1" > /dev/null 2>&1; then
echo -ne "${YELLOW}Installation de $1..... ${NC}"
$2 install -y "$1" > /dev/null 2>&1
check_cmd $1
else
echo -e "${GREEN}OK pour $1 : déjà installé.${NC}"
fi
}
if [[ $(id -u) -ne 0 ]]; then
echo -e "${RED}Le script doit être exécuter en tant que superutilisateur (root).${NC}"
exit 4
fi
if [[ "$#" -ne 2 ]]; then
echo "Utilisation : $0 <adresse_email> <gestionnaire de paquet (apt, dnf, pacman....)>"
exit 1
fi
email="$1"
install_app "git" $2
echo -ne "${YELLOW}Configuration de git avec $email.....${NC} "
sudo -u "$ME" git config --global user.email "$email"
check_cmd ""
echo -ne "${YELLOW}Génération clé SSH avec $email.....${NC} "
sudo -u "$ME" ssh-keygen -t rsa -b 4096 -C "$email"
check_cmd ""
cat "/home/$ME/.ssh/id_rsa.pub"
echo -ne "${PURPLE}Une fois la clé ssh copiée dans votre compte github, appuyez sur la touche ENTRÉE${NC}"
read reponse