commit feb1dea6559334d70f2d8cb071346fcf9bd36d61 parent c3c0bfdfdfca0b5dcc0edc5e5ba1ef67d7c0c56e Author: Petar Yotsev <petar@yotsev.xyz> Date: Tue, 14 Dec 2021 11:23:26 +0000 Fix bug: wrong conditions for utilities Diffstat:
M | files/madduser | | | 35 | +++++++++++++++++++++-------------- |
M | files/mdeluser | | | 23 | ++++++++++++++--------- |
M | files/mpasswd | | | 26 | ++++++++++++++++---------- |
3 files changed, 51 insertions(+), 33 deletions(-)
diff --git a/files/madduser b/files/madduser @@ -1,23 +1,30 @@ #!/bin/sh -[ $# != 2 ] && -echo "Error: Invalid number of arguments" && -echo "Usage: madduser DOMAIN USERNAME" +if [ $# != 2 ] then + echo "Error: Invalid number of arguments" + echo "Usage: madduser DOMAIN USERNAME" + return 1 +fi domain=$1 user=$2 -grep "$domain" /etc/mail/domains > /dev/null || -echo "Error: Invalid domain" && -echo "Info: It should be one of the following:" && -cat /etc/mail/domains && -return 1 - -grep "^$user@$domain" /etc/mail/credentials > /dev/null || -echo "Error: User already exists in /etc/mail/credentials" && return 1 - -grep "^$user@$domain" /etc/mail/virtuals > /dev/null || -echo "Error: User already exists in /etc/mail/virtuals" && return 1 +if [ -z $(grep "$domain" /etc/mail/domains 2> /dev/null) ] then + echo "Error: Invalid domain" + echo "Info: It should be one of the following:" + cat /etc/mail/domains + return 1 +fi + +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 + echo "Error: User already exists in /etc/mail/virtuals" + return 1 +fi echo -n "Password: " stty -echo diff --git a/files/mdeluser b/files/mdeluser @@ -7,17 +7,22 @@ echo "Usage: mdeluser DOMAIN USERNAME" domain=$1 user=$2 -grep "$domain" /etc/mail/domains > /dev/null || -echo "Error: Invalid domain" && -echo "Info: It should be one of the following:" && -cat /etc/mail/domains && -return 1 +if [ -z $(grep "$domain" /etc/mail/domains 2> /dev/null) ] then + echo "Error: Invalid domain" + echo "Info: It should be one of the following:" + cat /etc/mail/domains + return 1 +fi -grep "^$user@" /etc/mail/credentials > /dev/null || -echo "Error: User already exists" && return 1 +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 -grep "^$user@" /etc/mail/virtuals > /dev/null || -echo "Error: User already exists in /etc/mail/virtuals" && return 1 +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 echo -n "Delete records for user \"$user\"? (yes/no): " && read responce && diff --git a/files/mpasswd b/files/mpasswd @@ -7,16 +7,22 @@ echo "Usage: mpasswd DOMAIN USERNAME" domain=$1 user=$2 -grep "$domain" /etc/mail/domains > /dev/null || -echo "Error: Invalid domain" && -echo "Info: It should be one of the following:" && -cat /etc/mail/domains && -return 1 - -grep "^$user@$domain" /etc/mail/credentials > /dev/null && -grep "^$user@$domain" /etc/mail/virtuals > /dev/null || -echo "Error: Invalid username" && -return 1 +if [ -z $(grep "$domain" /etc/mail/domains 2> /dev/null) ] then + echo "Error: Invalid domain" + echo "Info: It should be one of the following:" + cat /etc/mail/domains + return 1 +fi + +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 + echo "Error: User doesn't exist in /etc/mail/virtuals" + return 1 +fi echo -n "Password: " stty -echo