mergemaster.sh revision 200416
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
8186678Sdougb# Copyright 1998-2009 Douglas Barton
973651Sdougb# DougB@FreeBSD.org
1052400Sbillf
1152495Sbillf# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 200416 2009-12-11 23:03:35Z dougb $
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}"
18189992Sdougb  echo 'Usage: mergemaster [-scrvahipFCPU]'
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"
33189763Sdougb  echo ''
3452400Sbillf  echo "  -m /path/directory  Specify location of source to do the make in"
3552400Sbillf  echo "  -t /path/directory  Specify temp root directory"
3652400Sbillf  echo "  -d  Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
3752400Sbillf  echo "  -u N  Specify a numeric umask"
3852400Sbillf  echo "  -w N  Specify a screen width in columns to sdiff"
39155309Srwatson  echo "  -A architecture  Alternative architecture name to pass to make"
4067949Sdougb  echo '  -D /path/directory  Specify the destination directory to install files to'
4152400Sbillf  echo ''
4252400Sbillf}
4352400Sbillf
4452400Sbillfdisplay_help () {
4552400Sbillf  echo "* To specify a directory other than /var/tmp/temproot for the"
4652400Sbillf  echo "  temporary root environment, use -t /path/to/temp/root"
4752400Sbillf  echo "* The -w option takes a number as an argument for the column width"
4867859Sdougb  echo "  of the screen.  The default is 80."
4967949Sdougb  echo '* The -a option causes mergemaster to run without prompting.'
5052400Sbillf}
5152400Sbillf
5258910Salfred# Loop allowing the user to use sdiff to merge files and display the merged
5358910Salfred# file.
5458910Salfredmerge_loop () {
5567850Sdougb  case "${VERBOSE}" in
5667850Sdougb  '') ;;
5767850Sdougb  *)
5867850Sdougb      echo "   *** Type h at the sdiff prompt (%) to get usage help"
5967850Sdougb      ;;
6067850Sdougb  esac
6167850Sdougb  echo ''
6267850Sdougb  MERGE_AGAIN=yes
6367850Sdougb  while [ "${MERGE_AGAIN}" = "yes" ]; do
6467850Sdougb    # Prime file.merged so we don't blat the owner/group id's
6567850Sdougb    cp -p "${COMPFILE}" "${COMPFILE}.merged"
6667850Sdougb    sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
6767949Sdougb      --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
6867850Sdougb    INSTALL_MERGED=V
6967850Sdougb    while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
7067850Sdougb      echo ''
7167850Sdougb      echo "  Use 'i' to install merged file"
7267850Sdougb      echo "  Use 'r' to re-do the merge"
7367850Sdougb      echo "  Use 'v' to view the merged file"
7467850Sdougb      echo "  Default is to leave the temporary file to deal with by hand"
7567850Sdougb      echo ''
7667859Sdougb      echo -n "    *** How should I deal with the merged file? [Leave it for later] "
7767859Sdougb      read INSTALL_MERGED
7858910Salfred
7967850Sdougb      case "${INSTALL_MERGED}" in
8067850Sdougb      [iI])
8167850Sdougb        mv "${COMPFILE}.merged" "${COMPFILE}"
8267850Sdougb        echo ''
8367850Sdougb        if mm_install "${COMPFILE}"; then
8467850Sdougb          echo "     *** Merged version of ${COMPFILE} installed successfully"
8567859Sdougb        else
8667850Sdougb          echo "     *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
8767859Sdougb        fi
8867850Sdougb        unset MERGE_AGAIN
8967850Sdougb        ;;
9067850Sdougb      [rR])
9167850Sdougb        rm "${COMPFILE}.merged"
9267859Sdougb        ;;
9367850Sdougb      [vV])
9467850Sdougb        ${PAGER} "${COMPFILE}.merged"
9567850Sdougb        ;;
9667850Sdougb      '')
9767850Sdougb        echo "   *** ${COMPFILE} will remain for your consideration"
9867850Sdougb        unset MERGE_AGAIN
9967850Sdougb        ;;
10067850Sdougb      *)
10167850Sdougb        echo "invalid choice: ${INSTALL_MERGED}"
10267850Sdougb        INSTALL_MERGED=V
10367850Sdougb        ;;
10467850Sdougb      esac
10567850Sdougb    done
10667850Sdougb  done
10758910Salfred}
10858910Salfred
10958910Salfred# Loop showing user differences between files, allow merge, skip or install
11058910Salfred# options
11158910Salfreddiff_loop () {
11258910Salfred
11367850Sdougb  HANDLE_COMPFILE=v
11458910Salfred
11577323Sdougb  while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \
11677323Sdougb    "${HANDLE_COMPFILE}" = "NOT V" ]; do
11767949Sdougb    if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
118192230Sdougb      if [ -n "${AUTO_UPGRADE}" -a -n "${CHANGED}" ]; then
119192230Sdougb        case "${CHANGED}" in
120192230Sdougb        *:${DESTDIR}${COMPFILE#.}:*) ;;		# File has been modified
121192230Sdougb        *)
122158149Sgordon          echo ''
123158149Sgordon          echo "  *** ${COMPFILE} has not been user modified."
124158149Sgordon          echo ''
125158149Sgordon
126158149Sgordon          if mm_install "${COMPFILE}"; then
127158149Sgordon            echo "   *** ${COMPFILE} upgraded successfully"
128158149Sgordon            echo ''
129158149Sgordon            # Make the list print one file per line
130158149Sgordon            AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES}      ${DESTDIR}${COMPFILE#.}
131158149Sgordon"
132158149Sgordon          else
133192230Sdougb            echo "   *** Problem upgrading ${COMPFILE}, it will remain to merge by hand"
134158149Sgordon          fi
135158149Sgordon          return
136192230Sdougb          ;;
137192230Sdougb        esac
138158149Sgordon      fi
13967850Sdougb      if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
14090564Sdougb	echo ''
141109993Sdillon	echo '   ======================================================================   '
142109993Sdillon	echo ''
143109993Sdillon        (
144109993Sdillon          echo "  *** Displaying differences between ${COMPFILE} and installed version:"
145109993Sdillon          echo ''
146110377Sdougb          diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
147109993Sdillon        ) | ${PAGER}
148109993Sdillon        echo ''
14967850Sdougb      fi
15067850Sdougb    else
151109993Sdillon      echo ''
15267850Sdougb      echo "  *** There is no installed version of ${COMPFILE}"
15391193Sdougb      echo ''
15467949Sdougb      case "${AUTO_INSTALL}" in
15567949Sdougb      [Yy][Ee][Ss])
15667949Sdougb        echo ''
15767949Sdougb        if mm_install "${COMPFILE}"; then
15867949Sdougb          echo "   *** ${COMPFILE} installed successfully"
15968507Sdougb          echo ''
16067949Sdougb          # Make the list print one file per line
16167949Sdougb          AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES}      ${DESTDIR}${COMPFILE#.}
16267949Sdougb"
16367949Sdougb        else
16467949Sdougb          echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
16567949Sdougb        fi
16667949Sdougb        return
16767949Sdougb        ;;
16867949Sdougb      *)
16967949Sdougb        NO_INSTALLED=yes
17067949Sdougb        ;;
17167949Sdougb      esac
17267850Sdougb    fi
17367859Sdougb
17467850Sdougb    echo "  Use 'd' to delete the temporary ${COMPFILE}"
17567850Sdougb    echo "  Use 'i' to install the temporary ${COMPFILE}"
17667850Sdougb    case "${NO_INSTALLED}" in
17767850Sdougb    '')
17877326Sdougb      echo "  Use 'm' to merge the temporary and installed versions"
179109993Sdillon      echo "  Use 'v' to view the diff results again"
18067850Sdougb      ;;
18167850Sdougb    esac
18267850Sdougb    echo ''
18367850Sdougb    echo "  Default is to leave the temporary file to deal with by hand"
18467850Sdougb    echo ''
18567859Sdougb    echo -n "How should I deal with this? [Leave it for later] "
18667859Sdougb    read HANDLE_COMPFILE
18767859Sdougb
18867850Sdougb    case "${HANDLE_COMPFILE}" in
18967850Sdougb    [dD])
19067850Sdougb      rm "${COMPFILE}"
19167850Sdougb      echo ''
19267850Sdougb      echo "   *** Deleting ${COMPFILE}"
19367850Sdougb      ;;
19467850Sdougb    [iI])
19567850Sdougb      echo ''
19667850Sdougb      if mm_install "${COMPFILE}"; then
19767850Sdougb        echo "   *** ${COMPFILE} installed successfully"
19867850Sdougb      else
19967850Sdougb        echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
20067850Sdougb      fi
20167850Sdougb      ;;
20267850Sdougb    [mM])
20367850Sdougb      case "${NO_INSTALLED}" in
20467850Sdougb      '')
20567850Sdougb        # interact with user to merge files
20667850Sdougb        merge_loop
20767850Sdougb        ;;
20867850Sdougb      *)
20967850Sdougb        echo ''
21067850Sdougb        echo "   *** There is no installed version of ${COMPFILE}"
21167850Sdougb        echo ''
21267850Sdougb        HANDLE_COMPFILE="NOT V"
21367850Sdougb        ;;
21467850Sdougb      esac # End of "No installed version of file but user selected merge" test
21567850Sdougb      ;;
21667850Sdougb    [vV])
21767850Sdougb      continue
21867850Sdougb      ;;
21967850Sdougb    '')
22067850Sdougb      echo ''
22167850Sdougb      echo "   *** ${COMPFILE} will remain for your consideration"
22267850Sdougb      ;;
22367850Sdougb    *)
22467850Sdougb      # invalid choice, show menu again.
22567850Sdougb      echo "invalid choice: ${HANDLE_COMPFILE}"
22667850Sdougb      echo ''
22767850Sdougb      HANDLE_COMPFILE="NOT V"
22867850Sdougb      continue
22967850Sdougb      ;;
23067850Sdougb    esac  # End of "How to handle files that are different"
23167859Sdougb  done
23267850Sdougb  unset NO_INSTALLED
23367850Sdougb  echo ''
23467850Sdougb  case "${VERBOSE}" in
23567850Sdougb  '') ;;
23667850Sdougb  *)
23767850Sdougb    sleep 3
23867850Sdougb    ;;
23967850Sdougb  esac
24058910Salfred}
24158910Salfred
24297960Sdougbpress_to_continue () {
24397960Sdougb  local DISCARD
24497960Sdougb  echo -n ' *** Press the [Enter] or [Return] key to continue '
24597960Sdougb  read DISCARD
24697960Sdougb}
24797960Sdougb
24852400Sbillf# Set the default path for the temporary root environment
24952400Sbillf#
25052400SbillfTEMPROOT='/var/tmp/temproot'
25152400Sbillf
25273651Sdougb# Read /etc/mergemaster.rc first so the one in $HOME can override
25373651Sdougb#
25473651Sdougbif [ -r /etc/mergemaster.rc ]; then
25573651Sdougb  . /etc/mergemaster.rc
25673651Sdougbfi
25773651Sdougb
25852400Sbillf# Read .mergemasterrc before command line so CLI can override
25952400Sbillf#
26067949Sdougbif [ -r "$HOME/.mergemasterrc" ]; then
26152400Sbillf  . "$HOME/.mergemasterrc"
26252400Sbillffi
26352400Sbillf
264186678Sdougb# Assign the location of the mtree database
265186678Sdougb#
266200416SdougbMTREEDB=${MTREEDB:-${DESTDIR}/var/db}
267186678SdougbMTREEFILE="${MTREEDB}/mergemaster.mtree"
268186678Sdougb
26952400Sbillf# Check the command line options
27052400Sbillf#
271189992Sdougbwhile getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do
27252400Sbillf  case "${COMMAND_LINE_ARGUMENT}" in
273155309Srwatson  A)
274186678Sdougb    ARCHSTRING='TARGET_ARCH='${OPTARG}
275155309Srwatson    ;;
276189992Sdougb  F)
277189992Sdougb    FREEBSD_ID=yes
278189992Sdougb    ;;
279158149Sgordon  U)
280158149Sgordon    AUTO_UPGRADE=yes
281158149Sgordon    ;;
28252400Sbillf  s)
28352400Sbillf    STRICT=yes
284110377Sdougb    unset DIFF_OPTIONS
28552400Sbillf    ;;
28652400Sbillf  c)
28752400Sbillf    DIFF_FLAG='-c'
28852400Sbillf    ;;
28952400Sbillf  r)
29052400Sbillf    RERUN=yes
29152400Sbillf    ;;
29252400Sbillf  v)
29352400Sbillf    case "${AUTO_RUN}" in
29452400Sbillf    '') VERBOSE=yes ;;
29552400Sbillf    esac
29652400Sbillf    ;;
29752400Sbillf  a)
29852400Sbillf    AUTO_RUN=yes
29952400Sbillf    unset VERBOSE
30052400Sbillf    ;;
30152400Sbillf  h)
30252400Sbillf    display_usage
30352400Sbillf    display_help
30452400Sbillf    exit 0
30552400Sbillf    ;;
30667949Sdougb  i)
30767949Sdougb    AUTO_INSTALL=yes
30867949Sdougb    ;;
30996045Sdougb  C)
31096045Sdougb    COMP_CONFS=yes
31196045Sdougb    ;;
312114501Sdougb  P)
313114501Sdougb    PRESERVE_FILES=yes
314114501Sdougb    ;;
31591193Sdougb  p)
31691193Sdougb    PRE_WORLD=yes
31796045Sdougb    unset COMP_CONFS
31896045Sdougb    unset AUTO_RUN
31991193Sdougb    ;;
32052400Sbillf  m)
32152400Sbillf    SOURCEDIR=${OPTARG}
32252400Sbillf    ;;
32352400Sbillf  t)
32452400Sbillf    TEMPROOT=${OPTARG}
32552400Sbillf    ;;
32652400Sbillf  d)
32752400Sbillf    TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
32852400Sbillf    ;;
32952400Sbillf  u)
33052400Sbillf    NEW_UMASK=${OPTARG}
33152400Sbillf    ;;
33252400Sbillf  w)
33352400Sbillf    SCREEN_WIDTH=${OPTARG}
33452400Sbillf    ;;
33567949Sdougb  D)
33667949Sdougb    DESTDIR=${OPTARG}
33767949Sdougb    ;;
33852400Sbillf  *)
33952400Sbillf    display_usage
34052400Sbillf    exit 1
34152400Sbillf    ;;
34252400Sbillf  esac
34352400Sbillfdone
34452400Sbillf
345114501Sdougb# Don't force the user to set this in the mergemaster rc file
346114501Sdougbif [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then
347114501Sdougb  PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S`
348114501Sdougbfi
349114501Sdougb
350186678Sdougb# Check for the mtree database in DESTDIR
351186678Sdougbcase "${AUTO_UPGRADE}" in
352186678Sdougb'') ;;	# If the option is not set no need to run the test or warn the user
353186678Sdougb*)
354200416Sdougb  if [ ! -s "${MTREEFILE}" ]; then
355186678Sdougb    echo ''
356200416Sdougb    echo "*** Unable to find mtree database (${MTREEFILE})."
357200416Sdougb    echo "    Skipping auto-upgrade on this run."
358193853Sdougb    echo "    It will be created for the next run when this one is complete."
359186678Sdougb    echo ''
360186678Sdougb    press_to_continue
361186678Sdougb    unset AUTO_UPGRADE
362186678Sdougb  fi
363186678Sdougb  ;;
364186678Sdougbesac
365186678Sdougb
366186689Sdougbif [ -e "${DESTDIR}/etc/fstab" ]; then
367186689Sdougb  if grep -q nodev ${DESTDIR}/etc/fstab; then
368186689Sdougb    echo ''
369186689Sdougb    echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab."
370186689Sdougb    echo "    This can prevent the filesystem from being mounted on reboot."
371186689Sdougb    echo "    Please update your fstab before continuing."
372186689Sdougb    echo "    See fstab(5) for more information."
373186689Sdougb    echo ''
374186689Sdougb    exit 1
375186689Sdougb  fi
376158149Sgordonfi
377158149Sgordon
37852400Sbillfecho ''
37952400Sbillf
38052400Sbillf# If the user has a pager defined, make sure we can run it
38152400Sbillf#
38252400Sbillfcase "${DONT_CHECK_PAGER}" in
38352400Sbillf'')
384186695Sdougbcheck_pager () {
385186695Sdougb  while ! type "${PAGER%% *}" >/dev/null; do
38652400Sbillf    echo " *** Your PAGER environment variable specifies '${PAGER}', but"
38764467Sbrian    echo "     due to the limited PATH that I use for security reasons,"
38867859Sdougb    echo "     I cannot execute it.  So, what would you like to do?"
38952400Sbillf    echo ''
39052400Sbillf    echo "  Use 'e' to exit mergemaster and fix your PAGER variable"
39164467Sbrian    if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then
39264467Sbrian    echo "  Use 'l' to set PAGER to 'less' for this run"
39352400Sbillf    fi
39452400Sbillf    echo "  Use 'm' to use plain old 'more' as your PAGER for this run"
39552400Sbillf    echo ''
39652400Sbillf    echo "  Default is to use plain old 'more' "
39752400Sbillf    echo ''
39867859Sdougb    echo -n "What should I do? [Use 'more'] "
39967859Sdougb    read FIXPAGER
40067859Sdougb
40152400Sbillf    case "${FIXPAGER}" in
40258910Salfred    [eE])
40352400Sbillf       exit 0
40452400Sbillf       ;;
40558910Salfred    [lL])
40664467Sbrian       if [ -x /usr/bin/less ]; then
40764467Sbrian         PAGER=/usr/bin/less
40864467Sbrian       elif [ -x /usr/local/bin/less ]; then
40958910Salfred         PAGER=/usr/local/bin/less
41064467Sbrian       else
41164467Sbrian         echo ''
41264467Sbrian         echo " *** Fatal Error:"
41364467Sbrian         echo "     You asked to use 'less' as your pager, but I can't"
41464467Sbrian         echo "     find it in /usr/bin or /usr/local/bin"
41564467Sbrian         exit 1
41658910Salfred       fi
41752400Sbillf       ;;
41860420Sbsd    [mM]|'')
41952400Sbillf       PAGER=more
42052400Sbillf       ;;
42158910Salfred    *)
42258910Salfred       echo ''
42358910Salfred       echo "invalid choice: ${FIXPAGER}"
42452400Sbillf    esac
42552400Sbillf    echo ''
42658910Salfred  done
427186695Sdougb}
428186695Sdougb  if [ -n "${PAGER}" ]; then
429186695Sdougb    check_pager
430186695Sdougb  fi
43152400Sbillf  ;;
43252400Sbillfesac
43352400Sbillf
43452400Sbillf# If user has a pager defined, or got assigned one above, use it.
43552400Sbillf# If not, use more.
43652400Sbillf#
43752400SbillfPAGER=${PAGER:-more}
43852400Sbillf
43952400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
44052400Sbillf  echo " *** You have ${PAGER} defined as your pager so we will use that"
44152400Sbillf  echo ''
44252400Sbillf  sleep 3
44352400Sbillffi
44452400Sbillf
44552400Sbillf# Assign the diff flag once so we will not have to keep testing it
44652400Sbillf#
44752400SbillfDIFF_FLAG=${DIFF_FLAG:--u}
44852400Sbillf
44952400Sbillf# Assign the source directory
45052400Sbillf#
451186678SdougbSOURCEDIR=${SOURCEDIR:-/usr/src}
452186678Sdougbif [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
453186678Sdougb   -f ${SOURCEDIR}/../Makefile.inc1 ]; then
454186678Sdougb  echo " *** The source directory you specified (${SOURCEDIR})"
455186678Sdougb  echo "     will be reset to ${SOURCEDIR}/.."
456186678Sdougb  echo ''
457186678Sdougb  sleep 3
458186678Sdougb  SOURCEDIR=${SOURCEDIR}/..
459186678Sdougbfi
46052400Sbillf
461186678Sdougb# Setup make to use system files from SOURCEDIR
462186695SdougbMM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk"
463186678Sdougb
464158149Sgordon# Check DESTDIR against the mergemaster mtree database to see what
465158149Sgordon# files the user changed from the reference files.
466158149Sgordon#
467200416Sdougbif [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then
468192230Sdougb	CHANGED=:
469200416Sdougb	for file in `mtree -eqL -f ${MTREEFILE} -p ${DESTDIR}/ \
470158149Sgordon		2>/dev/null | awk '($2 == "changed") {print $1}'`; do
471158149Sgordon		if [ -f "${DESTDIR}/$file" ]; then
472192230Sdougb			CHANGED="${CHANGED}${DESTDIR}/${file}:"
473158149Sgordon		fi
474158149Sgordon	done
475192230Sdougb	[ "$CHANGED" = ':' ] && unset CHANGED
476158149Sgordonfi
477158149Sgordon
47896045Sdougb# Check the width of the user's terminal
47996045Sdougb#
48096045Sdougbif [ -t 0 ]; then
481110377Sdougb  w=`tput columns`
48296045Sdougb  case "${w}" in
48396045Sdougb  0|'') ;; # No-op, since the input is not valid
48496045Sdougb  *)
48596045Sdougb    case "${SCREEN_WIDTH}" in
48696045Sdougb    '') SCREEN_WIDTH="${w}" ;;
48796045Sdougb    "${w}") ;; # No-op, since they are the same
48896045Sdougb    *)
48996045Sdougb      echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty "
49096045Sdougb      echo "thinks it is ${w}."
49196045Sdougb      echo ''
49296045Sdougb      echo -n "What would you like to use? [${w}] "
49396045Sdougb      read SCREEN_WIDTH
49497380Sdougb      case "${SCREEN_WIDTH}" in
49597380Sdougb      '') SCREEN_WIDTH="${w}" ;;
49697380Sdougb      esac
49796045Sdougb      ;;
49896045Sdougb    esac
49996045Sdougb  esac
50096045Sdougbfi
50196045Sdougb
50273651Sdougb# Define what CVS $Id tag to look for to aid portability.
50373651Sdougb#
50473651SdougbCVS_ID_TAG=FreeBSD
50573651Sdougb
50699152Sdougbdelete_temproot () {
507101362Sdougb  rm -rf "${TEMPROOT}" 2>/dev/null
508101362Sdougb  chflags -R 0 "${TEMPROOT}" 2>/dev/null
509101362Sdougb  rm -rf "${TEMPROOT}" || exit 1
51099152Sdougb}
51199152Sdougb
51252400Sbillfcase "${RERUN}" in
51352400Sbillf'')
51452400Sbillf  # Set up the loop to test for the existence of the
51552400Sbillf  # temp root directory.
51652400Sbillf  #
51752400Sbillf  TEST_TEMP_ROOT=yes
51852400Sbillf  while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
51952400Sbillf    if [ -d "${TEMPROOT}" ]; then
52052400Sbillf      echo "*** The directory specified for the temporary root environment,"
52167859Sdougb      echo "    ${TEMPROOT}, exists.  This can be a security risk if untrusted"
52252400Sbillf      echo "    users have access to the system."
52352400Sbillf      echo ''
52452400Sbillf      case "${AUTO_RUN}" in
52552400Sbillf      '')
52652400Sbillf        echo "  Use 'd' to delete the old ${TEMPROOT} and continue"
52752400Sbillf        echo "  Use 't' to select a new temporary root directory"
52852400Sbillf        echo "  Use 'e' to exit mergemaster"
52952400Sbillf        echo ''
53052400Sbillf        echo "  Default is to use ${TEMPROOT} as is"
53152400Sbillf        echo ''
53267859Sdougb        echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
53367859Sdougb        read DELORNOT
53467859Sdougb
53567859Sdougb        case "${DELORNOT}" in
53667859Sdougb        [dD])
53767859Sdougb          echo ''
53867859Sdougb          echo "   *** Deleting the old ${TEMPROOT}"
53967859Sdougb          echo ''
54099152Sdougb          delete_temproot || exit 1
54167859Sdougb          unset TEST_TEMP_ROOT
54252400Sbillf          ;;
54367859Sdougb        [tT])
54467859Sdougb          echo "   *** Enter new directory name for temporary root environment"
54567859Sdougb          read TEMPROOT
54667859Sdougb          ;;
54767859Sdougb        [eE])
54867859Sdougb          exit 0
54967859Sdougb          ;;
55067859Sdougb        '')
55167859Sdougb          echo ''
55267859Sdougb          echo "   *** Leaving ${TEMPROOT} intact"
55367859Sdougb          echo ''
55467859Sdougb          unset TEST_TEMP_ROOT
55567859Sdougb          ;;
55667859Sdougb        *)
55767859Sdougb          echo ''
55867859Sdougb          echo "invalid choice: ${DELORNOT}"
55967859Sdougb          echo ''
56067859Sdougb          ;;
56167859Sdougb        esac
56267859Sdougb        ;;
56352400Sbillf      *)
56477323Sdougb        # If this is an auto-run, try a hopefully safe alternative then
56577323Sdougb        # re-test anyway.
56652400Sbillf        TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
56752400Sbillf        ;;
56852400Sbillf      esac
56952400Sbillf    else
57052400Sbillf      unset TEST_TEMP_ROOT
57152400Sbillf    fi
57252400Sbillf  done
57352400Sbillf
57452400Sbillf  echo "*** Creating the temporary root environment in ${TEMPROOT}"
57552400Sbillf
57652400Sbillf  if mkdir -p "${TEMPROOT}"; then
57752400Sbillf    echo " *** ${TEMPROOT} ready for use"
57852400Sbillf  fi
57952400Sbillf
58052400Sbillf  if [ ! -d "${TEMPROOT}" ]; then
58152400Sbillf    echo ''
58252400Sbillf    echo "  *** FATAL ERROR: Cannot create ${TEMPROOT}"
58352400Sbillf    echo ''
58452400Sbillf    exit 1
58552400Sbillf  fi
58652400Sbillf
58752400Sbillf  echo " *** Creating and populating directory structure in ${TEMPROOT}"
58852400Sbillf  echo ''
58952400Sbillf
59052400Sbillf  case "${VERBOSE}" in
59152400Sbillf  '') ;;
59252400Sbillf  *)
59397960Sdougb    press_to_continue
59452400Sbillf    ;;
59552400Sbillf  esac
59652400Sbillf
59791193Sdougb  case "${PRE_WORLD}" in
59891193Sdougb  '')
59991193Sdougb    { cd ${SOURCEDIR} &&
60091193Sdougb      case "${DESTDIR}" in
60191193Sdougb      '') ;;
60291193Sdougb      *)
603186695Sdougb        ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs
60491193Sdougb        ;;
60591193Sdougb      esac
606186749Sdougb      od=${TEMPROOT}/usr/obj
607186695Sdougb      ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs &&
608186749Sdougb      MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc &&
609186749Sdougb      MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc &&
610186749Sdougb      MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} ||
61191193Sdougb    { echo '';
61291193Sdougb     echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
61391193Sdougb      echo "      the temproot environment";
61491193Sdougb      echo '';
61591193Sdougb      exit 1;}
61691193Sdougb    ;;
61791193Sdougb  *)
61891193Sdougb    # Only set up files that are crucial to {build|install}world
61991193Sdougb    { mkdir -p ${TEMPROOT}/etc &&
620186678Sdougb      cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc &&
621186678Sdougb      cp -p ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} ||
62291193Sdougb    { echo '';
62391193Sdougb      echo '  *** FATAL ERROR: Cannot copy files to the temproot environment';
62491193Sdougb      echo '';
62591193Sdougb      exit 1;}
62691193Sdougb    ;;
62791193Sdougb  esac
62852400Sbillf
62977323Sdougb  # Doing the inventory and removing files that we don't want to compare only
63077323Sdougb  # makes sense if we are not doing a rerun, since we have no way of knowing
63177323Sdougb  # what happened to the files during previous incarnations.
63267949Sdougb  case "${VERBOSE}" in
63367949Sdougb  '') ;;
63467949Sdougb  *)
63567949Sdougb    echo ''
63667949Sdougb    echo ' *** The following files exist only in the installed version of'
63767949Sdougb    echo "     ${DESTDIR}/etc.  In the vast majority of cases these files"
63867949Sdougb    echo '     are necessary parts of the system and should not be deleted.'
63967949Sdougb    echo '     However because these files are not updated by this process you'
64067949Sdougb    echo '     might want to verify their status before rebooting your system.'
64167949Sdougb    echo ''
64297960Sdougb    press_to_continue
643101348Sdougb    diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER}
64467949Sdougb    echo ''
64597960Sdougb    press_to_continue
64667949Sdougb    ;;
64767949Sdougb  esac
64867949Sdougb
64952534Sbillf  # Avoid comparing the motd if the user specifies it in .mergemasterrc
650186678Sdougb  # Compatibility shim to be removed in FreeBSD 9.x
65152534Sbillf  case "${IGNORE_MOTD}" in
65252534Sbillf  '') ;;
653186678Sdougb  *) IGNORE_FILES="${IGNORE_FILES} /etc/motd"
654186678Sdougb     echo ''
655186678Sdougb     echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file."
656186678Sdougb     echo "    This option is deprecated in favor of the IGNORE_FILES option."
657186678Sdougb     echo "    Please update your rc file accordingly."
658186678Sdougb     echo ''
659186678Sdougb     press_to_continue
66052534Sbillf     ;;
66152534Sbillf  esac
66252534Sbillf
663186678Sdougb  # Avoid comparing the following user specified files
664186678Sdougb  for file in ${IGNORE_FILES}; do
665186688Sdougb    test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file}
666186678Sdougb  done
66752400Sbillf  ;; # End of the "RERUN" test
66852400Sbillfesac
66952400Sbillf
670111901Sdougb# We really don't want to have to deal with files like login.conf.db, pwd.db,
671111901Sdougb# or spwd.db.  Instead, we want to compare the text versions, and run *_mkdb.
672111901Sdougb# Prompt the user to do so below, as needed.
67377478Sdougb#
674111905Sdougbrm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd
67577478Sdougb
67694196Sdougb# We only need to compare things like freebsd.cf once
67796045Sdougbfind ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
67894196Sdougb
679193853Sdougb# Delete stuff we do not need to keep the mtree database small,
680193853Sdougb# and to make the actual comparison faster.
681193853Sdougbfind ${TEMPROOT}/usr -type l -delete 2>/dev/null
682158149Sgordonfind ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
683193853Sdougbfind -d ${TEMPROOT} -type d -empty -delete 2>/dev/null
684158149Sgordon
685158149Sgordon# Build the mtree database in a temporary location.
686186678SdougbMTREENEW=`mktemp -t mergemaster.mtree`
687158149Sgordoncase "${PRE_WORLD}" in
688189761Sdougb'') mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
689158149Sgordon    ;;
690158149Sgordon*) # We don't want to mess with the mtree database on a pre-world run.
691158149Sgordon   ;;
692158149Sgordonesac
693158149Sgordon
69452400Sbillf# Get ready to start comparing files
69552400Sbillf
69698084Sdougb# Check umask if not specified on the command line,
69798084Sdougb# and we are not doing an autorun
69852400Sbillf#
69998084Sdougbif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
70098084Sdougb  USER_UMASK=`umask`
70152400Sbillf  case "${USER_UMASK}" in
70277335Sdougb  0022|022) ;;
70352400Sbillf  *)
70452400Sbillf    echo ''
70598084Sdougb    echo " *** Your umask is currently set to ${USER_UMASK}.  By default, this script"
70698084Sdougb    echo "     installs all files with the same user, group and modes that"
707186678Sdougb    echo "     they are created with by ${SOURCEDIR}/etc/Makefile, compared to"
70898084Sdougb    echo "     a umask of 022.  This umask allows world read permission when"
70998084Sdougb    echo "     the file's default permissions have it."
71052400Sbillf    echo ''
71198084Sdougb    echo "     No world permissions can sometimes cause problems.  A umask of"
71298084Sdougb    echo "     022 will restore the default behavior, but is not mandatory."
71398084Sdougb    echo "     /etc/master.passwd is a special case.  Its file permissions"
71498084Sdougb    echo "     will be 600 (rw-------) if installed."
71597960Sdougb    echo ''
71698084Sdougb    echo -n "What umask should I use? [${USER_UMASK}] "
71798084Sdougb    read NEW_UMASK
71898084Sdougb
71998084Sdougb    NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
72052400Sbillf    ;;
72152400Sbillf  esac
72252400Sbillf  echo ''
72398084Sdougbfi
72452400Sbillf
72598084SdougbCONFIRMED_UMASK=${NEW_UMASK:-0022}
72698084Sdougb
72752400Sbillf#
728114501Sdougb# Warn users who still have old rc files
729114501Sdougb#
730179315Sbzfor file in atm devfs diskless1 diskless2 network network6 pccard \
731114523Sdougb  serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
732114501Sdougb  if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
733114501Sdougb    OLD_RC_PRESENT=1
734114501Sdougb    break
735114501Sdougb  fi
736114501Sdougbdone
737114501Sdougb
738114501Sdougbcase "${OLD_RC_PRESENT}" in
739114501Sdougb1)
74052400Sbillf  echo ''
741114501Sdougb  echo " *** There are elements of the old rc system in ${DESTDIR}/etc/."
74267949Sdougb  echo ''
743114501Sdougb  echo '     While these scripts will not hurt anything, they are not'
744114501Sdougb  echo '     functional on an up to date system, and can be removed.'
74567949Sdougb  echo ''
746114501Sdougb
74752400Sbillf  case "${AUTO_RUN}" in
74852400Sbillf  '')
749114501Sdougb    echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] '
750114501Sdougb    read MOVE_OLD_RC
75167859Sdougb
752114501Sdougb    case "${MOVE_OLD_RC}" in
753114501Sdougb    [nN]*) ;;
75452400Sbillf    *)
755114501Sdougb      mkdir -p /var/tmp/mergemaster/old_rc
756179315Sbz        for file in atm devfs diskless1 diskless2 network network6 pccard \
757114523Sdougb          serial syscons sysctl alpha amd64 i386 ia64 sparc64; do
758114501Sdougb          if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
759114501Sdougb            mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/
760114501Sdougb          fi
761114501Sdougb        done
762114501Sdougb      echo '  The files have been moved'
763114501Sdougb      press_to_continue
76452400Sbillf      ;;
76552400Sbillf    esac
76652400Sbillf    ;;
76752400Sbillf  *) ;;
76852400Sbillf  esac
769114501Sdougbesac
77052400Sbillf
77198084Sdougb# Use the umask/mode information to install the files
77252400Sbillf# Create directories as needed
77352400Sbillf#
774186678Sdougbinstall_error () {
775186678Sdougb  echo "*** FATAL ERROR: Unable to install ${1} to ${2}"
776186678Sdougb  echo ''
777186678Sdougb  exit 1
778186678Sdougb}
779186678Sdougb
78078490Sdougbdo_install_and_rm () {
781114501Sdougb  case "${PRESERVE_FILES}" in
782114501Sdougb  [Yy][Ee][Ss])
783114501Sdougb    if [ -f "${3}/${2##*/}" ]; then
784114565Sdougb      mkdir -p ${PRESERVE_FILES_DIR}/${2%/*}
785114565Sdougb      cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*}
786114501Sdougb    fi
787114501Sdougb    ;;
788114501Sdougb  esac
789114501Sdougb
790186678Sdougb  if [ ! -d "${3}/${2##*/}" ]; then
791186678Sdougb    if install -m ${1} ${2} ${3}; then
792186678Sdougb      unlink ${2}
793186678Sdougb    else
794186678Sdougb      install_error ${2} ${3}
795186678Sdougb    fi
796186678Sdougb  else
797186678Sdougb    install_error ${2} ${3}
798186678Sdougb  fi
79978490Sdougb}
80078490Sdougb
80198084Sdougb# 4095 = "obase=10;ibase=8;07777" | bc
80298084Sdougbfind_mode () {
80398084Sdougb  local OCTAL
80498084Sdougb  OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 &
805124053Sdougb    $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) ))
80698084Sdougb  printf "%04o\n" ${OCTAL}
80798084Sdougb}
80898084Sdougb
80952400Sbillfmm_install () {
81052400Sbillf  local INSTALL_DIR
81152400Sbillf  INSTALL_DIR=${1#.}
81252400Sbillf  INSTALL_DIR=${INSTALL_DIR%/*}
81367949Sdougb
81452400Sbillf  case "${INSTALL_DIR}" in
81552400Sbillf  '')
81652400Sbillf    INSTALL_DIR=/
81752400Sbillf    ;;
81852400Sbillf  esac
81952400Sbillf
82067949Sdougb  if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
82198084Sdougb    DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"`
82267949Sdougb    install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}"
82352400Sbillf  fi
82452400Sbillf
82598084Sdougb  FILE_MODE=`find_mode "${1}"`
82652400Sbillf
82752400Sbillf  if [ ! -x "${1}" ]; then
82852400Sbillf    case "${1#.}" in
82964625Sgshapiro    /etc/mail/aliases)
83052400Sbillf      NEED_NEWALIASES=yes
83152400Sbillf      ;;
83252400Sbillf    /etc/login.conf)
83352400Sbillf      NEED_CAP_MKDB=yes
83452400Sbillf      ;;
83552400Sbillf    /etc/master.passwd)
83678490Sdougb      do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
83752400Sbillf      NEED_PWD_MKDB=yes
83852400Sbillf      DONT_INSTALL=yes
83952400Sbillf      ;;
84052400Sbillf    /.cshrc | /.profile)
84177335Sdougb    case "${AUTO_INSTALL}" in
84277335Sdougb    '')
84352400Sbillf      case "${LINK_EXPLAINED}" in
84452400Sbillf      '')
84567859Sdougb        echo "   *** Historically BSD derived systems have had a"
84667859Sdougb        echo "       hard link from /.cshrc and /.profile to"
84767859Sdougb        echo "       their namesakes in /root.  Please indicate"
84867859Sdougb        echo "       your preference below for bringing your"
84967859Sdougb        echo "       installed files up to date."
85052400Sbillf        echo ''
85152400Sbillf        LINK_EXPLAINED=yes
85252400Sbillf        ;;
85352400Sbillf      esac
85452400Sbillf
85552400Sbillf      echo "   Use 'd' to delete the temporary ${COMPFILE}"
85667949Sdougb      echo "   Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link"
85752400Sbillf      echo ''
85852400Sbillf      echo "   Default is to leave the temporary file to deal with by hand"
85952400Sbillf      echo ''
86067859Sdougb      echo -n "  How should I handle ${COMPFILE}? [Leave it to install later] "
86167859Sdougb      read HANDLE_LINK
86277335Sdougb      ;;
86377335Sdougb    *)  # Part of AUTO_INSTALL
86477335Sdougb      HANDLE_LINK=l
86577335Sdougb      ;;
86677335Sdougb    esac
86767859Sdougb
86852400Sbillf      case "${HANDLE_LINK}" in
86952400Sbillf      [dD]*)
87052400Sbillf        rm "${COMPFILE}"
87152400Sbillf        echo ''
87252400Sbillf        echo "   *** Deleting ${COMPFILE}"
87352400Sbillf        ;;
87452400Sbillf      [lL]*)
87552400Sbillf        echo ''
87667949Sdougb        rm -f "${DESTDIR}${COMPFILE#.}"
87767949Sdougb        if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then
87867949Sdougb          echo "   *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
87952400Sbillf          rm "${COMPFILE}"
88052400Sbillf        else
88167949Sdougb          echo "   *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand"
88252400Sbillf        fi
88352400Sbillf        ;;
88452400Sbillf      *)
88552400Sbillf        echo "   *** ${COMPFILE} will remain for your consideration"
88652400Sbillf        ;;
88752400Sbillf      esac
88852400Sbillf      DONT_INSTALL=yes
88952400Sbillf      ;;
89052400Sbillf    esac
89152400Sbillf
89252400Sbillf    case "${DONT_INSTALL}" in
89352400Sbillf    '')
89478490Sdougb      do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
89552400Sbillf      ;;
89652400Sbillf    *)
89752400Sbillf      unset DONT_INSTALL
89852400Sbillf      ;;
89952400Sbillf    esac
90078490Sdougb  else	# File matched -x
90178490Sdougb    do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
90252400Sbillf  fi
90352400Sbillf  return $?
90452400Sbillf}
90552400Sbillf
906174841Sdougbif [ ! -d "${TEMPROOT}" ]; then
907174841Sdougb	echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})"
908174841Sdougb	echo '                 has disappeared!'
909174841Sdougb	echo ''
910174841Sdougb	exit 1
911174841Sdougbfi
912174841Sdougb
91367949Sdougbecho ''
91467949Sdougbecho "*** Beginning comparison"
91567949Sdougbecho ''
91652400Sbillf
917124136Sdougb# Pre-world does not populate /etc/rc.d.
918124053Sdougb# It is very possible that a previous run would have deleted files in
919124053Sdougb# ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives.
920124136Sdougbif [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then
921124053Sdougb  echo "   *** Checking ${DESTDIR}/etc/rc.d for stale files"
922124053Sdougb  echo ''
923124053Sdougb  cd "${DESTDIR}/etc/rc.d" &&
924124053Sdougb  for file in *; do
925124053Sdougb    if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then
926124053Sdougb      STALE_RC_FILES="${STALE_RC_FILES} ${file}"
927124053Sdougb    fi
928124053Sdougb  done
929124053Sdougb  case "${STALE_RC_FILES}" in
930126718Sdougb  ''|' *')
931124053Sdougb    echo '   *** No stale files found'
932124053Sdougb    ;;
933124053Sdougb  *)
934124053Sdougb    echo "   *** The following files exist in ${DESTDIR}/etc/rc.d but not in"
935124053Sdougb    echo "       ${TEMPROOT}/etc/rc.d/:"
936124053Sdougb    echo ''
937124053Sdougb    echo "${STALE_RC_FILES}"
938124053Sdougb    echo ''
939124053Sdougb    echo '       The presence of stale files in this directory can cause the'
940124053Sdougb    echo '       dreaded unpredictable results, and therefore it is highly'
941124053Sdougb    echo '       recommended that you delete them.'
942124053Sdougb    case "${AUTO_RUN}" in
943124053Sdougb    '')
944124053Sdougb      echo ''
945153604Sdougb      echo -n '   *** Delete them now? [n] '
946124053Sdougb      read DELETE_STALE_RC_FILES
947124053Sdougb      case "${DELETE_STALE_RC_FILES}" in
948153604Sdougb      [yY])
949124053Sdougb        echo '      *** Deleting ... '
950124053Sdougb        rm ${STALE_RC_FILES}
951124053Sdougb        echo '                       done.'
952124053Sdougb        ;;
953153604Sdougb      *)
954153604Sdougb        echo '      *** Files will not be deleted'
955153604Sdougb        ;;
956124053Sdougb      esac
957124053Sdougb      sleep 2
958124053Sdougb      ;;
959124053Sdougb    esac
960124053Sdougb    ;;
961124053Sdougb  esac
962124053Sdougb  echo ''
963124136Sdougbfi
964124053Sdougb
96567949Sdougbcd "${TEMPROOT}"
96667949Sdougb
96767949Sdougbif [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
96867949Sdougb  . "${MM_PRE_COMPARE_SCRIPT}"
96967949Sdougbfi
97067949Sdougb
971193853Sdougbfor COMPFILE in `find . -type f`; do
97267949Sdougb
97367949Sdougb  # First, check to see if the file exists in DESTDIR.  If not, the
97467949Sdougb  # diff_loop function knows how to handle it.
97567949Sdougb  #
97667949Sdougb  if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
97777325Sdougb    case "${AUTO_RUN}" in
97877325Sdougb      '')
97977325Sdougb        diff_loop
98077325Sdougb        ;;
98177325Sdougb      *)
98277325Sdougb        case "${AUTO_INSTALL}" in
98377325Sdougb        '')
98477325Sdougb          # If this is an auto run, make it official
98577325Sdougb          echo "   *** ${COMPFILE} will remain for your consideration"
98677325Sdougb          ;;
98777325Sdougb        *)
98877325Sdougb          diff_loop
98977325Sdougb          ;;
99077325Sdougb        esac
99177325Sdougb        ;;
99277325Sdougb    esac # Auto run test
99367949Sdougb    continue
99467949Sdougb  fi
99567949Sdougb
99652400Sbillf  case "${STRICT}" in
99752400Sbillf  '' | [Nn][Oo])
99852400Sbillf    # Compare CVS $Id's first so if the file hasn't been modified
99952400Sbillf    # local changes will be ignored.
100052400Sbillf    # If the files have the same $Id, delete the one in temproot so the
100152400Sbillf    # user will have less to wade through if files are left to merge by hand.
100252400Sbillf    #
100373651Sdougb    CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
100490564Sdougb    CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none
100552400Sbillf
100667949Sdougb    case "${CVSID2}" in
100773651Sdougb    "${CVSID1}")
100867949Sdougb      echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting"
100967949Sdougb      rm "${COMPFILE}"
101067949Sdougb      ;;
101167949Sdougb    esac
101252400Sbillf    ;;
101352400Sbillf  esac
101452400Sbillf
101552400Sbillf  # If the file is still here either because the $Ids are different, the
101652400Sbillf  # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
101752400Sbillf  #
101852400Sbillf  if [ -f "${COMPFILE}" ]; then
101952400Sbillf
102052400Sbillf    # Do an absolute diff first to see if the files are actually different.
102152400Sbillf    # If they're not different, delete the one in temproot.
102252400Sbillf    #
1023110377Sdougb    if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1024110377Sdougb      /dev/null 2>&1; then
102552400Sbillf      echo " *** Temp ${COMPFILE} and installed are the same, deleting"
102652400Sbillf      rm "${COMPFILE}"
102752400Sbillf    else
102877323Sdougb      # Ok, the files are different, so show the user where they differ.
102977323Sdougb      # Use user's choice of diff methods; and user's pager if they have one.
103077323Sdougb      # Use more if not.
103167859Sdougb      # Use unified diffs by default.  Context diffs give me a headache. :)
103252400Sbillf      #
1033189992Sdougb      # If the user chose the -F option, test for that before proceeding
1034189992Sdougb      #
1035189992Sdougb      if [ -n "$FREEBSD_ID" ]; then
1036189992Sdougb        if diff -q -I'[$]FreeBSD:.*$' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1037189992Sdougb            /dev/null 2>&1; then
1038189992Sdougb          if mm_install "${COMPFILE}"; then
1039189992Sdougb            echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}"
1040189992Sdougb          else
1041189992Sdougb            echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later"
1042189992Sdougb          fi
1043189992Sdougb          continue
1044189992Sdougb        fi
1045189992Sdougb      fi
104652400Sbillf      case "${AUTO_RUN}" in
104752400Sbillf      '')
104858910Salfred        # prompt user to install/delete/merge changes
104958910Salfred        diff_loop
105052400Sbillf        ;;
105152400Sbillf      *)
105252400Sbillf        # If this is an auto run, make it official
105352400Sbillf        echo "   *** ${COMPFILE} will remain for your consideration"
105452400Sbillf        ;;
105552400Sbillf      esac # Auto run test
105652400Sbillf    fi # Yes, the files are different
105752400Sbillf  fi # Yes, the file still remains to be checked
1058189763Sdougbdone # This is for the for way up there at the beginning of the comparison
105952400Sbillf
106052534Sbillfecho ''
106152400Sbillfecho "*** Comparison complete"
1062158149Sgordon
1063192230Sdougbif [ -s "${MTREENEW}" ]; then
1064158149Sgordon  echo "*** Saving mtree database for future upgrades"
1065200416Sdougb  test -e "${MTREEFILE}" && unlink ${MTREEFILE}
1066200416Sdougb  mv ${MTREENEW} ${MTREEFILE}
1067158149Sgordonfi
1068158149Sgordon
106952400Sbillfecho ''
107052400Sbillf
107152400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
107252400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then
107352400Sbillf  echo "*** Files that remain for you to merge by hand:"
107452400Sbillf  find "${TEMPROOT}" -type f -size +0
107577335Sdougb  echo ''
107652400Sbillffi
107752400Sbillf
107852400Sbillfcase "${AUTO_RUN}" in
107952400Sbillf'')
108067859Sdougb  echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
108167859Sdougb  read DEL_TEMPROOT
108267859Sdougb
108352400Sbillf  case "${DEL_TEMPROOT}" in
108452400Sbillf  [yY]*)
108599152Sdougb    if delete_temproot; then
108652400Sbillf      echo " *** ${TEMPROOT} has been deleted"
108752400Sbillf    else
108852400Sbillf      echo " *** Unable to delete ${TEMPROOT}"
108952400Sbillf    fi
109052400Sbillf    ;;
109152400Sbillf  *)
109252400Sbillf    echo " *** ${TEMPROOT} will remain"
109352400Sbillf    ;;
109452400Sbillf  esac
109552400Sbillf  ;;
109652400Sbillf*) ;;
109752400Sbillfesac
109852400Sbillf
109968153Sdougbcase "${AUTO_INSTALLED_FILES}" in
110068153Sdougb'') ;;
110168153Sdougb*)
110273651Sdougb  case "${AUTO_RUN}" in
110373651Sdougb  '')
110473651Sdougb    (
110573651Sdougb      echo ''
110677323Sdougb      echo '*** You chose the automatic install option for files that did not'
110777323Sdougb      echo '    exist on your system.  The following were installed for you:'
110873651Sdougb      echo "${AUTO_INSTALLED_FILES}"
110973651Sdougb    ) | ${PAGER}
111073651Sdougb    ;;
111173651Sdougb  *)
111268153Sdougb    echo ''
111377323Sdougb    echo '*** You chose the automatic install option for files that did not'
111477323Sdougb    echo '    exist on your system.  The following were installed for you:'
111568153Sdougb    echo "${AUTO_INSTALLED_FILES}"
111673651Sdougb    ;;
111773651Sdougb  esac
111868153Sdougb  ;;
111968153Sdougbesac
112068153Sdougb
1121158149Sgordoncase "${AUTO_UPGRADED_FILES}" in
1122158149Sgordon'') ;;
1123158149Sgordon*)
1124158149Sgordon  case "${AUTO_RUN}" in
1125158149Sgordon  '')
1126158149Sgordon    (
1127158149Sgordon      echo ''
1128158149Sgordon      echo '*** You chose the automatic upgrade option for files that you did'
1129158149Sgordon      echo '    not alter on your system.  The following were upgraded for you:'
1130158149Sgordon      echo "${AUTO_UPGRADED_FILES}"
1131158149Sgordon    ) | ${PAGER}
1132158149Sgordon    ;;
1133158149Sgordon  *)
1134158149Sgordon    echo ''
1135158149Sgordon    echo '*** You chose the automatic upgrade option for files that you did'
1136158149Sgordon    echo '    not alter on your system.  The following were upgraded for you:'
1137158149Sgordon    echo "${AUTO_UPGRADED_FILES}"
1138158149Sgordon    ;;
1139158149Sgordon  esac
1140158149Sgordon  ;;
1141158149Sgordonesac
1142158149Sgordon
114373651Sdougbrun_it_now () {
114473651Sdougb  case "${AUTO_RUN}" in
114573651Sdougb  '')
114673651Sdougb    unset YES_OR_NO
114773651Sdougb    echo ''
114877335Sdougb    echo -n '    Would you like to run it now? y or n [n] '
114973651Sdougb    read YES_OR_NO
115073651Sdougb
115173651Sdougb    case "${YES_OR_NO}" in
115273651Sdougb    y)
115377335Sdougb      echo "    Running ${1}"
115477335Sdougb      echo ''
115573651Sdougb      eval "${1}"
115673651Sdougb      ;;
115777335Sdougb    ''|n)
115877335Sdougb      echo ''
115977335Sdougb      echo "       *** Cancelled"
116077335Sdougb      echo ''
116177335Sdougb      echo "    Make sure to run ${1} yourself"
116277335Sdougb      ;;
116373651Sdougb    *)
116477335Sdougb      echo ''
116577335Sdougb      echo "       *** Sorry, I do not understand your answer (${YES_OR_NO})"
116677335Sdougb      echo ''
116777335Sdougb      echo "    Make sure to run ${1} yourself"
116873651Sdougb    esac
116973651Sdougb    ;;
117073651Sdougb  *) ;;
117173651Sdougb  esac
117273651Sdougb}
117373651Sdougb
117452400Sbillfcase "${NEED_NEWALIASES}" in
117552400Sbillf'') ;;
117652400Sbillf*)
117752400Sbillf  echo ''
117877335Sdougb  if [ -n "${DESTDIR}" ]; then
117977335Sdougb    echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
118077335Sdougb    echo "    the newaliases command is limited to the directories configured"
118177335Sdougb    echo "    in sendmail.cf.  Make sure to create your aliases database by"
118277335Sdougb    echo "    hand when your sendmail configuration is done."
118377335Sdougb  else
118477335Sdougb    echo "*** You installed a new aliases file, so make sure that you run"
118577335Sdougb    echo "    '/usr/bin/newaliases' to rebuild your aliases database"
118677335Sdougb    run_it_now '/usr/bin/newaliases'
118777335Sdougb  fi
118852400Sbillf  ;;
118952400Sbillfesac
119052400Sbillf
119152400Sbillfcase "${NEED_CAP_MKDB}" in
119252400Sbillf'') ;;
119352400Sbillf*)
119452400Sbillf  echo ''
119552400Sbillf  echo "*** You installed a login.conf file, so make sure that you run"
119677335Sdougb  echo "    '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
119777335Sdougb  echo "     to rebuild your login.conf database"
119877335Sdougb  run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
119952400Sbillf  ;;
120052400Sbillfesac
120152400Sbillf
120252400Sbillfcase "${NEED_PWD_MKDB}" in
120352400Sbillf'') ;;
120452400Sbillf*)
120552400Sbillf  echo ''
120652400Sbillf  echo "*** You installed a new master.passwd file, so make sure that you run"
120777335Sdougb  if [ -n "${DESTDIR}" ]; then
120877335Sdougb    echo "    '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
120977335Sdougb    echo "    to rebuild your password files"
121077335Sdougb    run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
121177335Sdougb  else
121277335Sdougb    echo "    '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
121377335Sdougb    echo "     to rebuild your password files"
121477335Sdougb    run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
121577335Sdougb  fi
121652400Sbillf  ;;
121752400Sbillfesac
121852400Sbillf
121952400Sbillfecho ''
122052400Sbillf
122167949Sdougbif [ -r "${MM_EXIT_SCRIPT}" ]; then
122267949Sdougb  . "${MM_EXIT_SCRIPT}"
122367949Sdougbfi
122467949Sdougb
122591193Sdougbcase "${COMP_CONFS}" in
122691193Sdougb'') ;;
122791193Sdougb*)
122891193Sdougb  . ${DESTDIR}/etc/defaults/rc.conf
122991193Sdougb
123091193Sdougb  (echo ''
123191193Sdougb  echo "*** Comparing conf files: ${rc_conf_files}"
123291193Sdougb
123391193Sdougb  for CONF_FILE in ${rc_conf_files}; do
123491193Sdougb    if [ -r "${DESTDIR}${CONF_FILE}" ]; then
123591193Sdougb      echo ''
123691193Sdougb      echo "*** From ${DESTDIR}${CONF_FILE}"
123791193Sdougb      echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
123891193Sdougb
123991193Sdougb      for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
124091193Sdougb        cut -d '=' -f 1`; do
124191193Sdougb        echo ''
124291223Sdougb        grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
124391223Sdougb        grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
124491193Sdougb          echo ' * No default variable with this name'
124591193Sdougb      done
124691193Sdougb    fi
124791193Sdougb  done) | ${PAGER}
124891193Sdougb  echo ''
124991193Sdougb  ;;
125091193Sdougbesac
125191193Sdougb
125291193Sdougbcase "${PRE_WORLD}" in
125391193Sdougb'') ;;
125491193Sdougb*)
1255186678Sdougb  MAKE_CONF="${SOURCEDIR}/share/examples/etc/make.conf"
125691193Sdougb
125791193Sdougb  (echo ''
125891193Sdougb  echo '*** Comparing make variables'
125991193Sdougb  echo ''
126091193Sdougb  echo "*** From ${DESTDIR}/etc/make.conf"
126191193Sdougb  echo "*** From ${MAKE_CONF}"
126291193Sdougb
1263101348Sdougb  for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do
126491193Sdougb    echo ''
126591223Sdougb    grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf
126691223Sdougb    grep -w ^#${MAKE_VAR} ${MAKE_CONF} ||
126791193Sdougb      echo ' * No example variable with this name'
126891193Sdougb  done) | ${PAGER}
126991193Sdougb  ;;
127091193Sdougbesac
127191193Sdougb
127252400Sbillfexit 0
127367850Sdougb
1274