diff options
author | eivind <eivind@FreeBSD.org> | 2003-07-31 00:55:35 +0800 |
---|---|---|
committer | eivind <eivind@FreeBSD.org> | 2003-07-31 00:55:35 +0800 |
commit | 22b039cc5e5e81d423e9b05ef5cf934e9f94fbbf (patch) | |
tree | 7f0f8f8c15f8cecf197edd85e269445ea550cceb /sysutils | |
parent | 1ec2ae98a02646c996c64163462111a585f1c28b (diff) | |
download | freebsd-ports-gnome-22b039cc5e5e81d423e9b05ef5cf934e9f94fbbf.tar.gz freebsd-ports-gnome-22b039cc5e5e81d423e9b05ef5cf934e9f94fbbf.tar.zst freebsd-ports-gnome-22b039cc5e5e81d423e9b05ef5cf934e9f94fbbf.zip |
3-way merge for /etc (mergemaster replacement)
Diffstat (limited to 'sysutils')
-rw-r--r-- | sysutils/Makefile | 1 | ||||
-rw-r--r-- | sysutils/etcmerge/Makefile | 34 | ||||
-rw-r--r-- | sysutils/etcmerge/pkg-descr | 4 | ||||
-rw-r--r-- | sysutils/etcmerge/pkg-plist | 1 | ||||
-rw-r--r-- | sysutils/etcmerge/src/etcmerge.8 | 269 | ||||
-rw-r--r-- | sysutils/etcmerge/src/etcmerge.sh | 401 |
6 files changed, 710 insertions, 0 deletions
diff --git a/sysutils/Makefile b/sysutils/Makefile index 416a7fbda9ab..1490e6ba6c8b 100644 --- a/sysutils/Makefile +++ b/sysutils/Makefile @@ -78,6 +78,7 @@ SUBDIR += e2fsprogs SUBDIR += eject SUBDIR += enteruser + SUBDIR += etcmerge SUBDIR += extipl SUBDIR += fastest_cvsup SUBDIR += fastresolve diff --git a/sysutils/etcmerge/Makefile b/sysutils/etcmerge/Makefile new file mode 100644 index 000000000000..1b22484e20e5 --- /dev/null +++ b/sysutils/etcmerge/Makefile @@ -0,0 +1,34 @@ +# New ports collection makefile for: etcmerge +# Date created: 05 July 2003 +# Whom: eivind +# +# $FreeBSD$ +# +# This port is self contained in the src directory. +# + +PORTNAME= etcmerge +PORTVERSION= 0.1 +CATEGORIES= sysutils textproc +MASTER_SITES= # none +DISTFILES= # none + +MAINTAINER= eivind@FreeBSD.org +COMMENT= "Automatic 3-way merge of /etc updates" + +NO_BUILD= yes +NO_WRKSUBDIR= yes +NO_MAN= yes + +SRC= ${.CURDIR}/src + +MAN8= ${PORTNAME}.8 + +do-fetch: + @${DO_NADA} + +do-install: + @${INSTALL_SCRIPT} ${SRC}/${PORTNAME}.sh ${PREFIX}/sbin/${PORTNAME} + @${INSTALL_MAN} ${SRC}/${PORTNAME}.8 ${PREFIX}/man/man8 + +.include <bsd.port.mk> diff --git a/sysutils/etcmerge/pkg-descr b/sysutils/etcmerge/pkg-descr new file mode 100644 index 000000000000..cb9c3b50c6fe --- /dev/null +++ b/sysutils/etcmerge/pkg-descr @@ -0,0 +1,4 @@ +etcmerge is a tool for keeping /etc up to date when updating. +The primary difference from mergemaster is that etcmerge +requires much less manual work than mergemaster, due to the +use of a three way merge. diff --git a/sysutils/etcmerge/pkg-plist b/sysutils/etcmerge/pkg-plist new file mode 100644 index 000000000000..d370acbd6f37 --- /dev/null +++ b/sysutils/etcmerge/pkg-plist @@ -0,0 +1 @@ +sbin/etcmerge diff --git a/sysutils/etcmerge/src/etcmerge.8 b/sysutils/etcmerge/src/etcmerge.8 new file mode 100644 index 000000000000..37205c8080c1 --- /dev/null +++ b/sysutils/etcmerge/src/etcmerge.8 @@ -0,0 +1,269 @@ +.\"- +.\" Copyright (c) 2003 Eivind Eklund +.\" All rights reserved. +.\" +.\" 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 +.\" in this position and unchanged. +.\" 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. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. +.\" +.\" $FreeBSD$ +.\" +.Dd July 5, 2003 +.Dt ETCMERGE 1 +.Sh NAME +.Nm etcmerge +.Nd 3-way merge of /etc with updates from /usr/src +.Sh SYNOPSIS +.Nm etcmerge +.Cm init +.Nm +.Cm install +.Sh DESCRIPTION +.Pp +WARNING: ETCMERGE HAS NOT UNDERGONE EXTENSIVE PRODUCTION USE, SO USE AT YOUR +OWN RISK. +Taking a backup of +.Pa /etc +before running it won't hurt. +.Pp +.Nm +is a tool for keeping your +.Pa /etc +up to date as you update your system. +It fills the same niche as +.Xr mergemaster 8 , +with the primary difference being that +.Nm +requires much less manual work. +This is because +.Nm +merges two sets of changes instead of two copies of etc: +The changes you have done locally are merged with the changes done by +.Fx . +.Nm +does this by tracking three instead of two copies of +.Pa etc +- the active +.Pa /etc +(the one you are running your system on), the new etc distributed from +.Fx +(generated from +.Pa /usr/src +by +.Nm +), and a reference copy of the etc that was originally distributed from +.Fx +and which you have changed to get the active +.Pa /etc . +.Pp +The use of all three copies allow +.Nm +to find the two sets of changes - changes by you (the difference from +reference to installed etc) and changes by +.Fx +(the difference from reference etc to new etc). +.Pp +A three way merge is usually fully automated - no user interaction is needed +for the merge itself. +However, sometimes conflicting changes have been made - you have done one +change, and +.Fx +has done a different change to the same part of +.Pa /etc . +.Sh "ROUGH DESCRIPTION OF USE" +.Pp +First, ensure you have a copy of the /etc distributed by FreeBSD (BEFORE you or +.Xr sysinstall 8 +started modifying it) stored in +.Pa /var/db/etc . +The easiest way to do this is to run +.Xr mergemaster 8 +one last time, and copy +.Pa /var/tmp/temproot/etc +to +.Pa /var/db/etc . +.Pp +When you have +.Pa /var/db/etc +initialized, start a merge with +.Ic "etcmerge init" +(as root). +.Nm +will run for a while, and start printing out information about what operations +it does, prefixed with ETCMERGE:. +When it is finished, it will print out a line saying which work directory it +has worked in (by default, ${HOME}/etc-work/<date>). +Change to this directory, and check if you have any .conflicts files there. +If you do, check through them, and resolve the conflicts. +The conflicts will be recorded in different ways depending on what kind of +conflicts they are. +Under the directory +.Pa etc-merged +you'll find a replacement for /etc, including both changes done by you and +FreeBSD. +Any files that have normal change conflicts (you and FreeBSD have made +different changes) will have conflict markers ("<<<<<<<<", "=====" and +">>>>>>>") indicating where the conflict is. +See +.Xr merge 1 +for details. +The files with this kind of conflict will be listed in +.Pa 7.conflicts . +Other forms of conflicts will be listed in other .conflict files; see below +for details if you get any of these. +.Pp +When you are finished with resolving conflicts, type +.Ic "etcmerge install" +to make the present +.Pa etc-merged +directory replace +.Pa /etc , +and make +.Pa etc-new +(newly generated etc, based on the present +.Pa /usr/src ) +the new reference etc. +.Sh "INTERNAL DESCRIPTION" +.Pp +In order to do its work, +.Nm +divides the files it operate in into different classes, and do different +operations depending on which class the files belong in. +This division makes a difference for how each file is treated. +The exact treatment of each class will be printed out by +.Nm +when you run it, along with how many files is in each class, and how many +conflicts occur. +Each conflict is registered in +.Pa <class-number>.conflicts - +e.g. +.Pa 7.conflicts +for conflicts in class 7 (3-way merged files). +.Sh CLASSES +.Pp +The following table define what the class numbers refer to. +The headings "Reference", "New", and "Active" refers to various copies of +.Pa etc +- the one generated from +.Pa /usr/src +(New), the one stored as a Reference copy (basically the one generated from +.Pa /usr/src +the last time you ran +.Nm +or the one distributed with the +.Fx +you installed), and the one presently Active (ie, the one stored in +.Pa /etc +when you run +.Nm etcmerge ). +.Bl -column -offset indent ".Sy Class" ".Sy Reference" "Reference" ".Sy Active" +.It Sy Class Ta Sy Reference Ta Sy New Ta Sy Active +.It Li 1 Ta Absent Ta Absent Ta Present +.It Li 2 Ta Absent Ta Present Ta Absent +.It Li 3 Ta Absent Ta Present Ta Present +.It Li 4 Ta Present Ta Absent Ta Absent +.It Li 5 Ta Present Ta Absent Ta Present +.It Li 6 Ta Present Ta Present Ta Absent +.It Li 7 Ta Present Ta Present Ta Present +.El +.Pp +Depending on what class each file (and I'm talking flat files here) is in, it +will be handled differently. +(See separate description for handling of directories and special files.) +The following table describes how each class of files are handled when there +are no conflicts in the file. +.Bl -column -offset indent ".Sy Class" ".Sy Reference" "Reference" ".Sy Active" +.It Sy Class Ta Sy "File merge handling" +.It Li 1 Ta "Copy from Active" +.It Li 2 Ta "Copy from New" +.It Li 3 Ta "Copy from New" +.It Li 4 Ta "Drop file" +.It Li 5 Ta "Drop file (store in conflict dir if diffs)" +.It Li 6 Ta "Drop file (store in conflict dir)" +.It Li 7 Ta "Do a 3-way merge between all variant, and store result in etc-merged" +.El +Depending on what class a file is in, conflicts will be detected differently, +and handled differently. +The below table detail how conflicts are detected and handled for each class. +.Bl -column -offset indent ".Sy Class" ".Sy Reference" "Reference" ".Sy Active" +.It Sy Class Ta Sy "File conflict handling" +.It Li 1 Ta "Cannot be a conflict" +.It Li 2 Ta "Cannot be a conflict" +.It Li 3 Ta "If there are differences between New and Active, store a diff file in merged-changed." +.It Li 4 Ta "Cannot be a conflict" +.It Li 5 Ta "If there are differences between New and Active, store a diff file in merged-removed." +.It Li 6 Ta "Store file in merged-conflicts, with a diff file if there are diffs between Reference and New" +.It Li 7 Ta "Conflicts are indicated inside the file, using <<<<<<<<<, ======= and >>>>>>>>> as markers. See merge(1)." +.El +Directories and special files are also handled by +.Nm etcmerge . +Empty directories and special files are handled by class (see the tables +below). +Directories with content is handled alongside files. +When a file is copied over to the merged etc (the one +.Nm +generates), all prefix directories will be copied too, using permissions +either from the active (if available) or the new +.Pa etc . +Ie, if +.Nm +decide to copy +.Pa etc/ssh/ssh_config +from +.Pa /etc , +then +.Pa merged-etc/ssh +will get the same permissions as +.Pa /etc/ssh . +.Pp +This table details how special files (symlinks, device nodes, pipes, etc) and +empty directories are handled. +.Nm +does not look for conflicts for these, but just copies them as appropriate. +.Bl -column -offset indent ".Sy Class" ".Sy Directory/special.file.handling" +.It Sy Class Ta Sy "Directory/special file handling" +.It Li 1 Ta "Copy from Active" +.It Li 2 Ta "Copy from New" +.It Li 3 Ta "Copy from Active" +.It Li 4 Ta "Ignore dir/special file" +.It Li 5 Ta "Ignore dir/special file" +.It Li 6 Ta "Ignore dir/special file" +.It Li 7 Ta "Copy from Active" +.El +.Sh "DIRECTORIES USED" +.Pp +.Bl -column -offset indent "Directory" "Description" +.It Li "etc-merged" Ta "Merged etc directory, based on etc-new but customized with on your changes." +.It Li "etc-new" Ta "New etc directory, as distributed by FreeBSD. Created based on /usr/src." +.It Li "classes" Ta "Data about what goes in what class" +.It Li "merged-removed" Ta "Files that have been removed, along with .diff files if the active file was different from the reference file." +.It Li "merged-changed" Ta "Files that have been replaced by the update, along with .diff files saying what changes this has resulted in." +.It Li "merged-conflicts" Ta "Files that are present in new and reference, but +not in the active etc. If these are changed, a .diff is also stored here." +.El +.Sh REFERENCES +.Pp +.Xr mergemaster 8 , +.Xr merge 1 . +.Sh AUTHOR +.Pp +Eivind Eklund <eivind@FreeBSD.org> diff --git a/sysutils/etcmerge/src/etcmerge.sh b/sysutils/etcmerge/src/etcmerge.sh new file mode 100644 index 000000000000..d5d8d4edcbab --- /dev/null +++ b/sysutils/etcmerge/src/etcmerge.sh @@ -0,0 +1,401 @@ +#!/bin/sh +# ex:ts=8 +# vim:sts=4:sw=4:tw=120 +# +# etcmerge - a program to merge an old and a new copy of the FreeBSD /etc +# directory +# + +# +# Exit on encountering an error or unknown variable +# +set -e -u + +usage() { + echo "Usage:" 1>&2 + echo " etcmerge [-d <workdir>] [-e <etcdir>] [-r <refdir>] [-s <srcdir>] \\" 1>&2 + echo " [init|install]" 1>&2 + echo 1>&2 + echo " -d Set work directory for merge. Defaults to" 1>&2 + echo " ${HOME}/etc-work/$(date +%Y%m%d%H%M)" 1>&2 + echo " -e Set etc directory to merge. Defaults to /etc" 1>&2 + echo " -r Reference copy of etc. Defaults to /var/db/etc" 1>&2 + echo " -s FreeBSD source directory. Defaults to /usr/src" 1>&2 + echo 1>&2 + echo " init: Do full generation of a new etc directory, including merge from the" 1>&2 + echo " active etc." 1>&2 + echo 1>&2 + echo " install: Make the merged etc active, and the newly generated from source etc" 1>&2 + echo " the new reference. This prepares for a new merge." 1>&2 + echo 1>&2 + echo 1>&2 + echo " IMPORTANT: Before running 'install', you should resolve any conflicts" 1>&2 + echo " reported." 1>&2 + echo " Any '.diff' files that are left in merged-* directories represent" 1>&2 + echo " changes that are LOST in the newly merged etc. These should either" 1>&2 + echo " be hand-applied or deemed OK to loose." 1>&2 +} + +# +# Where we store our work files +# +WORKDIR=${HOME}/etc-work/$(date +%Y%m%d%H%M) + +while getopts ":d:e:r:s:" ARGUMENT ; do + case "${ARGUMENT}" in + d) WORKDIR="${OPTARG}" ;; + e) ACTIVEETC="${OPTARG}" ;; + r) REFETC="${OPTARG}" ;; + s) USRSRC="${OPTARG}" ;; + *) usage; exit 1 ;; + esac +done + + +# +# Where we store class files +# +CLASSDIR=${WORKDIR}/classes +mkdir -p ${CLASSDIR} + +# +# Where the new "root" is linked from +# +NEWROOT="${WORKDIR}/new-base" + +# +# Where the new etc is fetched from +# +NEWETC="${WORKDIR}/etc-new" + +# +# Where we store our backup copy of an unmodified etc +# +REFETC=/var/db/etc + +# +# Where the active copy of etc is stored +# +ACTIVEETC=/etc + +# +# Where does our main merged tree go? +# +MERGEDETC=${WORKDIR}/etc-merged + +# +# Where is our source code? +# +USRSRC=/usr/src + +# +# How do we use CPIO for extract? +# +CPIO_EXTRACT="cpio -i -d -u --quiet" + +# +# How do we use CPIO for archiving? +# +CPIO_ARCHIVE="cpio -o -H crc --quiet" + +# +# Show number of conflicts for a particular class +# +conflictshow() { + id=$1 + if [ -s "${WORKDIR}/${id}.conflicts" ]; then + echo "ETCMERGE: >>>>" + echo "ETCMERGE: >>>> Class ${id}: $(cat "${WORKDIR}/${id}.conflicts" | wc -l) conflict(s)" + fi +} + +case "$1" in + init) ;; + install) + if ! [ -d "etc-merged" -a "etc-new" ]; then + echo "install attempted without standing in work directory" 1>&2 + echo "cd to work directory (by default under ${HOME}/etc-work/) and try again." 1>&2 + exit 1 + fi + for i in $(cat *.conflicts 2> /dev/null); do + if egrep -q '^(<<<<<<< |=======$|>>>>>>> )' etc-merged/$i; then + echo "Unresolved conflicts in ${i}" 1>&2 + exit 1 + fi + done + tmpetc=/etc.$(date +%Y%m%d) + # XXX The entire set of operations below should be transactional. + # This could be achieved by doing the updates as a series of + # ln operations, then syncing, then removing the extra files, + # and ending with removing the temporary directories, at each + # phase recording what phase we are in. + # + # Instead, the system now just prays that error does not + # happen in the tiny section where it does the actual rename + # operations, and syncs around this. This is probably still + # quicker than doing it the safe way. + # + # FIXME Should check for existance beforehand + mv etc-merged ${tmpetc} + mv etc-new ${REFETC}.etcmerge + fsync / + fsync ${REFETC}.etcmerge + fsync /var/db + # Should get everything to disk, one would hope. + sync && sleep 0.5 && sync && sleep 0.5 && sync && sleep 0.5 + mv /etc/ /etc.etcmergeold + mv ${tmpetc} /etc + fsync / + mv ${REFETC} ${REFETC}.etcmergeold + mv ${REFETC}.etcmerge ${REFETC} + fsync /var/db + # Do a sync that can keep running after the program exists. + sync && sync && sync + echo "Install done - removing copies of old /etc and old reference." 1>&2 + rm -rf /etc.etcmergeold ${REFETC}.etcmergeold + echo "Done." 1>&2 + exit 0 + ;; + *) + usage + exit 1 + ;; +esac + + +echo "ETCMERGE: >>> Creating new etc data from ${USRSRC}" +# +# XXX Make sure we have all needed users and groups before this +# +if ! (mkdir -p "${NEWROOT}" && \ + cd ${USRSRC}/etc && \ + make DESTDIR="${NEWROOT}" distrib-dirs && \ + make DESTDIR="${NEWROOT}" distribution && \ + mv ${NEWROOT}/etc ${NEWETC}); then + echo "Unable to create new etc directory" 1>& 2 + echo "MERGE FAILED" 1>&2 + exit 1 +else + rm -rf ${NEWROOT} 2> /dev/null || (chflags -R noschg ${NEWROOT} && rm -rf ${NEWROOT}) || \ + (echo "Unable to clean out temp root" 1>&2; echo "MERGE FAILED" 1>&2; exit 1) +fi + +echo "ETCMERGE: >>> Finding classes of files" +echo "ETCMERGE: >>> Working from" +echo "ETCMERGE: >>> Active: ${ACTIVEETC}" +echo "ETCMERGE: >>> Reference: ${REFETC}" +echo "ETCMERGE: >>> New: ${NEWETC}" + +# +# Find list of new files and list of old (reference) files +# +cd $WORKDIR +(cd "${NEWETC}" && find . -type f -print | sort > ${CLASSDIR}/newetc.files) +(cd "${NEWETC}" && find . -type d -links 2 -print | sort > ${CLASSDIR}/newetc.emptydirs) +(cd "${NEWETC}" && find . \! \( -type d -or -type f \) -print | sort > ${CLASSDIR}/newetc.others) +(cd "${REFETC}" && find . -type f -print | sort > ${CLASSDIR}/refetc.files) +(cd "${REFETC}" && find . -type d -links 2 -print | sort > ${CLASSDIR}/refetc.emptydirs) +(cd "${REFETC}" && find . \! \( -type d -or -type f \) -print | sort > ${CLASSDIR}/refetc.others) +(cd "${ACTIVEETC}" && find . -type f -print | sort > ${CLASSDIR}/activeetc.files) +(cd "${ACTIVEETC}" && find . -type d -links 2 -print | sort > ${CLASSDIR}/activeetc.emptydirs) +(cd "${ACTIVEETC}" && find . \! \( -type d -or -type f \) -print | sort > ${CLASSDIR}/activeetc.others) + +# +# Generate lists of differences on a file level, which effectively divides all +# files into classes: +# +# Id Ref New Active Action +# 0 Absent Absent Absent (Irrelevant case) +# 1 Absent Absent Present Copy file over, with directory if necessary +# 2 Absent Present Absent Copy file over, with directory if necessary +# 3 Absent Present Present Store NEW file +# If there are differences: +# Store diff +# Add to conflict list +# 4 Present Absent Absent Ignore file +# 5 Present Absent Present No differences: Ignore files +# With differences: Store in conflict +# directory, with separate diff file +# 6 Present Present Absent Store in conflict directory +# 7 Present Present Present Do a 3-way merge, with directory if +# necessary. +cd ${CLASSDIR} +for extension in files emptydirs others; do + cat refetc.${extension} newetc.${extension} activeetc.${extension} | sort -u > alletc.${extension} + cat refetc.${extension} newetc.${extension} | sort | uniq -d | cat - activeetc.${extension} | sort | uniq -d > ${CLASSDIR}/7.${extension} + cat alletc.${extension} refetc.${extension} newetc.${extension} | sort | uniq -u > ${CLASSDIR}/1.${extension} + cat alletc.${extension} refetc.${extension} activeetc.${extension} | sort | uniq -u > ${CLASSDIR}/2.${extension} + cat alletc.${extension} newetc.${extension} activeetc.${extension} | sort | uniq -u > ${CLASSDIR}/4.${extension} + cat newetc.${extension} activeetc.${extension} | sort | uniq -d | cat - refetc.${extension} refetc.${extension} | sort | uniq -u > ${CLASSDIR}/3.${extension} + cat refetc.${extension} activeetc.${extension} | sort | uniq -d | cat - newetc.${extension} newetc.${extension} | sort | uniq -u > ${CLASSDIR}/5.${extension} + cat refetc.${extension} newetc.${extension} | sort | uniq -d | cat - activeetc.${extension} activeetc.${extension} | sort | uniq -u > ${CLASSDIR}/6.${extension} +done + +for i in 1 2 3 4 5 6 7; do + echo "ETCMERGE: >>>> Class ${i}: $(cat ${CLASSDIR}/$i.files | wc -l) files, $(cat ${CLASSDIR}/$i.emptydirs | wc -l) empty dirs, $(cat ${CLASSDIR}/$i.others | wc -l) others" +done + +# +# Create directory for merged data +# +mkdir ${MERGEDETC} + +echo "ETCMERGE: >>>" +echo "ETCMERGE: >>> Handling class 7 files - present everywhere" +echo "ETCMERGE: >>>> Files are handled as an ascii 3-way merge." +echo "ETCMERGE: >>>> Non-files get copied from the ACTIVE etc dir." + +# +# Class 7 - present everywhere. Create a merged directory tree. +# +cd ${MERGEDETC} +(cd ${ACTIVEETC} && cat ${CLASSDIR}/7.files ${CLASSDIR}/7.emptydirs ${CLASSDIR}/7.others | ${CPIO_ARCHIVE}) | ${CPIO_EXTRACT} +for i in $(cat ${CLASSDIR}/7.files); do + if ! merge -q $i ${REFETC}/$i ${NEWETC}/$i; then + echo ${i} >> ${WORKDIR}/7.conflicts + fi +done +conflictshow 7 + +# +# Class 1 - only present in active directory. Copy over. +# +echo "ETCMERGE: >>>" +echo "ETCMERGE: >>> Handling class 1 - only present in active directory" +echo "ETCMERGE: >>>> Both files and non-files get copied." +echo "ETCMERGE: >>>" +cd ${MERGEDETC} +(cd ${ACTIVEETC} && cat ${CLASSDIR}/1.files ${CLASSDIR}/1.emptydirs ${CLASSDIR}/1.others | ${CPIO_ARCHIVE}) | ${CPIO_EXTRACT} + +# +# Class 2 - only present in new directory. Copy over. +# +echo "ETCMERGE: >>>" +echo "ETCMERGE: >>> Handling class 2 - only present in new directory" +echo "ETCMERGE: >>>> Both files and non-files get copied." +echo "ETCMERGE: >>>" +cd ${MERGEDETC} +(cd ${NEWETC} && cat ${CLASSDIR}/2.files ${CLASSDIR}/2.emptydirs ${CLASSDIR}/2.others | ${CPIO_ARCHIVE}) | ${CPIO_EXTRACT} + +# +# Class 3 - present in new and active directory, but not ref. +# Use the active directory permissions, but the new file. +# If the files differ, store filename in 3.conflicts and the active version and a diff in merged-changed. +# +echo "ETCMERGE: >>>" +echo "ETCMERGE: >>>> Handling class 3 - present in new and active directory only" +echo "ETCMERGE: >>>> Files with differences get a copy of NEW file in both" +echo "ETCMERGE: >>>> etc-merged and merged-changed, with a .diff from the NEW to" +echo "ETCMERGE: >>>> the ACTIVE file in merged-changed." +echo "ETCMERGE: >>>> Non-files are fetched from the ACTIVE directory." +echo "ETCMERGE: >>>" +cd ${MERGEDETC} +(cd ${ACTIVEETC} && cat ${CLASSDIR}/3.files ${CLASSDIR}/3.emptydirs ${CLASSDIR}/3.others | ${CPIO_ARCHIVE}) | ${CPIO_EXTRACT} +(cd ${NEWETC} && cat ${CLASSDIR}/3.files | ${CPIO_ARCHIVE}) | ${CPIO_EXTRACT} +for i in $(cat ${CLASSDIR}/3.files); do + if ! diff -q ${ACTIVEETC}/$i ${REFETC}/$i > /dev/null; then + # Files differ + echo $i >> ${WORKDIR}/3.conflicts + fi +done +conflictshow 3 +# +# Handle differing files (if any) +# +if [ -s ${WORKDIR}/3.conflicts ]; then + mkdir -p ${WORKDIR}/merged-changed + cd ${WORKDIR}/merged-changed + (cd ${ACTIVEETC} && cat ${WORKDIR}/3.conflicts | ${CPIO_ARCHIVE}) | ${CPIO_EXTRACT} + for i in $(cat ${WORKDIR}/3.conflicts); do + diff -u ${REFETC}/$i $i > $i.diff + done +fi + +# +# Class 4 - present in ref, removed in new and active +# +echo "ETCMERGE: >>>" +echo "ETCMERGE: >>> Handling class 4 - present in reference only" +echo "ETCMERGE: >>>> A copy of each file is stored in merged-removed." +echo "ETCMERGE: >>>> Non-files get dropped." +echo "ETCMERGE: >>>" +if [ -s ${CLASSDIR}/4.files ]; then + mkdir -p ${WORKDIR}/merged-removed + cd ${WORKDIR}/merged-removed + (cd ${REFETC} && cat ${CLASSDIR}/4.files | ${CPIO_ARCHIVE}) | ${CPIO_EXTRACT} +fi + +# +# Class 5 - present in ref and active, removed in new +# +# For all files where the active is different from the reference, create a copy in merged-removed, with a .diff that +# shows what the differences are. +# For all unchanged files, just copy them over. +# +echo "ETCMERGE: >>>" +echo "ETCMERGE: >>> Handling class 5 - present in reference and active only" +echo "ETCMERGE: >>>> A copy of each ACTIVE file is stored in merged-removed." +echo "ETCMERGE: >>>> If there is a difference between the ACTIVE and the" +echo "ETCMERGE: >>>> REFERENCE file, a diff from REFERENCE to ACTIVE gets" +echo "ETCMERGE: >>>> stored in merged-removed/" +echo "ETCMERGE: >>>> Non-files get dropped." +echo "ETCMERGE: >>>" +if [ -s ${CLASSDIR}/5.files ]; then + mkdir -p ${WORKDIR}/merged-removed + cd ${WORKDIR}/merged-removed + (cd ${ACTIVEETC} && cat ${CLASSDIR}/5.files | ${CPIO_ARCHIVE}) | ${CPIO_EXTRACT} + for i in $(cat ${CLASSDIR}/5.files); do + if ! diff -q ${ACTIVEETC}/$i ${REFETC}/$i > /dev/null; then + # Files differ + echo $i >> ${WORKDIR}/5.conflicts + diff -u ${REFETC}/$i ${ACTIVEETC}/$i > $i.diff + fi + done +fi +conflictshow 5 + +# +# Class 6 - present in ref and new, but removed in active +# Files are copied from new to merged-conflicts, and if the files differ, the filename is added to 6.conflicts, +# and a .diff file with the changes that are lost is stored alongside the file. +# +echo "ETCMERGE: >>>" +echo "ETCMERGE: >>> Handling class 6 - present in reference and new only" +echo "ETCMERGE: >>>> A copy of the NEW version of each file is stored in" +echo "ETCMERGE: >>>> merged-conflicts/" +echo "ETCMERGE: >>>> If there are differences the REFERENCE and NEW file," +echo "ETCMERGE: >>>> a .diff file with these is also stored." +echo "ETCMERGE: >>>> Non-files get dropped." +echo "ETCMERGE: >>>" +if [ -s ${CLASSDIR}/6.files ]; then + mkdir ${WORKDIR}/merged-conflicts + cd ${WORKDIR}/merged-conflicts + (cd ${NEWETC} && cat ${CLASSDIR}/6.files | ${CPIO_ARCHIVE}) | ${CPIO_EXTRACT} + for i in $(cat ${CLASSDIR}/6.files); do + if ! diff -q $i ${REFETC}/$i > /dev/null; then + # Files differ + echo $i >> ${WORKDIR}/6.conflicts + diff -u ${REFETC}/$i $i > $i.diff + fi + done +fi +conflictshow 6 + +cat <<EOM + +Directories (only present if they would have contents) + etc-merged Replaced etc/ directory, ready for use (potentially after + conflict resolution) + etc-new New etc, generated from ${USRSRC}, and used to generate + etc-merged. + merged-removed Files that have been removed, along with .diff files if + the active file was different from the reference file. + merged-changed Files that have been replaced by the update, along with + .diff files saying what changes this has resulted in. + merged-conflicts Files that are present in new and reference, but not in + the active etc. If these are changed, a .diff is + also stored here. + classes Internal overview of what files belong to what classes + +Work directory: ${WORKDIR} +EOM |