diff options
Diffstat (limited to 'sysutils/etcupdate')
-rw-r--r-- | sysutils/etcupdate/DESCR | 9 | ||||
-rw-r--r-- | sysutils/etcupdate/Makefile | 25 | ||||
-rw-r--r-- | sysutils/etcupdate/PLIST | 3 | ||||
-rwxr-xr-x | sysutils/etcupdate/files/etcupdate | 415 | ||||
-rw-r--r-- | sysutils/etcupdate/files/etcupdate.8 | 166 |
5 files changed, 618 insertions, 0 deletions
diff --git a/sysutils/etcupdate/DESCR b/sysutils/etcupdate/DESCR new file mode 100644 index 00000000000..8f2a7473cbd --- /dev/null +++ b/sysutils/etcupdate/DESCR @@ -0,0 +1,9 @@ +etcupdate helps you to update the configuration files in /etc after +performing an operating system upgrade. + +The idea for this script (including code fragments, variable names etc.) +came from the FreeBSD mergemaster (by Douglas Barton). Unlike the FreeBSD +mergemaster, this does not use CVS version tags to compare if the files +need to be updated. Files are compared with /usr/bin/cmp as this is more +reliable and the only way if the version numbers are same even though the +files are different. diff --git a/sysutils/etcupdate/Makefile b/sysutils/etcupdate/Makefile new file mode 100644 index 00000000000..e9baad6c68e --- /dev/null +++ b/sysutils/etcupdate/Makefile @@ -0,0 +1,25 @@ +# $NetBSD: Makefile,v 1.1.1.1 2001/11/20 09:53:54 martti Exp $ + +DISTNAME= etcupdate-20011114 +CATEGORIES= sysutils +MASTER_SITES= # empty +DISTFILES= # empty + +MAINTAINER= packages@netbsd.org +HOMEPAGE= http://www.netbsd.org/Documentation/current/ +COMMENT= Script to update configuration files in /etc + +EXTRACT_ONLY= # defined +WRKSRC= ${WRKDIR} +NO_CHECKSUM= # defined +NO_PATCH= # defined +NO_CONFIGURE= # defined +NO_BUILD= # defined + +.include "../../mk/bsd.prefs.mk" + +do-install: + ${INSTALL_SCRIPT} ${FILESDIR}/etcupdate ${PREFIX}/bin/etcupdate + ${INSTALL_MAN} ${FILESDIR}/etcupdate.8 ${PREFIX}/man/man8 + +.include "../../mk/bsd.pkg.mk" diff --git a/sysutils/etcupdate/PLIST b/sysutils/etcupdate/PLIST new file mode 100644 index 00000000000..b2cbb95e97f --- /dev/null +++ b/sysutils/etcupdate/PLIST @@ -0,0 +1,3 @@ +@comment $NetBSD: PLIST,v 1.1.1.1 2001/11/20 09:53:54 martti Exp $ +bin/etcupdate +man/man8/etcupdate.8 diff --git a/sysutils/etcupdate/files/etcupdate b/sysutils/etcupdate/files/etcupdate new file mode 100755 index 00000000000..d18117317b5 --- /dev/null +++ b/sysutils/etcupdate/files/etcupdate @@ -0,0 +1,415 @@ +#!/bin/sh +# +# $NetBSD: etcupdate,v 1.1.1.1 2001/11/20 09:53:55 martti Exp $ +# +# Copyright (c) 2001 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Martti Kuparinen. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by the NetBSD +# Foundation, Inc. and its contributors. +# 4. Neither the name of The NetBSD Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# +# This script helps you to update the configuration files in /etc +# after an operating system upgrade. Instead of running "make distribution" +# in /usr/src/etc (and losing your current configuration) you can easily +# see the modifications and either install the new version or merge the +# changes in to your current configuration files. +# +# This script was written by Martti Kuparinen <martti@netbsd.org> and +# improved by several other NetBSD users. +# +# The idea for this script (including code fragments, variable names etc.) +# came from the FreeBSD mergemaster (by Douglas Barton). +# +PATH=/sbin:/usr/sbin:/bin:/usr/bin + +# Default settings +TEMPROOT="${TEMPROOT:=/tmp/temproot}" +SRCDIR="${SRCDIR:=/usr/src}" +PAGER="${PAGER:=/usr/bin/more}" +WIDTH="${WIDTH:=80}" +VERBOSE= +CONTINUE= + +# Settings for post-installlation procedures +NEED_MTREE= +NEED_MAKEDEV= +NEED_NEWALIASES= +NEED_PWD_MKDB= + +usage() { + cat << EOF + +Usage: `basename $0` [options] + +Options: + + -p pager Which pager to use (default: /usr/bin/more) + -s srcdir Location of the source files (default: /usr/src) + -t temproot Where to store temporary files (default: /tmp/temproot) + -w width Screen width (default: 80) + + -h This help text + -v Be more verbose + +EOF + exit 1 +} + +verbose() { + # $* = message to display if in verbose mode + + [ ! -z "${VERBOSE}" ] && echo ${*} +} + +yesno() { + # $* = message to display + + echo -n "${*} (y/[n]) " + read ANSWER + case "${ANSWER}" in + y|Y) + return 0 + ;; + *) + return 1 + ;; + esac +} + +install_dir() { + # $1 = target directory + + if yesno "Create ${1}"; then + verbose "Creating ${1}" + mkdir -p "${1}" || exit 1 + NEED_MTREE=YES + fi +} + +install_file() { + # $1 = target file + + # Install the new file + verbose "Installing ${1}" + cp -p "${TEMPROOT}${1}" "${1}" && rm -f "${TEMPROOT}${1}" + + # Check if this was a special file + case "${1}" in + /dev/MAKEDEV) + NEED_MAKEDEV=YES + ;; + /dev/MAKEDEV.local) + NEED_MAKEDEV=YES + ;; + /etc/mail/aliases) + NEED_NEWALIASES=YES + ;; + /etc/master.passwd) + NEED_PWD_MKDB=YES + ;; + esac +} + +diff_and_merge_file() { + # $1 = target file + + if cmp -s "${TEMPROOT}${1}" "${1}"; then + verbose "===> ${1} (ok)" + rm -f "${TEMPROOT}${1}" + return + fi + + if [ ! -f "${1}" ]; then + verbose "===> ${1} (missing)" + DOES_EXIST= + else + verbose "===> ${1} (modified)" + verbose "" + DOES_EXIST=YES + diff -u "${1}" "${TEMPROOT}${1}" | ${PAGER} + fi + + STAY_HERE=YES + while [ "x${STAY_HERE}" = "xYES" ]; do + + # Ask the user if (s)he wants to install the new + # version or perform a more complicated manual work. + echo "" + echo -n "File: ${1}" + if [ ! -f "${1}" ]; then + echo -n " (missing)" + else + echo -n " (modified)" + fi + echo "" + echo "" + echo "Please select one of the following operations:" + echo "" + if [ -z "${DOES_EXIST}" ]; then + cat << EOF + d Don't install the missing file + i Install the missing file + v Show the missing file + +EOF + else + cat << EOF + i Install the new file + m Merge the currently installed and new file + s Show the differences between the installed and new file + v Show the new file + +EOF + fi + echo -n "What do you want to do? [Leave it for later] " + read ANSWER + case "${ANSWER}" in + [dD]) + verbose "Removing ${TEMPROOT}${1}" + rm -f "${TEMPROOT}${1}" + STAY_HERE=NO + ;; + [iI]) + install_file "${1}" + STAY_HERE=NO + ;; + [mM]) + [ -z "${DOES_EXIST}" ] && continue + cp "${TEMPROOT}${1}" "${TEMPROOT}${1}.merged" + sdiff -o "${TEMPROOT}${1}.merged" \ + --width=${WIDTH} \ + --suppress-common-lines --text \ + "${1}" "${TEMPROOT}${1}" + mv -f "${TEMPROOT}${1}.merged" "${TEMPROOT}${1}" + ;; + [sS]) + [ -z "${DOES_EXIST}" ] && continue + diff -u "${1}" "${TEMPROOT}${1}" | ${PAGER} + ;; + [vV]) + ${PAGER} "${TEMPROOT}${1}" + ;; + "") + STAY_HERE=NO + ;; + *) + echo "*** Invalid selection!" + ;; + esac + done +} + +# +# main() +# + +# Read global configuration +GLOBALRC="/etc/`basename $0`.conf" +[ -r ${GLOBALRC} ] && . ${GLOBALRC} + +# Read user configuration +USERRC="${HOME}/.`basename $0`rc" +[ -r ${USERRC} ] && . ${USERRC} + +# Read command line arguments +ARGV=`getopt hp:s:t:vw: $*` +[ $? != 0 ] && usage +set -- ${ARGV} +for i; do + case "${i}" in + -h) + usage + ;; + -p) + PAGER="${2}" + shift + ;; + -s) + SRCDIR="${2}" + shift + ;; + -t) + TEMPROOT="${2}" + shift + ;; + -v) + VERBOSE=YES + shift + ;; + -w) + WIDTH="${2}" + shift + ;; + --) + shift + break + ;; + esac +done + +# Last minute sanity checks +if [ `id -u` -ne 0 ]; then + echo "*** WARNING: You MUST be root" + exit 1 +fi +if [ -z "${SRCDIR}" -o -z "${TEMPROOT}" ]; then + echo "*** ERROR: One of the following variables is undefined" + echo "" + echo "SRCDIR=\"${SRCDIR}\"" + echo "TEMPROOT=\"${TEMPROOT}\"" + echo "" + exit 1 +fi +if [ -r "${TEMPROOT}" ]; then + echo "" + echo "*** WARNING: ${TEMPROOT} already exists" + echo "" + if yesno "Continue previously aborted update"; then + CONTINUE=YES + elif yesno "Remove the old ${TEMPROOT}"; then + echo "*** Removing ${TEMPROOT}" + rm -rf "${TEMPROOT}" + fi +fi + +if [ -z "${CONTINUE}" ]; then + # Create the temporary root directory + echo "*** Creating ${TEMPROOT}" + mkdir -p "${TEMPROOT}" + if [ ! -d "${TEMPROOT}" ]; then + echo "*** ERROR: Unable to create ${TEMPROOT}" + exit 1 + fi + + # Populate ${TEMPROOT} from ${SRCDIR} + if [ ! -f "${SRCDIR}/etc/Makefile" ]; then + echo "*** ERROR: Unable to find ${SRCDIR}/etc/Makefile" + exit 1 + fi + echo "*** Populating ${TEMPROOT} from ${SRCDIR}" + cd ${SRCDIR}/etc + if [ -z "${VERBOSE}" ]; then + make DESTDIR="${TEMPROOT}" INSTALL_DONE=1 NO_SENDMAIL=1 \ + distribution > /dev/null + else + make DESTDIR="${TEMPROOT}" INSTALL_DONE=1 NO_SENDMAIL=1 \ + distribution + fi + + # Ignore the following files during comparision + rm -f "${TEMPROOT}"/etc/passwd + rm -f "${TEMPROOT}"/etc/pwd.db + rm -f "${TEMPROOT}"/etc/spwd.db + find "${TEMPROOT}" -type f -size 0 -exec rm {} \; + + # Are there any new directories? + echo "*** Checking for new directories" + for i in `find ${TEMPROOT} -type d`; do + D=`echo ${i} | sed "s#${TEMPROOT}##"` + [ "x${i}" = "x${TEMPROOT}" ] && continue + [ ! -d "${D}" ] && install_dir "${D}" + done +fi + +# Start the comparision +echo "*** Checking for added/modified files" +for i in `find ${TEMPROOT} -type f`; do + D=`echo ${i} | sed "s#${TEMPROOT}##"` + diff_and_merge_file "${D}" +done + +# Do we have files which were not processed? +REMAINING=`find "${TEMPROOT}" -type f` +if [ ! -z "${REMAINING}" ]; then + echo "" + echo "*** The following files need your attention:" + echo "" + for i in ${REMAINING}; do + echo " ${i}" + done + echo "" +fi +if yesno "Remove ${TEMPROOT}"; then + echo "*** Removing ${TEMPROOT}" + rm -rf "${TEMPROOT}" +else + echo "*** Keeping ${TEMPROOT}" +fi + +# Do some post-installation tasks +if [ ! -z "${NEED_MTREE}" ]; then + if yesno "You have created new directories. Run mtree to set" \ + "permissions" + then + mtree -Udef /etc/mtree/NetBSD.dist + fi +fi +if [ ! -z "${NEED_MAKEDEV}" ]; then + if yesno "Do you want to rebuild the device nodes in /dev"; then + verbose "Running MAKEDEV in /dev" + (cd "/dev" && ./MAKEDEV all) + else + echo "" + echo "*** You SHOULD rebuild the device nodes in /dev" + echo "*** This is done by running \"(cd /dev &&" \ + "./MAKEDEV all)\" as root". + echo "" + fi +fi +if [ ! -z "${NEED_NEWALIASES}" ]; then + if yesno "Do you want to rebuild the mail alias database"; then + verbose "Running newaliases" + newaliases + else + echo "" + echo "*** You MUST rebuild the mail alias database to make" \ + "the changes visible" + echo "*** This is done by running \"newaliases\" as root" + echo "" + fi +fi +if [ ! -z "${NEED_PWD_MKDB}" ]; then + if yesno "Do you want to rebuild the password databases from the" \ + "new master.passwd" + then + verbose "Running pwd_mkdb" + pwd_mkdb -p "/etc/master.passwd" + else + echo "" + echo "*** Do MUST rebuild the password databases to make" \ + "the changes visible" + echo "*** This is done by running \"pwd_mkdb -p" \ + "/etc/master.passwd\" as root" + echo "" + fi +fi +echo "*** All done" diff --git a/sysutils/etcupdate/files/etcupdate.8 b/sysutils/etcupdate/files/etcupdate.8 new file mode 100644 index 00000000000..d9a1f5fb70d --- /dev/null +++ b/sysutils/etcupdate/files/etcupdate.8 @@ -0,0 +1,166 @@ +.\" $NetBSD: etcupdate.8,v 1.1.1.1 2001/11/20 09:53:55 martti Exp $ +.\" +.\" Copyright (c) 2001 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Martti Kuparinen. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd November 14, 2001 +.Dt ETCUPDATE 8 +.Os +.Sh NAME +.Nm etcupdate +.Nd update the configuration files in +.Pa /etc +.Sh SYNOPSIS +.Nm +.Op Fl h +.Op Fl p Ar pager +.Op Fl s Ar srcdir +.Op Fl t Ar temproot +.Op Fl v +.Op Fl w Ar width +.Sh DESCRIPTION +.Pa etcupdate +is a tool to update the configuration files in +.Pa /etc +without the need of manually checking and modifying every file. +The user should run this script after performing an operating system +update (i.e. after running +.Pa make build +in +.Pa /usr/src +) to use the latest configuration files during reboot. + +.Pa etcupdate +will first create a copy of the new configuration files and compare these +against the installed files. The user is given an option of installing, +merging or deleting of each modified or missing files. + +.Pa etcupdate +also notes if the user installs certain special files and performs +corresponding tasks like remaking the device nodes or rebuilding a database +from the +.Pa /etc/mail/aliases +file. +.Sh ENVIRONMENT +.Pa TEMPROOT + +The temporary files created from +.Pa /usr/src/etc +will be stored here. These files will then be compared +against the currently installed files in the +.Pa /etc +directory. By default this is +.Pa /tmp/temproot +but can be changed either with the +.Fl t Ar temproot +argument or by defining the +.Pa TEMPROOT +variable. + +.Pa SRCDIR + +The location of the NetBSD sources files. By default this is +.Pa /usr/src +but can be changed either with the +.Fl s Ar srcdir +argument or by defining the +.Pa SRCDIR +variable. + +.Pa PAGER + +The pager to use when displaying files. By default this is +.Pa /usr/bin/more +but can be changed either with the +.Fl p Ar pager +argument or by defining the +.Pa PAGER +variable. + +.Pa WIDTH + +The screen width used during interactive merge. By default this is +.Pa 80 +but can be changed either with the +.Fl w Ar width +argument or by defining the +.Pa WIDTH +variable. +This is useful for +.Pa xterm(1) +users with wider shell windows. +.Sh FILES +The environment variables can also be defined in the following configuration +files. The user's personal configuration file settings override the global +settings. + +.Pa /etc/etcupdate.conf + +.Pa ~/.etcupdaterc +.Sh EXAMPLES +You have just upgraded your NetBSD host from 1.5.2 to 1.5.3 and now it's time +to update the configuration files as well. This can be done with the +following command: + +.Dl etcupdate + +To get a better idea what's going on, use the +.Fl v +flag: + +.Dl etcupdate -v + +The default location of the source files is +.Pa /usr/src +but this may be overridden with the +.Fl s Ar srcdir +command line argument: + +.Dl etcupdate -s /some/where/src +.Sh HISTORY +The +.Pa etcupdate +command appeared in NetBSD 1.5.3. +.Sh AUTHORS +The +script was written by Martti Kuparinen <martti@netbsd.org> and +improved by several other NetBSD users. + +The idea for this script (including code fragments, variable names etc.) +came from the FreeBSD mergemaster (by Douglas Barton). Unlike the +FreeBSD mergemaster, this does not use CVS version tags to compare if +the files need to be updated. Files are compared with +.Pa /usr/bin/cmp +as this is more reliable and the only way if the version numbers are +same even though the files are different. |