#!/bin/bash
# $Id: dovecot_adduser.bash 622 2024-12-04 16:52:22Z bertrand $
# Ce script permet d'ajouter un utilisateur Dovecot (POP3 et IMAP) 
# nécessaire pour l'identification dans Postfix.
# external parameters
domain=$1
username=$2
password=$3
uid=$4
gid=$5
# internal parameters
file="/etc/dovecot/users"
home=""
# tools
doveadm_tool=$(which doveadm)
if [[ -n $domain && -n $username && -n $password && -n $uid && -n $gid && -f $doveadm_tool ]]; then
	full_username=$username@$domain
	crypted_password=`$doveadm_tool pw -s CRYPT -p $password` 
	echo "$full_username:$crypted_password:$uid:$gid:(gecos):$home:(shell):" >> $file
else
	if [[ -z $domain || -z $username || -z $password || -z $uid || -z $gid ]]; then
		echo "Usage: $0 domain username password uid gid"
	fi
	if [[ -z $doveadm_tool ]]; then
		echo "doveadm not found"
	fi
fi
