Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Pondelok, 23. jún 2025

Súbor: [Platon] / scripts / shell / Mix / packages-log.sh (stiahnutie)

Revízia 1.6, Tue Mar 16 19:51:04 2004 UTC (21 years, 3 months ago) by rajo


Zmeny od 1.5: +1 -1 [lines]

Changed email address from <8host AT pauli.fmph.uniba.sk> to <rajo AT platon.sk>

#!/bin/bash

# Author:      Lubomir Host 'rajo' <rajo AT platon.sk>
#
# 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


Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok