Here, unpolished, is a script I used to use to
determine what changes I had made to an rpm-based
system. It requires a least light editing
(line 45, 49, and 52 at a minimum)
to run on CentOS; probably won't hurt anything.


#! /bin/bash
# Charles Polisher 2003-10-05

#
# Summarize the key facts about the currently installed packages
# in a form useful for building a host with the same complement
# of packages. Creates 3 lists:
#   - the original install package list,
#   - packages that have been (upgraded/downgraded/added) 
#     but are from the same distributor
#   - packages that have been added from another distribution
#     or from free-standing rpm's

# TODO: identify packages built from tarballs, and either
#   - installed a new program not available in the distro, or
#     avail from the distro but not sourced from it.
#   - installed a program that was available from the distro,
#     but was (upgraded/downgraded/patched/built-from-source)
#     nonetheless.
#   Maybe build a list of all libraries / executables in
#   /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin,
#   /lib, /usr/lib, /usr/local/lib, (etc?), then run through
#   rpm's official list (rpm -qal) using it to delete from
#   the first list. Anything remaining is unaccounted for by
#   the rpmdb, and may represent an "outboard" package.
#   Note that the file versions/dates will need to be checked,
#   and the possibility of multiple versions of the same
#   program should be handled.

# DISTRO value ( matches key used in "DISTRIBUTION" field of RPMs)
export DISTRO=SuSE

# Package installed later than this are designated as upgrades,
# not part of the original installation. Format: YYYY-MM-DD 
export INSTALL_FINAL="2002-09-03"

# Reports directory, omit trailing /
export OUTDIR=/home/chas/ADMIN/LOGS/rpm


export DATE=/bin/date
export GREP=/usr/bin/egrep
export SORT=/usr/bin/sort
export RPM=/bin/rpm
export TEE=/usr/bin/tee
export AWK=/usr/bin/awk
export CAT=/bin/cat
export RM=/bin/rm

# --------- no changes below this line -------------------

export L_DATE=`${DATE} +%Y-%m-%d-%H%M`
export EVENT=`date +%s --date="${INSTALL_FINAL}"`
export TMPFILE=`mktemp /tmp/awkscript.XXXXXX`

#
# RPM formatted output fields are in this order: 
#
# Installtime  Cookie         Name Epoch  Ver Fstate  Packager  Distribution
# ------------ -------------- ---- ------ --- ------  --------- ------------
# 1054517704   rags.suse 1018 rpm  none)  3.0 0       k...@suse.de SuSE Linux 8
# ------------ -------------- ---- ------ --- ------  --------- ------------
# Field 1      Field 3        F 5  F7     F9  F11     Field 13  Field 15
#    
export FORMAT='%-30{INSTALLTIME} %-30{COOKIE} %-30{NAME} %-5{EPOCH} 
%-30{VERSION}  %-30{FILESTATES} %-30{PACKAGER} %-30{DISTRIBUTION}\n'

cat << "EOS" > ${TMPFILE}
BEGIN { FIELDWIDTHS="30 1 30 1 30 1 5 1 30 1 30 1 30 1 30";   
}
{ 
        # FIXME:         SuSE -> ${DISTRO}
        a =  match($15, /SuSE /) == 0 ? 0 : 1
        if ( a != filter ) {
                printf("name: %-20s version: %-10s epoch: %-8s installed: %s 
packager: %-20s distro: %-15s\n", \
                substr( $5,1,20),                                               
\
                  substr( $9,1,10),                                             
\
                    substr( $7,1, 6),                                   \
                      strftime("%Y-%m-%d %H:%M",$1),    \
                        substr($13,1,20),                               \
                          substr($15,1,15)                              \
                );
        }
}
EOS

${RPM}    -qa --queryformat "${FORMAT}" \
| ${AWK}  -f ${TMPFILE} filter=0                \
| ${SORT}                                                               \
> ${OUTDIR}/packages-installed-all-${DISTRO}-${L_DATE}.out

${RPM}    -qa --queryformat "${FORMAT}" \
| ${AWK}  -f ${TMPFILE} filter=1                \
| ${SORT}                                                               \
>  ${OUTDIR}/packages-installed-non-${DISTRO}-${L_DATE}.out

${RM}     ${TMPFILE}

cat << "EOS" > ${TMPFILE}
BEGIN { FIELDWIDTHS="30 1 30 1 30 1 5 1 30 1 30 1 30 1 30";   
                print "Packages installed after " eventdate ":" ;
}
{ 
        if ( ( $1 > eventdate ) && ( match($15, /SuSE /) > 0 ) ) {
                printf("name: %-20s version: %-10s epoch: %-8s installed: %s 
packager: %-20s distro: %-15s\n", \
                substr( $5,1,20),                                               
\
                  substr( $9,1,10),                                             
\
                    substr( $7,1, 6),                                   \
                      strftime("%Y-%m-%d %H:%M",$1),    \
                        substr($13,1,20),                               \
                          substr($15,1,15)                              \
                );
        }
}
EOS

${RPM}    -qa --queryformat "${FORMAT}"         \
| ${AWK}  -f ${TMPFILE} eventdate=${EVENT}      \
| ${SORT}                                                                       
\
> ${OUTDIR}/packages-upgraded------${DISTRO}-${L_DATE}.out

${RM}     ${TMPFILE}

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

Reply via email to