2 # Copyright 2006 by Steinar H. Gunderson
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of version 2 (only) of the GNU General Public License
6 # as published by the Free Software Foundation.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 PROGNAME=`basename $0`
17 MODIFIED_CONF_MSG='Default settings modified by devscripts configuration files:'
22 Generate a diff for an NMU and mail it to the BTS.
24 --new Submit a new bug report rather than sending messages
25 to the fixed bugs (default if more than one bug being
26 closed or no bugs being closed)
27 --old Send reports to the bugs which are being closed rather
28 than submit a new bug (default if only one bug being
30 --sendmail=SENDMAILCMD
31 Use SENDMAILCMD instead of \"/usr/sbin/sendmail -t\"
32 --mutt Use mutt to mail the message (default)
33 --no-mutt Mail the message directly, don't use mutt
34 --from=EMAIL Use EMAIL address for message to BTS; defaults to
35 value of DEBEMAIL or EMAIL
36 --delay=DELAY Indicate that the NMU has been uploaded to the
37 DELAYED queue, with a delay of DELAY days; defaults
38 to a placeholder value of "XX". If DELAY is 0 then
39 no reference is made to the DELAYED queue.
40 --no-delay Equivalent to \"--delay=0\"
42 Don't read devscripts config files;
43 must be the first option given
44 --help, -h Show this help information.
45 --version Show version and copyright information.
52 This is $PROGNAME, from the Debian devscripts package, version ###VERSION###
53 This code is copyright 2006 by Steinar H. Gunderson, with modifications
54 copyright 2006 by Julian Gilbey <jdg@debian.org>.
55 The software may be freely redistributed under the terms and conditions
56 of the GNU General Public License, version 2.
60 # Boilerplate: set config variables
61 DEFAULT_NMUDIFF_DELAY="XX"
62 DEFAULT_NMUDIFF_MUTT="yes"
63 DEFAULT_NMUDIFF_NEWREPORT="maybe"
64 DEFAULT_BTS_SENDMAIL_COMMAND="/usr/sbin/sendmail"
65 VARS="NMUDIFF_DELAY NMUDIFF_MUTT NMUDIFF_NEWREPORT BTS_SENDMAIL_COMMAND"
66 # Don't think it's worth including this stuff
67 # DEFAULT_DEVSCRIPTS_CHECK_DIRNAME_LEVEL=1
68 # DEFAULT_DEVSCRIPTS_CHECK_DIRNAME_REGEX='PACKAGE(-.+)?'
69 # VARS="BTS_SENDMAIL_COMMAND DEVSCRIPTS_CHECK_DIRNAME_LEVEL DEVSCRIPTS_CHECK_DIRNAME_REGEX"
71 if [ "$1" = "--no-conf" -o "$1" = "--noconf" ]; then
73 MODIFIED_CONF_MSG="$MODIFIED_CONF_MSG
74 (no configuration files read)"
78 eval "$var=\$DEFAULT_$var"
81 # Run in a subshell for protection against accidental errors
86 eval "$var=\$DEFAULT_$var"
89 for file in /etc/devscripts.conf ~/.devscripts
91 [ -r $file ] && . $file
94 set | egrep '^(NMUDIFF|BTS|DEVSCRIPTS)_')
97 case "$BTS_SENDMAIL_COMMAND" in
98 "") BTS_SENDMAIL_COMMAND=/usr/sbin/sendmail ;;
101 if [ "$NMUDIFF_DELAY" = "XX" ]; then
105 if ! [ "$NMUDIFF_DELAY" -ge 0 ] 2>/dev/null; then
109 case "$NMUDIFF_MUTT" in
111 *) NMUDIFF_MUTT=yes ;;
113 case "$NMUDIFF_NEWREPORT" in
115 *) NMUDIFF_NEWREPORT=maybe ;;
117 # case "$DEVSCRIPTS_CHECK_DIRNAME_LEVEL" in
119 # *) DEVSCRIPTS_CHECK_DIRNAME_LEVEL=1 ;;
125 eval "if [ \"\$$var\" != \"\$DEFAULT_$var\" ]; then
126 MODIFIED_CONF_MSG=\"\$MODIFIED_CONF_MSG
132 if [ -z "$MODIFIED_CONF" ]; then
133 MODIFIED_CONF_MSG="$MODIFIED_CONF_MSG
139 # CHECK_DIRNAME_LEVEL="$DEVSCRIPTS_CHECK_DIRNAME_LEVEL"
140 # CHECK_DIRNAME_REGEX="$DEVSCRIPTS_CHECK_DIRNAME_REGEX"
142 # Need -o option to getopt or else it doesn't work
143 # Removed: --long check-dirname-level:,check-dirname-regex: \
144 TEMP=$(getopt -s bash -o "h" \
145 --long sendmail:,from:,new,old,mutt,no-mutt,nomutt \
146 --long delay:,no-delay,nodelay \
147 --long no-conf,noconf \
148 --long help,version -n "$PROGNAME" -- "$@")
149 if [ $? != 0 ] ; then exit 1 ; fi
156 # --check-dirname-level)
159 # 0|1|2) CHECK_DIRNAME_LEVEL=$1 ;;
160 # *) echo "$PROGNAME: unrecognised --check-dirname-level value (allowed are 0,1,2)" >&2
164 # --check-dirname-regex)
165 # shift; CHECK_DIRNAME_REGEX="$1" ;;
168 if [ "$1" = "XX" ]; then
172 if ! [ "$1" -ge 0 ] 2>/dev/null; then
179 --nodelay|--no-delay)
186 NMUDIFF_NEWREPORT=yes ;;
188 NMUDIFF_NEWREPORT=no ;;
192 "") echo "$PROGNAME: SENDMAIL command cannot be empty, using default" >&2
194 *) BTS_SENDMAIL_COMMAND="$1" ;;
202 echo "$PROGNAME: $1 is only acceptable as the first command-line option!" >&2
204 --help|-h) usage; exit 0 ;;
205 --version) version; exit 0 ;;
207 *) echo "$PROGNAME: bug in option parser, sorry!" >&2 ; exit 1 ;;
213 if [ $# -gt 0 ]; then
214 echo "$PROGNAME takes no non-option arguments;" >&2
215 echo "try $PROGNAME --help for usage information" >&2
219 if [ "$NMUDIFF_MUTT" = yes ] && ! command -v mutt > /dev/null 2>&1; then
220 echo "$PROGNAME: can't find mutt, falling back to sendmail instead" >&2
224 if [ "$NMUDIFF_MUTT" = no ]; then
225 if [ -z "$FROM" ]; then
226 : ${FROMNAME:="$DEBFULLNAME"}
227 : ${FROMNAME:="$NAME"}
229 : ${FROM:="$DEBEMAIL"}
231 if [ -z "$FROM" ]; then
232 echo "$PROGNAME: must set email address either with DEBEMAIL environment variable" >&2
233 echo "or EMAIL environment variable or using --from command line option." >&2
236 if [ -n "$FROMNAME" ]; then
237 # If $FROM looks like "Name <email@address>" then extract just the address
238 if [ "$FROM" = "$(echo "$FROM" | sed -ne '/^\(.*\) *<\(.*\)> *$/p')" ]; then
239 FROM="$(echo "$FROM" | sed -ne 's/^\(.*\) *<\(.*\)> *$/\2/p')"
241 FROM="$FROMNAME <$FROM>"
245 if ! [ -f debian/changelog ]; then
246 echo "nmudiff: must be run from top of NMU build tree!" >&2
250 SOURCE=$( dpkg-parsechangelog | grep ^Source: | cut -d" " -f2 )
251 if [ -z "$SOURCE" ]; then
252 echo "nmudiff: could not determine source package name from changelog!" >&2
256 VERSION=$( dpkg-parsechangelog | grep ^Version: | cut -d" " -f2 )
257 if [ -z "$VERSION" ]; then
258 echo "nmudiff: could not determine source package version from changelog!" >&2
262 CLOSES=$( dpkg-parsechangelog | grep ^Closes: | cut -d" " -f2- )
264 if [ -z "$CLOSES" ]; then
265 # no bug reports, so make a new report in any event
266 NMUDIFF_NEWREPORT=yes
269 if [ "$NMUDIFF_NEWREPORT" = "maybe" ]; then
270 if $(expr match "$CLOSES" ".* " > /dev/null); then
271 # multiple bug reports, so make a new report
272 NMUDIFF_NEWREPORT=yes
278 OLDVERSION=$( sed -n "s/^[^ .][^ ]* (\(.*\)).*$/\1/p" debian/changelog | \
280 if [ -z "$OLDVERSION" ]; then
281 echo "nmudiff: could not determine previous package version from changelog!" >&2
285 VERSION_NO_EPOCH=$( echo "$VERSION" | sed "s/^[0-9]\+://" )
286 OLDVERSION_NO_EPOCH=$( echo "$OLDVERSION" | sed "s/^[0-9]\+://" )
288 if [ ! -r ../${SOURCE}_${OLDVERSION_NO_EPOCH}.dsc ]; then
289 echo "nmudiff: could not read ../${SOURCE}_${OLDVERSION_NO_EPOCH}.dsc" >&2
292 if [ ! -r ../${SOURCE}_${VERSION_NO_EPOCH}.dsc ]; then
293 echo "nmudiff: could not read ../${SOURCE}_${VERSION_NO_EPOCH}.dsc" >&2
298 debdiff ../${SOURCE}_${OLDVERSION_NO_EPOCH}.dsc \
299 ../${SOURCE}_${VERSION_NO_EPOCH}.dsc \
300 > ../${SOURCE}-${VERSION_NO_EPOCH}-nmu.diff || ret=$?
301 if [ $ret -ne 0 ] && [ $ret -ne 1 ]; then
302 echo "nmudiff: debdiff failed, aborting." >&2
303 rm -f ../${SOURCE}-${VERSION_NO_EPOCH}-nmu.diff
307 TO_ADDRESSES_SENDMAIL=""
309 BCC_ADDRESS_SENDMAIL=""
312 if [ "$NMUDIFF_NEWREPORT" = "yes" ]; then
313 TO_ADDRESSES_SENDMAIL="submit@bugs.debian.org"
314 TO_ADDRESSES_MUTT="submit@bugs.debian.org"
315 TAGS="Package: $SOURCE
321 TO_ADDRESSES_SENDMAIL="$TO_ADDRESSES_SENDMAIL,
323 TO_ADDRESSES_MUTT="$TO_ADDRESSES_MUTT $b@bugs.debian.org"
324 if [ "`bts select bugs:$b tag:patch`" != "$b" ]; then
328 if [ "$NMUDIFF_DELAY" != "0" ] && [ "`bts select bugs:$b tag:pending`" != "$b" ]; then
333 TO_ADDRESSES_SENDMAIL=$(echo "$TO_ADDRESSES_SENDMAIL" | tail -n +2)
334 if [ "$TAGS" != "" ]; then
335 TAGS=$(echo "$TAGS" | tail -n +2)
338 BCC_ADDRESS_SENDMAIL="control@bugs.debian.org"
339 BCC_ADDRESS_MUTT="-b control@bugs.debian.org"
343 TMPNAM="$( tempfile )"
345 if [ "$NMUDIFF_DELAY" = "XX" ]; then
347 [Replace XX with correct value]"
350 if [ "$NMUDIFF_DELAY" = "0" ]; then
351 BODY="$(printf "%s\n%s\n" \
352 "I've prepared an NMU for $SOURCE (versioned as $VERSION). The diff" \
353 "is attached to this message.")"
355 BODY="$(printf "%s\n%s\n%s\n" \
356 "I've prepared an NMU for $SOURCE (versioned as $VERSION) and" \
357 "uploaded it to DELAYED/$NMUDIFF_DELAY. Please feel free to tell me if I" \
358 "should delay it longer.")"
361 if [ "$NMUDIFF_MUTT" = no ]; then
362 cat <<EOF > "$TMPNAM"
364 To: $TO_ADDRESSES_SENDMAIL
366 Bcc: $BCC_ADDRESS_SENDMAIL
367 Subject: $SOURCE: diff for NMU version $VERSION
369 X-NMUDIFF-Version: ###VERSION###
380 cat ../${SOURCE}-${VERSION_NO_EPOCH}-nmu.diff >> "$TMPNAM"
381 sensible-editor "$TMPNAM"
382 if [ $? -ne 0 ]; then
383 echo "nmudiff: sensible-editor exited with error, aborting." >&2
384 rm -f ../${SOURCE}-${VERSION_NO_EPOCH}-nmu.diff "$TMPNAM"
389 echo -n "Do you want to go ahead and submit the bug report now? (y/n) "
393 n*) echo "OK, then, aborting." >&2
394 rm -f ../${SOURCE}-${VERSION_NO_EPOCH}-nmu.diff "$TMPNAM"
400 case "$BTS_SENDMAIL_COMMAND" in
401 /usr/sbin/sendmail*|/usr/sbin/exim*)
402 BTS_SENDMAIL_COMMAND="$BTS_SENDMAIL_COMMAND -t" ;;
406 $BTS_SENDMAIL_COMMAND < "$TMPNAM"
408 else # NMUDIFF_MUTT=yes
409 cat <<EOF > "$TMPNAM"
419 mutt -s "$SOURCE: diff for NMU version $VERSION" -i "$TMPNAM" \
420 -e "my_hdr X-NMUDIFF-Version: ###VERSION###" \
421 -a ../${SOURCE}-${VERSION_NO_EPOCH}-nmu.diff $BCC_ADDRESS_MUTT \
422 -- $TO_ADDRESSES_MUTT
426 rm -f ../${SOURCE}-${VERSION_NO_EPOCH}-nmu.diff "$TMPNAM"