-
Notifications
You must be signed in to change notification settings - Fork 0
/
SRV_COS_08_USERS.sh
executable file
·307 lines (241 loc) · 8.61 KB
/
SRV_COS_08_USERS.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/bash
echo
echo ##########################
echo # Creado por: gomgardav #
echo # [ David Gómez García ] #
echo ##########################
echo
if [ "$(readlink /proc/$$/exe)" != "/bin/bash" ] && [ "$(readlink /proc/$$/exe)" != "/usr/bin/bash" ]
then
echo "Este Script debe ser ejecutado con: [ /bin/bash ]"
exit
fi
log=./srv_cos_08_salida.sal
cd ~/samba || exit
source ./00_00_VAR.sh
Menu () {
SalidaMenu=$(whiptail --title "Script 08" \
--menu "Selecciona una Opción" 13 35 5 \
1 "Actualizar" \
2 "Generar History" \
3 "Ejecutar Script" \
4 "Reiniciar" \
0 "Salir" 3>&1 1>&2 2>&3)
EstadoSalidaMenu=$?
}
_convert_to_array () {
for Var_Name in "$@"
do
a=0
Var="${!Var_Name}"
export Bak_$Var_Name="$Var"
# echo $A_Var=\"${!A_Var}\" >> Variables.txt
declare -a Var_Array=()
declare -g "A_$Var_Name=()"
if $( echo "$Var" | grep -q ',' )
then
while [ -n "$( echo $Var | awk -F',' '{print $2}' )" ]
do
Var_Value="$( echo $Var | awk -F',' '{print $1}' )"
Var="$( echo $Var | cut -d',' -f 2- )"
#Var_Array+=([$n]=$Var_Value)
declare -g A_$Var_Name[$a]="$Var_Value"
((a++))
done
#Var_Array+=([$n]=$Var)
declare -g A_$Var_Name[$a]="$Var"
((a++))
else
#Var_Array+=([$n]=$Var)
declare -g A_$Var_Name[$a]="$Var"
((a++))
fi
#echo "${Var_Array[@]}"
#declare -g "A_$Var_Name[$n]=$( echo ${Var_Array[$n]} )"
done
}
_initialize_array () {
for i in "$@"; do
declare -g "$i=()"
done
}
_initialize_arrays () {
_initialize_array A_Counter A_UserUID A_User \
A_UserFullName A_UserFullName_64 A_UserFullName_Unaccent \
A_UserNameSurname A_UserNameSurname_64 \
A_UserNameSurname_Unaccent A_UserName A_UserName_64 \
A_UserName_Unaccent A_Initials A_UE_GrupoP A_UE_GruposS \
A_UE_Bak_GruposS
}
#_initialize_arrays () {
# declare -g A_Counter=()
# declare -g A_UserUID=()
# declare -g A_User=()
# declare -g A_UserFullName=()
# declare -g A_UserFullName_64=()
# declare -g A_UserFullName_Unaccent=()
# declare -g A_UserNameSurname=()
# declare -g A_UserNameSurname_64=()
# declare -g A_UserNameSurname_Unaccent=()
# declare -g A_UserName=()
# declare -g A_UserName_64=()
# declare -g A_UserName_Unaccent=()
# declare -g A_Initials=()
# declare -g A_UE_GrupoP=()
# declare -g A_UE_GruposS=()
# declare -g A_UE_Bak_GruposS=()
#}
_process_Add_Users_file () {
n=0
while read UserEntry
do
if [[ -z "$UserEntry" || "$( echo "$UserEntry" | cut -c 1 )" = "#" ]]
then
((n--))
else
## Comprobación:
A_Counter+=([$n]=$n)
## 1º Campo:
A_UserUID+=([$n]="$( echo "$UserEntry" | awk -F':' '{print $1}' )")
## 2º Campo:
A_User+=([$n]="$( echo "$UserEntry" | awk -F':' '{print $2}' )")
## 3º Campo:
A_UserFullName+=([$n]="$( echo "$UserEntry" | awk -F':' '{print $3}' )")
A_UserFullName_64+=([$n]="$( echo "${UserFullName[$n]}" | base64 )")
A_UserFullName_Unaccent+=([$n]="$( echo "${UserFullName[$n]}" | iconv -f utf8 -t ascii//TRANSLIT )")
if $( echo "$UserFullName" | grep -q ' - ' )
then
A_UserNameSurname+=([$n]="$( echo "$UserFullName" | awk -F' - ' '{print $2}' )")
else
A_UserNameSurname+=([$n]="$UserFullName")
fi
A_UserNameSurname_64+=([$n]="$( echo "${UserNameSurname[$n]}" | base64 )")
A_UserNameSurname_Unaccent+=([$n]="$( echo "${UserNameSurname[$n]}" | iconv -f utf8 -t ascii//TRANSLIT )")
A_UserName+=([$n]="$( echo "$UserNameSurname" | awk -F' ' '{print $1}' )")
A_UserName_64+=([$n]="$( echo "${UserName[$n]}" | base64 )")
A_UserName_Unaccent+=([$n]="$( echo "${UserName[$n]}" | iconv -f utf8 -t ascii//TRANSLIT )")
A_Initials+=([$n]="$( echo "${UserNameUnaccent[$n]}" | cut -c 1 )""$( echo "${UserSurnameUnaccent[$n]}" | cut -c 1 )")
## 4º Campo:
A_UE_GrupoP+=([$n]="$( echo "$UserEntry" | awk -F':' '{print $4}' )")
## 5º Campo:
export UE_GruposS_$n="$( echo "$UserEntry" | awk -F':' '{print $5}' )"
export UE_Bak_GruposS_$n="$( echo "$UserEntry" | awk -F':' '{print $5}' )"
fi
((n++))
done < "$UserAddVariables"
}
EstadoSalidaMenu=0
while [ "$EstadoSalidaMenu" = 0 ]; do
Menu
Exit=no
case "$SalidaMenu" in
1 ) yum update -y && ym upgrade -y;;
2 ) HISTFILE=~/.bash_history && set -o history && history > ./srv_cos_08-history_"$(date +%F_%H-%M-%S)".his && history -c && set +o history && HISTFILE="";;
3 )
_convert_to_array GruposP GruposS GruposM
_initialize_arrays
_process_Add_Users_file
samba-tool group add "Unix Admins" --gid-number $UnixAdmins_GID --nis-domain="$dominio"
#m=$n+1
cat << EOF > ~/samba/SRV_COS_09_QUOTA.sh
#!/bin/bash
echo
echo ##########################
echo # Creado por: gomgardav #
echo # [ David Gómez García ] #
echo ##########################
echo
log=./srv_cos_09_salida.sal
cd ~/samba || exit
source ./00_00_VAR.sh
useradd general -M -N -u 1001
passwd -l general
setquota -u general $QuotaDefaultSize $QuotaDefaultSize 0 0 /home/$dominio
setquota -u general $QuotaDefaultSize $QuotaDefaultSize 0 0 /comun
#setquota -u $QuotaDefaultSize $QuotaDefaultSize 0 0 /home/$dominio
#setquota -u $QuotaDefaultSize $QuotaDefaultSize 0 0 /comun
EOF
for (( i = 0, n = 0 ; i <= 0 ; n++ ))
do
samba-tool group add "${A_GruposP[$n]}" --gid-number 1500$n --nis-domain="$dominio"
export "${A_GruposP[$n]}"=1500$n
nn=$((n+1))
if [[ -z "${A_GruposP[$nn]}" ]]
then
i=1
fi
done
for (( i = 0, n = 0 ; i <= 0 ; n++ ))
do
samba-tool group add "${A_GruposS[$n]}" --gid-number 1700$n --nis-domain="$dominio"
export "${A_GruposS[$n]}"=1700$n
nn=$((n+1))
if [[ -z "${A_GruposS[$nn]}" ]]
then
i=1
fi
done
for (( i = 0, n = 0 ; i <= 0 ; n++ ))
do
samba-tool user create "${A_User[$n]}" abc123. --nis-domain="$dominio" --login-shell=/bin/bash --uid-number="${A_UserUID[$n]}" --gid-number="${!A_UE_GrupoP[$n]}" --unix-home=/home/"$dominio"/users/"${A_User[$n]}" --home-directory="\\\\S1\users\\${A_User[$n]}" --home-drive=L: --profile-path="\\\\S1\profiles\\${A_User[$n]}" --script-path="\\\\S1\netlogon\\${A_User[$n]}.cmd"
samba-tool group addmembers "${A_UE_GrupoP[$n]}" "${A_User[$n]}"
samba-tool group addmembers "Domain Users" "${A_User[$n]}"
echo -e "abc123." | net rpc user setprimarygroup "${A_User[$n]}" "${A_UE_GrupoP[$n]}" -U Administrator
_convert_to_array UE_GruposS_$n
Var_Name=A_UE_GruposS_$n
export Var_Content="$(eval echo \${$Var_Name[@]})"
for m in $Var_Content
do
samba-tool group addmembers "$m" "${A_User[$n]}"
done
mkdir /home/"$dominio"/users/"${A_User[$n]}"
chown "$dominio\\${A_User[$n]}":"$dominio\\${A_UE_GrupoP[$n]}" /home/"$dominio"/users/"${A_User[$n]}"
#mkdir /home/"$dominio"/profiles/"${A_User[$n]}".V6
#chown "$dominio\\${A_User[$n]}":"$dominio\\${A_UE_GrupoP[$n]}" /home/"$dominio"/profiles/"${A_User[$n]}".V6
cat << EOF > /home/"$dominio"/scripts/"${A_User[$n]}".cmd
@echo off
chcp 65001
net use S: \\\\$HostnameServ\comun
net use V: \\\\$HostnameServ\Ventas
net use L: \\\\$HostnameServ\users\${A_User[$n]}
EOF
chown "$dominio\\${A_User[$n]}":"BUILTIN\\Administrators" /home/"$dominio"/scripts/"${A_User[$n]}".cmd
chmod u+x /home/"$dominio"/scripts/"${A_User[$n]}".cmd
mkdir -p /home/$dominio/users/${A_User[$n]}/.config/gtk-3.0
cat << EOF > /home/$dominio/users/${A_User[$n]}/.config/gtk-3.0/bookmarks
file:///comun comun
file:///comun/Ventas Ventas
EOF
chown -R "$dominio\\${A_User[$n]}":"$dominio\\${A_UE_GrupoP[$n]}" /home/"$dominio"/users/${A_User[$n]}
cat << EOF >> ~/samba/SRV_COS_09_QUOTA.sh
edquota -p general "${A_User[$n]}"
EOF
nn=$((n+1))
if [[ "${A_Counter[$nn]}" != "$nn" ]]
then
i=1
fi
done
cat << EOF >> ~/samba/SRV_COS_09_QUOTA.sh
repquota -vugas | tee ./repquota.sal
EOF
chmod +x ~/samba/SRV_COS_09_QUOTA.sh
Enter="Enter"
while [[ -n "$Enter" ]]; do
echo
read -sp "Pulsa Enter para Continuar..." Enter
done
HISTFILE=~/.bash_history && set -o history && history > ./srv_cos_07-history_"$(date +%F_%H-%M-%S)".his && history -c && set +o history && HISTFILE="";;
4 ) reboot; exit;;
0 ) Exit=yes; break;;
* ) echo "Error en el Script !!!";;
esac
done
#clear
if [ "$Exit" = "yes" ] && [ "$EstadoSalidaMenu" = "0" ]; then
echo "Has Salido Correctamente !"
elif [ "$EstadoSalidaMenu" = "1" ]; then
echo "Has seleccionado Cancelar !"
else
echo "Ha habido un Error !!!"
fi