summaryrefslogtreecommitdiffstats
path: root/share/hooks/notification-mail
blob: 8033c01e7c6eaf1b866db89cbfd536686e8a7623 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh

set -e

if echo "${OPTIONS}" | grep -qs "\--no-notification"
then
	exit 0
fi

case "${COMMAND}" in
	create|remove|rm|restart|start|stop)
		DATE="$(date +%Y-%m-%d\ %H:%M:%S)"
		HOST="$(hostname -f)"
		USER="${SUDO_USER:-${USER}}"

		TMPFILE="$(mktemp ${SOFTWARE}.XXXXXX)"

cat >> "${TMPFILE}" << EOF
From: ${SOFTWARE} <${USER}@${HOST}>
To: root@localhost
Subject: [${SOFTWARE}] ${PROGRAM} ${COMMAND}

${DATE}
${USER}@${HOST}
${PROGRAM} ${COMMAND} ${OPTIONS}
EOF

		cat "${TMPFILE}" | /usr/sbin/sendmail -t
		rm -f "${TMPFILE}"
		;;
esac