1
|
#!/bin/bash
|
2
|
#################################################
|
3
|
# enregistrement_domaine.sh
|
4
|
#################################################
|
5
|
set -e
|
6
|
. /usr/lib/eole/ihm.sh
|
7
|
|
8
|
TYPE_AUTH=$(CreoleGet type_squid_auth aucun)
|
9
|
|
10
|
if [ "$TYPE_AUTH" != 'NTLM/KERBEROS' -a "$TYPE_AUTH" != 'NTLM/SMB' ]; then
|
11
|
EchoRouge "L'authentification du proxy n'est pas de type NTLM"
|
12
|
exit 1
|
13
|
fi
|
14
|
|
15
|
if [ "$TYPE_AUTH" == 'NTLM/KERBEROS' ];then
|
16
|
nom_domaine=$(CreoleGet nom_domaine_windows)
|
17
|
else
|
18
|
nom_domaine=$(CreoleGet nom_domaine_smb)
|
19
|
fi
|
20
|
|
21
|
question() {
|
22
|
echo "Le serveur est déjà intégré à un domaine."
|
23
|
CreoleRun "/usr/bin/wbinfo -t -D $nom_domaine" proxy
|
24
|
QUESTION="Relancer l'intégration ?"
|
25
|
Question_ouinon "$QUESTION" True non warn || exit 0
|
26
|
}
|
27
|
|
28
|
status=$(CreoleRun "systemctl is-system-running" proxy || true)
|
29
|
case $status in
|
30
|
initializing|starting)
|
31
|
EchoRouge "Le serveur est en cours de démarrage, veuillez relancer quand il sera démarré"
|
32
|
exit 1
|
33
|
;;
|
34
|
*)
|
35
|
;;
|
36
|
esac
|
37
|
CreoleRun "/usr/bin/wbinfo -t" proxy &>/dev/null && question || true
|
38
|
|
39
|
#redemarrage de samba
|
40
|
echo "*** Redémarrage des services pour l'enregistrement au domaine ***"
|
41
|
CreoleService winbind stop -c proxy
|
42
|
ret=$(CreoleService winbind start -c proxy) && echo -e $ret || true
|
43
|
|
44
|
if [ $TYPE_AUTH = 'NTLM/KERBEROS' ]; then
|
45
|
ip_serveur=$(CreoleGet ip_serveur_krb)
|
46
|
nom_serveur="$(CreoleGet nom_serveur_krb).$(CreoleGet nom_domaine_krb)"
|
47
|
type_serveur="ads"
|
48
|
elif [ "$TYPE_AUTH" = 'NTLM/SMB' ]; then
|
49
|
ip_serveur=$(CreoleGet ip_serveur_smb)
|
50
|
nom_serveur=$(CreoleGet nom_serveur_smb)
|
51
|
type_serveur="rpc"
|
52
|
fi
|
53
|
|
54
|
iterator=1
|
55
|
tentative=""
|
56
|
max=5
|
57
|
|
58
|
PRIVATE_DIR="$(CreoleGet container_path_domaine /)/etc/eole/private"
|
59
|
PASSWORD_FILE="${PRIVATE_DIR}/eole-seth-education.password"
|
60
|
while true; do
|
61
|
if [ -f "$PASSWORD_FILE" ]; then
|
62
|
user_admin=eole-seth-education
|
63
|
mdp_admin=$(cat $PASSWORD_FILE)
|
64
|
else
|
65
|
echo
|
66
|
echo -n "Nom de l'administrateur du contrôleur de domaine (${tentative}annule si vide) : "
|
67
|
read user_admin
|
68
|
if [ -z $user_admin ]; then
|
69
|
echo "Annulation"
|
70
|
exit 0
|
71
|
fi
|
72
|
echo -n "Mot de passe de l'administrateur du contrôleur de domaine : "
|
73
|
read -s mdp_admin
|
74
|
echo
|
75
|
fi
|
76
|
cmd="/usr/bin/net $type_serveur join"
|
77
|
if [ ! -z $ip_serveur ]; then
|
78
|
cmd="$cmd -I $ip_serveur"
|
79
|
fi
|
80
|
cmd="$cmd -U $user_admin%'${mdp_admin}' -S $nom_serveur"
|
81
|
#inscription de la station dans un domaine
|
82
|
CreoleRun "$cmd" proxy && break || true
|
83
|
if [ $iterator = $max ]; then
|
84
|
echo "Impossible de joindre le domaine"
|
85
|
exit 1
|
86
|
fi
|
87
|
iterator=$((iterator+1))
|
88
|
tentative="$iterator/$max "
|
89
|
done
|
90
|
echo
|
91
|
|
92
|
#redemarrage de samba
|
93
|
echo "*** Redémarrage des services pour confirmer l'enregistrement au domaine ***"
|
94
|
CreoleService winbind stop -c proxy
|
95
|
CreoleService winbind start -c proxy || true
|
96
|
echo
|
97
|
|
98
|
#test de l'intégration
|
99
|
CreoleRun "/usr/bin/wbinfo -t -D $nom_domaine" proxy
|
100
|
if [ $? -eq 1 ]; then
|
101
|
echo
|
102
|
EchoRouge "L'intégration au domaine $nom_domaine a échoué"
|
103
|
exit 1
|
104
|
else
|
105
|
echo
|
106
|
EchoVert "L'intégration au domaine $nom_domaine a réussi"
|
107
|
fi
|
108
|
|
109
|
exit 0
|