Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Aug 1997 00:29:25 +0930
From:      Matthew Thyer <thyerm@box.net.au>
To:        freebsd-current@FreeBSD.ORG
Subject:   Keeping your /etc directory up to date.
Message-ID:  <33F46ECC.5FF69529@box.net.au>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------A220918225F8DFB68062F26C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I saw the need so I wrote the attached script.

Read the comments at the top of the script but basically the bourne
shell script "etcud"
(meaning /etc update) does a comparison between /usr/src/etc and /etc
with MD5
checksums.  It will optionally show you RCS version id's, diffs between
files, and all
files (not only those where the MD5 checksums mismatch).  One of the
best features
is the ability to specify an egrep exclusion or inclusion pattern for
file names.  And there
is also option -t for typical usage which excludes common files which
are bound to
mismatch the MD5 checksum comparison.

I seriously think this script should be run by people after each make
world like:
"etcud -t -v".

Anyway, here is the usage:

Usage: etcud [-a] [-v] [-d] [-n] [-t] [-r <dir>] [-i <patt> | -e <patt>]

       -a          Also output information for files where the checksums
match
       -v          Display RCS version strings if present
       -d          Display diffs between the files
       -n          Non-exact mode - i.e. dont use '-x' with egrep
       -t          Typical usage.  This is the same as etcud -e
"group|hosts|motd|shells|rc.local|master.passwd"
       -r <dir>    Directory where the source distribution is found
       -i <patt>   Inclusion filename pattern (those files to check)
       -e <patt>   Exclusion filename pattern (those file to ignore)

And here is some sample output for my -CURRENT upgrade from
ctm-src-cur.2947
to ctm-src-cur.3002:

matte: {34} etcud -t -v
MD5 check FAILED for /usr/src/etc/etc.i386/rc.i386 /etc/etc.i386/rc.i386

/usr/src/etc/etc.i386/rc.i386 VER> #    $Id: rc.i386,v 1.29 1997/07/06
07:19:12 peter Exp $
        /etc/etc.i386/rc.i386 VER> #    $Id: rc.i386,v 1.28 1997/06/02
06:43:52 markm Exp $
MD5 check FAILED for /usr/src/etc/mtree/BSD.var.dist
/etc/mtree/BSD.var.dist
/usr/src/etc/mtree/BSD.var.dist VER> #  $Id: BSD.var.dist,v 1.31
1997/07/29 11:23:14 ache Exp $
        /etc/mtree/BSD.var.dist VER> #  $Id: BSD.var.dist,v 1.30
1997/05/03 20:15:15 jkh Exp $
MD5 check FAILED for /usr/src/etc/mtree/BSD.local.dist
/etc/mtree/BSD.local.dist
/usr/src/etc/mtree/BSD.local.dist VER> #     $Id: BSD.local.dist,v 1.30
1997/08/01 13:16:39 phk Exp $
        /etc/mtree/BSD.local.dist VER> #     $Id: BSD.local.dist,v 1.28
1997/06/10 07:55:10 asami Exp $
MD5 check FAILED for /usr/src/etc/mtree/BSD.usr.dist
/etc/mtree/BSD.usr.dist
/usr/src/etc/mtree/BSD.usr.dist VER> #  $Id: BSD.usr.dist,v 1.94
1997/08/01 13:16:40 phk Exp $
        /etc/mtree/BSD.usr.dist VER> #  $Id: BSD.usr.dist,v 1.91
1997/06/04 10:51:09 asami Exp $
MD5 check FAILED for /usr/src/etc/namedb/make-localhost
/etc/namedb/make-localhost
MD5 check FAILED for /usr/src/etc/aliases /etc/aliases
/usr/src/etc/aliases VER> #     $Id: aliases,v 1.5 1997/08/09 14:58:49
phk Exp $
        /etc/aliases VER> #     $Id: aliases,v 1.4 1997/06/29 23:09:07
wosch Exp $
MD5 check FAILED for /usr/src/etc/amd.map /etc/amd.map
MD5 check FAILED for /usr/src/etc/hosts.lpd /etc/hosts.lpd
MD5 check FAILED for /usr/src/etc/login.access /etc/login.access
MD5 check FAILED for /usr/src/etc/netstart /etc/netstart
/usr/src/etc/netstart VER> #    $Id: netstart,v 1.52 1997/07/05 19:35:45
pst Exp $
        /etc/netstart VER> #    $Id: netstart,v 1.51 1997/05/18 20:11:44
jkh Exp $
MD5 check FAILED for /usr/src/etc/rpc /etc/rpc
MD5 check FAILED for /usr/src/etc/ttys /etc/ttys
MD5 check FAILED for /usr/src/etc/Makefile /etc/Makefile
/usr/src/etc/Makefile VER> #    $Id: Makefile,v 1.154 1997/08/02
00:22:44 davidn Exp $
        /etc/Makefile VER> #    $Id: Makefile,v 1.151 1997/06/04
