-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadddovecotuser
More file actions
executable file
·51 lines (48 loc) · 1.88 KB
/
adddovecotuser
File metadata and controls
executable file
·51 lines (48 loc) · 1.88 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
#!/bin/sh
if [ ! $# = 1 ]
then
echo "Usage: $0 username@domain"
exit 1
else
user=`echo "$1" | cut -f1 -d "@"`
domain=`echo "$1" | cut -s -f2 -d "@"`
if [ -x $domain ]
then
echo "No domain given\nUsage: $0 username@domain"
exit 2
fi
echo "Adding user $user@$domain to /usr/local/etc/dovecot/users"
echo "$user@$domain::5000:5000::/home/vmail/$domain/$user/:/bin/false::" >> /usr/local/etc/dovecot/users
# Create the needed Maildir directories
echo "Creating user directory /home/vmail/$domain/$user"
# maildirmake.dovecot does only chown on user directory, we'll create domain directory instead
if [ ! -x /usr/home/vmail/$domain ]
then
mkdir /usr/home/vmail/$domain
chown 5000:5000 /usr/home/vmail/$domain
chmod 700 /usr/home/vmail/$domain
fi
/usr/local/bin/maildirmake.dovecot /home/vmail/$domain/$user 5000:5000
# Also make folders for Drafts, Sent, Junk and Trash
/usr/local/bin/maildirmake.dovecot /home/vmail/$domain/$user/.Drafts 5000:5000
/usr/local/bin/maildirmake.dovecot /home/vmail/$domain/$user/.Sent 5000:5000
/usr/local/bin/maildirmake.dovecot /home/vmail/$domain/$user/.Junk 5000:5000
/usr/local/bin/maildirmake.dovecot /home/vmail/$domain/$user/.Trash 5000:5000
# To add user to Postfix virtual map file and relode Postfix
echo "Adding user to /usr/local/etc/postfix/vmaps"
echo $1 $domain/$user/ >> /usr/local/etc/postfix/vmaps
postmap /usr/local/etc/postfix/vmaps
postfix reload
fi
echo "\nCreate a password for the new email user"
#SWAP THE FOLLOWING passwd LINES IF USING A UBUNTU VERSION PRIOR TO 12.04
#passwd=`dovecotpw`
passwd=`doveadm pw -u $user`
echo "Adding password for $user@$domain to /usr/local/etc/dovecot/passwd"
if [ ! -x /usr/local/etc/dovecot/passwd ]
then
touch /usr/local/etc/dovecot/passwd
chmod 640 /usr/local/etc/dovecot/passwd
fi
echo "$user@$domain:$passwd" >> /usr/local/etc/dovecot/passwd
exit 0