#!/bin/sh
# $Id: cfmsr,v 1.4 2000/04/11 17:13:55 dmetz Exp $
# $crtd:  by  Derald Metzger  on  990831 $
# $cmnt:  Make a cm status report based on cfm & rpm derived info.
#   Data files holding output from cfmh, cfmd, and cfmv are rqd.
#   The recommended dir for these files is /cm/cfm/status.
#   Names assumed for the files are: `hostname`_<d|h|v>.
#   The cfmds, cfmhs, and cfmvs cmds will create these files.
#           Copyright (c) 1998 1999  Derald Metzger 
#  This file is part of the cfm pkg (GPL).
# $

base=`basename $0`
dbr_flg=1                # report cfmd data
dir=.                    # Default data file dir for source
[ -d $CFMROOT/status ] && dir=$CFMROOT/status
[ -n "$CFM_STAT_DIR" ] && dir=$CFM_STAT_DIR
echo=/bin/echo
hnam=`hostname`          # hostname from cfmrc
hr_flg=1                 # report cfmh data
vf_flg=1                 # report cfmv data

usage="
NAME
  cfmsr - cfm & rpm based cm status report
SYNOPSIS
  cfmsr -D dir [-d] [-h] [-v] { . | host [...] }
DESCR
  Make a cm status report based on data files output from the
  cfmd, cfmh, and cfmv cmds. The 1st two cmds identify config
  file discrepancies using lists based on existing host files and
  on existing cfm database files respectively. The cfmv cmd 
  reports discrepancies for installed files which are not config
  files. You can use the combined output of these cmds to guarantee
  that the installed software present on one or more hosts is what
  its supposed to be and nothing more. When it isn't you can use
  one or more of the previous cmds to examine the differences in 
  more detail.
OPTIONS
  -D dir - data files dir. Default is cwd overridden by \$CFMROOT/status 
           then by \$CFM_STAT_DIR, then by cmdline opt -D
  -d     - report cfmd status
  -h     - report cfmh status
  -v     - report cfmv status
  .      - report for the executing host
  host   - report for host list
ALSO
  See also cfm(8), cfmd(8), cfmds, cfmh(8), cfmhs, cfmdb(8), cfmsr(8),
  cfmv(8), cfmvs, rcsintro(1), doc/cfm*/*
AUTHORS
           Copyright (c) 1998 1999  Derald Metzger 
  This file is part of the cfm pkg (GPL).
"

while getopts D:dhv c; do
  case $c in
    D) dir=$OPTARG ;;
    d) dbr_flg=0 ;;
    h) hr_flg=0 ;;
    v) vf_flg=0 ;;
  esac
done
shift `expr $OPTIND - 1`

if [ $# -lt 1 ]; then $echo "### $base: insufficient args $usage"; exit 1; fi

# Go to data files dir
cd $dir || (echo "### $base: Can't access dir $dir! Exiting" && exit 1)

hosts=$*
[ $1 = . ]  && hosts=$hnam

if [ $dbr_flg -ne 0 ]; then echo \
"================  DATABASE relative reports  ============================
==    Errs reported here are for missing files or uncaptured changes."
  for host in $hosts; do tail -1 ${host}_d; done
fi
if [ $hr_flg -ne 0 ]; then echo \
"================  HOST relative reports  ================================
==    Errs reported here are for uncontrolled files or uncaptured changes."
  for host in $hosts; do tail -1 ${host}_h; done
fi
if [ $vf_flg -ne 0 ]; then echo \
"================  VERIFY (filtered) reports  ============================
==    Errs reported here are for uncontrolled changes to file params."
  for host in $hosts; do tail -1 ${host}_v; done
fi
