#!/bin/bash # Author: Lubomir Host 'rajo' # # Description: Use this script if you will be noticed about changes # in installation of packages in your system. # You may put sufropiate line to your crontab. # # Usage: Use ./packages-log.sh --help to see help message # # $Id: packages-log.sh,v 1.6 2004/03/16 19:51:04 rajo Exp $ # Security options !!! umask 077 previous() { if [ "x$1" = "x" ] ; then echo "`date --date '1 days ago' '+%Y%m%d'`" else echo "`date --date \"$1 days ago\" '+%Y%m%d'`" fi } usage() { cat << EOF Usage: ./packages-log.sh [-d DIR] [--suffix SUFFIX] [--daily] --daily Silently exit if today logfile already exists, don't remove old logfiles. --directory=DIR Set output directory to DIR. --suffix=SUFFIX Add suffix to logfiles. Use this if you wish keep some logfiles. Parameter is added to the name of logfile. EOF exit 1; } directory="." suffix="" # Cmdline parsing {{{ for option do # If the previous option needs an argument, assign it. if test -n "$prev"; then eval "$prev=\$option" prev= continue fi case "$option" in -*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) optarg= ;; esac case "$option" in --daily | --dail | --dai | --da | \ -daily | -dail | -dai | -da) daily="yes" ;; --daily=* | --dail=* | --dai=* | --da=* | \ -daily=* | -dail=* | -dai=* | -da=*) daily="$optarg" ;; --directory | --director | --directo | --direct | --direc | --dire | \ --dir | --di | \ -directory | -director | -directo | -direct | -direc | -dire | \ -dir | -di) prev=directory ;; --directory=* | --director=* | --directo=* | --direct=* | --direc=* | --dire=* | \ --dir=* | --di=* | \ -directory=* | -director=* | -directo=* | -direct=* | -direc=* | -dire=* | \ -dir=* | -di=*) directory="$optarg" ;; --suffix | --suffi | --suff | --suf | --su | --s | -s) prev=suffix ;; --suffix=* | --suffi=* | --suff=* | --suf=* | --su=* | --s=* | -s=*) suffix="$optarg" ;; --help | --hel | --he | --h | -h | \ -help | -hel | -he | -h | -h) usage ;; -*) { echo "error: $option: invalid option; use --help to show usage" 1>&2; exit 1; } ;; esac done # Cmdline parsing }}} LOG="$directory/`previous 0`$suffix" PREVIOUS_LOG="$directory/`previous 1`$suffix" OLD_LOG="$directory/`previous 2`$suffix" DIFF_LOG="$directory/`previous 1`-`previous 0`$suffix.diff" # if argument '--daily' is specified, silently exit if $LOG already exists if [ ! -z "$daily" ]; then if [ -f "$LOG" ]; then exit; fi fi # If you have 'dpkg', probably you are on Linux Debian. # If dpkg not found (or not executable), use rpm # (Linux Mandrake, RedHat, etc.. probably doesn't have dpkg) if [ -z "`which dpkg`" ]; then PACKAGER="rpm -qa" else PACKAGER="dpkg -l" fi # save today's list of packages $PACKAGER > "$LOG" # compare with previous log if [ -f "$LOG" -a -f "$PREVIOUS_LOG" ]; then diff -u "$PREVIOUS_LOG" "$LOG" > "$DIFF_LOG" fi # print diferences if any and delete empty file if [ -s "$DIFF_LOG" ]; then cat "$DIFF_LOG"; else rm -f "$DIFF_LOG" fi # remove old log if '--daily' parameter is NOT specified if [ -z "$daily" ]; then rm -f "$OLD_LOG" fi # Modeline for ViM # vim600: fdm=marker fdl=0