[type/__dma_auth] Send messages

This commit is contained in:
Dennis Camera 2020-05-31 15:18:11 +02:00
parent b848fca929
commit 3f72ca1341
2 changed files with 38 additions and 18 deletions

View File

@ -1,20 +1,31 @@
#!/bin/sh -e #!/bin/sh -e
if [ -f "${__object}/parameter/send-test-email" ]; then if test -f "${__object}/parameter/send-test-email"
SEND_EMAIL="YES" then
modified=false
if grep -q '^__mail_alias/root:' "${__messages_in}"
then
modified=true
elif grep -q '^__dma_auth/' "${__messages_in}"
then
modified=true
elif grep -q '^__dma/' "${__messages_in}"
then
modified=true
fi fi
if [ "${SEND_EMAIL}" != "YES" ]; then if $modified
exit 0 then
fi cat <<-EOF
cat <<EOF
sendmail root <<EOM sendmail root <<EOM
Subject: [cdist] Testing root mail on '${__target_host}' Subject: [cdist] Testing mail on '${__target_host}'
You can safely ignore this message, it means your system will notify you You can safely ignore this message. It means your system will notify you
correctly of any relevant messages. correctly of any relevant messages.
Enjoy! Enjoy!
EOM EOM
EOF EOF
fi
fi

View File

@ -43,12 +43,21 @@ in
test -n "${login}" || { echo '--login must be non-empty' >&2; exit 1 } test -n "${login}" || { echo '--login must be non-empty' >&2; exit 1 }
mode=1 mode=1
if test -s "${__object}/explorer/authusers"
then
printf 'set authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out}"
else
printf 'add authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out}"
fi
;; ;;
(absent) (absent)
# no matching logins present -> nothing to do # no matching logins present -> nothing to do
test -s "${__object}/explorer/authusers" || exit 0 test -s "${__object}/explorer/authusers" || exit 0
mode=0 mode=0
printf 'delete authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out}"
;; ;;
(*) (*)
printf 'Invalid --state: %s' "${state_should}" >&2 printf 'Invalid --state: %s' "${state_should}" >&2