-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.sh
executable file
·420 lines (384 loc) · 5.16 KB
/
manager.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#! /bin/bash
#------------User menu------------
function user_menu()
{
while true;
do
clear
echo -e "\tUser menu\n"
echo -e "1) Create\n"
echo -e "2) Mod\n"
echo -e "3) Delete\n"
echo -e "4) Back\n"
read entered
case $entered in
1)
create_user
;;
2)
mod_user
;;
3)
del_user
;;
4)
main_menu
;;
esac
done
}
function del_user()
{
clear
echo -e "\tDelete user\n"
echo -e "Enter name "
read name
if grep $name /etc/passwd
then
userdel $name
echo -e "Succes\n"
read w
else
echo -e "$name does not exist\n"
read w
fi
}
function mod_user()
{
while true;
do
clear
echo -e "\tModification user\n"
echo -e "1) Name\n"
echo -e "2) UID\n"
echo -e "3) GID\n"
echo -e "4) Password\n"
echo -e "5) Expire\n"
echo -e "6) Comment\n"
echo -e "7) Back\n"
read entered
case $entered in
1)
clear
echo -e "Enter user name "
read user_name
echo -e "Enter new user name "
read new_user_name
if grep $new_user_name /etc/passwd;
then
clear
echo -e "This name alredy taken\n"
read w
else
usermod -l $new_user_mod $user_name
echo -e "Succes\n"
read w
fi
;;
2)
clear
echo -e "Enter user name "
read user_name
echo -e "Enter new UID "
read new_uid
if grep $new_uid /etc/passwd;
then
clear
echo -e "UID $new_uid alredy taken\n"
read w
else
usermod -u $new_uid $username
echo -e "Oh yea,this operation has been succes\n"
read w
fi
;;
3)
clear
echo -e "Enter user name "
read user_name
echo -e "Enter new GID "
read new_gid
if grep $new_gid /etc/passwd;
then
echo -e "This $new_gid alredy taken\n"
read w
else
usermod -g $new_gid $user_name
echo -e "Succes\n"
read w
fi
;;
4)
clear
echo -e "Enter user name "
read user_name
echo -e "Enter new passwod "
read new_passwd
if grep $new_passwd /etc/passwd;
then
echo -e "This password alredy taken\n"
read w
else
usermod -p $new_passwd $user_name
echo -e "Success\n"
read w
fi
;;
5)
clear
echo -e "Enter user name "
read user_name
echo -e "Enter new expire (year-month-day) "
read new_expire
usermod -e $new_expire $user_name
echo -e "Succes\n"
read w
;;
6)
clear
echo -e "Enter user name "
read user_name
echo -e "Enter new comment "
read new_comment
useradd -c $new_comment $user_name
echo -e "Succes\n"
read w
;;
7)
user_menu
;;
esac
done
}
function create_user()
{
while true;
do
clear
echo -e "\tCreate user\n"
echo -e "1) Default\n"
echo -e "2) Custom\n"
echo -e "3) Back\n"
read entered
case $entered in
1)
clear
echo -e "Enter name "
read user_name
echo -e "Enter password "
read user_password
if grep $user_name /etc/passwd;
then
echo -e "This user alredy exist\n"
read w
else
useradd -p $user_password $user_name
echo -e "Succes\n"
read w
fi
;;
2)
create_custom_user
;;
3)
user_menu
;;
esac
done
}
function create_custom_user()
{
clear
echo -e "\tCustom user create"
echo -e "Enter name "
read name
echo -e "Enter UID "
read uid
echo -e "Enter GID "
read gid
echo -e "Enter password "
read password
echo -e "Enter expire "
read expire
echo -e "Enter comment "
read comment
if grep -eo $name -eo $uid -eo $gid /etc/passwd;
then
echo -e "User wasnt create\n"
read w
else
useradd -u $uid -g $gid -p $password -e $expire -c $comment $name
echo -e "User created\n"
read w
fi
}
#---------Group---------------
function group_menu()
{
while true;
do
clear
echo -e "\tGroup menu\n"
echo -e "1) Create\n"
echo -e "2) Mod\n"
echo -e "3) Delete\n"
echo -e "4) Back\n"
read entered
case $entered in
1)
create_group
;;
2)
mod_group
;;
3)
clear
echo -e "Enter group name"
read groupname
groupdel $groupname
;;
4)
main_menu
;;
esac
done
}
function mod_group()
{
while true;
do
clear
echo -e "\tMod group"
echo -e "1) Change GID"
echo -e "2) Change group name"
echo -e "3) Back"
read entered
case $entered in
1)
clear
echo -e "Enter group name"
read group_name
echo -e "Enter new GID "
read new_gid
groupmod -g $new_gid $groupname
;;
2)
clear
echo -e "Enter group name"
read _group_name
echo -e "Enter new group name"
read new_group_name
groupmod -n $new_group_name $_group_name
;;
3)
group_menu
;;
esac
done
}
function create_group()
{
while true;
do
clear
echo -e "\tCreate group\n"
echo -e "1) Default\n"
echo -e "2) Custom\n"
echo -e "3) Back\n"
read entered
case $entered in
1)
clear
echo -e "\tCreate default\n"
echo -e "Enter name "
read group_name
if grep $group_name /etc/group;
then
echo -e "This name alredy exist\n"
read wai
else
groupadd $group_name
fi
;;
2)
custom_group
;;
3)
group_menu
;;
esac
done
}
function custom_group()
{
clear
echo -e "\tCreate custom group\n"
echo -e "Enter name "
read group_name
echo -e "Enter group id "
read group_id
if grep $group_name /etc/group && grep $group_id /etc/group;
then
echo -e "Error\n"
read wai
else
groupadd -g $group_id $group_name
fi
}
#-------------Main menu-------------
function show_info()
{
while true;
do
clear
echo -e "\tInfo\n"
echo -e "1) Show group info\n"
echo -e "2) Show user info\n"
echo -e "3) Back\n"
read entered
case $entered in
1)
clear
echo -e "\tGroup info\n"
cat /etc/group
read w
;;
2)
echo -e "\tUser info\n"
cat /etc/passwd
read w
;;
3)
main_menu
;;
esac
done
}
function main_menu()
{
while true;
do
clear
echo -e "\tMenu\n"
echo -e "1) Users menu\n"
echo -e "2) Groups menu\n"
echo -e "3) Show info\n"
echo -e "4) Exit\n"
read entered
case $entered in
1)
user_menu
;;
2)
group_menu
;;
3)
show_info
;;
4)
exit
;;
esac
done
}
main_menu