chiark / gitweb /
devscripts (2.10.69+squeeze4) stable-security; urgency=high
[devscripts.git] / scripts / who-uploads.sh
1 #! /bin/bash
2
3 # who-uploads sourcepkg [ sourcepkg ... ]
4 # Tells you who made the latest uploads of a source package.
5 # NB: I'm encoded in UTF-8!!
6
7 # Written and copyright 2006 by Julian Gilbey <jdg@debian.org> 
8 # Based on an original script
9 # copyright 2006 Adeodato Simó <dato@net.com.org.es>
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23
24 PROGNAME=`basename $0`
25 MODIFIED_CONF_MSG='Default settings modified by devscripts configuration files:'
26
27 usage () {
28     echo \
29 "Usage: $PROGNAME [options] package ...
30   Display the most recent three uploaders of each package.
31   Packages should be source packages, not binary packages.
32
33   Options:
34     -M, --max-uploads=N
35                       Display at most the N most recent uploads (default: 3)
36     --keyring KEYRING Add KEYRING as a GPG keyring for Debian Developers'
37                       keys in addition to /usr/share/keyrings/debian-keyring.*
38                       and /usr/share/keyrings/debian-maintainers.gpg;
39                       this option may be given multiple times
40     --no-default-keyrings
41                       Do not use the default keyrings
42     --no-conf, --noconf
43                       Don't read devscripts config files;
44                       must be the first option given
45     --date            Display the date of the upload
46     --no-date, --nodate
47                       Don't display the date of the upload (default)
48     --help            Show this message
49     --version         Show version and copyright information
50
51 $MODIFIED_CONF_MSG"
52 }
53
54 version () {
55     echo \
56 "This is $PROGNAME, from the Debian devscripts package, version ###VERSION###
57 This code is copyright 2006 by Julian Gilbey <jdg@debian.org>,
58 all rights reserved.
59 Based on original code copyright 2006 Adeodato Simó <dato@net.com.org.es>
60 This program comes with ABSOLUTELY NO WARRANTY.
61 You are free to redistribute this code under the terms of the
62 GNU General Public License, version 2 or later."
63 }
64
65
66 # Boilerplate: set config variables
67 DEFAULT_WHOUPLOADS_KEYRINGS=/usr/share/keyrings/debian-keyring.gpg:/usr/share/keyrings/debian-keyring.pgp:/usr/share/keyrings/debian-maintainers.gpg
68 DEFAULT_WHOUPLOADS_MAXUPLOADS=3
69 DEFAULT_WHOUPLOADS_DATE=no
70 VARS="WHOUPLOADS_KEYRINGS WHOUPLOADS_MAXUPLOADS WHOUPLOADS_DATE"
71
72 if [ "$1" = "--no-conf" -o "$1" = "--noconf" ]; then
73     shift
74     MODIFIED_CONF_MSG="$MODIFIED_CONF_MSG
75   (no configuration files read)"
76
77     # set defaults
78     for var in $VARS; do
79         eval "$var=\$DEFAULT_$var"
80     done
81 else
82     # Run in a subshell for protection against accidental errors
83     # in the config files
84     eval $(
85         set +e
86         for var in $VARS; do
87             eval "$var=\$DEFAULT_$var"
88         done
89
90         for file in /etc/devscripts.conf ~/.devscripts
91           do
92           [ -r $file ] && . $file
93         done
94
95         set | grep "^WHOUPLOADS_")
96
97     # check sanity
98     if [ "$WHOUPLOADS_MAXUPLOADS" != \
99             "$(echo \"$WHOUPLOADS_MAXUPLOADS\" | tr -cd 0-9)" ]; then
100         WHOUPLOADS_MAXUPLOADS=3
101     fi
102
103     WHOUPLOADS_DATE="$(echo "$WHOUPLOADS_DATE" | tr A-Z a-z)"
104     if [ "$WHOUPLOADS_DATE" != "yes" ] && [ "$WHOUPLOADS_DATE" != "no" ]; then
105         WHOUPLOADS_DATE=no
106     fi
107
108     # don't check WHOUPLOADS_KEYRINGS here
109
110     # set config message
111     MODIFIED_CONF=''
112     for var in $VARS; do
113         eval "if [ \"\$$var\" != \"\$DEFAULT_$var\" ]; then
114             MODIFIED_CONF_MSG=\"\$MODIFIED_CONF_MSG
115   $var=\$$var\";
116         MODIFIED_CONF=yes;
117         fi"
118     done
119
120     if [ -z "$MODIFIED_CONF" ]; then
121         MODIFIED_CONF_MSG="$MODIFIED_CONF_MSG
122   (none)"
123     fi
124 fi
125
126 MAXUPLOADS=$WHOUPLOADS_MAXUPLOADS
127 WANT_DATE=$WHOUPLOADS_DATE
128
129 OIFS="$IFS"
130 IFS=:
131 declare -a GPG_DEFAULT_KEYRINGS
132
133 for keyring in $WHOUPLOADS_KEYRINGS; do
134     if [ -f "$keyring" ]; then
135         GPG_DEFAULT_KEYRINGS=("${GPG_DEFAULT_KEYRINGS[@]}" "--keyring" "$keyring")
136     elif [ -n "$keyring" ]; then
137         echo "Could not find keyring $keyring, skipping it" >&2
138     fi
139 done
140 IFS="${OIFS:-   }"
141
142 declare -a GPG_KEYRINGS
143
144 # Command-line options
145 TEMP=$(getopt -s bash -o 'h' \
146         --long max-uploads:,keyring:,no-default-keyrings \
147         --long no-conf,noconf \
148         --long date,nodate,no-date \
149         --long help,version \
150         --options M: \
151         -n "$PROGNAME" -- "$@")
152 if [ $? != 0 ] ; then exit 1 ; fi
153
154 eval set -- $TEMP
155
156 # Process Parameters
157 while [ "$1" ]; do
158     case $1 in
159     --max-uploads|-M)
160         shift
161         if [ "$1" = "$(echo \"$1\" | tr -cd 0-9)" ]; then
162             MAXUPLOADS=$1
163         fi
164         ;;
165     --keyring)
166         shift
167         if [ -f "$1" ]; then
168             GPG_KEYRINGS=("${GPG_KEYRINGS[@]}" "--keyring" "$1")
169         else
170             echo "Could not find keyring $1, skipping" >&2
171         fi
172         ;;
173     --no-default-keyrings)
174         GPG_DEFAULT_KEYRINGS=( ) ;;
175     --no-conf|--noconf)
176         echo "$PROGNAME: $1 is only acceptable as the first command-line option!" >&2
177         exit 1 ;;
178     --date) WANT_DATE=yes ;;
179     --no-date|--nodate) WANT_DATE=no ;;
180     --help|-h) usage; exit 0 ;;
181     --version) version; exit 0 ;;
182     --) shift; break ;;
183     *) echo "$PROGNAME: bug in option parser, sorry!" >&2 ; exit 1 ;;
184     esac
185     shift
186 done
187
188 # Some useful abbreviations for gpg options
189 GPG_NO_KEYRING="--no-options --no-auto-check-trustdb --no-default-keyring --keyring /dev/null"
190 GPG_OPTIONS="--no-options --no-auto-check-trustdb --no-default-keyring"
191
192 if [ $# -eq 0 ]; then
193     usage;
194     exit 1
195 fi
196
197 # Now actually get the reports :)
198
199 for package; do
200     echo "Uploads for $package:"
201
202     prefix=$(echo $package | sed -re 's/^((lib)?.).*$/\1/')
203     pkgurl="http://packages.qa.debian.org/${prefix}/${package}.html"
204     baseurl="http://packages.qa.debian.org/${prefix}/"
205
206     # only grab the actual "Accepted" news announcements; hopefully this
207     # won't pick up many false positives
208     WGETOPTS="-q -O - --timeout=30 "
209     count=0
210     for news in $(wget $WGETOPTS $pkgurl |
211                   sed -ne 's%^.*<a href="\('$package'/news/[0-9A-Z]*\.html\)">Accepted .*%\1%p'); do
212         HTML_TEXT=$(wget $WGETOPTS "$baseurl$news")
213         GPG_TEXT=$(echo "$HTML_TEXT" |
214                    sed -ne 's/^<pre>//; /-----BEGIN PGP SIGNED MESSAGE-----/,/-----END PGP SIGNATURE-----/p')
215
216         test -n "$GPG_TEXT" || continue
217
218         VERSION=$(echo "$GPG_TEXT" | awk '/^Version/ { print $2; exit }')
219         DISTRO=$(echo "$GPG_TEXT" | awk '/^Distribution/ { print $2; exit }')
220         if [ "$WANT_DATE" = "yes" ]; then
221             DATE=$(echo "$HTML_TEXT" |  sed -ne 's%<li><em>Date</em>: \(.*\)</li>%\1%p')
222         fi
223
224         GPG_ID=$(echo "$GPG_TEXT" | LC_ALL=C gpg $GPG_NO_KEYRING --verify 2>&1 |
225                  sed -rne 's/.*ID ([0-9A-Z]+).*/\1/p')
226
227         UPLOADER=$(gpg $GPG_OPTIONS \
228                    "${GPG_DEFAULT_KEYRINGS[@]}" "${GPG_KEYRINGS[@]}" \
229                    --list-key --with-colons $GPG_ID 2>/dev/null |
230                    awk  -F: '/@debian\.org>/ { a = $10; exit} /^pub/ { a = $10 } END { print a }' )
231         if [ -z "$UPLOADER" ]; then UPLOADER="<unrecognised public key ($GPG_ID)>"; fi
232
233         output="$VERSION to $DISTRO: $UPLOADER" 
234         [ "$WANT_DATE" = "yes" ] && output="$output on $DATE"
235         echo $output | iconv -c -f UTF-8
236
237         count=$(($count + 1))
238         [ $count -eq $MAXUPLOADS ] && break
239     done
240     test $# -eq 1 || echo
241 done
242
243 exit 0