Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Aug 1998 00:19:34 +0930
From:      Matthew Thyer <thyerm@camtech.net.au>
To:        "Jordan K. Hubbard" <jkh@time.cdrom.com>
Cc:        Mike Smith <mike@smith.net.au>, committers@FreeBSD.ORG
Subject:   Re: make.conf
Message-ID:  <35E814FE.AA26BD0E@camtech.net.au>
References:  <23567.904356631@time.cdrom.com>

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

Maybe someone can make use of my 'etcud' script for updating the
/etc directory.

It's got a pretty comprehensive set of options and automatically
updates certain types of files. (these would probably have to be
changed).


Jordan K. Hubbard wrote:
> 
> > Agreed.  It's not *impossibly* hard to merge at least some of this
> > stuff; both rc.conf and make.conf are reasonably straightforward.
> > Don't we have any aspiring Perl5 or Tcl weenies out there that would
> > like to make their mark?  8)
> 
> I'll further commit to using any auto-merger tools that people may
> come up with from sysinstall if they make that a comparatively easy
> thing to do.  It's long been on the TODO list, just not done.
> 
> For rc.conf and make.conf, which contains only variable declarations,
> this is actually pretty easy since you really just have to:
> 
> 1. Read in the new file, preserving comments and storing all the
>    name/value pairs in some sort of table (sysinstall actually does
>    this now).
> 
> 2. Read just the name/value pairs from the old file and override
>    any existing values in the table with the previous data.
> 
> 3. Write back out a composite file with comments and updated variable
>    values.
> 
> Erm, right?  I don't see any reason why that wouldn't work unless the
> default value of something has changed and you end up propagating an
> old default value back into your new file.  I guess that's the one
> downside to this approach.
> 
> - Jordan
> 
> >
> > --
> > \\  Sometimes you're ahead,       \\  Mike Smith
> > \\  sometimes you're behind.      \\  mike@smith.net.au
> > \\  The race is long, and in the  \\  msmith@freebsd.org
> > \\  end it's only with yourself.  \\  msmith@cdrom.com
> >
> >

-- 
/=====================================================================\
|Work: Matthew.Thyer@dsto.defence.gov.au | Home: thyerm@camtech.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
--------------6B383DCEA3975B017CDAC09E
Content-Type: text/plain; charset=us-ascii;
 name="etcud"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="etcud"

#!/bin/sh
#
# etcud 2.2 - Compare /etc with /usr/src/etc to check for updated files (for
#                      this machines hardware platform).
#
# etcud [-a] [-v] [-d] [-n] [-t] [-u] [-f] [-s] [-r <directory>] [-i <pattern> | -e <pattern>]
#
# This script compares the MD5 checksums of all 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
#  -u          Automatically update sendmail.cf.additions, files in the periodic
#              directories and files ending with *.dist and *.sample.
#  -f          Pretend you're not running DEVFS (if you are).  i.e. dont ignore
#              files destined to live under the first mounted DEVFS.
#  -s          Dont ignore mismatches on files of the same version (as determined by ident string).
#  -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.
#
#    -  v 2.2 - Now ignores files destined for the first mounted DEVFS found
#          (if using DEVFS - can be turned off with -f)
#
#    -  Version 2.1 - added -u
#
#    -  Version 2.0 - a minor cosmetic fix.
#
#    -  Version 1.9 knows what this platform is when dealing with platform
#         specific directories (e.g. /usr/src/etc/etc.i386).  It ignores
#         subdirectories in /usr/src/etc that start with 'etc.' other than
#         etc.`uname -m`  (by default).
#
#    -  Previous versions were not worth mentioning (including my first attempt
#         sent in as a pr).
#
# AUTHOR:  Matthew Thyer  1997, 1998
#
###############################################################################
# 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"
#
# You shouldn't change this unless you want to make your /etc for another
#   platform (e.g. put PLATFORM=alpha)
PLATFORM=`uname -m`
#
opt_all=0
opt_ver=0
opt_diffs=0
opt_non_exact=0
opt_typical=0
opt_update=0
opt_nodevfs=0
opt_samever=0
opt_inc=0
opt_exc=0
error=0
cmd_name=`basename $0`

