Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo "Candlekeep maildir creator by NH3CL"
- echo "Version: 1.1 - 2015.08.17"
- users="/home/vmail/users"
- echo -n "Give domain [ENTER]: "
- read domain
- echo -n "Give the username [ENTER]:"
- read user
- echo -n "Mailbox size (MB):"
- read mailboxsize
- echo
- grep -i "$user@$domain" "$users"
- if [ $? == 0 ]; then
- echo -e "\e[4;31mERROR:\e[0m Mailbox already exists, exit."
- exit 1
- else
- #If folder not exists, create
- if [ ! -d "/home/vmail/$domain" ]; then
- mkdir "/home/vmail/$domain"
- fi
- #go to folder
- cd "/home/vmail/$domain"
- #Creating mailbox
- maildirmake.courier $user
- fi
- #giving rights to system user
- chown -R vmail:vmail /home/vmail/$domain
- #Write into the textfile. Full e-mail address
- echo -e "$user@$domain" >> $users
- #Write into the database
- mysql -h localhost -umail_admin -p[password] <<EOF
- use mail;
- INSERT INTO domains(domain) VALUES('$domain');
- EOF
- #Generating password (A-Z, a-z, 0-9)
- password=$(makepasswd --chars 8)
- #Mailbox size convert to byte
- bytemailboxsize=$(($mailboxsize*1024*1024))
- #Writeing mailbox details into database
- mysql -h localhost -umail_admin -p[password] <<EOF
- use mail;
- INSERT INTO users(email,password,quota) VALUES('$user@$domain',ENCRYPT('$password'),'$bytemailboxsize');
- EOF
- echo -e "Congratulation \e[32m$user@$domain\e[0m created. Password: \e[32m$password\e[0m Thanks!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement