commit 96811c0f5ecebfabb7628d6e68bb74c10c41e988 Author: Brennen T. Mazur <dev@brennen.work> Date: Fri, 21 Jun 2024 07:48:45 -0600 Add new email account automation Diffstat:
A | NewEmail.sh | | | 55 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 55 insertions(+), 0 deletions(-)
diff --git a/NewEmail.sh b/NewEmail.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +set -a +newemaillog="${XDG_CONFIG_HOME:-$HOME/.config}/elevate-mail/newuser.log" + +# Define create_username fn, concatenates first and last name strings, returns lowercase value +create_username() { + local fname=$1 + local lname=$2 + echo "${fname}${lname}" | tr '[:upper:]' '[:lower:]' +} + +# TODO CREATE VALUES FROM READ INPUT + +if [[ "$(id -u)" -eq 0 ]] +then + # portable read, read -p and echo -n fail depending on shell + #printf "%s" "Enter first name: " + #read ifname + #printf "%s" "Enter last name: " + #read ilname + # pass values to script.sh + ifname=$1 + ilname=$2 + + # Prompt user for password + printf "%s" "Enter Password: " + read initpass + encpass="$(smtpctl encrypt ${initpass})" + + # create email username from firstname and lastname + emailuser=$(create_username "$ifname" "$ilname") + newaddress="${emailuser}@elev8rehab.com" + + CREDENTIALLINE="${newaddress}:${encpass}:vmail:2000:2000:/var/vmail/elev8rehab.com/${emailuser}::userdb_mail=maildir:/var/vmail/elev8rehab.com/${emailuser}" + # append credential to credential list + chmod u+w /etc/mail/credentials + echo "${CREDENTIALLINE}" >> /etc/mail/credentials + chmod 0440 /etc/mail/credentials + + # create virtual mail account + echo "${newaddress}:vmail" >> /etc/mail/virtuals + + # GENERAL FINAL NOTES + # CHECK IF CAN BE SECURE ECHOING PASS(Plaintext) + #$(mail -b specdir@elev8rehab.com -r "postmaster" -s "Created new Elevate Rehab email user" tech@elev8rehab.com) + echo "Created email: ${newaddress} with pw: ${initpass}" + echo "NOTE YOU MUST ADD USER TO GROUPS MANUALLY RIGHT NOW" + + echo "generated credential line: ${CREDENTIALLINE}" + echo "logging to: ${newemaillog}" +else + echo "needs to be run as root" + exit 1 +fi