Guest User

Untitled

a guest
Jul 19th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.70 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. if [ ! $# = 1 ]
  4.  then
  5.   echo "Usage: $0 username@domain"
  6.   exit 1
  7.  else
  8.   user=`echo "$1" | cut -f1 -d "@"`
  9.   domain=`echo "$1" | cut -s -f2 -d "@"`
  10.   if [ -x $domain ]
  11.    then
  12.     echo "No domain given\nUsage: $0 username@domain"
  13.     exit 2
  14.   fi
  15.   echo "\nCreate a password for the new email user"
  16.   #SWAP THE FOLLOWING passwd LINES IF USING A UBUNTU VERSION PRIOR TO 12.04
  17.   #passwd=`dovecotpw`
  18.   passwd=`doveadm pw -u $user`
  19.   echo "Adding user $user@$domain to /maildata/userpass"
  20.   if [ ! -x /maildata/userpass ]
  21.    then
  22.     touch /maildata/userpass
  23.     chmod 640 /maildata/userpass
  24.   fi
  25.   echo  "$user@$domain:$passwd" >> /maildata/userpass
  26.  
  27.   # Create the needed Maildir directories
  28.   echo "Creating user directory /home/vmail/$domain/$user"
  29.   # maildirmake.dovecot does only chown on user directory, we'll create domain directory instead
  30.   if [ ! -x /maildata/mailbox/$domain ]
  31.    then
  32.     mkdir -p /maildata/mailbox/$domain
  33.     chown 2000:2000 /maildata/mailbox/$domain
  34.     chmod 700 /maildata/mailbox/$domain
  35.   fi
  36.   /usr/bin/maildirmake.dovecot /maildata/mailbox/$domain/$user 2000:2000
  37.   # Also make folders for Drafts, Sent, Junk and Trash
  38.   /usr/bin/maildirmake.dovecot /maildata/mailbox/$domain/$user/.Drafts 2000:2000
  39.   /usr/bin/maildirmake.dovecot /maildata/mailbox/$domain/$user/.Sent 2000:2000
  40.   /usr/bin/maildirmake.dovecot /maildata/mailbox/$domain/$user/.Junk 2000:2000
  41.   /usr/bin/maildirmake.dovecot /maildata/mailbox/$domain/$user/.Trash 2000:2000
  42.  
  43.   # To add user to Postfix virtual map file and relode Postfix
  44.   echo "Adding user to /etc/postfix/vmaps"
  45.   echo $1  $domain/$user/ >> /maildata/vmaps
  46.   postmap /maildata/vmaps
  47.   postfix reload
  48. fi
  49.  
  50. exit 0
Add Comment
Please, Sign In to add comment