refactoring: split helper functions into smaller scripts (#2420)

This commit is contained in:
Georg Lauterbach 2022-02-21 11:56:57 +01:00 committed by GitHub
parent 2927cc47c7
commit b61dfe1e24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 389 additions and 396 deletions

View file

@ -1,14 +1,14 @@
#! /bin/bash
# shellcheck source=../scripts/helper-functions.sh
. /usr/local/bin/helper-functions.sh
# shellcheck source=../scripts/helpers/index.sh
source /usr/local/bin/helpers/index.sh
MODE="${1}"
USER="${3}"
function usage { echo "Usage: ${0} <add|del|list> <send|receive> [<email@domain.com>]" ; }
[[ -z ${MODE} ]] && errex "missing parameters: <add|del|list> <send|receive> [<email@domain.com>]"
[[ -z ${MODE} ]] && _errex "missing parameters: <add|del|list> <send|receive> [<email@domain.com>]"
case ${2} in
send)
@ -19,7 +19,7 @@ case ${2} in
;;
*)
usage
errex "missing parameters. Specify \"send\" or \"receive\""
_errex "missing parameters. Specify \"send\" or \"receive\""
;;
esac
@ -27,12 +27,12 @@ if [[ -z ${USER} ]] && [[ ${MODE} != list ]]
then
read -r -p "User(user@domain.com): " USER
echo
[[ -z ${USER} ]] && errex "User must not be empty"
[[ -z ${USER} ]] && _errex "User must not be empty"
fi
case ${MODE} in
add)
grep -qi "^$(escape "${USER}")" "${DATABASE}" 2>/dev/null && errex "User \"${USER}\" already denied to ${2} mails"
grep -qi "^$(_escape "${USER}")" "${DATABASE}" 2>/dev/null && _errex "User \"${USER}\" already denied to ${2} mails"
if [[ ! -f ${DATABASE} ]]
then
@ -48,7 +48,7 @@ case ${MODE} in
;;
del)
sed -ie "/^$(escape "${USER}")/d" "${DATABASE}" 2>/dev/null || errex "User \"${USER}\" not found."
sed -ie "/^$(_escape "${USER}")/d" "${DATABASE}" 2>/dev/null || _errex "User \"${USER}\" not found."
;;
list)
@ -56,7 +56,7 @@ case ${MODE} in
;;
*)
usage
errex "missing mode. Specify \"add\", \"del\" or \"list\""
_errex "missing mode. Specify \"add\", \"del\" or \"list\""
;;
esac