mmv

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

commit 650bf0cd58c05853e0d39ca90db21ec15c31da65
parent 7d7961e5ef459f0618b7e5134a31000329f1cd7c
Author: Petar Yotsev <petar@yotsev.xyz>
Date:   Tue, 14 Dec 2021 12:25:41 +0000

Fix utilities

Diffstat:
Mfiles/madduser | 4++--
Mfiles/mdeluser | 6+++---
Mfiles/mpasswd | 9++++-----
3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/files/madduser b/files/madduser @@ -16,12 +16,12 @@ if [ -z "$(grep "$domain" /etc/mail/domains 2> /dev/null)" ]; then return 1 fi -if [ -n "$(grep "$user@$domain" /etc/mail/credentials 2> /dev/null)" ]; then +if [ -n "$(grep "^$user@$domain" /etc/mail/credentials 2> /dev/null)" ]; then echo "Error: User already exists in /etc/mail/credentials" return 1 fi -if [ -n "$(grep "$user@$domain" /etc/mail/virtuals 2> /dev/null)" ]; then +if [ -n "$(grep "^$user@$domain" /etc/mail/virtuals 2> /dev/null)" ]; then echo "Error: User already exists in /etc/mail/virtuals" return 1 fi diff --git a/files/mdeluser b/files/mdeluser @@ -16,7 +16,7 @@ if [ -z "$(grep "$domain" /etc/mail/domains 2> /dev/null)" ]; then return 1 fi -if [ -z "$(grep "$user@$domain" /etc/mail/credentials 2> /dev/null)" ]; then +if [ -z "$(grep "^^$user@$domain" /etc/mail/credentials 2> /dev/null)" ]; then echo "Error: User doesn't exist in /etc/mail/credentials" return 1 fi @@ -29,9 +29,9 @@ fi echo -n "Delete records for user \"$user\"? (yes/no): " && read responce && [ $responce = "yes" ] && -sed "/$user@$domain/d" /etc/mail/credentials > temp-cred-file && +sed "/^$user@$domain/d" /etc/mail/credentials > temp-cred-file && mv temp-cred-file /etc/mail/credentials && -sed "/$user@$domain/d" /etc/mail/virtuals > temp-virt-file && +sed "/^$user@$domain/d" /etc/mail/virtuals > temp-virt-file && mv temp-virt-file /etc/mail/virtuals && echo -n "Delete all mail associated with user \"$user\"? (yes/no): " && diff --git a/files/mpasswd b/files/mpasswd @@ -16,12 +16,12 @@ if [ -z "$(grep "$domain" /etc/mail/domains 2> /dev/null)" ]; then return 1 fi -if [ -z "$(grep "$user@$domain" /etc/mail/credentials 2> /dev/null)" ]; then +if [ -z "$(grep "^$user@$domain" /etc/mail/credentials 2> /dev/null)" ]; then echo "Error: User doesn't exist in /etc/mail/credentials" return 1 fi -if [ -z "$(grep "$user@$domain" /etc/mail/virtuals 2> /dev/null)" ]; then +if [ -z "$(grep "^$user@$domain" /etc/mail/virtuals 2> /dev/null)" ]; then echo "Error: User doesn't exist in /etc/mail/virtuals" return 1 fi @@ -34,6 +34,5 @@ stty echo record="$(smtpctl encrypt "$password")" record="$user@$domain:$record:vmail:2000:2000:/var/vmail/$domain/$user::userdb_mail=maildir:/var/vmail/$domain/$user" -sed "s#^$user@$domain.*#$record#g" - -echo "$record" >> /etc/mail/credentials +sed "s#^$user@$domain.*#$record#g" > temp-cred-file +mv temp-cred-file /etc/mail/credentials