Email address to user
My goal is to build a bash script to which I give "mihamina@rktmb.org" and "password" as argument, and then it creates a system user named "mihamina-rktmb-org".
The discribed method requires you to install the package "whois", containing "mkpasswd". Dont ask me why.
At the same time, the script will insert an alias entry into an alias flat file. For "mihamina@rktmb.org", it will insert
mihamina: mihamina-rktmb-orgin "/etc/exim4/virtual/rktmb.org".
The BASH script
#!/bin/bash EMAIL=$1 PASS=$2 EXIM_VIRT_DIR="/etc/exim4/virtual/" DOMAINE=$(echo ${EMAIL} | awk -F"@" '{print $2}') LOCALPART=$(echo ${EMAIL} | awk -F"@" '{print $1}') U=$(echo ${EMAIL} | sed 's/\./-/g' | sed 's/@/-/g') CRYPT1_PASS=$(mkpasswd ${PASS}) echo ${EMAIL} echo ${PASS} echo ${DOMAINE} echo ${LOCALPART} echo ${CRYPT1_PASS} echo ${U} useradd \ --home-dir /home/${U} \ --create-home \ --password ${CRYPT1_PASS} \ --shell "/bin/bash" ${U} echo "${LOCALPART}: ${U}" >> ${EXIM_VIRT_DIR}${DOMAINE} invoke-rc.d exim4 restart