MIT krb5-1.6 HACK patch
[metze/wireshark/wip.git] / tools / gen-bugnote
1 #!/bin/bash
2 #
3 # Given a Wireshark bug ID, fetch its title and prepare an entry suitable
4 # for pasting into the release notes. Requires curl, grep, and sed.
5 #
6 # Usage: gen-bugnote <bug number>
7 #
8 # $Id$
9 #
10 # Copyright 2013 Gerald Combs
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
25 #
26
27 output_fmt="docbook"
28 if [ -f release-notes.asciidoc -o -f docbook/release-notes.asciidoc ] ; then
29     output_fmt="asciidoc"
30 fi
31
32 while getopts "o:" OPT ; do
33     case $OPT in
34         o) output_fmt=$OPTARG
35         ;;
36     esac
37 done
38 shift $(($OPTIND - 1))
39
40 bz_url_pfx="https://bugs.wireshark.org/bugzilla/show_bug.cgi?id="
41 bug_id="$1"
42
43 recode_cmd="cat"
44 hash recode > /dev/null 2>&1 && recode_cmd="recode html..utf8"
45
46 case "$OSTYPE" in
47     darwin*)
48         clipboard_cmd="pbcopy -Pascii"
49         ;;
50     cygwin*)
51         clipboard_cmd="cat > /dev/clipboard"
52         ;;
53     linux*)
54         clipboard_cmd="xsel --clipboard"
55         ;;
56     *)
57         echo "Unable to copy to clipboard"
58         clipboard_cmd="cat > /dev/null"
59         ;;
60 esac
61
62 if [ -z "$bug_id" ] ; then
63     echo "Usage: " `basename $0` " <bug id>"
64     exit 1
65 fi
66
67 bug_title=`
68     curl -s -o - "https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=$bug_id" |
69     grep -i '<title>' |
70     sed \
71         -e 's:.*<title>.*ndash; ::' \
72         -e 's:</title>.*::' \
73         -e 's/[^\.]$/&./' \
74     `
75
76 case "$output_fmt" in
77     asciidoc)
78         echo -e "* $bug_title (ws-buglink:$bug_id[])\n" \
79                 | $recode_cmd \
80                 | $clipboard_cmd
81     ;;
82     docbook)
83 $clipboard_cmd <<Fin
84         <listitem><para>
85           $bug_title
86           (<ulink url="https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=$bug_id">Bug
87           $bug_id</ulink>)
88         </para></listitem>
89
90 Fin
91     ;;
92 esac
93
94 echo "Copied $bug_id: $bug_title"