This file is indexed.

/usr/share/monotone/scripts/monotone-mail-notify is in monotone-extras 1.1-7.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#! /usr/bin/env bash

# Install the corresponding .lua file in monotone.  Its
# comments holds instructions on how to configure this
# notification system.
#
# Call this script from cron or similar to process files
# generated by the .lua file.
#
# Copyright (c) 2007, Matthew Sackman (matthew at wellquite dot org)
#                     LShift Ltd (http://www.lshift.net)
# Copyright (c) 2010, Richard Levitte <richard@levitte.org)
# License: GPLv2 or later

MTN="mtn"
HIGHLIGHT="source-highlight"
MIMECONSTRUCT="mime-construct"
BASE="/var/spool/monotone"

if [ -n "$1" ]; then BASE="$1"; fi

function processFile() {
    local fileBase=$1

    local dat="$fileBase.dat.txt"
    local hdr="$fileBase.hdr.txt"
    local rev="$fileBase.rev.txt"
    if [ ! -f $hdr ]
    then
	echo "Specified header file '$hdr' does not exist"
	exit 1
    fi

    if [ ! -f $rev ]
    then
	echo "Specified revision file '$rev' does not exist"
	exit 1
    fi

    if [ ! -f $dat ]
    then
	echo "Specified data file '$dat' does not exist"
	exit 1
    fi

    local server=
    local keydir=
    local key=
    . $dat
    # There must ALWAYS be a key, but it's possible to set things up to
    # allow for the null key.
    key="--key=$key";

    local mtn_cmd="$MTN -q -q --no-workspace --no-standard-rcfiles --keydir=$keydir $key automate remote --remote-stdio-host=$server --"

    local revision=$(cat $rev | grep '^revision:' | sed -e 's/^revision:[ ][ ]*//')

    local parts=()
    local files=()
    let fIdx=0
    let pIdx=0
    local parents=$($mtn_cmd parents $revision)
    if [ "x" = "x$parents" ]
    then
	local plainDiff="$revision.noparent.diff"
	local htmlDiff="$revision.noparent.html"
	local partFile="$revision.noparent.part"
	files[0]=$plainDiff
	files[1]=$htmlDiff
	parts[0]=$partFile

	local fn
	local content_id
	local l
	$mtn_cmd 2>/dev/null get_revision $revision | while read l; do
	    set $l;
	    case $1 in
		add_file)
		    fn=$(echo "$2" | cut -f2 -d'"')
		    content_id=
		    ;;
		content)
		    content_id=$(echo "$2" | cut -f2 -d'[' | cut -f1 -d']')
		    ;;
	    esac
	    if [ -n "$fn" -a -n "$content_id" ]; then
		(
		    $mtn_cmd 2>/dev/null get_file $content_id > ".tmp.$fn"
		    local lcnt=$(wc -l < ".tmp.$fn")
		    echo "============================================================"
		    echo "--- /dev/null	"
		    echo "+++ $fn	$content_id"
		    case $lcnt in
			0)
			    ;;
			1)
			    echo "@@ -0,0 +1 @@"
			    ;;
			*)
			    echo "@@ -0,0 +1,$lcnt @@"
			    ;;
		    esac
		    cat ".tmp.$fn" | sed -e 's/^/+/'
		    rm ".tmp.$fn"
		) > $plainDiff
		fn=
		content=
	    fi
	done
	cat $plainDiff | $HIGHLIGHT -s diff -f html > $htmlDiff
	$MIMECONSTRUCT --subpart --multipart multipart/alternative \
	    --type text/plain --part-header "Content-Type: text/plain" --encoding quoted-printable --file $plainDiff \
	    --type text/html --encoding quoted-printable --file $htmlDiff \
	    > $partFile
    else
	for p in $parents
	do
	  local plainDiff="$revision.$p.diff"
	  local htmlDiff="$revision.$p.html"
	  local partFile="$revision.$p.part"
	  files[$fIdx]=$plainDiff
	  files[$fIdx+1]=$htmlDiff
	  let fIdx+=2
	  $mtn_cmd 2>/dev/null content_diff --revision=$p --revision=$revision > $plainDiff
	  cat $plainDiff | $HIGHLIGHT -s diff -f html > $htmlDiff
	  $MIMECONSTRUCT --subpart --multipart multipart/alternative \
	      --type text/plain --part-header "Content-Type: text/plain" --encoding quoted-printable --file $plainDiff \
	      --type text/html --encoding quoted-printable --file $htmlDiff \
	      > $partFile
	  parts[$pIdx]=$partFile
	  let pIdx+=1
	done
    fi

    local margs=""
    for p in ${parts[@]}
    do
      margs="$margs --subpart-file $p"
    done

    local hdrargs=$(cat $hdr)
    $MIMECONSTRUCT --embedded-to --header "$hdrargs" --multipart multipart/mixed \
	--type text/plain --part-header "Content-Type: text/plain" --encoding quoted-printable --file $rev \
	$margs

    for p in ${parts[@]}
    do
      rm $p
    done

    for f in ${files[@]}
    do
      rm $f
    done

    rm $dat
    rm $hdr
    rm $rev
}

if [ "x" = "x$(ls $BASE)" ]
then
    echo >&2 "monotone-mail-notify: no files in $BASE, exiting"
    exit 0
fi

cwd=$(pwd)
if cd $BASE; then

    mkdir -p .notify.redo
    mkdir .notify.lock || \
	(echo 'Mail notifier locked by another process'; exit 1) && \
	(
	while [ -d .notify.redo ]; do
            rmdir .notify.redo
	    ls | grep '\.hdr\.txt$' | while read f
	    do
		name=$(basename "$f" '.hdr.txt')
		processFile "$name"
	    done
	done
	rmdir .notify.lock
    )

fi
cd "$cwd"