summaryrefslogtreecommitdiff
path: root/cmdline/apt-changelog
blob: 6d7c0e95fca2ca219755f1973266f2e971177477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
# Fetch Package changelog for given source or binary package. Send it through
# a pager if stdout is a terminal.
# (C) 2010 Canonical Ltd
# Author: Martin Pitt <martin.pitt@ubuntu.com>

set -e

# evaluate and check CLI argumens
pkg="$1"

if [ -z "$1" -o -n "$3" ]; then
    echo "Usage: $0 <package_name> [ <version> | candidate ]" >&2
    exit 1
fi

version="$2"

# do we want the log for the currently installed version?
if [ -z "$version" ]; then
    if ! dpkgs=`dpkg -s $pkg 2>/dev/null`; then
	echo "ERROR: Package $pkg is not installed; try 'candidate' version for uninstalled packages" >&2
	exit 1
    fi
    version=`echo "$dpkgs" | grep ^Version`
fi

# turn binary package names into source
if src=`apt-cache show $pkg 2>/dev/null| grep -m 1 ^Source:`; then
    pkg=${src#Source: }
fi

# get version and directory
if ! showsrc=`apt-cache showsrc $pkg 2>/dev/null` || [ -z "$showsrc" ] ; then
    echo "ERROR: Source or binary package $pkg does not exist" >&2
    exit 1
fi

if [ "$version" = "candidate" ]; then
    version=`echo "$showsrc"| grep -m 1 ^Version:`
fi

# strip off tag name and epoch
version=${version#Version: }
version=${version#*:}

dir=`echo "$showsrc"| grep ^Directory:`
dir=${dir#Directory: }

# get configuration
eval `apt-config shell SERVER Apt::Changelog::Server`

if [ -z "$SERVER" ]; then
    echo "ERROR: You need to set Apt::Changelog::Server configuration option" >&2
    exit 1
fi

# fetch it
OUT=`mktemp -t "${pkg}.changes.XXXXXX"`
trap "rm $OUT" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
if ! wget -q -O- ${SERVER}/$dir/${pkg}_${version}/changelog > "$OUT"
then
    echo "ERROR: changelog for this version is not (yet) available; try https://launchpad.net/ubuntu/+source/$pkg/+changelog" >&2
    exit 1
fi
sensible-pager "$OUT"