-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcadduser
74 lines (61 loc) · 1.51 KB
/
dcadduser
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
#!/bin/sh
USERDB="/etc/dovecot/users"
DOMAIN="" #set this variable for adding domain after username
check_user()
{
if [ -n "$DOMAIN" ];then #add default domain if set this
USERNAME="$USERNAME@$DOMAIN"
fi
USERNAME=`echo "$USERNAME"|awk '{print tolower($0)}'` #to lowercase
if [ ! -f "$USERDB" ];then
return;
fi
for V in $(awk -F':' '{print $1}' "$USERDB")
do
V=`echo "$V"|awk '{print tolower($0)}' ` #to lowercase
if [ "$USERNAME" == "$V" ]; then
echo "User exist!"
exit 1
fi
done
}
if [ "$1" = "--help" -o "$1" = "-h" ];then
echo "Use "`basename $0` " <username> <password>"
echo "<username> - username and domain (e.g. [email protected])"
echo "<password> - password"
echo
echo "If no parameters, script running in interactive mode"
exit 0
fi
if [ "x$1" = "x" -o "x$2" = "x" ];then
#interactive mode
read -p 'Username: ' USERNAME
check_user
read -sp 'Password: ' P1
echo
read -sp 'Repeat password: ' P2
echo
if [ -z "$USERNAME" ]; then
echo "Username not entered!"
exit 1
fi
if [ -z "$P1" ]; then
echo "Password not entered!"
exit 1
fi
if [ -z "$P2" ]; then
echo "Password not entered!"
exit 1
fi
if [ "$P1" != "$P2" ]; then
echo "Passwords do not match!"
exit 1
fi
PASSWORD="$P1"
else
USERNAME="$1"
check_user
PASSWORD="$2"
fi
cp "$USERDB" "$USERDB-" #backup file before user add
echo $USERNAME:$(doveadm pw -s ssha512 -p $PASSWORD):::::: >> $USERDB