]> git.saurik.com Git - apt.git/blob - cmdline/apt-changelog
merged from debian-sid
[apt.git] / cmdline / apt-changelog
1 #!/bin/sh
2 # Fetch Package changelog for given source or binary package. Send it through
3 # a pager if stdout is a terminal.
4 # (C) 2010 Canonical Ltd
5 # Author: Martin Pitt <martin.pitt@ubuntu.com>
6
7 set -e
8
9 # evaluate and check CLI argumens
10 pkg="$1"
11
12 if [ -z "$1" -o -n "$3" ]; then
13 echo "Usage: $0 <package_name> [ <version> | candidate ]" >&2
14 exit 1
15 fi
16
17 version="$2"
18
19 # do we want the log for the currently installed version?
20 if [ -z "$version" ]; then
21 if ! dpkgs=`dpkg -s $pkg 2>/dev/null`; then
22 echo "ERROR: Package $pkg is not installed; try 'candidate' version for uninstalled packages" >&2
23 exit 1
24 fi
25 version=`echo "$dpkgs" | grep ^Version`
26 fi
27
28 # turn binary package names into source
29 if src=`apt-cache show $pkg 2>/dev/null| grep -m 1 ^Source:`; then
30 pkg=${src#Source: }
31 fi
32
33 # get version and directory
34 if ! showsrc=`apt-cache showsrc $pkg 2>/dev/null` || [ -z "$showsrc" ] ; then
35 echo "ERROR: Source or binary package $pkg does not exist" >&2
36 exit 1
37 fi
38
39 if [ "$version" = "candidate" ]; then
40 version=`echo "$showsrc"| grep -m 1 ^Version:`
41 fi
42
43 # strip off tag name and epoch
44 version=${version#Version: }
45 version=${version#*:}
46
47 dir=`echo "$showsrc"| grep ^Directory:`
48 dir=${dir#Directory: }
49
50 # get configuration
51 eval `apt-config shell SERVER Apt::Changelog::Server`
52
53 if [ -z "$SERVER" ]; then
54 echo "ERROR: You need to set Apt::Changelog::Server configuration option" >&2
55 exit 1
56 fi
57
58 # fetch it
59 OUT=`mktemp -t "${pkg}.changes.XXXXXX"`
60 trap "rm $OUT" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
61 if ! wget -q -O- ${SERVER}/$dir/${pkg}_${version}/changelog > "$OUT"
62 then
63 echo "ERROR: changelog for this version is not (yet) available; try https://launchpad.net/ubuntu/+source/$pkg/+changelog" >&2
64 exit 1
65 fi
66 sensible-pager "$OUT"
67