dockcheck/notify_templates/notify_smtp.sh

72 lines
2.3 KiB
Bash
Raw Normal View History

2024-01-05 20:42:25 +01:00
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
NOTIFY_SMTP_VERSION="v0.1"
# INFO: ssmtp is depcerated - consider to use msmtp instead.
2024-01-05 20:42:25 +01:00
#
# Copy/rename this file to notify.sh to enable the notification snipppet.
# mSMTP/sSMTP has to be installed and configured manually.
2024-01-06 17:29:35 +01:00
# Modify to fit your setup - changing SendMailFrom, SendMailTo, SubjectTag
2024-01-05 20:42:25 +01:00
MSMTP=$(which msmtp)
SSMTP=$(which ssmtp)
2024-10-10 09:48:41 +02:00
if [ -n "$MSMTP" ] ; then
MailPkg=$MSMTP
elif [ -n "$SSMTP" ] ; then
MailPkg=$SSMTP
else
echo "No msmtp or ssmtp binary found in PATH: $PATH" ; exit 1
fi
2024-01-05 20:42:25 +01:00
FromHost=$(hostname)
2025-02-10 19:46:23 +01:00
trigger_notification() {
2024-01-06 17:29:35 +01:00
# User variables:
SendMailFrom="me@mydomain.tld"
SendMailTo="me@mydomain.tld"
SubjectTag="dockcheck"
$MailPkg $SendMailTo << __EOF
2024-01-05 20:42:25 +01:00
From: "$FromHost" <$SendMailFrom>
date:$(date -R)
To: <$SendMailTo>
2025-02-10 19:46:23 +01:00
Subject: [$SubjectTag] $MessageTitle $FromHost
2024-01-05 20:42:25 +01:00
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
2024-10-10 10:22:17 +02:00
$MessageBody
2024-01-05 20:42:25 +01:00
__EOF
}
2025-02-10 19:46:23 +01:00
send_notification() {
[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
printf "\nSending email notification.\n"
MessageTitle="Updates available on"
# Setting the MessageBody variable here.
printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n\n$UpdToString"
trigger_notification
}
2025-02-15 13:35:47 +01:00
### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
2025-02-10 19:46:23 +01:00
### to not send notifications when dockcheck itself has updates.
dockcheck_notification() {
printf "\nSending email dockcheck notification.\n"
MessageTitle="New version of dockcheck available on"
# Setting the MessageBody variable here.
printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_smtp.sh"
LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_SMTP_VERSION/s/NOTIFY_SMTP_VERSION=//p" | tr -d '"')"
if [[ "$NOTIFY_SMTP_VERSION" != "$LatestNotifyRelease" ]] ; then
printf -v NotifyUpdate "\n\nnotify_smtp.sh update avialable:\n $NOTIFY_SMTP_VERSION -> $LatestNotifyRelease\n"
MessageBody="${MessageBody}${NotifyUpdate}"
fi
2025-02-10 19:46:23 +01:00
trigger_notification
}