mmv

mailserver bootstrap script
git clone git://git.yotsev.xyz/mmv.git
Log | Files | Refs | README | LICENSE

mpasswd (1053B)


      1 #!/bin/sh
      2 
      3 if [ $# != 1 ]; then
      4     echo "Error: Invalid number of arguments"
      5     echo "Usage: mpasswd username@domain.tld"
      6     return 1
      7 fi
      8 
      9 user="$(echo $1 | cut -d '@' -f 1)"
     10 domain="$(echo $1 | cut -d '@' -f 2)"
     11 
     12 if [ -z "$(grep "$domain" /etc/mail/domains 2> /dev/null)" ]; then
     13     echo "Error: Invalid domain"
     14     echo "Info: It should be one of the following:"
     15     cat /etc/mail/domains
     16     return 1
     17 fi
     18 
     19 if [ -z "$(grep "^$user@$domain" /etc/mail/credentials 2> /dev/null)" ]; then
     20     echo "Error: User doesn't exist in /etc/mail/credentials"
     21     return 1
     22 fi
     23 
     24 if [ -z "$(grep "^$user@$domain" /etc/mail/virtuals 2> /dev/null)" ]; then
     25     echo "Error: User doesn't exist in /etc/mail/virtuals"
     26     return 1
     27 fi
     28 
     29 echo "Please enter a password."
     30 password=$(encrypt -p)
     31 
     32 record="$user@$domain:$password:vmail:2000:2000:/var/vmail/$domain/$user::userdb_mail=maildir:/var/vmail/$domain/$user"
     33 
     34 sed "s#^$user@$domain.*#$record#g" /etc/mail/credentials > temp-cred-file
     35 mv temp-cred-file /etc/mail/credentials
     36 
     37 rcctl restart smtpd
     38 rcctl restart dovecot