-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserop
More file actions
executable file
·125 lines (104 loc) · 2.25 KB
/
userop
File metadata and controls
executable file
·125 lines (104 loc) · 2.25 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
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
#!/bin/bash
HOMES='/home'
USERADD='/usr/sbin/useradd'
USERDEL='/usr/sbin/userdel'
PASSWD='/usr/bin/passwd'
USERMOD='/usr/sbin/usermod'
SMBPASSWD='/usr/bin/smbpasswd'
PDBEDIT='/usr/bin/pdbedit'
DEFAULTGRP='Data'
MINUID=1000
failmessage() {
echo -e "Fail!"
exit
}
needusername() {
echo "I need a username for that"
echo "Do userop help for help.."
}
do_add() {
if [ -z $1 ]; then
needusername
exit
else
echo -e "Adding user...\n\n"
echo -n "To the system..." && $USERADD -b $HOMES -m $1 && echo -e "Done.\n" || failmessage
echo "..set password for the system... "
$PASSWD $1 && echo -e "...Done.\n" || echo -e "FAIL"
$USERMOD -G $DEFAULTGRP $1
echo -n "To Samba..." && $SMBPASSWD -a $1 && echo -e "Done.\n" || echo -e "FAIL"
fi
}
do_delete() {
if [ -z $1 ]; then
needusername
exit
else
if [ `id -u $1` -gt $MINUID ]; then
echo -e "Deleting user...\n\n"
echo -n "From samba Db.." && $PDBEDIT -x -u $1 && echo -e "Done.\n" || echo -e "Fail!"
echo -n "From system.." && $USERDEL $1 && echo -e "Done.\n" || echo -e "Fail!"
else
echo -e "No. thats a protected user.\n"
exit
fi
fi
}
do_pass() {
if [ -z $1 ]; then
needusername
exit
else
if [ `id -u $1` -gt $MINUID ]; then
echo -e "Changing password for user..\n Sorry, you'll have to type the password 4 times.....\n\n"
$PASSWD $1
$SMBPASSWD $1
else
echo -e "No. thats a protected user.\n"
exit
fi
fi
}
do_usage() {
cat <<EOF
User Operations:
userop Usage:
userop add <username> - Add a user
userop del <username> - Delete a user
userop pass <username> - Change the password for a user
userop manual - manual steps information
EOF
}
do_manual() {
cat <<EOF
User Operations - Manual Steps:
For adding a user do:
sudo useradd -b $HOMES -m <username>
sudo smbpasswd -a <username>
For deleting a user do:
sudo pdbedit -x -u <username>
sudo userdel <username>
This will not delete the users home directory
For changing a password do:
sudo passwd <username>
sudo smbpasswd <username>
EOF
}
case "$1" in
add)
do_add $2
;;
del)
do_delete $2
;;
pass)
do_pass $2
;;
manual)
do_manual
;;
*|help)
do_usage
exit
;;
esac