moved getopts up

This commit is contained in:
Matthew Saunders Brown 2021-02-11 14:21:45 -08:00
parent bb87bf83f1
commit 198afdfd63

View File

@ -21,33 +21,6 @@ help()
exit
}
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
dbcmdopts="-e"
dbquery="SELECT vm_aliases.alias, vm_mboxes.mbox, vm_domains.domain FROM vm_aliases, vm_mboxes, vm_domains WHERE vm_aliases.mbox_id = vm_mboxes.id AND vm_mboxes.domain_id = vm_domains.id"
# check for and set alias search term(s)
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
elif [[ ! $1 =~ ^- ]] ; then
searchterm=$1
shift
if [[ $searchterm =~ "@" ]] ; then
alias=${searchterm%@*}
domain=${searchterm##*@}
if ! vmail::validate_domain $domain; then
echo "ERROR: $searchterm is not a valid email address."
exit
fi
elif vmail::validate_domain $searchterm; then
domain=$searchterm
else
echo "ERROR: $searchterm is not a valid search term."
help
fi
fi
fi
# set any options that were passed
while getopts "achs" opt; do
case "${opt}" in
@ -69,6 +42,35 @@ while getopts "achs" opt; do
esac
done
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
dbcmdopts="-e"
dbquery="SELECT vm_aliases.alias, vm_mboxes.mbox, vm_domains.domain FROM vm_aliases, vm_mboxes, vm_domains WHERE vm_aliases.mbox_id = vm_mboxes.id AND vm_mboxes.domain_id = vm_domains.id"
# check for and set alias search term(s)
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
elif [[ ! $1 =~ ^- ]] ; then
searchterm=$1
shift
if [[ $searchterm =~ "@" ]] ; then
alias=${searchterm%@*}
domain=${searchterm##*@}
if ! vmail::validate_domain $domain; then
echo "ERROR: $searchterm is not a valid email address."
exit 1
fi
elif vmail::validate_domain $searchterm; then
domain=$searchterm
else
echo "ERROR: $searchterm is not a valid search term."
help
fi
fi
fi
# build query
if [ -n "$domain" ]; then
# add specific domain