mergemaster.sh revision 244454
152400Sbillf#!/bin/sh
252400Sbillf
352400Sbillf# mergemaster
452400Sbillf
552400Sbillf# Compare files created by /usr/src/etc/Makefile (or the directory
652400Sbillf# the user specifies) with the currently installed copies.
752400Sbillf
8241337Sdougb# Copyright (c) 1998-2012 Douglas Barton, All rights reserved
9241337Sdougb# Please see detailed copyright below
1052400Sbillf
1152495Sbillf# $FreeBSD: stable/9/usr.sbin/mergemaster/mergemaster.sh 244454 2012-12-20 00:26:46Z eadler $
1252400Sbillf
1368507SdougbPATH=/bin:/usr/bin:/usr/sbin
1452400Sbillf
1552400Sbillfdisplay_usage () {
1652533Sbillf  VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
1752400Sbillf  echo "mergemaster version ${VERSION_NUMBER}"
18227145Sdougb  echo 'Usage: mergemaster [-scrvhpCP] [-a|[-iFU]] [--run-updates=always|never]'
19189763Sdougb  echo '    [-m /path] [-t /path] [-d] [-u N] [-w N] [-A arch] [-D /path]'
2052400Sbillf  echo "Options:"
2152400Sbillf  echo "  -s  Strict comparison (diff every pair of files)"
2252400Sbillf  echo "  -c  Use context diff instead of unified diff"
2352400Sbillf  echo "  -r  Re-run on a previously cleaned directory (skip temproot creation)"
2452400Sbillf  echo "  -v  Be more verbose about the process, include additional checks"
2552400Sbillf  echo "  -a  Leave all files that differ to merge by hand"
2652400Sbillf  echo "  -h  Display more complete help"
2767949Sdougb  echo '  -i  Automatically install files that do not exist in destination directory'
2891193Sdougb  echo '  -p  Pre-buildworld mode, only compares crucial files'
29190320Sdougb  echo '  -F  Install files that differ only by revision control Id ($FreeBSD)'
3091193Sdougb  echo '  -C  Compare local rc.conf variables to the defaults'
31114501Sdougb  echo '  -P  Preserve files that are overwritten'
32189763Sdougb  echo "  -U  Attempt to auto upgrade files that have not been user modified"
33224726Sdougb  echo '      ***DANGEROUS***'
34227145Sdougb  echo '  --run-updates=  Specify always or never to run newalises, pwd_mkdb, etc.'
35189763Sdougb  echo ''
3652400Sbillf  echo "  -m /path/directory  Specify location of source to do the make in"
3752400Sbillf  echo "  -t /path/directory  Specify temp root directory"
3852400Sbillf  echo "  -d  Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
3952400Sbillf  echo "  -u N  Specify a numeric umask"
4052400Sbillf  echo "  -w N  Specify a screen width in columns to sdiff"
41155309Srwatson  echo "  -A architecture  Alternative architecture name to pass to make"
4267949Sdougb  echo '  -D /path/directory  Specify the destination directory to install files to'
4352400Sbillf  echo ''
4452400Sbillf}
4552400Sbillf
4652400Sbillfdisplay_help () {
4752400Sbillf  echo "* To specify a directory other than /var/tmp/temproot for the"
4852400Sbillf  echo "  temporary root environment, use -t /path/to/temp/root"
4952400Sbillf  echo "* The -w option takes a number as an argument for the column width"
5067859Sdougb  echo "  of the screen.  The default is 80."
5167949Sdougb  echo '* The -a option causes mergemaster to run without prompting.'
5252400Sbillf}
5352400Sbillf
5458910Salfred# Loop allowing the user to use sdiff to merge files and display the merged
5558910Salfred# file.
5658910Salfredmerge_loop () {
5767850Sdougb  case "${VERBOSE}" in
5867850Sdougb  '') ;;
5967850Sdougb  *)
6067850Sdougb      echo "   *** Type h at the sdiff prompt (%) to get usage help"
6167850Sdougb      ;;
6267850Sdougb  esac
6367850Sdougb  echo ''
6467850Sdougb  MERGE_AGAIN=yes
6567850Sdougb  while [ "${MERGE_AGAIN}" = "yes" ]; do
6667850Sdougb    # Prime file.merged so we don't blat the owner/group id's
6767850Sdougb    cp -p "${COMPFILE}" "${COMPFILE}.merged"
6867850Sdougb    sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
6967949Sdougb      --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
7067850Sdougb    INSTALL_MERGED=V
7167850Sdougb    while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
7267850Sdougb      echo ''
7367850Sdougb      echo "  Use 'i' to install merged file"
7467850Sdougb      echo "  Use 'r' to re-do the merge"
7567850Sdougb      echo "  Use 'v' to view the merged file"
7667850Sdougb      echo "  Default is to leave the temporary file to deal with by hand"
7767850Sdougb      echo ''
7867859Sdougb      echo -n "    *** How should I deal with the merged file? [Leave it for later] "
7967859Sdougb      read INSTALL_MERGED
8058910Salfred
8167850Sdougb      case "${INSTALL_MERGED}" in
8267850Sdougb      [iI])
8367850Sdougb        mv "${COMPFILE}.merged" "${COMPFILE}"
8467850Sdougb        echo ''
8567850Sdougb        if mm_install "${COMPFILE}"; then
8667850Sdougb          echo "     *** Merged version of ${COMPFILE} installed successfully"
8767859Sdougb        else
8867850Sdougb          echo "     *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
8967859Sdougb        fi
9067850Sdougb        unset MERGE_AGAIN
9167850Sdougb        ;;
9267850Sdougb      [rR])
9367850Sdougb        rm "${COMPFILE}.merged"
9467859Sdougb        ;;
9567850Sdougb      [vV])
9667850Sdougb        ${PAGER} "${COMPFILE}.merged"
9767850Sdougb        ;;
9867850Sdougb      '')
9967850Sdougb        echo "   *** ${COMPFILE} will remain for your consideration"
10067850Sdougb        unset MERGE_AGAIN
10167850Sdougb        ;;
10267850Sdougb      *)
10367850Sdougb        echo "invalid choice: ${INSTALL_MERGED}"
10467850Sdougb        INSTALL_MERGED=V
10567850Sdougb        ;;
10667850Sdougb      esac
10767850Sdougb    done
10867850Sdougb  done
10958910Salfred}
11058910Salfred
11158910Salfred# Loop showing user differences between files, allow merge, skip or install
11258910Salfred# options
11358910Salfreddiff_loop () {
11458910Salfred
11567850Sdougb  HANDLE_COMPFILE=v
11658910Salfred
11777323Sdougb  while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \
11877323Sdougb    "${HANDLE_COMPFILE}" = "NOT V" ]; do
11967949Sdougb    if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
120192230Sdougb      if [ -n "${AUTO_UPGRADE}" -a -n "${CHANGED}" ]; then
121192230Sdougb        case "${CHANGED}" in
122192230Sdougb        *:${DESTDIR}${COMPFILE#.}:*) ;;		# File has been modified
123192230Sdougb        *)
124158149Sgordon          echo ''
125158149Sgordon          echo "  *** ${COMPFILE} has not been user modified."
126158149Sgordon          echo ''
127158149Sgordon
128158149Sgordon          if mm_install "${COMPFILE}"; then
129158149Sgordon            echo "   *** ${COMPFILE} upgraded successfully"
130158149Sgordon            echo ''
131158149Sgordon            # Make the list print one file per line
132158149Sgordon            AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES}      ${DESTDIR}${COMPFILE#.}
133158149Sgordon"
134158149Sgordon          else
135192230Sdougb            echo "   *** Problem upgrading ${COMPFILE}, it will remain to merge by hand"
136158149Sgordon          fi
137158149Sgordon          return
138192230Sdougb          ;;
139192230Sdougb        esac
140158149Sgordon      fi
14167850Sdougb      if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
14290564Sdougb	echo ''
143109993Sdillon	echo '   ======================================================================   '
144109993Sdillon	echo ''
145109993Sdillon        (
146109993Sdillon          echo "  *** Displaying differences between ${COMPFILE} and installed version:"
147109993Sdillon          echo ''
148110377Sdougb          diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
149109993Sdillon        ) | ${PAGER}
150109993Sdillon        echo ''
15167850Sdougb      fi
15267850Sdougb    else
153109993Sdillon      echo ''
15467850Sdougb      echo "  *** There is no installed version of ${COMPFILE}"
15591193Sdougb      echo ''
15667949Sdougb      case "${AUTO_INSTALL}" in
15767949Sdougb      [Yy][Ee][Ss])
15867949Sdougb        echo ''
15967949Sdougb        if mm_install "${COMPFILE}"; then
16067949Sdougb          echo "   *** ${COMPFILE} installed successfully"
16168507Sdougb          echo ''
16267949Sdougb          # Make the list print one file per line
16367949Sdougb          AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES}      ${DESTDIR}${COMPFILE#.}
16467949Sdougb"
16567949Sdougb        else
16667949Sdougb          echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
16767949Sdougb        fi
16867949Sdougb        return
16967949Sdougb        ;;
17067949Sdougb      *)
17167949Sdougb        NO_INSTALLED=yes
17267949Sdougb        ;;
17367949Sdougb      esac
17467850Sdougb    fi
17567859Sdougb
17667850Sdougb    echo "  Use 'd' to delete the temporary ${COMPFILE}"
17767850Sdougb    echo "  Use 'i' to install the temporary ${COMPFILE}"
17867850Sdougb    case "${NO_INSTALLED}" in
17967850Sdougb    '')
18077326Sdougb      echo "  Use 'm' to merge the temporary and installed versions"
181109993Sdillon      echo "  Use 'v' to view the diff results again"
18267850Sdougb      ;;
18367850Sdougb    esac
18467850Sdougb    echo ''
18567850Sdougb    echo "  Default is to leave the temporary file to deal with by hand"
18667850Sdougb    echo ''
18767859Sdougb    echo -n "How should I deal with this? [Leave it for later] "
18867859Sdougb    read HANDLE_COMPFILE
18967859Sdougb
19067850Sdougb    case "${HANDLE_COMPFILE}" in
19167850Sdougb    [dD])
19267850Sdougb      rm "${COMPFILE}"
19367850Sdougb      echo ''
19467850Sdougb      echo "   *** Deleting ${COMPFILE}"
19567850Sdougb      ;;
19667850Sdougb    [iI])
19767850Sdougb      echo ''
19867850Sdougb      if mm_install "${COMPFILE}"; then
19967850Sdougb        echo "   *** ${COMPFILE} installed successfully"
20067850Sdougb      else
20167850Sdougb        echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
20267850Sdougb      fi
20367850Sdougb      ;;
20467850Sdougb    [mM])
20567850Sdougb      case "${NO_INSTALLED}" in
20667850Sdougb      '')
20767850Sdougb        # interact with user to merge files
20867850Sdougb        merge_loop
20967850Sdougb        ;;
21067850Sdougb      *)
21167850Sdougb        echo ''
21267850Sdougb        echo "   *** There is no installed version of ${COMPFILE}"
21367850Sdougb        echo ''
21467850Sdougb        HANDLE_COMPFILE="NOT V"
21567850Sdougb        ;;
21667850Sdougb      esac # End of "No installed version of file but user selected merge" test
21767850Sdougb      ;;
21867850Sdougb    [vV])
21967850Sdougb      continue
22067850Sdougb      ;;
22167850Sdougb    '')
22267850Sdougb      echo ''
22367850Sdougb      echo "   *** ${COMPFILE} will remain for your consideration"
22467850Sdougb      ;;
22567850Sdougb    *)
22667850Sdougb      # invalid choice, show menu again.
22767850Sdougb      echo "invalid choice: ${HANDLE_COMPFILE}"
22867850Sdougb      echo ''
22967850Sdougb      HANDLE_COMPFILE="NOT V"
23067850Sdougb      continue
23167850Sdougb      ;;
23267850Sdougb    esac  # End of "How to handle files that are different"
23367859Sdougb  done
23467850Sdougb  unset NO_INSTALLED
23567850Sdougb  echo ''
23667850Sdougb  case "${VERBOSE}" in
23767850Sdougb  '') ;;
23867850Sdougb  *)
23967850Sdougb    sleep 3
24067850Sdougb    ;;
24167850Sdougb  esac
24258910Salfred}
24358910Salfred
24497960Sdougbpress_to_continue () {
24597960Sdougb  local DISCARD
24697960Sdougb  echo -n ' *** Press the [Enter] or [Return] key to continue '
24797960Sdougb  read DISCARD
24897960Sdougb}
24997960Sdougb
25052400Sbillf# Set the default path for the temporary root environment
25152400Sbillf#
25252400SbillfTEMPROOT='/var/tmp/temproot'
25352400Sbillf
25473651Sdougb# Read /etc/mergemaster.rc first so the one in $HOME can override
25573651Sdougb#
25673651Sdougbif [ -r /etc/mergemaster.rc ]; then
25773651Sdougb  . /etc/mergemaster.rc
25873651Sdougbfi
25973651Sdougb
26052400Sbillf# Read .mergemasterrc before command line so CLI can override
26152400Sbillf#
26267949Sdougbif [ -r "$HOME/.mergemasterrc" ]; then
26352400Sbillf  . "$HOME/.mergemasterrc"
26452400Sbillffi
26552400Sbillf
266227145Sdougbfor var in "$@" ; do
267227145Sdougb  case "$var" in
268227145Sdougb  --run-updates*)
269227145Sdougb    RUN_UPDATES=`echo ${var#--run-updates=} | tr [:upper:] [:lower:]`
270227145Sdougb    ;;
271227145Sdougb  *)
272227145Sdougb    newopts="$newopts $var"
273227145Sdougb    ;;
274227145Sdougb  esac
275227145Sdougbdone
276227145Sdougb
277227145Sdougbset -- $newopts
278227145Sdougbunset var newopts
279227145Sdougb
28052400Sbillf# Check the command line options
28152400Sbillf#
282189992Sdougbwhile getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do
28352400Sbillf  case "${COMMAND_LINE_ARGUMENT}" in
284155309Srwatson  A)
285186678Sdougb    ARCHSTRING='TARGET_ARCH='${OPTARG}
286155309Srwatson    ;;
287189992Sdougb  F)
288189992Sdougb    FREEBSD_ID=yes
289189992Sdougb    ;;
290158149Sgordon  U)
291158149Sgordon    AUTO_UPGRADE=yes
292158149Sgordon    ;;
29352400Sbillf  s)
29452400Sbillf    STRICT=yes
295110377Sdougb    unset DIFF_OPTIONS
29652400Sbillf    ;;
29752400Sbillf  c)
29852400Sbillf    DIFF_FLAG='-c'
29952400Sbillf    ;;
30052400Sbillf  r)
30152400Sbillf    RERUN=yes
30252400Sbillf    ;;
30352400Sbillf  v)
30452400Sbillf    case "${AUTO_RUN}" in
30552400Sbillf    '') VERBOSE=yes ;;
30652400Sbillf    esac
30752400Sbillf    ;;
30852400Sbillf  a)
30952400Sbillf    AUTO_RUN=yes
31052400Sbillf    unset VERBOSE
31152400Sbillf    ;;
31252400Sbillf  h)
31352400Sbillf    display_usage
31452400Sbillf    display_help
31552400Sbillf    exit 0
31652400Sbillf    ;;
31767949Sdougb  i)
31867949Sdougb    AUTO_INSTALL=yes
31967949Sdougb    ;;
32096045Sdougb  C)
32196045Sdougb    COMP_CONFS=yes
32296045Sdougb    ;;
323114501Sdougb  P)
324114501Sdougb    PRESERVE_FILES=yes
325114501Sdougb    ;;
32691193Sdougb  p)
32791193Sdougb    PRE_WORLD=yes
32896045Sdougb    unset COMP_CONFS
32996045Sdougb    unset AUTO_RUN
33091193Sdougb    ;;
33152400Sbillf  m)
33252400Sbillf    SOURCEDIR=${OPTARG}
33352400Sbillf    ;;
33452400Sbillf  t)
33552400Sbillf    TEMPROOT=${OPTARG}
33652400Sbillf    ;;
33752400Sbillf  d)
33852400Sbillf    TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
33952400Sbillf    ;;
34052400Sbillf  u)
34152400Sbillf    NEW_UMASK=${OPTARG}
34252400Sbillf    ;;
34352400Sbillf  w)
34452400Sbillf    SCREEN_WIDTH=${OPTARG}
34552400Sbillf    ;;
34667949Sdougb  D)
34767949Sdougb    DESTDIR=${OPTARG}
34867949Sdougb    ;;
34952400Sbillf  *)
35052400Sbillf    display_usage
35152400Sbillf    exit 1
35252400Sbillf    ;;
35352400Sbillf  esac
35452400Sbillfdone
35552400Sbillf
356205145Sdougbif [ -n "$AUTO_RUN" ]; then
357205145Sdougb  if [ -n "$FREEBSD_ID" -o -n "$AUTO_UPGRADE" -o -n "$AUTO_INSTALL" ]; then
358205145Sdougb    echo ''
359205145Sdougb    echo "*** You have included the -a option along with one or more options"
360205145Sdougb    echo '    that indicate that you wish mergemaster to actually make updates'
361205145Sdougb    echo '    (-F, -U, or -i), however these options are not compatible.'
362205145Sdougb    echo '    Please read mergemaster(8) for more information.'
363205145Sdougb    echo ''
364205145Sdougb    exit 1
365205145Sdougb  fi
366205145Sdougbfi
367205145Sdougb
368202817Sdougb# Assign the location of the mtree database
369202817Sdougb#
370202817SdougbMTREEDB=${MTREEDB:-${DESTDIR}/var/db}
371202817SdougbMTREEFILE="${MTREEDB}/mergemaster.mtree"
372202817Sdougb
373114501Sdougb# Don't force the user to set this in the mergemaster rc file
374114501Sdougbif [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then
375114501Sdougb  PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S`
376200425Sdougb  mkdir -p ${PRESERVE_FILES_DIR}
377114501Sdougbfi
378114501Sdougb
379186678Sdougb# Check for the mtree database in DESTDIR
380186678Sdougbcase "${AUTO_UPGRADE}" in
381186678Sdougb'') ;;	# If the option is not set no need to run the test or warn the user
382186678Sdougb*)
383200416Sdougb  if [ ! -s "${MTREEFILE}" ]; then
384186678Sdougb    echo ''
385200416Sdougb    echo "*** Unable to find mtree database (${MTREEFILE})."
386200416Sdougb    echo "    Skipping auto-upgrade on this run."
387193853Sdougb    echo "    It will be created for the next run when this one is complete."
388186678Sdougb    echo ''
389201291Sdougb    case "${AUTO_RUN}" in
390201291Sdougb    '')
391201291Sdougb      press_to_continue
392201291Sdougb      ;;
393201291Sdougb    esac
394186678Sdougb    unset AUTO_UPGRADE
395186678Sdougb  fi
396186678Sdougb  ;;
397186678Sdougbesac
398186678Sdougb
399186689Sdougbif [ -e "${DESTDIR}/etc/fstab" ]; then
400186689Sdougb  if grep -q nodev ${DESTDIR}/etc/fstab; then
401186689Sdougb    echo ''
402186689Sdougb    echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab."
403186689Sdougb    echo "    This can prevent the filesystem from being mounted on reboot."
404186689Sdougb    echo "    Please update your fstab before continuing."
405186689Sdougb    echo "    See fstab(5) for more information."
406186689Sdougb    echo ''
407186689Sdougb    exit 1
408186689Sdougb  fi
409158149Sgordonfi
410158149Sgordon
41152400Sbillfecho ''
41252400Sbillf
41352400Sbillf# If the user has a pager defined, make sure we can run it
41452400Sbillf#
41552400Sbillfcase "${DONT_CHECK_PAGER}" in
41652400Sbillf'')
417186695Sdougbcheck_pager () {
418186695Sdougb  while ! type "${PAGER%% *}" >/dev/null; do
41952400Sbillf    echo " *** Your PAGER environment variable specifies '${PAGER}', but"
42064467Sbrian    echo "     due to the limited PATH that I use for security reasons,"
42167859Sdougb    echo "     I cannot execute it.  So, what would you like to do?"
42252400Sbillf    echo ''
42352400Sbillf    echo "  Use 'e' to exit mergemaster and fix your PAGER variable"
42464467Sbrian    echo "  Use 'l' to set PAGER to 'less' for this run"
42552400Sbillf    echo "  Use 'm' to use plain old 'more' as your PAGER for this run"
42652400Sbillf    echo ''
42752400Sbillf    echo "  Default is to use plain old 'more' "
42852400Sbillf    echo ''
42967859Sdougb    echo -n "What should I do? [Use 'more'] "
43067859Sdougb    read FIXPAGER
43167859Sdougb
43252400Sbillf    case "${FIXPAGER}" in
43358910Salfred    [eE])
43452400Sbillf       exit 0
43552400Sbillf       ;;
43658910Salfred    [lL])
437244454Seadler       PAGER=less
43852400Sbillf       ;;
43960420Sbsd    [mM]|'')
44052400Sbillf       PAGER=more
44152400Sbillf       ;;
44258910Salfred    *)
44358910Salfred       echo ''
44458910Salfred       echo "invalid choice: ${FIXPAGER}"
44552400Sbillf    esac
44652400Sbillf    echo ''
44758910Salfred  done
448186695Sdougb}
449186695Sdougb  if [ -n "${PAGER}" ]; then
450186695Sdougb    check_pager
451186695Sdougb  fi
45252400Sbillf  ;;
45352400Sbillfesac
45452400Sbillf
45552400Sbillf# If user has a pager defined, or got assigned one above, use it.
45652400Sbillf# If not, use more.
45752400Sbillf#
45852400SbillfPAGER=${PAGER:-more}
45952400Sbillf
46052400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
46152400Sbillf  echo " *** You have ${PAGER} defined as your pager so we will use that"
46252400Sbillf  echo ''
46352400Sbillf  sleep 3
46452400Sbillffi
46552400Sbillf
46652400Sbillf# Assign the diff flag once so we will not have to keep testing it
46752400Sbillf#
46852400SbillfDIFF_FLAG=${DIFF_FLAG:--u}
46952400Sbillf
47052400Sbillf# Assign the source directory
47152400Sbillf#
472186678SdougbSOURCEDIR=${SOURCEDIR:-/usr/src}
473186678Sdougbif [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
474186678Sdougb   -f ${SOURCEDIR}/../Makefile.inc1 ]; then
475186678Sdougb  echo " *** The source directory you specified (${SOURCEDIR})"
476186678Sdougb  echo "     will be reset to ${SOURCEDIR}/.."
477186678Sdougb  echo ''
478186678Sdougb  sleep 3
479186678Sdougb  SOURCEDIR=${SOURCEDIR}/..
480186678Sdougbfi
48152400Sbillf
482186678Sdougb# Setup make to use system files from SOURCEDIR
483186695SdougbMM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk"
484186678Sdougb
485158149Sgordon# Check DESTDIR against the mergemaster mtree database to see what
486158149Sgordon# files the user changed from the reference files.
487158149Sgordon#
488200416Sdougbif [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then
489192230Sdougb	CHANGED=:
490200416Sdougb	for file in `mtree -eqL -f ${MTREEFILE} -p ${DESTDIR}/ \
491158149Sgordon		2>/dev/null | awk '($2 == "changed") {print $1}'`; do
492158149Sgordon		if [ -f "${DESTDIR}/$file" ]; then
493192230Sdougb			CHANGED="${CHANGED}${DESTDIR}/${file}:"
494158149Sgordon		fi
495158149Sgordon	done
496192230Sdougb	[ "$CHANGED" = ':' ] && unset CHANGED
497158149Sgordonfi
498158149Sgordon
49996045Sdougb# Check the width of the user's terminal
50096045Sdougb#
50196045Sdougbif [ -t 0 ]; then
502110377Sdougb  w=`tput columns`
50396045Sdougb  case "${w}" in
50496045Sdougb  0|'') ;; # No-op, since the input is not valid
50596045Sdougb  *)
50696045Sdougb    case "${SCREEN_WIDTH}" in
50796045Sdougb    '') SCREEN_WIDTH="${w}" ;;
50896045Sdougb    "${w}") ;; # No-op, since they are the same
50996045Sdougb    *)
51096045Sdougb      echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty "
51196045Sdougb      echo "thinks it is ${w}."
51296045Sdougb      echo ''
51396045Sdougb      echo -n "What would you like to use? [${w}] "
51496045Sdougb      read SCREEN_WIDTH
51597380Sdougb      case "${SCREEN_WIDTH}" in
51697380Sdougb      '') SCREEN_WIDTH="${w}" ;;
51797380Sdougb      esac
51896045Sdougb      ;;
51996045Sdougb    esac
52096045Sdougb  esac
52196045Sdougbfi
52296045Sdougb
523241337Sdougb# Define what $Id tag to look for to aid portability.
52473651Sdougb#
525241337SdougbID_TAG=FreeBSD
52673651Sdougb
52799152Sdougbdelete_temproot () {
528101362Sdougb  rm -rf "${TEMPROOT}" 2>/dev/null
529101362Sdougb  chflags -R 0 "${TEMPROOT}" 2>/dev/null
530201765Sdougb  rm -rf "${TEMPROOT}" || { echo "*** Unable to delete ${TEMPROOT}";  exit 1; }
53199152Sdougb}
53299152Sdougb
53352400Sbillfcase "${RERUN}" in
53452400Sbillf'')
53552400Sbillf  # Set up the loop to test for the existence of the
53652400Sbillf  # temp root directory.
53752400Sbillf  #
53852400Sbillf  TEST_TEMP_ROOT=yes
53952400Sbillf  while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
54052400Sbillf    if [ -d "${TEMPROOT}" ]; then
54152400Sbillf      echo "*** The directory specified for the temporary root environment,"
54267859Sdougb      echo "    ${TEMPROOT}, exists.  This can be a security risk if untrusted"
54352400Sbillf      echo "    users have access to the system."
54452400Sbillf      echo ''
54552400Sbillf      case "${AUTO_RUN}" in
54652400Sbillf      '')
54752400Sbillf        echo "  Use 'd' to delete the old ${TEMPROOT} and continue"
54852400Sbillf        echo "  Use 't' to select a new temporary root directory"
54952400Sbillf        echo "  Use 'e' to exit mergemaster"
55052400Sbillf        echo ''
55152400Sbillf        echo "  Default is to use ${TEMPROOT} as is"
55252400Sbillf        echo ''
55367859Sdougb        echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
55467859Sdougb        read DELORNOT
55567859Sdougb
55667859Sdougb        case "${DELORNOT}" in
55767859Sdougb        [dD])
55867859Sdougb          echo ''
55967859Sdougb          echo "   *** Deleting the old ${TEMPROOT}"
56067859Sdougb          echo ''
561201765Sdougb          delete_temproot
56267859Sdougb          unset TEST_TEMP_ROOT
56352400Sbillf          ;;
56467859Sdougb        [tT])
56567859Sdougb          echo "   *** Enter new directory name for temporary root environment"
56667859Sdougb          read TEMPROOT
56767859Sdougb          ;;
56867859Sdougb        [eE])
56967859Sdougb          exit 0
57067859Sdougb          ;;
57167859Sdougb        '')
57267859Sdougb          echo ''
57367859Sdougb          echo "   *** Leaving ${TEMPROOT} intact"
57467859Sdougb          echo ''
57567859Sdougb          unset TEST_TEMP_ROOT
57667859Sdougb          ;;
57767859Sdougb        *)
57867859Sdougb          echo ''
57967859Sdougb          echo "invalid choice: ${DELORNOT}"
58067859Sdougb          echo ''
58167859Sdougb          ;;
58267859Sdougb        esac
58367859Sdougb        ;;
58452400Sbillf      *)
58577323Sdougb        # If this is an auto-run, try a hopefully safe alternative then
58677323Sdougb        # re-test anyway.
58752400Sbillf        TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
58852400Sbillf        ;;
58952400Sbillf      esac
59052400Sbillf    else
59152400Sbillf      unset TEST_TEMP_ROOT
59252400Sbillf    fi
59352400Sbillf  done
59452400Sbillf
59552400Sbillf  echo "*** Creating the temporary root environment in ${TEMPROOT}"
59652400Sbillf
59752400Sbillf  if mkdir -p "${TEMPROOT}"; then
59852400Sbillf    echo " *** ${TEMPROOT} ready for use"
59952400Sbillf  fi
60052400Sbillf
60152400Sbillf  if [ ! -d "${TEMPROOT}" ]; then
60252400Sbillf    echo ''
60352400Sbillf    echo "  *** FATAL ERROR: Cannot create ${TEMPROOT}"
60452400Sbillf    echo ''
60552400Sbillf    exit 1
60652400Sbillf  fi
60752400Sbillf
60852400Sbillf  echo " *** Creating and populating directory structure in ${TEMPROOT}"
60952400Sbillf  echo ''
61052400Sbillf
61152400Sbillf  case "${VERBOSE}" in
61252400Sbillf  '') ;;
61352400Sbillf  *)
61497960Sdougb    press_to_continue
61552400Sbillf    ;;
61652400Sbillf  esac
61752400Sbillf
61891193Sdougb  case "${PRE_WORLD}" in
61991193Sdougb  '')
62091193Sdougb    { cd ${SOURCEDIR} &&
62191193Sdougb      case "${DESTDIR}" in
62291193Sdougb      '') ;;
62391193Sdougb      *)
624208088Sdougb        ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs >/dev/null
62591193Sdougb        ;;
62691193Sdougb      esac
627186749Sdougb      od=${TEMPROOT}/usr/obj
628208088Sdougb      ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs >/dev/null &&
629208088Sdougb      MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc >/dev/null &&
630208088Sdougb      MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc >/dev/null &&
631208088Sdougb      MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution >/dev/null;} ||
63291193Sdougb    { echo '';
63391193Sdougb     echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
63491193Sdougb      echo "      the temproot environment";
63591193Sdougb      echo '';
63691193Sdougb      exit 1;}
63791193Sdougb    ;;
63891193Sdougb  *)
63991193Sdougb    # Only set up files that are crucial to {build|install}world
64091193Sdougb    { mkdir -p ${TEMPROOT}/etc &&
641186678Sdougb      cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc &&
642224726Sdougb      install -p -o root -g wheel -m 0644 ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} ||
64391193Sdougb    { echo '';
64491193Sdougb      echo '  *** FATAL ERROR: Cannot copy files to the temproot environment';
64591193Sdougb      echo '';
64691193Sdougb      exit 1;}
64791193Sdougb    ;;
64891193Sdougb  esac
64952400Sbillf
65077323Sdougb  # Doing the inventory and removing files that we don't want to compare only
65177323Sdougb  # makes sense if we are not doing a rerun, since we have no way of knowing
65277323Sdougb  # what happened to the files during previous incarnations.
65367949Sdougb  case "${VERBOSE}" in
65467949Sdougb  '') ;;
65567949Sdougb  *)
65667949Sdougb    echo ''
65767949Sdougb    echo ' *** The following files exist only in the installed version of'
65867949Sdougb    echo "     ${DESTDIR}/etc.  In the vast majority of cases these files"
65967949Sdougb    echo '     are necessary parts of the system and should not be deleted.'
66067949Sdougb    echo '     However because these files are not updated by this process you'
66167949Sdougb    echo '     might want to verify their status before rebooting your system.'
66267949Sdougb    echo ''
66397960Sdougb    press_to_continue
664101348Sdougb    diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER}
66567949Sdougb    echo ''
66697960Sdougb    press_to_continue
66767949Sdougb    ;;
66867949Sdougb  esac
66967949Sdougb
67052534Sbillf  case "${IGNORE_MOTD}" in
671202340Sdougb  '') ;;
672202339Sdougb  *)
673186678Sdougb     echo ''
674186678Sdougb     echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file."
675186678Sdougb     echo "    This option is deprecated in favor of the IGNORE_FILES option."
676186678Sdougb     echo "    Please update your rc file accordingly."
677186678Sdougb     echo ''
678202339Sdougb     exit 1
67952534Sbillf     ;;
68052534Sbillf  esac
68152534Sbillf
682186678Sdougb  # Avoid comparing the following user specified files
683186678Sdougb  for file in ${IGNORE_FILES}; do
684186688Sdougb    test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file}
685186678Sdougb  done
68652400Sbillf
687201291Sdougb  # We really don't want to have to deal with files like login.conf.db, pwd.db,
688201291Sdougb  # or spwd.db.  Instead, we want to compare the text versions, and run *_mkdb.
689201291Sdougb  # Prompt the user to do so below, as needed.
690201291Sdougb  #
691201291Sdougb  rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd
69277478Sdougb
693201291Sdougb  # We only need to compare things like freebsd.cf once
694201291Sdougb  find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
69594196Sdougb
696201291Sdougb  # Delete stuff we do not need to keep the mtree database small,
697201291Sdougb  # and to make the actual comparison faster.
698201291Sdougb  find ${TEMPROOT}/usr -type l -delete 2>/dev/null
699201291Sdougb  find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
700201291Sdougb  find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null
701158149Sgordon
702201291Sdougb  # Build the mtree database in a temporary location.
703201291Sdougb  case "${PRE_WORLD}" in
704201323Sdougb  '') MTREENEW=`mktemp -t mergemaster.mtree`
705201323Sdougb      mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
706201291Sdougb      ;;
707201291Sdougb  *) # We don't want to mess with the mtree database on a pre-world run or
708201291Sdougb     # when re-scanning a previously-built tree.
709201291Sdougb     ;;
710201291Sdougb  esac
711201291Sdougb  ;; # End of the "RERUN" test
712158149Sgordonesac
713158149Sgordon
71452400Sbillf# Get ready to start comparing files
71552400Sbillf
71698084Sdougb# Check umask if not specified on the command line,
71798084Sdougb# and we are not doing an autorun
71852400Sbillf#
71998084Sdougbif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
72098084Sdougb  USER_UMASK=`umask`
72152400Sbillf  case "${USER_UMASK}" in
72277335Sdougb  0022|022) ;;
72352400Sbillf  *)
72452400Sbillf    echo ''
72598084Sdougb    echo " *** Your umask is currently set to ${USER_UMASK}.  By default, this script"
72698084Sdougb    echo "     installs all files with the same user, group and modes that"
727186678Sdougb    echo "     they are created with by ${SOURCEDIR}/etc/Makefile, compared to"
72898084Sdougb    echo "     a umask of 022.  This umask allows world read permission when"
72998084Sdougb    echo "     the file's default permissions have it."
73052400Sbillf    echo ''
73198084Sdougb    echo "     No world permissions can sometimes cause problems.  A umask of"
73298084Sdougb    echo "     022 will restore the default behavior, but is not mandatory."
73398084Sdougb    echo "     /etc/master.passwd is a special case.  Its file permissions"
73498084Sdougb    echo "     will be 600 (rw-------) if installed."
73597960Sdougb    echo ''
73698084Sdougb    echo -n "What umask should I use? [${USER_UMASK}] "
73798084Sdougb    read NEW_UMASK
73898084Sdougb
73998084Sdougb    NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
74052400Sbillf    ;;
74152400Sbillf  esac
74252400Sbillf  echo ''
74398084Sdougbfi
74452400Sbillf
74598084SdougbCONFIRMED_UMASK=${NEW_UMASK:-0022}
74698084Sdougb
74752400Sbillf#
748114501Sdougb# Warn users who still have old rc files
749114501Sdougb#
750179315Sbzfor file in atm devfs diskless1 diskless2 network network6 pccard \
751114523Sdougb  serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
752114501Sdougb  if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
753114501Sdougb    OLD_RC_PRESENT=1
754114501Sdougb    break
755114501Sdougb  fi
756114501Sdougbdone
757114501Sdougb
758114501Sdougbcase "${OLD_RC_PRESENT}" in
759114501Sdougb1)
76052400Sbillf  echo ''
761114501Sdougb  echo " *** There are elements of the old rc system in ${DESTDIR}/etc/."
76267949Sdougb  echo ''
763114501Sdougb  echo '     While these scripts will not hurt anything, they are not'
764114501Sdougb  echo '     functional on an up to date system, and can be removed.'
76567949Sdougb  echo ''
766114501Sdougb
76752400Sbillf  case "${AUTO_RUN}" in
76852400Sbillf  '')
769114501Sdougb    echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] '
770114501Sdougb    read MOVE_OLD_RC
77167859Sdougb
772114501Sdougb    case "${MOVE_OLD_RC}" in
773114501Sdougb    [nN]*) ;;
77452400Sbillf    *)
775114501Sdougb      mkdir -p /var/tmp/mergemaster/old_rc
776179315Sbz        for file in atm devfs diskless1 diskless2 network network6 pccard \
777114523Sdougb          serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
778114501Sdougb          if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
779114501Sdougb            mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/
780114501Sdougb          fi
781114501Sdougb        done
782114501Sdougb      echo '  The files have been moved'
783114501Sdougb      press_to_continue
78452400Sbillf      ;;
78552400Sbillf    esac
78652400Sbillf    ;;
78752400Sbillf  *) ;;
78852400Sbillf  esac
789114501Sdougbesac
79052400Sbillf
79198084Sdougb# Use the umask/mode information to install the files
79252400Sbillf# Create directories as needed
79352400Sbillf#
794186678Sdougbinstall_error () {
795186678Sdougb  echo "*** FATAL ERROR: Unable to install ${1} to ${2}"
796186678Sdougb  echo ''
797186678Sdougb  exit 1
798186678Sdougb}
799186678Sdougb
80078490Sdougbdo_install_and_rm () {
801114501Sdougb  case "${PRESERVE_FILES}" in
802114501Sdougb  [Yy][Ee][Ss])
803114501Sdougb    if [ -f "${3}/${2##*/}" ]; then
804114565Sdougb      mkdir -p ${PRESERVE_FILES_DIR}/${2%/*}
805114565Sdougb      cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*}
806114501Sdougb    fi
807114501Sdougb    ;;
808114501Sdougb  esac
809114501Sdougb
810186678Sdougb  if [ ! -d "${3}/${2##*/}" ]; then
811186678Sdougb    if install -m ${1} ${2} ${3}; then
812186678Sdougb      unlink ${2}
813186678Sdougb    else
814186678Sdougb      install_error ${2} ${3}
815186678Sdougb    fi
816186678Sdougb  else
817186678Sdougb    install_error ${2} ${3}
818186678Sdougb  fi
81978490Sdougb}
82078490Sdougb
82198084Sdougb# 4095 = "obase=10;ibase=8;07777" | bc
82298084Sdougbfind_mode () {
82398084Sdougb  local OCTAL
82498084Sdougb  OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 &
825124053Sdougb    $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) ))
82698084Sdougb  printf "%04o\n" ${OCTAL}
82798084Sdougb}
82898084Sdougb
82952400Sbillfmm_install () {
83052400Sbillf  local INSTALL_DIR
83152400Sbillf  INSTALL_DIR=${1#.}
83252400Sbillf  INSTALL_DIR=${INSTALL_DIR%/*}
83367949Sdougb
83452400Sbillf  case "${INSTALL_DIR}" in
83552400Sbillf  '')
83652400Sbillf    INSTALL_DIR=/
83752400Sbillf    ;;
83852400Sbillf  esac
83952400Sbillf
84067949Sdougb  if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
84198084Sdougb    DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"`
842200425Sdougb    install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" ||
843200425Sdougb      install_error $1 ${DESTDIR}${INSTALL_DIR}
84452400Sbillf  fi
84552400Sbillf
84698084Sdougb  FILE_MODE=`find_mode "${1}"`
84752400Sbillf
84852400Sbillf  if [ ! -x "${1}" ]; then
84952400Sbillf    case "${1#.}" in
85064625Sgshapiro    /etc/mail/aliases)
85152400Sbillf      NEED_NEWALIASES=yes
85252400Sbillf      ;;
85352400Sbillf    /etc/login.conf)
85452400Sbillf      NEED_CAP_MKDB=yes
85552400Sbillf      ;;
856207612Snork    /etc/services)
857207612Snork      NEED_SERVICES_MKDB=yes
858207612Snork      ;;
85952400Sbillf    /etc/master.passwd)
86078490Sdougb      do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
86152400Sbillf      NEED_PWD_MKDB=yes
86252400Sbillf      DONT_INSTALL=yes
86352400Sbillf      ;;
86452400Sbillf    /.cshrc | /.profile)
865200708Sdougb      local st_nlink
866200708Sdougb
867200708Sdougb      # install will unlink the file before it installs the new one,
868200708Sdougb      # so we have to restore/create the link afterwards.
869200708Sdougb      #
870200708Sdougb      st_nlink=0		# In case the file does not yet exist
871200708Sdougb      eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null)
872200708Sdougb
873200708Sdougb      do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
874200708Sdougb
875200708Sdougb      if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then
876200708Sdougb        HANDLE_LINK=l
877200708Sdougb      else
878200701Sdougb        case "${LINK_EXPLAINED}" in
879200701Sdougb        '')
880200701Sdougb          echo "   *** Historically BSD derived systems have had a"
881200701Sdougb          echo "       hard link from /.cshrc and /.profile to"
882200701Sdougb          echo "       their namesakes in /root.  Please indicate"
883200701Sdougb          echo "       your preference below for bringing your"
884200701Sdougb          echo "       installed files up to date."
885200701Sdougb          echo ''
886200701Sdougb          LINK_EXPLAINED=yes
887200701Sdougb          ;;
888200701Sdougb        esac
889200701Sdougb
890200701Sdougb        echo "   Use 'd' to delete the temporary ${COMPFILE}"
891200708Sdougb        echo "   Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link"
89252400Sbillf        echo ''
893200701Sdougb        echo "   Default is to leave the temporary file to deal with by hand"
894200701Sdougb        echo ''
895200701Sdougb        echo -n "  How should I handle ${COMPFILE}? [Leave it to install later] "
896200701Sdougb        read HANDLE_LINK
897200708Sdougb      fi
89852400Sbillf
89952400Sbillf      case "${HANDLE_LINK}" in
90052400Sbillf      [dD]*)
90152400Sbillf        rm "${COMPFILE}"
90252400Sbillf        echo ''
90352400Sbillf        echo "   *** Deleting ${COMPFILE}"
90452400Sbillf        ;;
90552400Sbillf      [lL]*)
90652400Sbillf        echo ''
907200708Sdougb        unlink ${DESTDIR}/root/${COMPFILE##*/}
908200708Sdougb        if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then
90967949Sdougb          echo "   *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
91052400Sbillf        else
911200708Sdougb          echo "   *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}"
912200708Sdougb          echo "   *** ${COMPFILE} will remain for your consideration"
91352400Sbillf        fi
91452400Sbillf        ;;
91552400Sbillf      *)
91652400Sbillf        echo "   *** ${COMPFILE} will remain for your consideration"
91752400Sbillf        ;;
91852400Sbillf      esac
919200708Sdougb      return
92052400Sbillf      ;;
92152400Sbillf    esac
92252400Sbillf
92352400Sbillf    case "${DONT_INSTALL}" in
92452400Sbillf    '')
92578490Sdougb      do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
92652400Sbillf      ;;
92752400Sbillf    *)
92852400Sbillf      unset DONT_INSTALL
92952400Sbillf      ;;
93052400Sbillf    esac
93178490Sdougb  else	# File matched -x
93278490Sdougb    do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
93352400Sbillf  fi
93452400Sbillf  return $?
93552400Sbillf}
93652400Sbillf
937174841Sdougbif [ ! -d "${TEMPROOT}" ]; then
938174841Sdougb	echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})"
939174841Sdougb	echo '                 has disappeared!'
940174841Sdougb	echo ''
941174841Sdougb	exit 1
942174841Sdougbfi
943174841Sdougb
94467949Sdougbecho ''
94567949Sdougbecho "*** Beginning comparison"
94667949Sdougbecho ''
94752400Sbillf
948124136Sdougb# Pre-world does not populate /etc/rc.d.
949124053Sdougb# It is very possible that a previous run would have deleted files in
950124053Sdougb# ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives.
951124136Sdougbif [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then
952124053Sdougb  echo "   *** Checking ${DESTDIR}/etc/rc.d for stale files"
953124053Sdougb  echo ''
954124053Sdougb  cd "${DESTDIR}/etc/rc.d" &&
955124053Sdougb  for file in *; do
956124053Sdougb    if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then
957124053Sdougb      STALE_RC_FILES="${STALE_RC_FILES} ${file}"
958124053Sdougb    fi
959124053Sdougb  done
960124053Sdougb  case "${STALE_RC_FILES}" in
961126718Sdougb  ''|' *')
962124053Sdougb    echo '   *** No stale files found'
963124053Sdougb    ;;
964124053Sdougb  *)
965124053Sdougb    echo "   *** The following files exist in ${DESTDIR}/etc/rc.d but not in"
966124053Sdougb    echo "       ${TEMPROOT}/etc/rc.d/:"
967124053Sdougb    echo ''
968124053Sdougb    echo "${STALE_RC_FILES}"
969124053Sdougb    echo ''
970124053Sdougb    echo '       The presence of stale files in this directory can cause the'
971124053Sdougb    echo '       dreaded unpredictable results, and therefore it is highly'
972124053Sdougb    echo '       recommended that you delete them.'
973124053Sdougb    case "${AUTO_RUN}" in
974124053Sdougb    '')
975124053Sdougb      echo ''
976153604Sdougb      echo -n '   *** Delete them now? [n] '
977124053Sdougb      read DELETE_STALE_RC_FILES
978124053Sdougb      case "${DELETE_STALE_RC_FILES}" in
979153604Sdougb      [yY])
980124053Sdougb        echo '      *** Deleting ... '
981124053Sdougb        rm ${STALE_RC_FILES}
982124053Sdougb        echo '                       done.'
983124053Sdougb        ;;
984153604Sdougb      *)
985153604Sdougb        echo '      *** Files will not be deleted'
986153604Sdougb        ;;
987124053Sdougb      esac
988124053Sdougb      sleep 2
989124053Sdougb      ;;
990201291Sdougb    *)
991201291Sdougb      if [ -n "${DELETE_STALE_RC_FILES}" ]; then
992201291Sdougb        echo '      *** Deleting ... '
993201291Sdougb        rm ${STALE_RC_FILES}
994201291Sdougb        echo '                       done.'
995201291Sdougb      fi
996124053Sdougb    esac
997124053Sdougb    ;;
998124053Sdougb  esac
999124053Sdougb  echo ''
1000124136Sdougbfi
1001124053Sdougb
100267949Sdougbcd "${TEMPROOT}"
100367949Sdougb
100467949Sdougbif [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
100567949Sdougb  . "${MM_PRE_COMPARE_SCRIPT}"
100667949Sdougbfi
100767949Sdougb
1008200425Sdougb# Things that were files/directories/links in one version can sometimes
1009200425Sdougb# change to something else in a newer version.  So we need to explicitly
1010200425Sdougb# test for this, and warn the user if what we find does not match.
1011200425Sdougb#
1012200700Sdougbfor COMPFILE in `find . | sort` ; do
1013200425Sdougb  if [ -e "${DESTDIR}${COMPFILE#.}" ]; then
1014200425Sdougb    INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}`
1015200425Sdougb  else
1016200425Sdougb    continue
1017200425Sdougb  fi
1018200425Sdougb  TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE`
1019200425Sdougb
1020200425Sdougb  if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then
1021200425Sdougb    [ "$COMPFILE" = '.' ] && continue
1022200425Sdougb    TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]`
1023200425Sdougb    INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]`
1024200425Sdougb
1025200425Sdougb    echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\""
1026200425Sdougb    echo "    but the new version has the type \"$TEMPROOT_TYPE\""
1027200425Sdougb    echo ''
1028200425Sdougb    echo "    How would you like to handle this?"
1029200425Sdougb    echo ''
1030200425Sdougb    echo "    Use 'r' to remove ${DESTDIR}${COMPFILE#.}"
1031200425Sdougb    case "$TEMPROOT_TYPE" in
1032200425Sdougb    'symbolic link')
1033200425Sdougb	TARGET=`readlink $COMPFILE`
1034200425Sdougb	echo "    and create a link to $TARGET in its place" ;;
1035200425Sdougb    *)	echo "    You will be able to install it as a \"$TEMPROOT_TYPE\"" ;;
1036200425Sdougb    esac
1037200425Sdougb    echo ''
1038200425Sdougb    echo "    Use 'i' to ignore this"
1039200425Sdougb    echo ''
1040200425Sdougb    echo -n "    How to proceed? [i] "
1041200425Sdougb    read ANSWER
1042200425Sdougb    case "$ANSWER" in
1043200425Sdougb    [rR])	case "${PRESERVE_FILES}" in
1044200425Sdougb		[Yy][Ee][Ss])
1045200425Sdougb		mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;;
1046200425Sdougb		*) rm -rf ${DESTDIR}${COMPFILE#.} ;;
1047200425Sdougb		esac
1048200425Sdougb		case "$TEMPROOT_TYPE" in
1049200425Sdougb		'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;;
1050200425Sdougb		esac ;;
1051200425Sdougb    *)	echo ''
1052200425Sdougb        echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES"
1053200425Sdougb        press_to_continue ;;
1054200425Sdougb    esac
1055200425Sdougb    echo ''
1056200425Sdougb  fi
1057200425Sdougbdone
1058200425Sdougb
1059200700Sdougbfor COMPFILE in `find . -type f | sort`; do
106067949Sdougb
106167949Sdougb  # First, check to see if the file exists in DESTDIR.  If not, the
106267949Sdougb  # diff_loop function knows how to handle it.
106367949Sdougb  #
106467949Sdougb  if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
106577325Sdougb    case "${AUTO_RUN}" in
106677325Sdougb      '')
106777325Sdougb        diff_loop
106877325Sdougb        ;;
106977325Sdougb      *)
107077325Sdougb        case "${AUTO_INSTALL}" in
107177325Sdougb        '')
107277325Sdougb          # If this is an auto run, make it official
107377325Sdougb          echo "   *** ${COMPFILE} will remain for your consideration"
107477325Sdougb          ;;
107577325Sdougb        *)
107677325Sdougb          diff_loop
107777325Sdougb          ;;
107877325Sdougb        esac
107977325Sdougb        ;;
108077325Sdougb    esac # Auto run test
108167949Sdougb    continue
108267949Sdougb  fi
108367949Sdougb
108452400Sbillf  case "${STRICT}" in
108552400Sbillf  '' | [Nn][Oo])
1086241337Sdougb    # Compare $Id's first so if the file hasn't been modified
108752400Sbillf    # local changes will be ignored.
108852400Sbillf    # If the files have the same $Id, delete the one in temproot so the
108952400Sbillf    # user will have less to wade through if files are left to merge by hand.
109052400Sbillf    #
1091241337Sdougb    ID1=`grep "[$]${ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
1092241337Sdougb    ID2=`grep "[$]${ID_TAG}:" ${COMPFILE} 2>/dev/null` || ID2=none
109352400Sbillf
1094241337Sdougb    case "${ID2}" in
1095241337Sdougb    "${ID1}")
1096241337Sdougb      echo " *** Temp ${COMPFILE} and installed have the same Id, deleting"
109767949Sdougb      rm "${COMPFILE}"
109867949Sdougb      ;;
109967949Sdougb    esac
110052400Sbillf    ;;
110152400Sbillf  esac
110252400Sbillf
110352400Sbillf  # If the file is still here either because the $Ids are different, the
110452400Sbillf  # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
110552400Sbillf  #
110652400Sbillf  if [ -f "${COMPFILE}" ]; then
110752400Sbillf
110852400Sbillf    # Do an absolute diff first to see if the files are actually different.
110952400Sbillf    # If they're not different, delete the one in temproot.
111052400Sbillf    #
1111110377Sdougb    if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1112110377Sdougb      /dev/null 2>&1; then
111352400Sbillf      echo " *** Temp ${COMPFILE} and installed are the same, deleting"
111452400Sbillf      rm "${COMPFILE}"
111552400Sbillf    else
111677323Sdougb      # Ok, the files are different, so show the user where they differ.
111777323Sdougb      # Use user's choice of diff methods; and user's pager if they have one.
111877323Sdougb      # Use more if not.
111967859Sdougb      # Use unified diffs by default.  Context diffs give me a headache. :)
112052400Sbillf      #
1121189992Sdougb      # If the user chose the -F option, test for that before proceeding
1122189992Sdougb      #
1123189992Sdougb      if [ -n "$FREEBSD_ID" ]; then
1124201291Sdougb        if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1125189992Sdougb            /dev/null 2>&1; then
1126189992Sdougb          if mm_install "${COMPFILE}"; then
1127189992Sdougb            echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}"
1128189992Sdougb          else
1129189992Sdougb            echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later"
1130189992Sdougb          fi
1131189992Sdougb          continue
1132189992Sdougb        fi
1133189992Sdougb      fi
113452400Sbillf      case "${AUTO_RUN}" in
113552400Sbillf      '')
113658910Salfred        # prompt user to install/delete/merge changes
113758910Salfred        diff_loop
113852400Sbillf        ;;
113952400Sbillf      *)
114052400Sbillf        # If this is an auto run, make it official
114152400Sbillf        echo "   *** ${COMPFILE} will remain for your consideration"
114252400Sbillf        ;;
114352400Sbillf      esac # Auto run test
114452400Sbillf    fi # Yes, the files are different
114552400Sbillf  fi # Yes, the file still remains to be checked
1146189763Sdougbdone # This is for the for way up there at the beginning of the comparison
114752400Sbillf
114852534Sbillfecho ''
114952400Sbillfecho "*** Comparison complete"
1150158149Sgordon
1151192230Sdougbif [ -s "${MTREENEW}" ]; then
1152158149Sgordon  echo "*** Saving mtree database for future upgrades"
1153200416Sdougb  test -e "${MTREEFILE}" && unlink ${MTREEFILE}
1154200416Sdougb  mv ${MTREENEW} ${MTREEFILE}
1155158149Sgordonfi
1156158149Sgordon
115752400Sbillfecho ''
115852400Sbillf
115952400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
116052400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then
116152400Sbillf  echo "*** Files that remain for you to merge by hand:"
1162200700Sdougb  find "${TEMPROOT}" -type f -size +0 | sort
116377335Sdougb  echo ''
116452400Sbillf
1165201765Sdougb  case "${AUTO_RUN}" in
1166201765Sdougb  '')
1167201765Sdougb    echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
1168201765Sdougb    read DEL_TEMPROOT
1169201765Sdougb    case "${DEL_TEMPROOT}" in
1170201765Sdougb    [yY]*)
1171201765Sdougb      delete_temproot
1172201765Sdougb      ;;
1173201765Sdougb    *)
1174201765Sdougb      echo " *** ${TEMPROOT} will remain"
1175201765Sdougb      ;;
1176201765Sdougb    esac
117752400Sbillf    ;;
1178201765Sdougb  *) ;;
117952400Sbillf  esac
1180201765Sdougbelse
1181201765Sdougb  echo "*** ${TEMPROOT} is empty, deleting"
1182201765Sdougb  delete_temproot
1183201765Sdougbfi
118452400Sbillf
118568153Sdougbcase "${AUTO_INSTALLED_FILES}" in
118668153Sdougb'') ;;
118768153Sdougb*)
118873651Sdougb  case "${AUTO_RUN}" in
118973651Sdougb  '')
119073651Sdougb    (
119173651Sdougb      echo ''
119277323Sdougb      echo '*** You chose the automatic install option for files that did not'
119377323Sdougb      echo '    exist on your system.  The following were installed for you:'
119473651Sdougb      echo "${AUTO_INSTALLED_FILES}"
119573651Sdougb    ) | ${PAGER}
119673651Sdougb    ;;
119773651Sdougb  *)
119868153Sdougb    echo ''
119977323Sdougb    echo '*** You chose the automatic install option for files that did not'
120077323Sdougb    echo '    exist on your system.  The following were installed for you:'
120168153Sdougb    echo "${AUTO_INSTALLED_FILES}"
120273651Sdougb    ;;
120373651Sdougb  esac
120468153Sdougb  ;;
120568153Sdougbesac
120668153Sdougb
1207158149Sgordoncase "${AUTO_UPGRADED_FILES}" in
1208158149Sgordon'') ;;
1209158149Sgordon*)
1210158149Sgordon  case "${AUTO_RUN}" in
1211158149Sgordon  '')
1212158149Sgordon    (
1213158149Sgordon      echo ''
1214158149Sgordon      echo '*** You chose the automatic upgrade option for files that you did'
1215158149Sgordon      echo '    not alter on your system.  The following were upgraded for you:'
1216158149Sgordon      echo "${AUTO_UPGRADED_FILES}"
1217158149Sgordon    ) | ${PAGER}
1218158149Sgordon    ;;
1219158149Sgordon  *)
1220158149Sgordon    echo ''
1221158149Sgordon    echo '*** You chose the automatic upgrade option for files that you did'
1222158149Sgordon    echo '    not alter on your system.  The following were upgraded for you:'
1223158149Sgordon    echo "${AUTO_UPGRADED_FILES}"
1224158149Sgordon    ;;
1225158149Sgordon  esac
1226158149Sgordon  ;;
1227158149Sgordonesac
1228158149Sgordon
122973651Sdougbrun_it_now () {
1230227145Sdougb  [ -n "$AUTO_RUN" ] && return
123173651Sdougb
1232227145Sdougb  local answer
1233227145Sdougb
1234227145Sdougb  echo ''
1235227145Sdougb  while : ; do
1236227145Sdougb    if [ "$RUN_UPDATES" = always ]; then
1237227145Sdougb      answer=y
1238227145Sdougb    elif [ "$RUN_UPDATES" = never ]; then
1239227145Sdougb      answer=n
1240227145Sdougb    else
1241227145Sdougb      echo -n '    Would you like to run it now? y or n [n] '
1242227145Sdougb      read answer
1243227145Sdougb    fi
1244227145Sdougb
1245227145Sdougb    case "$answer" in
124673651Sdougb    y)
124777335Sdougb      echo "    Running ${1}"
124877335Sdougb      echo ''
124973651Sdougb      eval "${1}"
1250227145Sdougb      return
125173651Sdougb      ;;
125277335Sdougb    ''|n)
1253227145Sdougb      if [ ! "$RUN_UPDATES" = never ]; then
1254227145Sdougb        echo ''
1255227145Sdougb        echo "       *** Cancelled"
1256227145Sdougb        echo ''
1257227145Sdougb      fi
125877335Sdougb      echo "    Make sure to run ${1} yourself"
1259227145Sdougb      return
126077335Sdougb      ;;
126173651Sdougb    *)
126277335Sdougb      echo ''
1263227145Sdougb      echo "       *** Sorry, I do not understand your answer (${answer})"
126477335Sdougb      echo ''
126573651Sdougb    esac
1266227145Sdougb  done
126773651Sdougb}
126873651Sdougb
126952400Sbillfcase "${NEED_NEWALIASES}" in
127052400Sbillf'') ;;
127152400Sbillf*)
127252400Sbillf  echo ''
127377335Sdougb  if [ -n "${DESTDIR}" ]; then
127477335Sdougb    echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
127577335Sdougb    echo "    the newaliases command is limited to the directories configured"
127677335Sdougb    echo "    in sendmail.cf.  Make sure to create your aliases database by"
127777335Sdougb    echo "    hand when your sendmail configuration is done."
127877335Sdougb  else
127977335Sdougb    echo "*** You installed a new aliases file, so make sure that you run"
128077335Sdougb    echo "    '/usr/bin/newaliases' to rebuild your aliases database"
128177335Sdougb    run_it_now '/usr/bin/newaliases'
128277335Sdougb  fi
128352400Sbillf  ;;
128452400Sbillfesac
128552400Sbillf
128652400Sbillfcase "${NEED_CAP_MKDB}" in
128752400Sbillf'') ;;
128852400Sbillf*)
128952400Sbillf  echo ''
129052400Sbillf  echo "*** You installed a login.conf file, so make sure that you run"
129177335Sdougb  echo "    '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
129277335Sdougb  echo "     to rebuild your login.conf database"
129377335Sdougb  run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
129452400Sbillf  ;;
129552400Sbillfesac
129652400Sbillf
1297207612Snorkcase "${NEED_SERVICES_MKDB}" in
1298207612Snork'') ;;
1299207612Snork*)
1300207612Snork  echo ''
1301207612Snork  echo "*** You installed a services file, so make sure that you run"
1302207612Snork  echo "    '/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services'"
1303207612Snork  echo "     to rebuild your services database"
1304207612Snork  run_it_now "/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services"
1305207612Snork  ;;
1306207612Snorkesac
1307207612Snork
130852400Sbillfcase "${NEED_PWD_MKDB}" in
130952400Sbillf'') ;;
131052400Sbillf*)
131152400Sbillf  echo ''
131252400Sbillf  echo "*** You installed a new master.passwd file, so make sure that you run"
131377335Sdougb  if [ -n "${DESTDIR}" ]; then
131477335Sdougb    echo "    '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
131577335Sdougb    echo "    to rebuild your password files"
131677335Sdougb    run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
131777335Sdougb  else
131877335Sdougb    echo "    '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
131977335Sdougb    echo "     to rebuild your password files"
132077335Sdougb    run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
132177335Sdougb  fi
132252400Sbillf  ;;
132352400Sbillfesac
132452400Sbillf
1325241337Sdougbif [ -e "${DESTDIR}/etc/localtime" -a -z "${PRE_WORLD}" ]; then	# Ignore if TZ == UTC
1326227145Sdougb  echo ''
1327228169Sdougb  [ -n "${DESTDIR}" ] && tzs_args="-C ${DESTDIR}"
1328227145Sdougb  if [ -f "${DESTDIR}/var/db/zoneinfo" ]; then
1329227145Sdougb    echo "*** Reinstalling `cat ${DESTDIR}/var/db/zoneinfo` as ${DESTDIR}/etc/localtime"
1330227145Sdougb    tzsetup $tzs_args -r
1331227145Sdougb  else
1332227145Sdougb    echo "*** There is no ${DESTDIR}/var/db/zoneinfo file to update ${DESTDIR}/etc/localtime."
1333227145Sdougb    echo '    You should run tzsetup'
1334228169Sdougb    run_it_now "tzsetup $tzs_args"
1335227145Sdougb  fi
1336227145Sdougbfi
1337227145Sdougb
133852400Sbillfecho ''
133952400Sbillf
134067949Sdougbif [ -r "${MM_EXIT_SCRIPT}" ]; then
134167949Sdougb  . "${MM_EXIT_SCRIPT}"
134267949Sdougbfi
134367949Sdougb
134491193Sdougbcase "${COMP_CONFS}" in
134591193Sdougb'') ;;
134691193Sdougb*)
134791193Sdougb  . ${DESTDIR}/etc/defaults/rc.conf
134891193Sdougb
134991193Sdougb  (echo ''
135091193Sdougb  echo "*** Comparing conf files: ${rc_conf_files}"
135191193Sdougb
135291193Sdougb  for CONF_FILE in ${rc_conf_files}; do
135391193Sdougb    if [ -r "${DESTDIR}${CONF_FILE}" ]; then
135491193Sdougb      echo ''
135591193Sdougb      echo "*** From ${DESTDIR}${CONF_FILE}"
135691193Sdougb      echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
135791193Sdougb
135891193Sdougb      for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
135991193Sdougb        cut -d '=' -f 1`; do
136091193Sdougb        echo ''
136191223Sdougb        grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
136291223Sdougb        grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
136391193Sdougb          echo ' * No default variable with this name'
136491193Sdougb      done
136591193Sdougb    fi
136691193Sdougb  done) | ${PAGER}
136791193Sdougb  echo ''
136891193Sdougb  ;;
136991193Sdougbesac
137091193Sdougb
1371200425Sdougbif [ -n "${PRESERVE_FILES}" ]; then
1372200425Sdougb  find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null
1373200425Sdougb  rmdir $PRESERVE_FILES_DIR 2>/dev/null
1374200425Sdougbfi
1375200425Sdougb
137652400Sbillfexit 0
1377241337Sdougb
1378241337Sdougb#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1379241337Sdougb
1380241337Sdougb#  Copyright (c) 1998-2012 Douglas Barton
1381241337Sdougb#  All rights reserved.
1382241337Sdougb#
1383241337Sdougb#  Redistribution and use in source and binary forms, with or without
1384241337Sdougb#  modification, are permitted provided that the following conditions
1385241337Sdougb#  are met:
1386241337Sdougb#  1. Redistributions of source code must retain the above copyright
1387241337Sdougb#     notice, this list of conditions and the following disclaimer.
1388241337Sdougb#  2. Redistributions in binary form must reproduce the above copyright
1389241337Sdougb#     notice, this list of conditions and the following disclaimer in the
1390241337Sdougb#     documentation and/or other materials provided with the distribution.
1391241337Sdougb#
1392241337Sdougb#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1393241337Sdougb#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1394241337Sdougb#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1395241337Sdougb#  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1396241337Sdougb#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1397241337Sdougb#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1398241337Sdougb#  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1399241337Sdougb#  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1400241337Sdougb#  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1401241337Sdougb#  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1402241337Sdougb#  SUCH DAMAGE.
1403