usage ()
{
	echo "Usage: $cmd_name [-a] [-v] [-d] [-n] [-t] [-u] [-f] [-s] [-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 "       -u          Automatically update sendmail.cf.additions, files in the periodic directories and files ending with *.dist and *.sample"
	echo "       -f          Dont ignore files destined to live under the first mounted DEVFS found on the system"
	echo "       -s          Dont ignore mismatches on files of the same version (as determined by ident string)"
	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:' $the_file`
	if [ $? -eq 0 ] ; then
		echo "        $the_file VER> $the_ver"
	fi
}

do_check ()
{
# First determine if we should check this file (and what its home is)
	auto_update=0
	case $x in
	etc\.${PLATFORM}/MAKEDEV)
		if [ $devfs_mtpt = /dev ] ; then
			the_file=SKIP
		else
			the_file=/dev/MAKEDEV
		fi
		;;
	etc\.${PLATFORM}/*)
		the_file=/etc/`echo $x | awk -F/ '{print $NF}'`
		;;
	etc\.*/*)
		the_file=SKIP
		;;
	*Makefile)
		the_file=SKIP
		;;
	MAKEDEV\.local)
		if [ $devfs_mtpt = /dev ] ; then
			the_file=SKIP
		else
			the_file=/dev/MAKEDEV.local
		fi
		;;
	mail/sendmail\.cf\.additions)
		auto_update=1
		the_file=/etc/$x
		;;
	*\.dist)
		auto_update=1
		the_file=/etc/$x
		;;
	*\.sample)
		auto_update=1
		the_file=/etc/$x
		;;
	*)
		if [ `echo $x | cut -d/ -f 1` = periodic ] ; then
			auto_update=1
		fi
		the_file=/etc/$x
		;;
	esac
	if [ $the_file != SKIP ] ; then
		if [ -r $the_file ] ; then
			if [ `md5 $the_file | cut -d' ' -f4` != `md5 $src_files/$x | cut -d' ' -f4` ] ; then
				if [ $opt_update -eq 1 -a $auto_update -eq 1 ] ; then
					cp -p $src_files/$x $the_file
				else
					ver1=`grep '$Id:' $src_files/$x`X
					ver2=`grep '$Id:' $the_file`X
					if [ $opt_samever -eq 0 -a \( "$ver1" = "$ver2" \) -a "$ver1" != X ] ; then
					else
						echo MISMATCH for $src_files/$x $the_file
						if [ $opt_ver -eq 1 ] ; then
							show_ver
						fi
						if [ $opt_diffs -eq 1 ] ; then
							diff $the_file $src_files/$x
							echo
						fi
					fi
				fi
			elif [ $opt_all -eq 1 ] ; then
				echo CHECK OK for $src_files/$x $the_file
				if [ $opt_ver -eq 1 ] ; then
					show_ver
				fi
			fi
		else # the file is not readable.... why ? perhaps it doesn't exist
			if [ ! -f $the_file ] ; then
				echo NONEXISTANT $the_file.  Maybe you should cp -p $src_files/$x $the_file
			else
				echo -n $the_file is not readable.
			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
	;;
	-u)	opt_update=1
	;;
	-f)	opt_nodevfs=1
	;;
	-s)	opt_samever=1
	;;
	-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

# Now check if running DEVFS (and whether to ignore it [-f]).
devfs_mtpt=`mount | grep "^devfs on /" | head -1 | awk '{print $3}'`
devfs_mtpt=${devfs_mtpt:-NO}
if [ $opt_nodevfs -eq 1 ] ; then
	devfs_mtpt=NO
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

--------------6B383DCEA3975B017CDAC09E--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?35E814FE.AA26BD0E>