03:58:52 asami Exp $
MD5 check FAILED for /usr/src/etc/csh.login /etc/csh.login
MD5 check FAILED for /usr/src/etc/inetd.conf /etc/inetd.conf
MD5 check FAILED for /usr/src/etc/rc /etc/rc
/usr/src/etc/rc VER> #  $Id: rc,v 1.133 1997/07/13 13:22:15 jkh Exp $
        /etc/rc VER> #  $Id: rc,v 1.131 1997/06/25 11:48:47 pst Exp $
MD5 check FAILED for /usr/src/etc/security /etc/security
/usr/src/etc/security VER> #    $Id: security,v 1.21 1997/08/01 01:25:21
brian Exp $
        /etc/security VER> #    $Id: security,v 1.20 1997/03/03 07:03:50
mpp Exp $
MD5 check FAILED for /usr/src/etc/rc.conf /etc/rc.conf
/usr/src/etc/rc.conf VER> #     $Id: rc.conf,v 1.20 1997/07/06 08:28:34
peter Exp $
        /etc/rc.conf VER> #     $Id: rc.conf,v 1.19 1997/06/24 22:36:42
dima Exp $
MD5 check FAILED for /usr/src/etc/login.conf /etc/login.conf
/usr/src/etc/login.conf VER> #  $Id: login.conf,v 1.13 1997/07/11
22:11:13 guido Exp $
        /etc/login.conf VER> #  $Id: login.conf,v 1.12 1997/05/23
12:46:52 ache Exp $
MD5 check FAILED for /usr/src/etc/rc.network /etc/rc.network
/usr/src/etc/rc.network VER> #  $Id: rc.network,v 1.9 1997/07/06
00:33:34 pst Exp $
        /etc/rc.network VER> #  $Id: rc.network,v 1.8 1997/05/19
07:46:48 jkh Exp $
/etc/rc.shutdown does not exist!


--
/=====================================================================\
|  Work: Matthew.Thyer@dsto.defence.gov.au | Home: thyerm@box.net.au  |
\=====================================================================/
"If it is true that our Universe has a zero net value for all conserved
quantities, then it may simply be a fluctuation of the vacuum of some
larger space in which our Universe is imbedded. In answer to the
question of why it happened, I offer the modest proposal that our
Universe is simply one of those things which happen from time to time."
 E. P. Tryon   from "Nature" Vol.246 Dec.14, 1973



--------------A220918225F8DFB68062F26C
Content-Type: text/plain; charset=us-ascii; name="etcud"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="etcud"

#!/bin/sh
#
# etcud 1.3 - Compare /etc with /usr/src/etc to check for updated files
#
# etcud [-a] [-v] [-d] [-n] [-t] [-r <directory>] [-i <pattern> | -e <pattern>]
#
# This script compares the MD5 checksums of files found in the etc
# directory of the source distribution (/usr/src/etc by default) with
# those in /etc to alert you when /etc files need updating.
#
# Options:
#
#  -a          Also output information for files where the checksums match.
#  -v          Display RCS version strings if present.
#  -d          Display diffs between the files.
#  -n          Non-exact mode.  i.e. dont use '-x' with egrep for inclusion
#              and exclusion patterns.  For power users only!
#  -t          Typical usage.  This is the same as etcud -e $DEF_EXCL
#  -r <dir>    Set the root directory of the source distribution.
#  -i <patt>   Inclusion filename pattern (those files to check).
#  -e <patt>   Exclusion filename pattern (those file to ignore).
#
# Inclusion and exclusion patterns must be an egrep pattern which is a list
#    of file names separated by the pipe character.  The filenames must be
#    relative to the etc directory of the source distribution (/usr/src/etc
#    by default).
#
# By default the script will use egrep -x which means the patterns must
#    exactly match for the files to be included or excluded.  This is
#    generally what you want as you probably want to be able to type
#    "etcud -e hosts" to exclude the file /etc/hosts but not the file
#    /etc/hosts.lpd.  Power users can use -n to disable the use of -x
#    with egrep.  This can be useful when dealing with the ppp directory
#    for example.
#
# NOTES
#    -  You can use EITHER an exclusion OR an inclusion file pattern, not
#       both.  Subsequent uses will be ignored with a warning.
#
#    -  Use of the typical option (-t) will run etcud with the default
#       exclusion pattern, set at $DEF_EXCL below.  This mode overrides
#       any previously specified inclusion or exclusion patterns with a
#       warning.  This mode also silently ignores -n.
#
# AUTHOR:  Matthew Thyer 3 August 1997
#
###############################################################################
# The default directory for the source distribution
DEF_SRC_ROOT=/usr/src
# The typical exclusion list
DEF_EXCL="group|hosts|motd|shells|rc.local|master.passwd"
#
opt_all=0
opt_ver=0
opt_diffs=0
opt_non_exact=0
opt_typical=0
opt_inc=0
opt_exc=0
error=0
cmd_name=`basename $0`

usage ()
{
	echo "Usage: $cmd_name [-a] [-v] [-d] [-n] [-t] [-r <dir>] [-i <patt> | -e <patt>]"
	echo "       -a          Also output information for files where the checksums match"
	echo "       -v          Display RCS version strings if present"
	echo "       -d          Display diffs between the files"
	echo "       -n          Non-exact mode - i.e. dont use '-x' with egrep"
	echo "       -t          Typical usage.  This is the same as etcud -e \"$DEF_EXCL\""
	echo "       -r <dir>    Directory where the source distribution is found"
	echo "       -i <patt>   Inclusion filename pattern (those files to check)"
	echo "       -e <patt>   Exclusion filename pattern (those file to ignore)"
}

show_ver ()
{
	the_ver=`grep '$Id:' $src_files/$x`
	if [ $? -eq 0 ] ; then
		echo "$src_files/$x VER> $the_ver"
	fi
	the_ver=`grep '$Id:' /etc/$x`
	if [ $? -eq 0 ] ; then
		echo "        /etc/$x VER> $the_ver"
	fi
}

do_check ()
{
	if [ -r /etc/$x ] ; then
		if [ `md5 /etc/$x | cut -d' ' -f4` != `md5 $src_files/$x | cut -d' ' -f4` ] ; then
			echo MD5 check FAILED for $src_files/$x /etc/$x
			if [ $opt_ver -eq 1 ] ; then
				show_ver
			fi
			if [ $opt_diffs -eq 1 ] ; then
				diff $src_files/$x /etc/$x
				echo
			fi
		elif [ $opt_all -eq 1 ] ; then
			echo MD5 check PASSED for $src_files/$x /etc/$x
			if [ $opt_ver -eq 1 ] ; then
				show_ver
			fi
		fi
	else # the file is not readable.... why ? perhaps it doesn't exist
		if [ ! -f /etc/$x ] ; then
			echo /etc/$x does not exist!
		else
			echo -n /etc/$x is not readable....
			if [ `id -u` -ne 0 ] ; then
				echo perhaps you should be ROOT!
			else
				echo for some strange reason!!!
			fi
		fi
	fi
}

# The main program begins.....

# First get the options
while [ $# -ne 0 ] ; do
	case $1 in
	-a)	opt_all=1
	;;
	-v)	opt_ver=1
	;;
	-d)	opt_diffs=1
	;;
	-n)	opt_non_exact=1
	;;
	-t)	opt_typical=1
		if [ $opt_inc -eq 1 -o $opt_exc -eq 1 ] ; then
			echo "Warning: Typical usage overriding prior inclusion or exclusion pattern"
			opt_inc=0
		fi
		opt_exc=1
		patt=$DEF_EXCL
	;;
	-r)	shift
		if [ $# -eq 0 ] ; then
			error=1
			echo "Error: -r requires an argument"
			usage
			break
		else
			if [ -d $1 ] ; then
				SRC_ROOT=$1
			else
				error=1
				echo "Error: Source directory \"$1\" does not exist"
				usage
				break
			fi
		fi
	;;
	-i)	shift
		if [ $# -eq 0 ] ; then
			error=1
			echo "Error: -i requires an argument"
			usage
			break
		else
			if [ $opt_inc -eq 1 -o $opt_exc -eq 1 ] ; then
				echo "Warning: subsequent inclusion pattern ignored"
			else
				patt=$1
				opt_inc=1
			fi
		fi
	;;
	-e)	shift
		if [ $# -eq 0 ] ; then
			error=1
			echo "Error: -e requires an argument"
			usage
			break
		else
			if [ $opt_inc -eq 1 -o $opt_exc -eq 1 ] ; then
				echo "Warning: subsequent exclusion pattern ignored"
			else
				patt=$1
				opt_exc=1
			fi
		fi
	;;
	*)	error=1
		usage
		break
	;;
	esac
	shift
done

if [ $error -eq 1 ] ; then
	exit
fi

src_files=`echo ${SRC_ROOT:=$DEF_SRC_ROOT}/etc | sed 's/\/\/$//'`
cd $src_files

# Can only do non_exact mode if we are not doing a typical
egrep_flags="-x"
if [ $opt_non_exact -eq 1 -a $opt_typical -eq 0 ] ; then
	egrep_flags=""
fi

if [ $opt_exc -eq 1 ] ; then
	egrep_flags=$egrep_flags" -v "
fi

if [ $opt_inc -eq 1 -o $opt_exc -eq 1 ] ; then
	find . -type f -exec echo {} \; | sed 's/^\.\///' | egrep $egrep_flags $patt | while read x ; do
		do_check
	done
else
	find . -type f -exec echo {} \; | sed 's/^\.\///' | while read x ; do
		do_check
	done
fi

--------------A220918225F8DFB68062F26C--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?33F46ECC.5FF69529>