monotone

monotone Mtn Source Tree

Root/contrib/monotone-mail-notify.sh

1#! /bin/sh
2
3# Create a file "notify" next to "read-permissions" and ensure
4# its contents are in the same format as "read-permissions",
5# except that the values for allow and deny must be real email
6# addresses. Install the corresponding .lua file in monotone.
7#
8# Call this script from cron or similar to process files
9# generated by the .lua file.
10#
11# Copyright (c) 2007, Matthew Sackman (matthew at wellquite dot org)
12# LShift Ltd (http://www.lshift.net)
13# License: GPLv2 or later
14
15DB="/path/to/a/private/unused/db.mtn"
16MTN="/usr/bin/mtn"
17SERVER="localhost"
18HIGHLIGHT="/usr/bin/source-highlight"
19MIMECONSTRUCT="/usr/bin/mime-construct"
20BASE="/tmp/notify"
21
22function processFile() {
23 local fileBase=$1
24
25 local hdr="$fileBase.hdr.txt"
26 local rev="$fileBase.rev.txt"
27 if [ ! -f $hdr ]
28 then
29echo "Specified header file '$hdr' does not exist"
30exit 1
31 fi
32
33 if [ ! -f $rev ]
34 then
35echo "Specified revision file '$hdr' does not exist"
36exit 1
37 fi
38
39 local revision=$(cat $rev | grep '^revision:' | sed -e 's/^revision:[ ]\+//')
40
41 local parts=()
42 local files=()
43 let fIdx=0
44 let pIdx=0
45 local parents=$($MTN --reallyquiet -d $DB automate parents $revision)
46 if [ "x" == "x$parents" ]
47 then
48local plainDiff="$revision.noparent.diff"
49local htmlDiff="$revision.noparent.html"
50local partFile="$revision.noparent.part"
51files[0]=$plainDiff
52files[1]=$htmlDiff
53parts[0]=$partFile
54$MTN --reallyquiet -d $DB log --diffs --brief --no-graph --from $revision --to $revision > $plainDiff
55cat $plainDiff | $HIGHLIGHT -s diff -f html > $htmlDiff
56$MIMECONSTRUCT --subpart --multipart multipart/alternative \
57 --type text/plain --part-header "Content-Type: text/plain" --encoding quoted-printable --file $plainDiff \
58 --type text/html --encoding quoted-printable --file $htmlDiff \
59 > $partFile
60 else
61for p in $parents
62do
63 local plainDiff="$revision.$p.diff"
64 local htmlDiff="$revision.$p.html"
65 local partFile="$revision.$p.part"
66 files[$fIdx]=$plainDiff
67 files[$fIdx+1]=$htmlDiff
68 let fIdx+=2
69 $MTN --reallyquiet -d $DB diff -r $p -r $revision > $plainDiff
70 cat $plainDiff | $HIGHLIGHT -s diff -f html > $htmlDiff
71 $MIMECONSTRUCT --subpart --multipart multipart/alternative \
72 --type text/plain --part-header "Content-Type: text/plain" --encoding quoted-printable --file $plainDiff \
73 --type text/html --encoding quoted-printable --file $htmlDiff \
74 > $partFile
75 parts[$pIdx]=$partFile
76 let pIdx+=1
77done
78 fi
79
80 local margs=""
81 for p in ${parts[@]}
82 do
83 margs="$margs --subpart-file $p"
84 done
85
86 local hdrargs=$(cat $hdr)
87 $MIMECONSTRUCT --embedded-to --header "$hdrargs" --multipart multipart/mixed \
88--type text/plain --part-header "Content-Type: text/plain" --encoding quoted-printable --file $rev \
89$margs
90
91 for p in ${parts[@]}
92 do
93 rm $p
94 done
95
96 for f in ${files[@]}
97 do
98 rm $f
99 done
100
101 rm $hdr
102 rm $rev
103}
104
105if [ "x" == "x$(ls $BASE)" ]
106then
107 exit 0
108fi
109
110$MTN --reallyquiet -d $DB pull $SERVER '*'
111
112cwd=$(pwd)
113cd $BASE
114
115for f in $(ls $BASE | grep '.hdr.txt$')
116do
117 name=$(basename "$f" '.hdr.txt')
118 processFile "$BASE/$name"
119done
120
121cd "$cwd"

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status