[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

ANN: changelog display thing



Hello world,

A cute crontab entry. It sends pleasant little mails to root giving a
description of any new packages installed/upgraded/removed on the system
during the day. The descriptions are either the output of dpkg -s,
the relevant changelog entries, or "Removed foo" as appropriate.

It needs cron, awk, debianutils and dpkg-dev installed to work.

Copy it into /etc/cron.daily, mark it executable, and that's about it.

Anyway, I think it's quite nice.

Thanks to Clinton Roy for the idea and making the code readable :)

(If someone wants to stick this in a convenient .deb, you're quite
welcome)

(The only problem I've noticed so far is that dpkg-parsechangelog -v
doesn't work so well when the `-v' version doesn't exist, for NMUs,
for example. Don't really know what to do about that)

----
#! /bin/bash
#
# Copyright (c) 1999 Anthony Towns
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

umask 022

PKGSTAT=/var/log/pkgstatus

pkgbreak () {
    echo "============================================================"
    echo
}

if [ -e "$PKGSTAT" ]; then
    mv $PKGSTAT $PKGSTAT.old
fi

cat /var/lib/dpkg/status | 
    awk '/^Package: / { P = $2 } 
         /^Status: / { S = $4 } 
         /^Version: / {
             V = $2;
             if ( S == "installed" ) 
               print P " " V
         }' |
    sort > $PKGSTAT

if ! [ -e $PKGSTAT.old ]; then
	echo "WARNING: Previous list of packages unavailable"
	exit 0
fi

MIDDLE=0
OUTPUT=`tempfile`

diff $PKGSTAT.old $PKGSTAT | 
    awk '/^</ { before[$2] = $3 } 
         /^>/ { after[$2] = $3 } 
         END {
             for (package in before) {
                 if (after[package])
                     print "2U " package " " before[package] " " after[package]
                 else
                     print "3R " package
             }

             for (package in after) {
                 if (!before[package]) 
                     print "1I " package " " after[package]
             } 
         }' |
    sort |
    sed 's/^[123]//' |
    while read act pkg v1 v2
    do 
        if [ "$MIDDLE" = "1" ];
        then
            pkgbreak
        fi
        MIDDLE=1

        if [ "$act" = "R" ]
        # the package was removed
        then 
            echo Removed $pkg
            echo
        elif [ "$act" = "I" ]
        # the package was newly installed
        then
            dpkg -s $pkg
        else
        # the package was upgraded

            if dpkg --compare-versions $v1 ge $v2
            then
                # package was downgraded
                echo "WARNING: $pkg was downgraded from $v1 to $v2"
                echo
            else
                # find out where the documentation for this package is
                # stored. either /usr/doc/$pkg or /usr/share/doc/$pkg
                DOCDIR=/usr/doc/$pkg
                if ! [ -e $DOCDIR ]
                then 
                    DOCDIR=/usr/share/doc/$pkg
                fi

                # if the package is not a debian native pacakge, use
                # the maintainers changelog, otherwise the original
                CL=$DOCDIR/changelog.Debian.gz

                if ! [ -e $CL ]; then
                    CL=$DOCDIR/changelog.gz
                fi

                if [ -e $CL ] 
                then 
                    T=`tempfile`
                    zcat $CL >$T
                    dpkg-parsechangelog -l$T -v$v1
                    echo
                    rm $T
                else 
                    echo "ERROR: Changelog for $pkg not found."
	            echo
                fi
            fi
        fi
    done 2>&1 |
    grep -v "no utmp entry available, using value of LOGNAME" > $OUTPUT

if [ -s $OUTPUT ]; then
    HOSTNAME=`hostname`
    mail -s "$HOSTNAME: changed packages" root < $OUTPUT
fi
rm -f $OUTPUT
----

Cheers,
aj

-- 
Anthony Towns <aj@humbug.org.au> <http://azure.humbug.org.au/~aj/>
I don't speak for anyone save myself. PGP encrypted mail preferred.

       ``There's nothing worse than people with a clue.
             They're always disagreeing with you.'' 
                                 -- Andrew Over

Attachment: pgpa6UNPwPNwo.pgp
Description: PGP signature


Reply to: