Review request for new port: sysutils/etcupdate

John Baldwin jhb at freebsd.org
Thu Jul 8 21:50:07 UTC 2010


This is a port for yet-another-/etc-merging tool that I wrote recently.  It
passes portlint -N with one bogus warning because /etc is in the comment.

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	.
#	./src
#	./src/etcupdate.sh
#	./src/etcupdate.8
#	./pkg-descr
#	./Makefile
#	./pkg-descr~
#
echo c - .
mkdir -p . > /dev/null 2>&1
echo c - ./src
mkdir -p ./src > /dev/null 2>&1
echo x - ./src/etcupdate.sh
sed 's/^X//' >./src/etcupdate.sh << '0aaf160dc5a25428702b4e8ff7be2998'
X#!/bin/sh -e
X#
X# Copyright (c) 2010 Advanced Computing Technologies LLC
X# Written by: John H. Baldwin <jhb at FreeBSD.org>
X# All rights reserved.
X#
X# Redistribution and use in source and binary forms, with or without
X# modification, are permitted provided that the following conditions
X# are met:
X# 1. Redistributions of source code must retain the above copyright
X#    notice, this list of conditions and the following disclaimer.
X# 2. Redistributions in binary form must reproduce the above copyright
X#    notice, this list of conditions and the following disclaimer in the
X#    documentation and/or other materials provided with the distribution.
X#
X# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
X# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
X# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X# SUCH DAMAGE.
X#
X# $FreeBSD$
X
X# This is a tool to manage updating files that are not updated as part
X# of 'make installworld' such as files in /etc.  Unlike other tools,
X# this one is specifically tailored to assisting with mass upgrades.
X# To that end it does not require user intervention while running.
X#
X# Theory of operation:
X#
X# The most reliable way to update changes to files that have local
X# modifications is to perform a three-way merge between the original
X# unmodified file, the new version of the file, and the modified file.
X# This requires having all three versions of the file available when
X# performing an update.
X#
X# To that end, etcupdate uses a strategy where the current unmodified
X# tree is kept in WORKDIR/current and the previous unmodified tree is
X# kept in WORKDIR/old.  When performing a merge, a new tree is built
X# if needed and then the changes are merged into DESTDIR.  Any files
X# with unresolved conflicts after the merge are left in a tree rooted
X# at WORKDIR/conflicts.
X#
X# To provide extra flexibility, etcupdate can also build tarballs of
X# root trees that can later be used.  It can also use a tarball as the
X# source of a new tree instead of building it from /usr/src.
X
X# Global settings.  These can be adjusted by config files and in some
X# cases by command line options.
X
X# TODO:
X# - automatable conflict resolution
X# - a 'revert' command to make a file "stock"
X# - invoke /etc/rc.d/motd if /etc/motd changes?
X
Xusage()
X{
X	cat <<EOF
Xusage: etcupdate [-nBF] [-d workdir] [-r | -s source | -t tarball] [-A patterns]
X                 [-D destdir] [-I patterns] [-L logfile] [-M options]
X       etcupdate build [-B] [-d workdir] [-s source] [-L logfile] [-M options]
X                 <tarball>
X       etcupdate diff [-d workdir] [-D destdir] [-I patterns] [-L logfile]
X       etcupdate extract [-B] [-d workdir] [-s source | -t tarball] [-L logfile]
X                 [-M options]
X       etcupdate resolve [-d workdir] [-D destdir] [-L logfile]
X       etcupdate status [-d workdir]
XEOF
X	exit 1
X}
X
X# Used to write a message prepended with '>>>' to the logfile.
Xlog()
X{
X	echo ">>>" "$@" >&3
X}
X
X# Used for assertion conditions that should never happen.
Xpanic()
X{
X	echo "PANIC:" "$@"
X	exit 10
X}
X
X# Used to write a warning message.  These are saved to the WARNINGS
X# file with "  " prepended.
Xwarn()
X{
X	echo -n "  " >> $WARNINGS
X	echo "$@" >> $WARNINGS
X}
X
X# Output a horizontal rule using the passed-in character.  Matches the
X# length used for Index lines in CVS and SVN diffs.
X#
X# $1 - character
Xrule()
X{
X	jot -b "$1" -s "" 67
X}
X
X# Output a text description of a specified file's type.
X#
X# $1 - file pathname.
Xfile_type()
X{
X	stat -f "%HT" $1 | tr "[:upper:]" "[:lower:]"
X}
X
X# Returns true (0) if a file exists
X#
X# $1 - file pathname.
Xexists()
X{
X	[ -e $1 -o -L $1 ]
X}
X
X# Returns true (0) if a file should be ignored, false otherwise.
X#
X# $1 - file pathname
Xignore()
X{
X	local pattern -
X
X	set -o noglob
X	for pattern in $IGNORE_FILES; do
X		set +o noglob
X		case $1 in
X			$pattern)
X				return 0
X				;;
X		esac
X		set -o noglob
X	done
X
X	# Ignore /.cshrc and /.profile if they are hardlinked to the
X	# same file in /root.  This ensures we only compare those
X	# files once in that case.
X	case $1 in
X		/.cshrc|/.profile)
X			if [ ${DESTDIR}$1 -ef ${DESTDIR}/root$1 ]; then
X				return 0
X			fi
X			;;
X		*)
X			;;
X	esac
X
X	return 1
X}
X
X# Returns true (0) if the new version of a file should always be
X# installed rather than attempting to do a merge.
X#
X# $1 - file pathname
Xalways_install()
X{
X	local pattern -
X
X	set -o noglob
X	for pattern in $ALWAYS_INSTALL; do
X		set +o noglob
X		case $1 in
X			$pattern)
X				return 0
X				;;
X		esac
X		set -o noglob
X	done
X
X	return 1
X}
X
X# Build a new tree
X#
X# $1 - directory to store new tree in
Xbuild_tree()
X{
X	local make
X
X	make="make $MAKE_OPTIONS"
X
X	log "Building tree at $1 with $make"
X	mkdir -p $1/usr/obj >&3 2>&1
X	(cd $SRCDIR; $make DESTDIR=$1 distrib-dirs) >&3 2>&1
X	if [ $? -ne 0 ]; then
X		echo "Failed to build tree at $1"
X		return 1
X	fi
X
X	if ! [ -n "$nobuild" ]; then
X		(cd $SRCDIR; \
X	    MAKEOBJDIRPREFIX=$1/usr/obj $make _obj SUBDIR_OVERRIDE=etc &&
X	    MAKEOBJDIRPREFIX=$1/usr/obj $make everything SUBDIR_OVERRIDE=etc &&
X	    MAKEOBJDIRPREFIX=$1/usr/obj $make DESTDIR=$1 distribution) >&3 2>&1
X		    >&3 2>&1
X	else
X		(cd $SRCDIR; $make DESTDIR=$1 distribution) >&3 2>&1
X	fi
X	if [ $? -ne 0 ]; then
X		echo "Failed to build tree at $1"
X		return 1
X	fi
X	chflags -R noschg $1 >&3 2>&1
X	rm -rf $1/usr/obj >&3 2>&1
X
X	# Purge auto-generated files.  Only the source files need to
X	# be updated after which these files are regenerated.
X	rm -f $1/etc/*.db $1/etc/passwd >&3 2>&1
X
X	# Remove empty files.  These just clutter the output of 'diff'.
X	find $1 -type f -size 0 -delete >&3 2>&1
X
X	# Trim empty directories.
X	find -d $1 -type d -empty -delete >&3 2>&1
X	return 0
X}
X
X# Generate a new NEWTREE tree.  If tarball is set, then the tree is
X# extracted from the tarball.  Otherwise the tree is built from a
X# source tree.
Xextract_tree()
X{
X	# If we have a tarball, extract that into the new directory.
X	if [ -n "$tarball" ]; then
X		(mkdir -p $NEWTREE && tar xf $tarball -C $NEWTREE) >&3 2>&1
X		if [ $? -ne 0 ]; then
X			echo "Failed to extract new tree."
X			remove_tree $NEWTREE
X			exit 1
X		fi
X	else
X		if ! build_tree $NEWTREE; then
X			remove_tree $NEWTREE
X			exit 1
X		fi
X	fi
X}
X
X# Forcefully remove a tree.  Returns true (0) if the operation succeeds.
X#
X# $1 - path to tree
Xremove_tree()
X{
X
X	rm -rf $1 >&3 2>&1
X	if [ -e $1 ]; then
X		chflags -R noschg $1 >&3 2>&1
X		rm -rf $1 >&3 2>&1
X	fi
X	[ ! -e $1 ]
X}
X
X# Return values for compare()
XCOMPARE_EQUAL=0
XCOMPARE_ONLYFIRST=1
XCOMPARE_ONLYSECOND=2
XCOMPARE_DIFFTYPE=3
XCOMPARE_DIFFLINKS=4
XCOMPARE_DIFFFILES=5
X
X# Compare two files/directories/symlinks.  Note that this does not
X# recurse into subdirectories.  Instead, if two nodes are both
X# directories, they are assumed to be equivalent.
X#
X# Returns true (0) if the nodes are identical.  If only one of the two
X# nodes are present, return one of the COMPARE_ONLY* constants.  If
X# the nodes are different, return one of the COMPARE_DIFF* constants
X# to indicate the type of difference.
X#
X# $1 - first node
X# $2 - second node
Xcompare()
X{
X	local first second
X
X	# If the first node doesn't exist, then check for the second
X	# node.  Note that -e will fail for a symbolic link that
X	# points to a missing target.
X	if ! exists $1; then
X		if exists $2; then
X			return $COMPARE_ONLYSECOND
X		else
X			return $COMPARE_EQUAL
X		fi
X	elif ! exists $2; then
X		return $COMPARE_ONLYFIRST
X	fi
X
X	# If the two nodes are different file types fail.
X	first=`stat -f "%Hp" $1`
X	second=`stat -f "%Hp" $2`
X	if [ "$first" != "$second" ]; then
X		return $COMPARE_DIFFTYPE
X	fi
X
X	# If both are symlinks, compare the link values.
X	if [ -L $1 ]; then
X		first=`readlink $1`
X		second=`readlink $2`
X		if [ "$first" = "$second" ]; then
X			return $COMPARE_EQUAL
X		else
X			return $COMPARE_DIFFLINKS
X		fi
X	fi
X
X	# If both are files, compare the file contents.
X	if [ -f $1 ]; then
X		if cmp -s $1 $2; then
X			return $COMPARE_EQUAL
X		else
X			return $COMPARE_DIFFFILES
X		fi
X	fi
X
X	# As long as the two nodes are the same type of file, consider
X	# them equivalent.
X	return $COMPARE_EQUAL
X}
X
X# Returns true (0) if the only difference between two regular files is a
X# change in the FreeBSD ID string.
X#
X# $1 - path of first file
X# $2 - path of second file
Xfbsdid_only()
X{
X
X	diff -qI '\$FreeBSD.*\$' $1 $2 >/dev/null 2>&1
X}
X
X# This is a wrapper around compare that will return COMPARE_EQUAL if
X# the only difference between two regular files is a change in the
X# FreeBSD ID string.  It only makes this adjustment if the -F flag has
X# been specified.
X#
X# $1 - first node
X# $2 - second node
Xcompare_fbsdid()
X{
X	local cmp
X
X	compare $1 $2
X	cmp=$?
X
X	if [ -n "$FREEBSD_ID" -a "$cmp" -eq $COMPARE_DIFFFILES ] && \
X	    fbsdid_only $1 $2; then
X		return $COMPARE_EQUAL
X	fi
X
X	return $cmp
X}
X
X# Returns true (0) if a directory is empty.
X#
X# $1 - pathname of the directory to check
Xempty_dir()
X{
X	local contents
X
X	contents=`ls -A $1`
X	[ -z "$contents" ]
X}
X
X# Returns true (0) if one directories contents are a subset of the
X# other.  This will recurse to handle subdirectories and compares
X# individual files in the trees.  Its purpose is to quiet spurious
X# directory warnings for dryrun invocations.
X#
X# $1 - first directory (sub)
X# $2 - second directory (super)
Xdir_subset()
X{
X	local contents file
X
X	if ! [ -d $1 -a -d $2 ]; then
X		return 1
X	fi
X
X	# Ignore files that are present in the second directory but not
X	# in the first.
X	contents=`ls -A $1`
X	for file in $contents; do
X		if ! compare $1/$file $2/$file; then
X			return 1
X		fi
X
X		if [ -d $1/$file ]; then
X			if ! dir_subset $1/$file $2/$file; then
X				return 1
X			fi
X		fi
X	done
X	return 0
X}
X
X# Returns true (0) if a directory in the destination tree is empty.
X# If this is a dryrun, then this returns true as long as the contents
X# of the directory are a subset of the contents in the old tree
X# (meaning that the directory would be empty in a non-dryrun when this
X# was invoked) to quiet spurious warnings.
X#
X# $1 - pathname of the directory to check relative to DESTDIR.
Xempty_destdir()
X{
X
X	if [ -n "$dryrun" ]; then
X		dir_subset $DESTDIR/$1 $OLDTREE/$1
X		return
X	fi
X
X	empty_dir $DESTDIR/$1
X}
X
X# Output a diff of two directory entries with the same relative name
X# in different trees.  Note that as with compare(), this does not
X# recurse into subdirectories.  If the nodes are identical, nothing is
X# output.
X#
X# $1 - first tree
X# $2 - second tree
X# $3 - node name 
X# $4 - label for first tree
X# $5 - label for second tree
Xdiffnode()
X{
X	local first second file old new diffargs
X
X	if [ -n "$FREEBSD_ID" ]; then
X		diffargs="-I \\\$FreeBSD.*\\\$"
X	else
X		diffargs=""
X	fi
X
X	compare_fbsdid $1/$3 $2/$3
X	case $? in
X		$COMPARE_EQUAL)
X			;;
X		$COMPARE_ONLYFIRST)
X			echo
X			echo "Removed: $3"
X			echo
X			;;
X		$COMPARE_ONLYSECOND)
X			echo
X			echo "Added: $3"
X			echo
X			;;
X		$COMPARE_DIFFTYPE)
X			first=`file_type $1/$3`
X			second=`file_type $2/$3`
X			echo
X			echo "Node changed from a $first to a $second: $3"
X			echo
X			;;
X		$COMPARE_DIFFLINKS)
X			first=`readlink $1/$file`
X			second=`readlink $2/$file`
X			echo
X			echo "Link changed: $file"
X			rule "="
X			echo "-$first"
X			echo "+$second"
X			echo
X			;;
X		$COMPARE_DIFFFILES)
X			echo "Index: $3"
X			rule "="
X			diff -u $diffargs -L "$3 ($4)" $1/$3 -L "$3 ($5)" $2/$3
X			;;
X	esac
X}
X
X# Create missing parent directories of a node in a target tree
X# preserving the owner, group, and permissions from a specified
X# template tree.
X#
X# $1 - template tree
X# $2 - target tree
X# $3 - pathname of the node (relative to both trees)
Xinstall_dirs()
X{
X	local args dir
X
X	dir=`dirname $3`
X
X	# Nothing to do if the parent directory exists.  This also
X	# catches the degenerate cases when the path is just a simple
X	# filename.
X	if [ -d ${2}$dir ]; then
X		return 0
X	fi
X
X	# If non-directory file exists with the desired directory
X	# name, then fail.
X	if exists ${2}$dir; then
X		# If this is a dryrun and we are installing the
X		# directory in the DESTDIR and the file in the DESTDIR
X		# matches the file in the old tree, then fake success
X		# to quiet spurious warnings.
X		if [ -n "$dryrun" -a "$2" = "$DESTDIR" ]; then
X			if compare $OLDTREE/$dir $DESTDIR/$dir; then
X				return 0
X			fi
X		fi
X
X		args=`file_type ${2}$dir`
X		warn "Directory mismatch: ${2}$dir ($args)"
X		return 1
X	fi
X
X	# Ensure the parent directory of the directory is present
X	# first.
X	if ! install_dirs $1 "$2" $dir; then
X		return 1
X	fi
X
X	# Format attributes from template directory as install(1)
X	# arguments.
X	args=`stat -f "-o %Su -g %Sg -m %0Mp%0Lp" $1/$dir`
X
X	log "install -d $args ${2}$dir"
X	if [ -z "$dryrun" ]; then
X		install -d $args ${2}$dir >&3 2>&1
X	fi
X	return 0
X}
X
X# Perform post-install fixups for a file.  This largely consists of
X# regenerating any files that depend on the newly installed file.
X#
X# $1 - pathname of the updated file (relative to DESTDIR)
Xpost_install_file()
X{
X	case $1 in
X		/etc/mail/aliases)
X			# Grr, newaliases only works for an empty DESTDIR.
X			if [ -z "$DESTDIR" ]; then
X				log "newaliases"
X				if [ -z "$dryrun" ]; then
X					newaliases >&3 2>&1
X				fi
X			else
X				NEWALIAS_WARN=yes
X			fi
X			;;
X		/etc/login.conf)
X			log "cap_mkdb ${DESTDIR}$1"
X			if [ -z "$dryrun" ]; then
X				cap_mkdb ${DESTDIR}$1 >&3 2>&1
X			fi
X			;;
X		/etc/master.passwd)
X			log "pwd_mkdb -p -d $DESTDIR/etc ${DESTDIR}$1"
X			if [ -z "$dryrun" ]; then
X				pwd_mkdb -p -d $DESTDIR/etc ${DESTDIR}$1 \
X				    >&3 2>&1
X			fi
X			;;
X	esac
X}
X
X# Install the "new" version of a file.  Returns true if it succeeds
X# and false otherwise.
X#
X# $1 - pathname of the file to install (relative to DESTDIR)
Xinstall_new()
X{
X
X	if ! install_dirs $NEWTREE "$DESTDIR" $1; then
X		return 1
X	fi
X	log "cp -Rp ${NEWTREE}$1 ${DESTDIR}$1"
X	if [ -z "$dryrun" ]; then
X		cp -Rp ${NEWTREE}$1 ${DESTDIR}$1 >&3 2>&1
X	fi
X	post_install_file $1
X	return 0
X}
X
X# Install the "resolved" version of a file.  Returns true if it succeeds
X# and false otherwise.
X#
X# $1 - pathname of the file to install (relative to DESTDIR)
Xinstall_resolved()
X{
X
X	# This should always be present since the file is already
X	# there (it caused a conflict).  However, it doesn't hurt to
X	# just be safe.
X	if ! install_dirs $NEWTREE "$DESTDIR" $1; then
X		return 1
X	fi
X
X	log "cp -Rp ${CONFLICTS}$1 ${DESTDIR}$1"
X	cp -Rp ${CONFLICTS}$1 ${DESTDIR}$1 >&3 2>&1
X	post_install_file $1
X	return 0
X}
X
X# Generate a conflict file when a "new" file conflicts with an
X# existing file in DESTDIR.
X#
X# $1 - pathname of the file that conflicts (relative to DESTDIR)
Xnew_conflict()
X{
X
X	if [ -n "$dryrun" ]; then
X		return
X	fi
X
X	install_dirs $NEWTREE $CONFLICTS $1
X	diff --changed-group-format='<<<<<<< (local)
X%<=======
X%>>>>>>>> (stock)
X' $DESTDIR/$1 $NEWTREE/$1 > $CONFLICTS/$1
X}
X
X# Remove the "old" version of a file.
X#
X# $1 - pathname of the old file to remove (relative to DESTDIR)
Xremove_old()
X{
X	log "rm -f ${DESTDIR}$1"
X	if [ -z "$dryrun" ]; then
X		rm -f ${DESTDIR}$1 >&3 2>&1
X	fi
X	echo "  D $1"
X}
X
X# Update a file that has no local modifications.
X#
X# $1 - pathname of the file to update (relative to DESTDIR)
Xupdate_unmodified()
X{
X	local new old
X
X	# If the old file is a directory, then remove it with rmdir
X	# (this should only happen if the file has changed its type
X	# from a directory to a non-directory).  If the directory
X	# isn't empty, then fail.  This will be reported as a warning
X	# later.
X	if [ -d $DESTDIR/$1 ]; then
X		if empty_destdir $1; then
X			log "rmdir ${DESTDIR}$1"
X			if [ -z "$dryrun" ]; then
X				rmdir ${DESTDIR}$1 >&3 2>&1
X			fi
X		else
X			return 1
X		fi
X
X	# If both the old and new files are regular files, leave the
X	# existing file.  This avoids breaking hard links for /.cshrc
X	# and /.profile.  Otherwise, explicitly remove the old file.
X	elif ! [ -f ${DESTDIR}$1 -a -f ${NEWTREE}$1 ]; then
X		log "rm -f ${DESTDIR}$1"
X		if [ -z "$dryrun" ]; then
X			rm -f ${DESTDIR}$1 >&3 2>&1
X		fi
X	fi
X
X	# If the new file is a directory, note that the old file has
X	# been removed, but don't do anything else for now.  The
X	# directory will be installed if needed when new files within
X	# that directory are installed.
X	if [ -d $NEWTREE/$1 ]; then
X		if empty_dir $NEWTREE/$1; then
X			echo "  D $file"
X		else
X			echo "  U $file"
X		fi
X	elif install_new $1; then
X		echo "  U $file"
X	fi
X	return 0
X}
X
X# Update the FreeBSD ID string in a locally modified file to match the
X# FreeBSD ID string from the "new" version of the file.
X#
X# $1 - pathname of the file to update (relative to DESTDIR)
Xupdate_freebsdid()
X{
X	local new dest file
X
X	# If the FreeBSD ID string is removed from the local file,
X	# there is nothing to do.  In this case, treat the file as
X	# updated.  Otherwise, if either file has more than one
X	# FreeBSD ID string, just punt and let the user handle the
X	# conflict manually.
X	new=`grep -c '\$FreeBSD.*\$' ${NEWTREE}$1`
X	dest=`grep -c '\$FreeBSD.*\$' ${DESTDIR}$1`
X	if [ "$dest" -eq 0 ]; then
X		return 0
X	fi
X	if [ "$dest" -ne 1 -o "$dest" -ne 1 ]; then
X		return 1
X	fi
X
X	# If the FreeBSD ID string in the new file matches the FreeBSD ID
X	# string in the local file, there is nothing to do.
X	new=`grep '\$FreeBSD.*\$' ${NEWTREE}$1`
X	dest=`grep '\$FreeBSD.*\$' ${DESTDIR}$1`
X	if [ "$new" = "$dest" ]; then
X		return 0
X	fi
X
X	# Build the new file in three passes.  First, copy all the
X	# lines preceding the FreeBSD ID string from the local version
X	# of the file.  Second, append the FreeBSD ID string line from
X	# the new version.  Finally, append all the lines after the
X	# FreeBSD ID string from the local version of the file.
X	file=`mktemp $WORKDIR/etcupdate-XXXXXXX`
X	awk '/\$FreeBSD.*\$/ { exit } { print }' ${DESTDIR}$1 >> $file
X	awk '/\$FreeBSD.*\$/ { print }' ${NEWTREE}$1 >> $file
X	awk '/\$FreeBSD.*\$/ { ok = 1; next } { if (ok) print }' \
X	    ${DESTDIR}$1 >> $file
X
X	# As an extra sanity check, fail the attempt if the updated
X	# version of the file has any differences aside from the
X	# FreeBSD ID string.
X	if ! fbsdid_only ${DESTDIR}$1 $file; then
X		rm -f $file
X		return 1
X	fi
X
X	log "cp $file ${DESTDIR}$1"
X	if [ -z "$dryrun" ]; then
X		cp $file ${DESTDIR}$1 >&3 2>&1
X	fi
X	rm -f $file
X	post_install_file $1
X	echo "  M $1"
X	return 0
X}
X
X# Attempt to update a file that has local modifications.  This routine
X# only handles regular files.  If the 3-way merge succeeds without
X# conflicts, the updated file is installed.  If the merge fails, the
X# merged version with conflict markers is left in the CONFLICTS tree.
X#
X# $1 - pathname of the file to merge (relative to DESTDIR)
Xmerge_file()
X{
X	local res
X
X	# Try the merge to see if there is a conflict.
X	merge -q -p ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1 >/dev/null 2>&3
X	res=$?
X	case $res in
X		0)
X			# No conflicts, so just redo the merge to the
X			# real file.
X			log "merge ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1"
X			if [ -z "$dryrun" ]; then
X				merge ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1
X			fi
X			post_install_file $1
X			echo "  M $1"
X			;;
X		1)
X			# Conflicts, save a version with conflict markers in
X			# the conflicts directory.
X			if [ -z "$dryrun" ]; then
X				install_dirs $NEWTREE $CONFLICTS $1
X				log "cp -Rp ${DESTDIR}$1 ${CONFLICTS}$1"
X				cp -Rp ${DESTDIR}$1 ${CONFLICTS}$1 >&3 2>&1
X				merge -A -q -L "yours" -L "original" -L "new" \
X				    ${CONFLICTS}$1 ${OLDTREE}$1 ${NEWTREE}$1
X			fi
X			echo "  C $1"
X			;;
X		*)
X			panic "merge failed with status $res"
X			;;
X	esac
X}
X
X# Returns true if a file contains conflict markers from a merge conflict.
X#
X# $1 - pathname of the file to resolve (relative to DESTDIR)
Xhas_conflicts()
X{
X	
X	egrep -q '^(<{7}|\|{7}|={7}|>{7}) ' $CONFLICTS/$1
X}
X
X# Attempt to resolve a conflict.  The user is prompted to choose an
X# action for each conflict.  If the user edits the file, they are
X# prompted again for an action.  The process is very similar to
X# resolving conflicts after an update or merge with Perforce or
X# Subversion.  The prompts are modelled on a subset of the available
X# commands for resolving conflicts with Subversion.
X#
X# $1 - pathname of the file to resolve (relative to DESTDIR)
Xresolve_conflict()
X{
X	local command junk
X
X	echo "Resolving conflict in '$1':"
X	edit=
X	while true; do
X		# Only display the resolved command if the file
X		# doesn't contain any conflicts.
X		echo -n "Select: (p) postpone, (df) diff-full, (e) edit,"
X		if ! has_conflicts $1; then
X			echo -n " (r) resolved,"
X		fi
X		echo
X		echo -n "        (h) help for more options: "
X		read command
X		case $command in
X			df)
X				diff -u ${DESTDIR}$1 ${CONFLICTS}$1
X				;;
X			e)
X				$EDITOR ${CONFLICTS}$1
X				;;
X			h)
X				cat <<EOF
X  (p)  postpone    - ignore this conflict for now
X  (df) diff-full   - show all changes made to merged file
X  (e)  edit        - change merged file in an editor
X  (r)  resolved    - accept merged version of file
X  (mf) mine-full   - accept local version of entire file (ignore new changes)
X  (tf) theirs-full - accept new version of entire file (lose local changes)
X  (h)  help        - show this list
XEOF
X				;;
X			mf)
X				# For mine-full, just delete the
X				# merged file and leave the local
X				# version of the file as-is.
X				rm ${CONFLICTS}$1
X				return
X				;;
X			p)
X				return
X				;;
X			r)
X				# If the merged file has conflict
X				# markers, require confirmation.
X				if has_conflicts $1; then
X					echo "File '$1' still has conflicts," \
X					    "are you sure? (y/n) "
X					read junk
X					if [ "$junk" != "y" ]; then
X						continue
X					fi
X				fi
X
X				if ! install_resolved $1; then
X					panic "Unable to install merged" \
X					    "version of $1"
X				fi
X				rm ${CONFLICTS}$1
X				return
X				;;
X			tf)
X				# For theirs-full, install the new
X				# version of the file over top of the
X				# existing file.
X				if ! install_new $1; then
X					panic "Unable to install new" \
X					    "version of $1"
X				fi
X				rm ${CONFLICTS}$1
X				return
X				;;
X			*)
X				echo "Invalid command."
X				;;
X		esac
X	done
X}
X
X# Handle a file that has been removed from the new tree.  If the file
X# does not exist in DESTDIR, then there is nothing to do.  If the file
X# exists in DESTDIR and is identical to the old version, remove it
X# from DESTDIR.  Otherwise, whine about the conflict but leave the
X# file in DESTDIR.  To handle directories, this uses two passes.  The
X# first pass handles all non-directory files.  The second pass handles
X# just directories and removes them if they are empty.
X#
X# If -F is specified, and the only difference in the file in DESTDIR
X# is a change in the FreeBSD ID string, then remove the file.
X#
X# $1 - pathname of the file (relative to DESTDIR)
Xhandle_removed_file()
X{
X	local dest file
X
X	file=$1
X	if ignore $file; then
X		log "IGNORE: removed file $file"
X		return
X	fi
X
X	compare_fbsdid $DESTDIR/$file $OLDTREE/$file
X	case $? in
X		$COMPARE_EQUAL)
X			if ! [ -d $DESTDIR/$file ]; then
X				remove_old $file
X			fi
X			;;
X		$COMPARE_ONLYFIRST)
X			panic "Removed file now missing"
X			;;
X		$COMPARE_ONLYSECOND)
X			# Already removed, nothing to do.
X			;;
X		$COMPARE_DIFFTYPE|$COMPARE_DIFFLINKS|$COMPARE_DIFFFILES)
X			dest=`file_type $DESTDIR/$file`
X			warn "Modified $dest remains: $file"
X			;;
X	esac
X}
X
X# Handle a directory that has been removed from the new tree.  Only
X# remove the directory if it is empty.
X#
X# $1 - pathname of the directory (relative to DESTDIR)
Xhandle_removed_directory()
X{
X	local dir
X
X	dir=$1
X	if ignore $dir; then
X		log "IGNORE: removed dir $dir"
X		return
X	fi
X
X	if [ -d $DESTDIR/$dir -a -d $OLDTREE/$dir ]; then
X		if empty_destdir $dir; then
X			log "rmdir ${DESTDIR}$dir"
X			if [ -z "$dryrun" ]; then
X				rmdir ${DESTDIR}$dir >/dev/null 2>&1
X			fi
X			echo "  D $dir"
X		else
X			warn "Non-empty directory remains: $dir"
X		fi
X	fi
X}
X
X# Handle a file that exists in both the old and new trees.  If the
X# file has not changed in the old and new trees, there is nothing to
X# do.  If the file in the destination directory matches the new file,
X# there is nothing to do.  If the file in the destination directory
X# matches the old file, then the new file should be installed.
X# Everything else becomes some sort of conflict with more detailed
X# handling.
X#
X# $1 - pathname of the file (relative to DESTDIR)
Xhandle_modified_file()
X{
X	local cmp dest file new newdestcmp old
X
X	file=$1
X	if ignore $file; then
X		log "IGNORE: modified file $file"
X		return
X	fi
X
X	compare $OLDTREE/$file $NEWTREE/$file
X	cmp=$?
X	if [ $cmp -eq $COMPARE_EQUAL ]; then
X		return
X	fi
X
X	if [ $cmp -eq $COMPARE_ONLYFIRST -o $cmp -eq $COMPARE_ONLYSECOND ]; then
X		panic "Changed file now missing"
X	fi
X
X	compare $NEWTREE/$file $DESTDIR/$file
X	newdestcmp=$?
X	if [ $newdestcmp -eq $COMPARE_EQUAL ]; then
X		return
X	fi
X
X	# If the only change in the new file versus the destination
X	# file is a change in the FreeBSD ID string and -F is
X	# specified, just install the new file.
X	if [ -n "$FREEBSD_ID" -a $newdestcmp -eq $COMPARE_DIFFFILES ] && \
X	    fbsdid_only $NEWTREE/$file $DESTDIR/$file; then
X		if update_unmodified $file; then
X			return
X		else
X			panic "Updating FreeBSD ID string failed"
X		fi
X	fi
X
X	# If the local file is the same as the old file, install the
X	# new file.  If -F is specified and the only local change is
X	# in the FreeBSD ID string, then install the new file as well.
X	if compare_fbsdid $OLDTREE/$file $DESTDIR/$file; then
X		if update_unmodified $file; then
X			return
X		fi
X	fi
X
X	# If the only change in the new file versus the old file is a
X	# change in the FreeBSD ID string and -F is specified, just
X	# update the FreeBSD ID string in the local file.
X	if [ -n "$FREEBSD_ID" -a $cmp -eq $COMPARE_DIFFFILES ] && \
X	    fbsdid_only $OLDTREE/$file $NEWTREE/$file; then
X		if update_freebsdid $file; then
X			continue
X		fi
X	fi
X
X	# If the file was removed from the dest tree, just whine.
X	if [ $newdestcmp -eq $COMPARE_ONLYFIRST ]; then
X		# If the removed file matches an ALWAYS_INSTALL glob,
X		# then just install the new version of the file.
X		if always_install $file; then
X			log "ALWAYS: adding $file"
X			if ! [ -d $NEWTREE/$file ]; then
X				if install_new $file; then
X					echo "  A $file"
X				fi
X			fi
X			return
X		fi
X
X		case $cmp in
X			$COMPARE_DIFFTYPE)
X				old=`file_type $OLDTREE/$file`
X				new=`file_type $NEWTREE/$file`
X				warn "Remove mismatch: $file ($old became $new)"
X				;;
X			$COMPARE_DIFFLINKS)
X				old=`readlink $OLDTREE/$file`
X				new=`readlink $NEWTREE/$file`
X				warn \
X		"Removed link changed: $file (\"$old\" became \"$new\")"
X				;;
X			$COMPARE_DIFFFILES)
X				warn "Removed file changed: $file"
X				;;
X		esac
X		return
X	fi
X
X	# Treat the file as unmodified and force install of the new
X	# file if it matches an ALWAYS_INSTALL glob.  If the update
X	# attempt fails, then fall through to the normal case so a
X	# warning is generated.
X	if always_install $file; then
X		log "ALWAYS: updating $file"
X		if update_unmodified $file; then
X			return
X		fi
X	fi
X
X	# If the file changed types between the old and new trees but
X	# the files in the new and dest tree are both of the same
X	# type, treat it like an added file just comparing the new and
X	# dest files.
X	if [ $cmp -eq $COMPARE_DIFFTYPE ]; then
X		case $newdestcmp in
X			$COMPARE_DIFFLINKS)
X				new=`readlink $NEWTREE/$file`
X				dest=`readlink $DESTDIR/$file`
X				warn \
X			"New link conflict: $file (\"$new\" vs \"$dest\")"
X				return
X				;;
X			$COMPARE_DIFFFILES)
X				new_conflict $file
X				echo "  C $file"
X				return
X				;;
X		esac
X	else
X		# If the file has not changed types between the old
X		# and new trees, but it is a different type in
X		# DESTDIR, then just warn.
X		if [ $newdestcmp -eq $COMPARE_DIFFTYPE ]; then
X			new=`file_type $NEWTREE/$file`
X			dest=`file_type $DESTDIR/$file`
X			warn "Modified mismatch: $file ($new vs $dest)"
X			return
X		fi
X	fi
X
X	case $cmp in
X		$COMPARE_DIFFTYPE)
X			old=`file_type $OLDTREE/$file`
X			new=`file_type $NEWTREE/$file`
X			dest=`file_type $DESTDIR/$file`
X			warn "Modified $dest changed: $file ($old became $new)"
X			;;
X		$COMPARE_DIFFLINKS)
X			old=`readlink $OLDTREE/$file`
X			new=`readlink $NEWTREE/$file`
X			warn \
X		"Modified link changed: $file (\"$old\" became \"$new\")"
X			;;
X		$COMPARE_DIFFFILES)
X			merge_file $file
X			;;
X	esac
X}
X
X# Handle a file that has been added in the new tree.  If the file does
X# not exist in DESTDIR, simply copy the file into DESTDIR.  If the
X# file exists in the DESTDIR and is identical to the new version, do
X# nothing.  Otherwise, generate a diff of the two versions of the file
X# and mark it as a conflict.
X#
X# $1 - pathname of the file (relative to DESTDIR)
Xhandle_added_file()
X{
X	local cmp dest file new
X
X	file=$1
X	if ignore $file; then
X		log "IGNORE: added file $file"
X		return
X	fi
X
X	compare $DESTDIR/$file $NEWTREE/$file
X	cmp=$?
X	case $cmp in
X		$COMPARE_EQUAL)
X			return
X			;;
X		$COMPARE_ONLYFIRST)
X			panic "Added file now missing"
X			;;
X		$COMPARE_ONLYSECOND)
X			# Ignore new directories.  They will be
X			# created as needed when non-directory nodes
X			# are installed.
X			if ! [ -d $NEWTREE/$file ]; then
X				if install_new $file; then
X					echo "  A $file"
X				fi
X			fi
X			return
X			;;
X	esac
X
X
X	# Treat the file as unmodified and force install of the new
X	# file if it matches an ALWAYS_INSTALL glob.  If the update
X	# attempt fails, then fall through to the normal case so a
X	# warning is generated.
X	if always_install $file; then
X		log "ALWAYS: updating $file"
X		if update_unmodified $file; then
X			return
X		fi
X	fi
X
X	case $cmp in
X		$COMPARE_DIFFTYPE)
X			new=`file_type $NEWTREE/$file`
X			dest=`file_type $DESTDIR/$file`
X			warn "New file mismatch: $file ($new vs $dest)"
X			;;
X		$COMPARE_DIFFLINKS)
X			new=`readlink $NEWTREE/$file`
X			dest=`readlink $DESTDIR/$file`
X			warn "New link conflict: $file (\"$new\" vs \"$dest\")"
X			;;
X		$COMPARE_DIFFFILES)
X			# If the only change in the new file versus
X			# the destination file is a change in the
X			# FreeBSD ID string and -F is specified, just
X			# install the new file.
X			if [ -n "$FREEBSD_ID" ] && \
X			    fbsdid_only $NEWTREE/$file $DESTDIR/$file; then
X				if update_unmodified $file; then
X					return
X				else
X					panic \
X					"Updating FreeBSD ID string failed"
X				fi
X			fi
X
X			new_conflict $file
X			echo "  C $file"
X			;;
X	esac
X}
X
X# Main routines for each command
X
X# Build a new tree and save it in a tarball.
Xbuild_cmd()
X{
X	local dir
X
X	if [ $# -ne 1 ]; then
X		echo "Missing required tarball."
X		echo
X		usage
X	fi
X
X	log "build command: $1"
X
X	# Create a temporary directory to hold the tree
X	dir=`mktemp -d $WORKDIR/etcupdate-XXXXXXX`
X	if [ $? -ne 0 ]; then
X		echo "Unable to create temporary directory."
X		exit 1
X	fi
X	if ! build_tree $dir; then
X		remove_tree $dir
X		exit 1
X	fi
X	if ! tar cfj $1 -C $dir . >&3 2>&1; then
X		echo "Failed to create tarball ."
X		remove_tree $dir
X		exit 1
X	fi
X	remove_tree $dir
X}
X
X# Output a diff comparing the tree at DESTDIR to the current
X# unmodified tree.  Note that this diff does not include files that
X# are present in DESTDIR but not in the unmodified tree.
Xdiff_cmd()
X{
X	local file
X
X	if [ $# -ne 0 ]; then
X		usage
X	fi
X
X	# Requires an unmodified tree to diff against.
X	if ! [ -d $NEWTREE ]; then
X		echo "Reference tree to diff against unavailable."
X		exit 1
X	fi
X
X	# Unfortunately, diff alone does not quite provide the right
X	# level of options that we want, so improvise.
X	for file in `(cd $NEWTREE; find .) | sed -e 's/^\.//'`; do
X		if ignore $file; then
X			continue
X		fi
X
X		diffnode $NEWTREE "$DESTDIR" $file "stock" "local"
X	done
X}
X
X# Just extract a new tree into NEWTREE either by building a tree or
X# extracting a tarball.  This can be used to bootstrap updates by
X# initializing the current "stock" tree to match the currently
X# installed system.
X#
X# Unlike 'update', this command does not rotate or preserve an
X# existing NEWTREE, it just replaces any existing tree.
Xextract_cmd()
X{
X
X	if [ $# -ne 0 ]; then
X		usage
X	fi
X
X	log "extract command: tarball=$tarball"
X
X	if [ -d $NEWTREE ]; then
X		if ! remove_tree $NEWTREE; then
X			echo "Unable to remove current tree."
X			exit 1
X		fi
X	fi
X
X	extract_tree
X}
X
X# Resolve conflicts left from an earlier merge.
Xresolve_cmd()
X{
X	local conflicts
X
X	if [ $# -ne 0 ]; then
X		usage
X	fi
X
X	if ! [ -d $CONFLICTS ]; then
X		return
X	fi
X
X	conflicts=`(cd $CONFLICTS; find . ! -type d) | sed -e 's/^\.//'`
X	for file in $conflicts; do
X		resolve_conflict $file
X	done
X
X	if [ -n "$NEWALIAS_WARN" ]; then
X		warn "Needs update: /etc/mail/aliases.db" \
X		    "(requires manual update via newaliases(1))"
X		echo
X		echo "Warnings:"
X		echo "  Needs update: /etc/mail/aliases.db" \
X		    "(requires manual update via newaliases(1))"
X	fi
X}
X
X# Report a summary of the previous merge.  Specifically, list any
X# remaining conflicts followed by any warnings from the previous
X# update.
Xstatus_cmd()
X{
X
X	if [ $# -ne 0 ]; then
X		usage
X	fi
X
X	if [ -d $CONFLICTS ]; then
X		(cd $CONFLICTS; find . ! -type d) | sed -e 's/^\./  C /'
X	fi
X	if [ -s $WARNINGS ]; then
X		echo "Warnings:"
X		cat $WARNINGS
X	fi
X}
X
X# Perform an actual merge.  The new tree can either already exist (if
X# rerunning a merge), be extracted from a tarball, or generated from a
X# source tree.
Xupdate_cmd()
X{
X	local dir
X
X	if [ $# -ne 0 ]; then
X		usage
X	fi
X
X	log "update command: rerun=$rerun tarball=$tarball"
X
X	if [ `id -u` -ne 0 ]; then
X		echo "Must be root to update a tree."
X		exit 1
X	fi
X
X	# Enforce a sane umask
X	umask 022
X
X	# XXX: Should existing conflicts be ignored and removed during
X	# a rerun?
X
X	# Trim the conflicts tree.  Whine if there is anything left.
X	if [ -e $CONFLICTS ]; then
X		find -d $CONFLICTS -type d -empty -delete >&3 2>&1
X		rmdir $CONFLICTS >&3 2>&1
X	fi
X	if [ -d $CONFLICTS ]; then
X		echo "Conflicts remain from previous update, aborting."
X		exit 1
X	fi
X
X	if [ -z "$rerun" ]; then
X		# For a dryrun that is not a rerun, do not rotate the existing
X		# stock tree.  Instead, extract a tree to a temporary directory
X		# and use that for the comparison.
X		if [ -n "$dryrun" ]; then
X			dir=`mktemp -d $WORKDIR/etcupdate-XXXXXXX`
X			if [ $? -ne 0 ]; then
X				echo "Unable to create temporary directory."
X				exit 1
X			fi
X			OLDTREE=$NEWTREE
X			NEWTREE=$dir
X
X		# Rotate the existing stock tree to the old tree.
X		elif [ -d $NEWTREE ]; then
X			# First, delete the previous old tree if it exists.
X			if ! remove_tree $OLDTREE; then
X				echo "Unable to remove old tree."
X				exit 1
X			fi
X
X			# Move the current stock tree.
X			if ! mv $NEWTREE $OLDTREE >&3 2>&1; then
X				echo "Unable to rename current stock tree."
X				exit 1
X			fi
X		fi
X
X		if ! [ -d $OLDTREE ]; then
X			cat <<EOF
XNo previous tree to compare against, a sane comparison is not possible.
XEOF
X			log "No previous tree to compare against."
X			if [ -n "$dir" ]; then
X				rmdir $dir
X			fi
X			exit 1
X		fi
X
X		# Populate the new tree.
X		extract_tree
X	fi
X
X	# Build lists of nodes in the old and new trees.
X	(cd $OLDTREE; find .) | sed -e 's/^\.//' | sort > $WORKDIR/old.files
X	(cd $NEWTREE; find .) | sed -e 's/^\.//' | sort > $WORKDIR/new.files
X
X	# Split the files up into three groups using comm.
X	comm -23 $WORKDIR/old.files $WORKDIR/new.files > $WORKDIR/removed.files
X	comm -13 $WORKDIR/old.files $WORKDIR/new.files > $WORKDIR/added.files
X	comm -12 $WORKDIR/old.files $WORKDIR/new.files > $WORKDIR/both.files
X
X	# Initialize conflicts and warnings handling.
X	rm -f $WARNINGS
X	mkdir -p $CONFLICTS
X	
X	# The order for the following sections is important.  In the
X	# odd case that a directory is converted into a file, the
X	# existing subfiles need to be removed if possible before the
X	# file is converted.  Similarly, in the case that a file is
X	# converted into a directory, the file needs to be converted
X	# into a directory if possible before the new files are added.
X
X	# First, handle removed files.
X	for file in `cat $WORKDIR/removed.files`; do
X		handle_removed_file $file
X	done
X
X	# For the directory pass, reverse sort the list to effect a
X	# depth-first traversal.  This is needed to ensure that if a
X	# directory with subdirectories is removed, the entire
X	# directory is removed if there are no local modifications.
X	for file in `sort -r $WORKDIR/removed.files`; do
X		handle_removed_directory $file
X	done
X
X	# Second, handle files that exist in both the old and new
X	# trees.
X	for file in `cat $WORKDIR/both.files`; do
X		handle_modified_file $file
X	done
X
X	# Finally, handle newly added files.
X	for file in `cat $WORKDIR/added.files`; do
X		handle_added_file $file
X	done
X
X	if [ -n "$NEWALIAS_WARN" ]; then
X		warn "Needs update: /etc/mail/aliases.db" \
X		    "(requires manual update via newaliases(1))"
X	fi
X
X	if [ -s $WARNINGS ]; then
X		echo "Warnings:"
X		cat $WARNINGS
X	fi
X
X	if [ -n "$dir" ]; then
X		if [ -z "$dryrun" -o -n "$rerun" ]; then
X			panic "Should not have a temporary directory"
X		fi
X		
X		remove_tree $dir
X	fi
X}
X
X# Determine which command we are executing.  A command may be
X# specified as the first word.  If one is not specified then 'update'
X# is assumed as the default command.
Xcommand="update"
Xif [ $# -gt 0 ]; then
X	case "$1" in
X		build|diff|extract|status|resolve)
X			command="$1"
X			shift
X			;;
X		-*)
X			# If first arg is an option, assume the
X			# default command.
X			;;
X		*)
X			usage
X			;;
X	esac
Xfi
X
X# Set default variable values.
X
X# Where the "old" and "new" trees are stored.
XWORKDIR=/var/db/etcupdate
X
X# The path to the source tree used to build trees.
XSRCDIR=/usr/src
X
X# The destination directory where the modified files live.
XDESTDIR=
X
X# Ignore changes in the FreeBSD ID string.
XFREEBSD_ID=
X
X# Files that should always have the new version of the file installed.
XALWAYS_INSTALL=
X
X# Files to ignore and never update during a merge.
XIGNORE_FILES=
X
X# Flags to pass to 'make' when building a tree.
XMAKE_OPTIONS=
X
X# Include a config file if it exists.  Note that command line options
X# override any settings in the config file.  More details are in the
X# manual, but in general the following variables can be set:
X# - ALWAYS_INSTALL
X# - DESTDIR
X# - EDITOR
X# - FREEBSD_ID
X# - IGNORE_FILES
X# - LOGFILE
X# - MAKE_OPTIONS
X# - SRCDIR
X# - WORKDIR
Xif [ -r /etc/etcupdate.conf ]; then
X	. /etc/etcupdate.conf
Xfi
X
X# Parse command line options
Xtarball=
Xrerun=
Xalways=
Xdryrun=
Xignore=
Xnobuild=
Xwhile getopts "d:nrs:t:A:BD:FI:L:M:" option; do
X	case "$option" in
X		d)
X			WORKDIR=$OPTARG
X			;;
X		n)
X			dryrun=YES
X			;;
X		r)
X			rerun=YES
X			;;
X		s)
X			SRCDIR=$OPTARG
X			;;
X		t)
X			tarball=$OPTARG
X			;;
X		A)
X			# To allow this option to be specified
X			# multiple times, accumulate command-line
X			# specified patterns in an 'always' variable
X			# and use that to overwrite ALWAYS_INSTALL
X			# after parsing all options.  Need to be
X			# careful here with globbing expansion.
X			set -o noglob
X			always="$always $OPTARG"
X			set +o noglob
X			;;
X		B)
X			nobuild=YES
X			;;
X		D)
X			DESTDIR=$OPTARG
X			;;
X		F)
X			FREEBSD_ID=YES
X			;;
X		I)
X			# To allow this option to be specified
X			# multiple times, accumulate command-line
X			# specified patterns in an 'ignore' variable
X			# and use that to overwrite IGNORE_FILES after
X			# parsing all options.  Need to be careful
X			# here with globbing expansion.
X			set -o noglob
X			ignore="$ignore $OPTARG"
X			set +o noglob
X			;;
X		L)
X			LOGFILE=$OPTARG
X			;;
X		M)
X			MAKE_OPTIONS="$OPTARG"
X			;;
X		*)
X			echo
X			usage
X			;;
X	esac
Xdone
Xshift $((OPTIND - 1))
X
X# Allow -A command line options to override ALWAYS_INSTALL set from
X# the config file.
Xset -o noglob
Xif [ -n "$always" ]; then
X	ALWAYS_INSTALL="$always"
Xfi
X
X# Allow -I command line options to override IGNORE_FILES set from the
X# config file.
Xif [ -n "$ignore" ]; then
X	IGNORE_FILES="$ignore"
Xfi
Xset +o noglob
X
X# Log file for verbose output from program that are run.  The log file
X# is opened on fd '3'.
XLOGFILE=${LOGFILE:-$WORKDIR/log}
X
X# The path of the "old" tree
XOLDTREE=$WORKDIR/old
X
X# The path of the "new" tree
XNEWTREE=$WORKDIR/current
X
X# The path of the "conflicts" tree where files with merge conflicts are saved.
XCONFLICTS=$WORKDIR/conflicts
X
X# The path of the "warnings" file that accumulates warning notes from an update.
XWARNINGS=$WORKDIR/warnings
X
X# Use $EDITOR for resolving conflicts.  If it is not set, default to vi.
XEDITOR=${EDITOR:-/usr/bin/vi}
X
X# Handle command-specific argument processing such as complaining
X# about unsupported options.  Since the configuration file is always
X# included, do not complain about extra command line arguments that
X# may have been set via the config file rather than the command line.
Xcase $command in
X	update)
X		if [ -n "$rerun" -a -n "$tarball" ]; then
X			echo "Only one of -r or -t can be specified."
X			echo
X			usage
X		fi
X		;;
X	build|diff|resolve|status)
X		if [ -n "$dryrun" -o -n "$rerun" -o -n "$tarball" ]; then
X			usage
X		fi
X		;;
X	extract)
X		if [ -n "$dryrun" -o -n "$rerun" ]; then
X			usage
X		fi
X		;;
Xesac
X
X# Open the log file.  Don't truncate it if doing a minor operation so
X# that a minor operation doesn't lose log info from a major operation.
Xif ! mkdir -p $WORKDIR 2>/dev/null; then
X	echo "Failed to create work directory $WORKDIR"
Xfi
X
Xcase $command in
X	diff|resolve|status)
X		exec 3>>$LOGFILE
X		;;
X	*)
X		exec 3>$LOGFILE
X		;;
Xesac
X
X${command}_cmd "$@"
0aaf160dc5a25428702b4e8ff7be2998
echo x - ./src/etcupdate.8
sed 's/^X//' >./src/etcupdate.8 << '2095c3a550b6dd43f25f4389f31b5702'
X.\" Copyright (c) 2010 Advanced Computing Technologies LLC
X.\" Written by: John H. Baldwin <jhb at FreeBSD.org>
X.\" All rights reserved.
X.\"
X.\" Redistribution and use in source and binary forms, with or without
X.\" modification, are permitted provided that the following conditions
X.\" are met:
X.\" 1. Redistributions of source code must retain the above copyright
X.\"    notice, this list of conditions and the following disclaimer.
X.\" 2. Redistributions in binary form must reproduce the above copyright
X.\"    notice, this list of conditions and the following disclaimer in the
X.\"    documentation and/or other materials provided with the distribution.
X.\"
X.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X.\" SUCH DAMAGE.
X.\"
X.\" $FreeBSD$
X.\"
X.Dd April 26, 2010
X.Dt ETCUPDATE 8
X.Os
X.Sh NAME
X.Nm etcupdate
X.Nd "manage updates to system files not updated by installworld"
X.Sh SYNOPSIS
X.Nm
X.Op Fl nBF
X.Op Fl d Ar workdir
X.Op Fl r | Fl s Ar source | Fl t Ar tarball
X.Op Fl A Ar patterns
X.Op Fl D Ar destdir
X.Op Fl I Ar patterns
X.Op Fl L Ar logfile
X.Op Fl M Ar options
X.Nm
X.Cm build
X.Op Fl B
X.Op Fl d Ar workdir
X.Op Fl s Ar source
X.Op Fl L Ar logfile
X.Op Fl M Ar options
X.Ar tarball
X.Nm
X.Cm diff
X.Op Fl d Ar workdir
X.Op Fl D Ar destdir
X.Op Fl I Ar patterns
X.Op Fl L Ar logfile
X.Nm
X.Cm extract
X.Op Fl B
X.Op Fl d Ar workdir
X.Op Fl s Ar source | Fl t Ar tarball
X.Op Fl L Ar logfile
X.Op Fl M Ar options
X.Nm
X.Cm resolve
X.Op Fl d Ar workdir
X.Op Fl D Ar destdir
X.Op Fl L Ar logfile
X.Nm
X.Cm status
X.Op Fl d Ar workdir
X.Sh DESCRIPTION
XThe
X.Nm
Xutility is a tool for managing updates to files that are not updated as
Xpart of
X.Sq make installworld
Xsuch as files in
X.Pa /etc .
XIt manages updates by doing a three-way merge of changes made to these
Xfiles against the local versions.
XIt is also designed to minimize the amount of user intervention with
Xthe goal of simplifying upgrades for clusters of machines.
X.Pp
XTo perform a three-way merge,
X.Nm
Xkeeps copies of the current and previous versions of files that it manages.
XThese copies are stored in two trees known as the
X.Dq current
Xand
X.Dq previous
Xtrees.
XDuring a merge,
X.Nm
Xcompares the
X.Dq current
Xand
X.Dq previous
Xcopies of each file to determine which changes need to be merged into the
Xlocal version of each file.
XIf a file can be updated without generating a conflict,
X.Nm
Xwill update the file automatically.
XIf the local changes to a file conflict with the changes made to a file in
Xthe source tree,
Xthen a merge conflict is generated.
XThe conflict must be resolved after the merge has finished.
XThe
X.Nm
Xutility will not perform a new merge until all conflicts from an earlier
Xmerge are resolved.
X.Sh MODES
X.Pp
XThe
X.Nm
Xutility supports several modes of operation.
XThe mode is specified via an optional command argument.
XIf present, the command must be the first argument on the command line.
XIf a command is not specified, the default mode is used.
X.Ss Default Mode
XThe default mode merges changes from the source tree to the destination
Xdirectory.
XFirst,
Xit updates the
X.Dq current
Xand
X.Dq previous
Xtrees.
XNext,
Xit compares the two trees merging changes into the destination directory.
XFinally,
Xit displays warnings for any conditions it could not handle automatically.
X.Pp
XIf the
X.Fl r
Xoption is not specified,
Xthen the first step taken is to update the
X.Dq current
Xand
X.Dq previous
Xtrees.
XIf a
X.Dq current
Xtree already exists,
Xthen that tree is saved as the
X.Dq previous
Xtree.
XAn older
X.Dq previous
Xtree is removed if it exists.
XBy default the new 
X.Dq current
Xtree is built from a source tree.
XHowever,
Xif a tarball is specified via the
X.Fl t
Xoption,
Xthen the tree is extracted from that tarball instead.
X.Pp
XNext,
X.Nm
Xcompares the files in the
X.Dq current
Xand
X.Dq previous
Xtrees.
XIf a file was removed from the
X.Dq current
Xtree,
Xthen it will be removed from the destination directory only if it
Xdoes not have any local modifications.
XIf a file was added to the
X.Dq current
Xtree,
Xthen it will be copied to the destination directory only if it
Xwould not clobber an existing file.
XIf a file is changed in the
X.Dq current
Xtree,
Xthen
X.Nm
Xwill attempt to merge the changes into the version of the file in the
Xdestination directory.
XIf the merge encounters conflicts,
Xthen a version of the file with conflict markers will be saved for
Xfuture resolution.
XIf the merge does not encounter conflicts,
Xthen the merged version of the file will be saved in the destination
Xdirectory.
XIf
X.Nm
Xis not able to safely merge in changes to a file other than a merge conflict,
Xit will generate a warning.
X.Pp
XFor each file that is updated a line will be output with a leading character
Xto indicate the action taken.
XThe possible actions follow:
X.Pp
X.Bl -tag -width "A" -compact -offset indent
X.It A
XAdded
X.It C
XConflict
X.It D
XDeleted
X.It M
XMerged
X.It U
XUpdated
X.El
X.Pp
XFinally,
Xif any warnings were encountered they are displayed after the merge has
Xcompleted.
X.Pp
XNote that for certain files
X.Nm
Xwill perform post-install actions any time that the file is updated.
XSpecifically,
X.Xr pwd_mkdb 8
Xis invoked if
X.Pa /etc/master.passwd
Xis changed,
X.Xr cap_mkdb 1
Xis invoked to update
X.Pa /etc/login.conf.db
Xif
X.Pa /etc/login.conf
Xis changed,
Xand
X.Xr newaliases 1
Xis invoked if
X.Pa /etc/mail/aliases
Xis changed.
XOne exception is that if
X.Pa /etc/mail/aliases
Xis changed and the destination directory is not the default,
Xthen a warning will be issued instead.
XThis is due to a limitation of the
X.Xr newaliases 1
Xcommand.
X.Ss Build Mode
XThe
X.Cm build
Xmode is used to build a tarball that contains a snapshot of a
X.Dq current
Xtree.
XThis tarball can be used by the default and extract modes.
XUsing a tarball can allow
X.Nm
Xto perform a merge without requiring a source tree that matches the
Xcurrently installed world.
XThe
X.Fa tarball
Xargument specifies the name of the file to create.
XThe file will be a
X.Xr tar 5
Xfile compressed with
X.Xr bzip2 1 .
X.Ss Diff Mode
XThe
X.Cm diff
Xmode compares the versions of files in the destination directory to the
X.Dq current
Xtree and generates a unified format diff of the changes.
XThis can be used to determine which files have been locally modified and how.
XNote that
X.Nm
Xdoes not manage files that are not maintained in the source tree such as
X.Pa /etc/fstab
Xand
X.Pa /etc/rc.conf .
X.Ss Extract Mode
XThe
X.Cm extract
Xmode generates a new
X.Dq current
Xtree.
XUnlike the default mode,
Xit does not save any existing
X.Dq current
Xtree and does not modify any existing
X.Dq previous
Xtree.
XThe new
X.Dq current
Xtree can either be built from a source tree or extracted from a tarball.
X.Ss Resolve Mode
XThe
X.Cm resolve
Xmode is used to resolve any conflicts encountered during a merge.
XIn this mode,
X.Nm
Xiterates over any existing conflicts prompting the user for actions to take
Xon each conflicted file.
XFor each file, the following actions are available:
X.Pp
X.Bl -tag -width "(tf) theirs-full" -compact
X.It (p)  postpone
XIgnore this conflict for now.
X.It (df) diff-full
XShow all changes made to the merged file as a unified diff.
X.It (e)  edit
XChange the merged file in an editor.
X.It (r)  resolved
XInstall the merged version of the file into the destination directory.
X.It (mf) mine-full
XUse the version of the file in the destination directory and ignore any
Xchanges made to the file in the
X.Dq current
Xtree.
X.It (tf) theirs-full
XUse the version of the file from the
X.Dq current
Xtree and discard any local changes made to the file.
X.It (h)  help
XDisplay the list of commands.
X.El
X.Ss Status Mode
XThe
X.Cm status
Xmode shows a summary of the results of the most recent merge.
XFirst it lists any files for which there are unresolved conflicts.
XNext it lists any warnings generated during the last merge.
XIf the last merge did not generate any conflicts or warnings,
Xthen nothing will be output.
X.Sh OPTIONS
XThe following options are available.
XNote that most options do not apply to all modes.
X.Bl -tag -width ".Fl d Ar workdir"
X.It Fl B
XDo not build generated files in a private object tree.
XInstead,
Xreuse the generated files from a previously built object tree that matches
Xthe source tree.
XThis can be useful to avoid gratuitous conflicts in sendmail configuration
Xfiles when bootstrapping.
XIt can also be useful for building a tarball that matches a specific
Xworld build.
X.It Fl d Ar workdir
XSpecify an alternate directory to use as the work directory.
XThe work directory is used to store the
X.Dq current
Xand
X.Dq previous
Xtrees as well as unresolved conflicts.
XThe default work directory is
X.Pa /var/db/etcupdate .
X.It Fl A Ar patterns
XAlways install the new version of any files that match any of the patterns
Xlisted in
X.Ar patterns .
XEach pattern is evaluated as an
X.Xr sh 1
Xshell pattern.
XThis option may be specified multiple times to specify multiple patterns.
XMultiple space-separated patterns may also be specified in a single
Xoption.
XNote that ignored files specified via the
X.Ev IGNORE_FILES
Xvariable or the
X.Fl I
Xoption will not be installed.
X.It Fl D Ar destdir
XSpecify an alternate destination directory as the target of a merge.
XThis is analagous to the
X.Dv DESTDIR
Xvariable used with
X.Sq make installworld .
XThe default destination directory is an empty string which results in
Xmerges updating
X.Pa /etc
Xon the local machine.
X.It Fl F
XIgnore changes in the FreeBSD ID string when comparing files in the
Xdestination directory to files in either of the
X.Dq current
Xor
X.Dq previous
Xtrees.
XIn
X.Cm diff
Xmode,
Xthis reduces noise due to FreeBSD ID string changes in the output.
XDuring an update this can simplify handling for harmless conflicts caused
Xby FreeBSD ID string changes.
X.Pp
XSpecifically,
Xif a file in the destination directory is identical to the same file in the
X.Dq previous
Xtree modulo the FreeBSD ID string,
Xthen the file is treated as if it was unmodified and the
X.Dq current
Xversion of the file will be installed.
XSimilarly,
Xif a file in the destination directory is identical to the same file in the
X.Dq current
Xtree modulo the FreeBSD ID string,
Xthen the
X.Dq current
Xversion of the file will be installed to update the ID string.
XIf the
X.Dq previous
Xand
X.Dq current
Xversions of the file are identical,
Xthen
X.Nm
Xwill not change the file in the destination directory.
X.Pp
XDue to limitations in the
X.Xr diff 1
Xcommand,
Xthis option may not have an effect if there are other changes in a file that
Xare close to the FreeBSD ID string.
X.It Fl I Ar patterns
XIgnore any files that match any of the patterns listed in
X.Ar patterns .
XNo warnings or other messages will be generated for those files during a
Xmerge.
XEach pattern is evaluated as an
X.Xr sh 1
Xshell pattern.
XThis option may be specified multiple times to specify multiple patterns.
XMultiple space-separated patterns may also be specified in a single
Xoption.
X.It Fl L Ar logfile
XSpecify an alternate path for the log file.
XThe
X.Nm
Xutility logs each command that it invokes along with the standard output
Xand standard error to this file.
XBy default the log file is stored in a file named
X.Pa log
Xin the work directory.
X.It Fl M Ar options
XPass
X.Ar options
Xas additional parameters to
X.Xr make 1
Xwhen building a
X.Dq current
Xtree.
XThis can be used for to set the
X.Dv TARGET
Xor
X.Dv TARGET_ARCH
Xvariables for a cross-build.
X.It Fl n
XEnable
X.Dq dry-run
Xmode.
XDo not merge any changes to the destination directory.
XInstead,
Xreport what actions would be taken during a merge.
XNote that the existing
X.Dq current
Xand
X.Dq previous
Xtrees will not be changed.
XIf the
X.Fl r
Xoption is not specified,
Xthen a temporary
X.Dq current
Xtree will be extracted to perform the comparison.
X.It Fl r
XDo not update the
X.Dq current
Xand
X.Dq previous
Xtrees during a merge.
XThis can be used to
X.Dq re-run
Xa previous merge operation.
X.It Fl s Ar source
XSpecify an alternate source tree to use when building or extracting a
X.Dq current
Xtree.
XThe default source tree is
X.Pa /usr/src .
X.It Fl t Ar tarball
XExtract a new
X.Dq current
Xtree from a tarball previously generated by the
X.Cm build
Xcommand rather than building the tree from a source tree.
X.El
X.Sh CONFIG FILE
XThe
X.Nm
Xutility can also be configured by setting variables in an optional
Xconfiguration file named
X.Pa /etc/etcupdate.conf .
XNote that command line options override settings in the configuration file.
XThe configuration file is executed by
X.Xr sh 1 ,
Xso it uses that syntax to set configuration variables.
XThe following variables can be set:
X.Bl -tag -width ".Ev ALWAYS_INSTALL"
X.It Ev ALWAYS_INSTALL
XAlways install files that match any of the patterns listed in this variable
Xsimilar to the
X.Fl A
Xoption.
X.It Ev DESTDIR
XSpecify an alternate destination directory similar to the
X.Fl D
Xoption.
X.It Ev EDITOR
XSpecify a program to edit merge conflicts.
X.It Ev FREEBSD_ID
XIgnore changes in the FreeBSD ID string similar to the
X.Fl F
Xoption.
XThis is enabled by setting the variable to a non-empty value.
X.It Ev IGNORE_FILES
XIgnore files that match any of the patterns listed in this variable
Xsimilar to the
X.Fl I
Xoption.
X.It Ev LOGFILE
XSpecify an alternate path for the log file similar to the
X.Fl L
Xoption.
X.It Ev MAKE_OPTIONS
XPass additional options to
X.Xr make 1
Xwhen building a
X.Dq current
Xtree similar to the
X.Fl M
Xoption.
X.It Ev SRCDIR
XSpecify an alternate source tree similar to the
X.Fl s
Xoption.
X.It Ev WORKDIR
XSpecify an alternate work directory similar to the
X.Fl d
Xoption.
X.El
X.Sh ENVIRONMENT
XThe
X.Nm
Xutility uses the program identified in the
X.Ev EDITOR
Xenvironment variable to edit merge conflicts.
XIf
X.Ev EDITOR
Xis not set,
X.Xr vi 1
Xis used as the default editor.
X.Sh FILES
X.Bl -tag -width ".Pa /var/db/etcupdate/log" -compact
X.It Pa /etc/etcupdate.conf
XOptional config file.
X.It Pa /var/db/etcupdate
XDefault work directory used to store trees and other data.
X.It Pa /var/db/etcupdate/log
XDefault log file.
X.El
X.Sh EXIT STATUS
X.Ex -std
X.Sh EXAMPLES
XIf the source tree matches the currently installed world,
Xthen the following can be used to bootstrap
X.Nm
Xso that it can be used for future upgrades:
X.Pp
X.Dl "etcupdate extract"
X.Pp
XTo merge changes after an upgrade via the buildworld and installworld process:
X.Pp
X.Dl "etcupdate"
X.Pp
XTo resolve any conflicts generated during a merge:
X.Pp
X.Dl "etcupdate resolve"
X.Sh DIAGNOSTICS
XThe following warning messages may be generated during a merge.
XNote that several of these warnings cover obscure cases that should occur
Xrarely if at all in practice.
XFor example,
Xif a file changes from a file to a directory in the
X.Dq current
Xtree
Xand the file was modified in the destination directory,
Xthen a warning will be triggered.
XIn general,
Xwhen a warning references a pathname,
Xthe corresponding file in the destination directory is not changed by a
Xmerge operation.
X.Bl -diag
X.It "Directory mismatch: <path> (<type>)"
XAn attempt was made to create a directory at
X.Pa path
Xbut an existing file of type
X.Dq type
Xalready exists for that path name.
X.It "Modified link changed: <file> (<old> became <new>)"
XThe target of a symbolic link named
X.Pa file
Xwas changed from
X.Dq old
Xto
X.Dq new
Xin the
X.Dq current
Xtree.
XThe symbolic link has been modified to point to a target that is neither
X.Dq old
Xnor
X.Dq new
Xin the destination directory.
X.It "Modified mismatch: <file> (<new> vs <dest>)"
XA file named
X.Pa file
Xof type
X.Dq new
Xwas modified in the
X.Dq current
Xtree,
Xbut the file exists as a different type
X.Dq dest
Xin the destination directory.
X.It "Modified <type> changed: <file> (<old> became <new>)"
XA file named
X.Pa file
Xchanged type from
X.Dq old
Xin the
X.Dq previous
Xtree to type
X.Dq new
Xin the
X.Dq current
Xtree.
XThe file in the destination directory of type
X.Dq type
Xhas been modified,
Xso it could not be merged automatically.
X.It "Modified <type> remains: <file>"
XThe file of type
X.Dq type
Xnamed
X.Pa file
Xhas been removed from the
X.Dq current
Xtree,
Xbut it has been locally modified.
XThe modified version of the file remains in the destination directory.
X.It "Needs update: /etc/mail/aliases.db (required manual update via newaliases(1))"
XThe file
X.Pa /etc/mail/aliases
Xwas updated during a merge with a non-empty destination directory.
XDue to a limitation of the
X.Xr newaliases 1
Xcommand,
X.Nm
Xwas not able to automatically update the corresponding aliases database.
X.It "New file mismatch: <file> (<new> vs <dest>)"
XA new file named
X.Pa file
Xof type
X.Dq new
Xhas been added to the
X.Dq current
Xtree.
XA file of that name already exists in the destination directory,
Xbut it is of a different type
X.Dq dest .
X.It "New link conflict: <file> (<new> vs <dest>)"
XA symbolic link named
X.Pa file
Xhas been added to the
X.Dq current
Xtree that links to
X.Dq new .
XA symbolic link of the same name already exists in the destination
Xdirectory,
Xbut it links to a different target
X.Dq dest .
X.It "Non-empty directory remains: <file>"
XThe directory
X.Pa file
Xwas removed from the
X.Dq current
Xtree,
Xbut it contains additional files in the destination directory.
XThese additional files as well as the directory remain.
X.It "Remove mismatch: <file> (<old> became <new>)"
XA file named
X.Pa file
Xchanged from type
X.Dq old
Xin the
X.Dq previous
Xtree to type
X.Dq new
Xin the
X.Dq current
Xtree,
Xbut it has been removed in the destination directory.
X.It "Removed file changed: <file>"
XA file named
X.Pa file
Xwas modified in the
X.Dq current
Xtree,
Xbut it has been removed in the destination directory.
X.It "Removed link changed: <file> (<old> became <new>)"
XThe target of a symbolic link named
X.Pa file
Xwas changed from
X.Dq old
Xto
X.Dq new
Xin the
X.Dq current
Xtree,
Xbut it has been removed in the destination directory.
X.El
X.Sh SEE ALSO
X.Xr cap_mkdb 1 ,
X.Xr diff 1 , 
X.Xr make 1 ,
X.Xr newaliases 1 ,
X.Xr sh 1 ,
X.Xr pwd_mkdb 8
X.\".Sh HISTORY
X.Sh AUTHORS
XThe
X.Nm
Xutility was written by
X.An John Baldwin Aq jhb at FreeBSD.org .
X.Sh BUGS
XRerunning a merge does not automatically delete conflicts left over from a
Xprevious merge.
XAny conflicts must be resolved before the merge can be rerun.
XIt it is not clear if this is a feature or a bug.
X.Pp
XThere is no way to easily automate conflict resolution for specific files.
XFor example, one can imagine a syntax along the lines of
X.Pp
X.Dl "etcupdate resolve tf /some/file"
X.Pp
Xto resolve a specific conflict in an automated fashion.
X.Pp
XIt might be nice to have something like a
X.Sq revert
Xcommand to replace a locally modified version of a file with the stock
Xversion of the file.
XFor example:
X.Pp
X.Dl "etcupdate revert /etc/mail/freebsd.cf"
X.Pp
XBootstrapping
X.Nm
Xoften results in gratuitous diffs in
X.Pa /etc/mail/*.cf
Xthat cause conflicts in the first merge.
XIf an object tree that matches the source tree is present when bootstrapping,
Xthen passing the
X.Fl B
Xflag to the
X.Cm extract
Xcommand can work around this.
2095c3a550b6dd43f25f4389f31b5702
echo x - ./pkg-descr
sed 's/^X//' >./pkg-descr << '0e313719ff012ceaf97a028d51caa8f5'
XThe etcupdate utility is a tool for managing updates to files that are
Xnot updated as part of `make installworld' such as files in /etc.  It
Xmanages updates by doing a three-way merge of changes made to these files
Xagainst the local versions.  It is also designed to minimize the amount
Xof user intervention with the goal of simplifying upgrades for clusters
Xof machines.
X
XThe primary difference from mergemaster is that etcupdate requires less
Xmanual work.  The primary difference from etcmerge is that etcupdate
Xupdates files in-place similar to mergemaster rather than building a
Xseparate /etc tree.
0e313719ff012ceaf97a028d51caa8f5
echo x - ./Makefile
sed 's/^X//' >./Makefile << '464ef7c6571951809b23e262cbe26e19'
X# New ports collection makefile for:		etcupdate
X# Date created:					08 July 2010
X# Whom:						jhb
X#
X# $FreeBSD$
X#
X# This port is self contained in the src directory.
X#
X
XPORTNAME=	etcupdate
XPORTVERSION=	0.1
XCATEGORIES=	sysutils textproc
XMASTER_SITES=	# none
XDISTFILES=	# none
X
XMAINTAINER=	jhb at FreeBSD.org
XCOMMENT=	Manage updates to /etc automatically
X
XNO_BUILD=	yes
XNO_WRKSUBDIR=	yes
X
XSRC=		${.CURDIR}/src
X
XMAN8=		${PORTNAME}.8
XPLIST_FILES=	sbin/etcupdate
X
Xdo-fetch:
X	@${DO_NADA}
X
Xdo-install:
X	@${INSTALL_SCRIPT} ${SRC}/${PORTNAME}.sh ${PREFIX}/sbin/${PORTNAME}
X	@${INSTALL_MAN} ${SRC}/${PORTNAME}.8 ${PREFIX}/man/man8
X
X.include <bsd.port.mk>
464ef7c6571951809b23e262cbe26e19
echo x - ./pkg-descr~
sed 's/^X//' >./pkg-descr~ << '59167ef78f12231be22161279fc99067'
XThe etcupdate utility is a tool for managing updates to files that are
Xnot updated as part of `make installworld' such as files in /etc.  It
Xmanages updates by doing a three-way merge of changes made to these files
Xagainst the local versions.  It is also designed to minimize the amount
Xof user intervention with the goal of simplifying upgrades for clusters
Xof machines.
X
XThe primary difference from mergemaster is that etcupdate requires less
Xmanual work.  The primary difference from etcmerge is that etcupdate
Xupdates files in-place similar to mergemaster rather than building a
Xseperate /etc tree.
59167ef78f12231be22161279fc99067
exit

-- 
John Baldwin


More information about the freebsd-ports mailing list