urlwatch: optionalise custom sendmail

This commit is contained in:
Kierán Meinhardt 2019-07-09 20:29:41 +02:00
parent 1d23dceb5d
commit 41a4936144

View File

@ -17,6 +17,8 @@ let
api = { api = {
enable = mkEnableOption "krebs.urlwatch"; enable = mkEnableOption "krebs.urlwatch";
customSendmail.enable = mkEnableOption "krebs.urlwatch.customSendmail";
dataDir = mkOption { dataDir = mkOption {
type = types.str; type = types.str;
default = "/var/lib/urlwatch"; default = "/var/lib/urlwatch";
@ -158,19 +160,21 @@ let
--urls=${shell.escape urlsFile} \ --urls=${shell.escape urlsFile} \
> changes || : > changes || :
if test -s changes; then ${optionalString cfg.customSendmail.enable /* sh */ ''
{ if test -s changes; then
echo Date: $(date -R) {
echo From: ${shell.escape cfg.from} echo Date: $(date -R)
echo Subject: $( echo From: ${shell.escape cfg.from}
sed -n 's/^\(CHANGED\|ERROR\|NEW\): //p' changes \ echo Subject: $(
| tr '\n' ' ' sed -n 's/^\(CHANGED\|ERROR\|NEW\): //p' changes \
) | tr '\n' ' '
echo To: ${shell.escape cfg.mailto} )
echo echo To: ${shell.escape cfg.mailto}
cat changes echo
} | /run/wrappers/bin/sendmail -t cat changes
fi } | /run/wrappers/bin/sendmail -t
fi
''}
''; '';
}; };
}; };