summaryrefslogtreecommitdiffstats
path: root/files/reprepro/custom/notify-incoming/reprepro-notify-incoming-changes
blob: e8446e4f2e9e36bf0f78609e8da4a77563b5f0ca (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
32
33
#!/bin/sh
set -eu

. /etc/default/reprepro-notify-incoming-changes

if [ -z "$MAILFROM" ]; then
	echo "Config error in /etc/default/reprepro-notify-incoming-changes: missing MAILFROM"
	exit 2
fi
if [ -z "$MAILTO" ]; then
        echo "Config error in /etc/default/reprepro-notify-incoming-changes: missing MAILTO"
        exit 3
fi
if [ -z "$REPREPRODIR" ]; then
        echo "Config error in /etc/default/reprepro-notify-incoming-changes: missing REPREPRODIR"
        exit 4
fi

CHANGES_FILE="${REPREPRODIR}${1}"

if [ ! -f "${CHANGES_FILE}" ]; then
	echo "Changes file ${CHANGES_FILE} does not exist."
	exit 5
fi

HOSTNAME=$(/bin/hostname --fqdn)
SUBJECT="Notification of incoming .changes file on $HOSTNAME"
CHANGES_CONTENT="$(cat ${CHANGES_FILE})"
UPLOADER="$(cat ${CHANGES_FILE} | sed -nr 's/Changed-By:\ .*<(.*)>/\1/p')"

printf 'From: %s\nTo: %s\nCc: %s\nSubject: %s\n%s' "$MAILFROM" "$MAILTO" "$UPLOADER" "$SUBJECT" "$CHANGES_CONTENT" | /usr/sbin/sendmail -t

printf 'Incoming change detected: %s\n' "$CHANGES_FILE"