mergemaster.sh revision 77478
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
873651Sdougb# Copyright 1998-2001 Douglas Barton
973651Sdougb# DougB@FreeBSD.org
1052400Sbillf
1152495Sbillf# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 77478 2001-05-30 08:50:10Z 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}"
1867949Sdougb  echo 'Usage: mergemaster [-scrvahi] [-m /path]'
1967949Sdougb  echo '         [-t /path] [-d] [-u N] [-w N] [-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'
2852400Sbillf  echo "  -m /path/directory  Specify location of source to do the make in"
2952400Sbillf  echo "  -t /path/directory  Specify temp root directory"
3052400Sbillf  echo "  -d  Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
3152400Sbillf  echo "  -u N  Specify a numeric umask"
3252400Sbillf  echo "  -w N  Specify a screen width in columns to sdiff"
3367949Sdougb  echo '  -D /path/directory  Specify the destination directory to install files to'
3452400Sbillf  echo ''
3552400Sbillf}
3652400Sbillf
3752400Sbillfdisplay_help () {
3852400Sbillf  echo "* To specify a directory other than /var/tmp/temproot for the"
3952400Sbillf  echo "  temporary root environment, use -t /path/to/temp/root"
4052400Sbillf  echo "* The -w option takes a number as an argument for the column width"
4167859Sdougb  echo "  of the screen.  The default is 80."
4267949Sdougb  echo '* The -a option causes mergemaster to run without prompting.'
4352400Sbillf}
4452400Sbillf
4558910Salfred# Loop allowing the user to use sdiff to merge files and display the merged
4658910Salfred# file.
4758910Salfredmerge_loop () {
4867850Sdougb  case "${VERBOSE}" in
4967850Sdougb  '') ;;
5067850Sdougb  *)
5167850Sdougb      echo "   *** Type h at the sdiff prompt (%) to get usage help"
5267850Sdougb      ;;
5367850Sdougb  esac
5467850Sdougb  echo ''
5567850Sdougb  MERGE_AGAIN=yes
5667850Sdougb  while [ "${MERGE_AGAIN}" = "yes" ]; do
5767850Sdougb    # Prime file.merged so we don't blat the owner/group id's
5867850Sdougb    cp -p "${COMPFILE}" "${COMPFILE}.merged"
5967850Sdougb    sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
6067949Sdougb      --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
6167850Sdougb    INSTALL_MERGED=V
6267850Sdougb    while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
6367850Sdougb      echo ''
6467850Sdougb      echo "  Use 'i' to install merged file"
6567850Sdougb      echo "  Use 'r' to re-do the merge"
6667850Sdougb      echo "  Use 'v' to view the merged file"
6767850Sdougb      echo "  Default is to leave the temporary file to deal with by hand"
6867850Sdougb      echo ''
6967859Sdougb      echo -n "    *** How should I deal with the merged file? [Leave it for later] "
7067859Sdougb      read INSTALL_MERGED
7158910Salfred
7267850Sdougb      case "${INSTALL_MERGED}" in
7367850Sdougb      [iI])
7467850Sdougb        mv "${COMPFILE}.merged" "${COMPFILE}"
7567850Sdougb        echo ''
7667850Sdougb        if mm_install "${COMPFILE}"; then
7767850Sdougb          echo "     *** Merged version of ${COMPFILE} installed successfully"
7867859Sdougb        else
7967850Sdougb          echo "     *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
8067859Sdougb        fi
8167850Sdougb        unset MERGE_AGAIN
8267850Sdougb        ;;
8367850Sdougb      [rR])
8467850Sdougb        rm "${COMPFILE}.merged"
8567859Sdougb        ;;
8667850Sdougb      [vV])
8767850Sdougb        ${PAGER} "${COMPFILE}.merged"
8867850Sdougb        ;;
8967850Sdougb      '')
9067850Sdougb        echo "   *** ${COMPFILE} will remain for your consideration"
9167850Sdougb        unset MERGE_AGAIN
9267850Sdougb        ;;
9367850Sdougb      *)
9467850Sdougb        echo "invalid choice: ${INSTALL_MERGED}"
9567850Sdougb        INSTALL_MERGED=V
9667850Sdougb        ;;
9767850Sdougb      esac
9867850Sdougb    done
9967850Sdougb  done
10058910Salfred}
10158910Salfred
10258910Salfred# Loop showing user differences between files, allow merge, skip or install
10358910Salfred# options
10458910Salfreddiff_loop () {
10558910Salfred
10667850Sdougb  HANDLE_COMPFILE=v
10758910Salfred
10877323Sdougb  while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \
10977323Sdougb    "${HANDLE_COMPFILE}" = "NOT V" ]; do
11067949Sdougb    if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
11167850Sdougb      if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
11267850Sdougb        (
11367949Sdougb          echo ''
11467850Sdougb          echo "  *** Displaying differences between ${COMPFILE} and installed version:"
11567850Sdougb          echo ''
11667949Sdougb          diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
11767850Sdougb        ) | ${PAGER}
11867850Sdougb        echo ''
11967850Sdougb      fi
12067850Sdougb    else
12167949Sdougb      echo ''
12267850Sdougb      echo "  *** There is no installed version of ${COMPFILE}"
12367949Sdougb      case "${AUTO_INSTALL}" in
12467949Sdougb      [Yy][Ee][Ss])
12567949Sdougb        echo ''
12667949Sdougb        if mm_install "${COMPFILE}"; then
12767949Sdougb          echo "   *** ${COMPFILE} installed successfully"
12868507Sdougb          echo ''
12967949Sdougb          # Make the list print one file per line
13067949Sdougb          AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES}      ${DESTDIR}${COMPFILE#.}
13167949Sdougb"
13267949Sdougb        else
13367949Sdougb          echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
13467949Sdougb        fi
13567949Sdougb        return
13667949Sdougb        ;;
13767949Sdougb      *)
13867949Sdougb        NO_INSTALLED=yes
13967949Sdougb        ;;
14067949Sdougb      esac
14167850Sdougb    fi
14267859Sdougb
14367850Sdougb    echo "  Use 'd' to delete the temporary ${COMPFILE}"
14467850Sdougb    echo "  Use 'i' to install the temporary ${COMPFILE}"
14567850Sdougb    case "${NO_INSTALLED}" in
14667850Sdougb    '')
14777326Sdougb      echo "  Use 'm' to merge the temporary and installed versions"
14877326Sdougb      echo "  Use 'v' to view the diff results again"
14967850Sdougb      ;;
15067850Sdougb    esac
15167850Sdougb    echo ''
15267850Sdougb    echo "  Default is to leave the temporary file to deal with by hand"
15367850Sdougb    echo ''
15467859Sdougb    echo -n "How should I deal with this? [Leave it for later] "
15567859Sdougb    read HANDLE_COMPFILE
15667859Sdougb
15767850Sdougb    case "${HANDLE_COMPFILE}" in
15867850Sdougb    [dD])
15967850Sdougb      rm "${COMPFILE}"
16067850Sdougb      echo ''
16167850Sdougb      echo "   *** Deleting ${COMPFILE}"
16267850Sdougb      ;;
16367850Sdougb    [iI])
16467850Sdougb      echo ''
16567850Sdougb      if mm_install "${COMPFILE}"; then
16667850Sdougb        echo "   *** ${COMPFILE} installed successfully"
16767850Sdougb      else
16867850Sdougb        echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
16967850Sdougb      fi
17067850Sdougb      ;;
17167850Sdougb    [mM])
17267850Sdougb      case "${NO_INSTALLED}" in
17367850Sdougb      '')
17467850Sdougb        # interact with user to merge files
17567850Sdougb        merge_loop
17667850Sdougb        ;;
17767850Sdougb      *)
17867850Sdougb        echo ''
17967850Sdougb        echo "   *** There is no installed version of ${COMPFILE}"
18067850Sdougb        echo ''
18167850Sdougb        HANDLE_COMPFILE="NOT V"
18267850Sdougb        ;;
18367850Sdougb      esac # End of "No installed version of file but user selected merge" test
18467850Sdougb      ;;
18567850Sdougb    [vV])
18667850Sdougb      continue
18767850Sdougb      ;;
18867850Sdougb    '')
18967850Sdougb      echo ''
19067850Sdougb      echo "   *** ${COMPFILE} will remain for your consideration"
19167850Sdougb      ;;
19267850Sdougb    *)
19367850Sdougb      # invalid choice, show menu again.
19467850Sdougb      echo "invalid choice: ${HANDLE_COMPFILE}"
19567850Sdougb      echo ''
19667850Sdougb      HANDLE_COMPFILE="NOT V"
19767850Sdougb      continue
19867850Sdougb      ;;
19967850Sdougb    esac  # End of "How to handle files that are different"
20067859Sdougb  done
20167850Sdougb  unset NO_INSTALLED
20267850Sdougb  echo ''
20367850Sdougb  case "${VERBOSE}" in
20467850Sdougb  '') ;;
20567850Sdougb  *)
20667850Sdougb    sleep 3
20767850Sdougb    ;;
20867850Sdougb  esac
20958910Salfred}
21058910Salfred
21152400Sbillf# Set the default path for the temporary root environment
21252400Sbillf#
21352400SbillfTEMPROOT='/var/tmp/temproot'
21452400Sbillf
21573651Sdougb# Read /etc/mergemaster.rc first so the one in $HOME can override
21673651Sdougb#
21773651Sdougbif [ -r /etc/mergemaster.rc ]; then
21873651Sdougb  . /etc/mergemaster.rc
21973651Sdougbfi
22073651Sdougb
22152400Sbillf# Read .mergemasterrc before command line so CLI can override
22252400Sbillf#
22367949Sdougbif [ -r "$HOME/.mergemasterrc" ]; then
22452400Sbillf  . "$HOME/.mergemasterrc"
22552400Sbillffi
22652400Sbillf
22752400Sbillf# Check the command line options
22852400Sbillf#
22967949Sdougbwhile getopts ":ascrvhim:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do
23052400Sbillf  case "${COMMAND_LINE_ARGUMENT}" in
23152400Sbillf  s)
23252400Sbillf    STRICT=yes
23352400Sbillf    ;;
23452400Sbillf  c)
23552400Sbillf    DIFF_FLAG='-c'
23652400Sbillf    ;;
23752400Sbillf  r)
23852400Sbillf    RERUN=yes
23952400Sbillf    ;;
24052400Sbillf  v)
24152400Sbillf    case "${AUTO_RUN}" in
24252400Sbillf    '') VERBOSE=yes ;;
24352400Sbillf    esac
24452400Sbillf    ;;
24552400Sbillf  a)
24652400Sbillf    AUTO_RUN=yes
24752400Sbillf    unset VERBOSE
24852400Sbillf    ;;
24952400Sbillf  h)
25052400Sbillf    display_usage
25152400Sbillf    display_help
25252400Sbillf    exit 0
25352400Sbillf    ;;
25467949Sdougb  i)
25567949Sdougb    AUTO_INSTALL=yes
25667949Sdougb    ;;
25752400Sbillf  m)
25852400Sbillf    SOURCEDIR=${OPTARG}
25952400Sbillf    ;;
26052400Sbillf  t)
26152400Sbillf    TEMPROOT=${OPTARG}
26252400Sbillf    ;;
26352400Sbillf  d)
26452400Sbillf    TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
26552400Sbillf    ;;
26652400Sbillf  u)
26752400Sbillf    NEW_UMASK=${OPTARG}
26852400Sbillf    ;;
26952400Sbillf  w)
27052400Sbillf    SCREEN_WIDTH=${OPTARG}
27152400Sbillf    ;;
27267949Sdougb  D)
27367949Sdougb    DESTDIR=${OPTARG}
27467949Sdougb    ;;
27552400Sbillf  *)
27652400Sbillf    display_usage
27752400Sbillf    exit 1
27852400Sbillf    ;;
27952400Sbillf  esac
28052400Sbillfdone
28152400Sbillf
28252400Sbillfecho ''
28352400Sbillf
28452400Sbillf# If the user has a pager defined, make sure we can run it
28552400Sbillf#
28652400Sbillfcase "${DONT_CHECK_PAGER}" in
28752400Sbillf'')
28864467Sbrian  while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do
28952400Sbillf    echo " *** Your PAGER environment variable specifies '${PAGER}', but"
29064467Sbrian    echo "     due to the limited PATH that I use for security reasons,"
29167859Sdougb    echo "     I cannot execute it.  So, what would you like to do?"
29252400Sbillf    echo ''
29352400Sbillf    echo "  Use 'e' to exit mergemaster and fix your PAGER variable"
29464467Sbrian    if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then
29564467Sbrian    echo "  Use 'l' to set PAGER to 'less' for this run"
29652400Sbillf    fi
29752400Sbillf    echo "  Use 'm' to use plain old 'more' as your PAGER for this run"
29852400Sbillf    echo ''
29952400Sbillf    echo "  Default is to use plain old 'more' "
30052400Sbillf    echo ''
30167859Sdougb    echo -n "What should I do? [Use 'more'] "
30267859Sdougb    read FIXPAGER
30367859Sdougb
30452400Sbillf    case "${FIXPAGER}" in
30558910Salfred    [eE])
30652400Sbillf       exit 0
30752400Sbillf       ;;
30858910Salfred    [lL])
30964467Sbrian       if [ -x /usr/bin/less ]; then
31064467Sbrian         PAGER=/usr/bin/less
31164467Sbrian       elif [ -x /usr/local/bin/less ]; then
31258910Salfred         PAGER=/usr/local/bin/less
31364467Sbrian       else
31464467Sbrian         echo ''
31564467Sbrian         echo " *** Fatal Error:"
31664467Sbrian         echo "     You asked to use 'less' as your pager, but I can't"
31764467Sbrian         echo "     find it in /usr/bin or /usr/local/bin"
31864467Sbrian         exit 1
31958910Salfred       fi
32052400Sbillf       ;;
32160420Sbsd    [mM]|'')
32252400Sbillf       PAGER=more
32352400Sbillf       ;;
32458910Salfred    *)
32558910Salfred       echo ''
32658910Salfred       echo "invalid choice: ${FIXPAGER}"
32752400Sbillf    esac
32852400Sbillf    echo ''
32958910Salfred  done
33052400Sbillf  ;;
33152400Sbillfesac
33252400Sbillf
33352400Sbillf# If user has a pager defined, or got assigned one above, use it.
33452400Sbillf# If not, use more.
33552400Sbillf#
33652400SbillfPAGER=${PAGER:-more}
33752400Sbillf
33852400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
33952400Sbillf  echo " *** You have ${PAGER} defined as your pager so we will use that"
34052400Sbillf  echo ''
34152400Sbillf  sleep 3
34252400Sbillffi
34352400Sbillf
34452400Sbillf# Assign the diff flag once so we will not have to keep testing it
34552400Sbillf#
34652400SbillfDIFF_FLAG=${DIFF_FLAG:--u}
34752400Sbillf
34852400Sbillf# Assign the source directory
34952400Sbillf#
35052400SbillfSOURCEDIR=${SOURCEDIR:-/usr/src/etc}
35152400Sbillf
35273651Sdougb# Define what CVS $Id tag to look for to aid portability.
35373651Sdougb#
35473651SdougbCVS_ID_TAG=FreeBSD
35573651Sdougb
35652400Sbillfcase "${RERUN}" in
35752400Sbillf'')
35852400Sbillf  # Set up the loop to test for the existence of the
35952400Sbillf  # temp root directory.
36052400Sbillf  #
36152400Sbillf  TEST_TEMP_ROOT=yes
36252400Sbillf  while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
36352400Sbillf    if [ -d "${TEMPROOT}" ]; then
36452400Sbillf      echo "*** The directory specified for the temporary root environment,"
36567859Sdougb      echo "    ${TEMPROOT}, exists.  This can be a security risk if untrusted"
36652400Sbillf      echo "    users have access to the system."
36752400Sbillf      echo ''
36852400Sbillf      case "${AUTO_RUN}" in
36952400Sbillf      '')
37052400Sbillf        echo "  Use 'd' to delete the old ${TEMPROOT} and continue"
37152400Sbillf        echo "  Use 't' to select a new temporary root directory"
37252400Sbillf        echo "  Use 'e' to exit mergemaster"
37352400Sbillf        echo ''
37452400Sbillf        echo "  Default is to use ${TEMPROOT} as is"
37552400Sbillf        echo ''
37667859Sdougb        echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
37767859Sdougb        read DELORNOT
37867859Sdougb
37967859Sdougb        case "${DELORNOT}" in
38067859Sdougb        [dD])
38167859Sdougb          echo ''
38267859Sdougb          echo "   *** Deleting the old ${TEMPROOT}"
38367859Sdougb          echo ''
38467859Sdougb          rm -rf "${TEMPROOT}"
38567859Sdougb          unset TEST_TEMP_ROOT
38652400Sbillf          ;;
38767859Sdougb        [tT])
38867859Sdougb          echo "   *** Enter new directory name for temporary root environment"
38967859Sdougb          read TEMPROOT
39067859Sdougb          ;;
39167859Sdougb        [eE])
39267859Sdougb          exit 0
39367859Sdougb          ;;
39467859Sdougb        '')
39567859Sdougb          echo ''
39667859Sdougb          echo "   *** Leaving ${TEMPROOT} intact"
39767859Sdougb          echo ''
39867859Sdougb          unset TEST_TEMP_ROOT
39967859Sdougb          ;;
40067859Sdougb        *)
40167859Sdougb          echo ''
40267859Sdougb          echo "invalid choice: ${DELORNOT}"
40367859Sdougb          echo ''
40467859Sdougb          ;;
40567859Sdougb        esac
40667859Sdougb        ;;
40752400Sbillf      *)
40877323Sdougb        # If this is an auto-run, try a hopefully safe alternative then
40977323Sdougb        # re-test anyway.
41052400Sbillf        TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
41152400Sbillf        ;;
41252400Sbillf      esac
41352400Sbillf    else
41452400Sbillf      unset TEST_TEMP_ROOT
41552400Sbillf    fi
41652400Sbillf  done
41752400Sbillf
41852400Sbillf  echo "*** Creating the temporary root environment in ${TEMPROOT}"
41952400Sbillf
42052400Sbillf  if mkdir -p "${TEMPROOT}"; then
42152400Sbillf    echo " *** ${TEMPROOT} ready for use"
42252400Sbillf  fi
42352400Sbillf
42452400Sbillf  if [ ! -d "${TEMPROOT}" ]; then
42552400Sbillf    echo ''
42652400Sbillf    echo "  *** FATAL ERROR: Cannot create ${TEMPROOT}"
42752400Sbillf    echo ''
42852400Sbillf    exit 1
42952400Sbillf  fi
43052400Sbillf
43152400Sbillf  echo " *** Creating and populating directory structure in ${TEMPROOT}"
43252400Sbillf  echo ''
43352400Sbillf
43452400Sbillf  case "${VERBOSE}" in
43552400Sbillf  '') ;;
43652400Sbillf  *)
43752400Sbillf    echo " *** Press [Enter] or [Return] key to continue"
43852400Sbillf    read ANY_KEY
43952400Sbillf    unset ANY_KEY
44052400Sbillf    ;;
44152400Sbillf  esac
44252400Sbillf
44352400Sbillf  { cd ${SOURCEDIR} &&
44468507Sdougb    case "${DESTDIR}" in
44568507Sdougb    '') ;;
44668507Sdougb    *)
44768507Sdougb      make DESTDIR=${DESTDIR} distrib-dirs
44868507Sdougb      ;;
44968507Sdougb    esac
45052400Sbillf    make DESTDIR=${TEMPROOT} distrib-dirs &&
45174992Sasmodai    make DESTDIR=${TEMPROOT} -DNO_MAKEDEV_RUN distribution;} ||
45252400Sbillf  { echo '';
45377323Sdougb    echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
45477323Sdougb    echo "      the temproot environment";
45552400Sbillf    echo '';
45652400Sbillf    exit 1;}
45752400Sbillf
45877323Sdougb  # Doing the inventory and removing files that we don't want to compare only
45977323Sdougb  # makes sense if we are not doing a rerun, since we have no way of knowing
46077323Sdougb  # what happened to the files during previous incarnations.
46167949Sdougb  case "${VERBOSE}" in
46267949Sdougb  '') ;;
46367949Sdougb  *)
46467949Sdougb    echo ''
46567949Sdougb    echo ' *** The following files exist only in the installed version of'
46667949Sdougb    echo "     ${DESTDIR}/etc.  In the vast majority of cases these files"
46767949Sdougb    echo '     are necessary parts of the system and should not be deleted.'
46867949Sdougb    echo '     However because these files are not updated by this process you'
46967949Sdougb    echo '     might want to verify their status before rebooting your system.'
47067949Sdougb    echo ''
47167949Sdougb    echo ' *** Press [Enter] or [Return] key to continue'
47267949Sdougb    read ANY_KEY
47367949Sdougb    unset ANY_KEY
47467949Sdougb    diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER}
47567949Sdougb    echo ''
47667949Sdougb    echo ' *** Press [Enter] or [Return] key to continue'
47767949Sdougb    read ANY_KEY
47867949Sdougb    unset ANY_KEY
47967949Sdougb    ;;
48067949Sdougb  esac
48167949Sdougb
48252534Sbillf  # Avoid comparing the motd if the user specifies it in .mergemasterrc
48352534Sbillf  case "${IGNORE_MOTD}" in
48452534Sbillf  '') ;;
48552534Sbillf  *) rm ${TEMPROOT}/etc/motd
48652534Sbillf     ;;
48752534Sbillf  esac
48852534Sbillf
48965115Sben  # Avoid trying to update MAKEDEV if /dev is on a devfs
49068507Sdougb  if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then
49165115Sben    rm ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local
49265115Sben  fi
49365115Sben
49452400Sbillf  ;; # End of the "RERUN" test
49552400Sbillfesac
49652400Sbillf
49777478Sdougb# We really don't want to have to deal with these files, since
49877478Sdougb# master.passwd is the real file that should be compared, then
49977478Sdougb# the user should run pwd_mkdb if necessary.
50077478Sdougb#
50177478Sdougb[ -f "${TEMPROOT}/etc/spwd.db" ] && rm "${TEMPROOT}/etc/spwd.db"
50277478Sdougb[ -f "${TEMPROOT}/etc/passwd" ]  && rm "${TEMPROOT}/etc/passwd"
50377478Sdougb[ -f "${TEMPROOT}/etc/pwd.db" ]  && rm "${TEMPROOT}/etc/pwd.db"
50477478Sdougb
50552400Sbillf# Get ready to start comparing files
50652400Sbillf
50752400Sbillf# Check umask if not specified on the command line,
50852400Sbillf# and we are not doing an autorun
50952400Sbillf#
51052400Sbillfif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
51152400Sbillf  USER_UMASK=`umask`
51252400Sbillf  case "${USER_UMASK}" in
51377335Sdougb  0022|022) ;;
51452400Sbillf  *)
51552400Sbillf    echo ''
51667859Sdougb    echo " *** Your umask is currently set to ${USER_UMASK}.  By default, this script"
51752400Sbillf    echo "     installs all files with the same user, group and modes that"
51852400Sbillf    echo "     they are created with by ${SOURCEDIR}/Makefile, compared to"
51967859Sdougb    echo "     a umask of 022.  This umask allows world read permission when"
52052400Sbillf    echo "     the file's default permissions have it."
52167859Sdougb    echo "     No world permissions can sometimes cause problems.  A umask of"
52252400Sbillf    echo "     022 will restore the default behavior, but is not mandatory."
52367859Sdougb    echo "     /etc/master.passwd is a special case.  Its file permissions"
52452400Sbillf    echo "     will be 600 (rw-------) if installed."
52552400Sbillf    echo ''
52667859Sdougb    echo -n "What umask should I use? [${USER_UMASK}] "
52767859Sdougb    read NEW_UMASK
52867859Sdougb
52952400Sbillf    NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
53052400Sbillf    ;;
53152400Sbillf  esac
53252400Sbillf  echo ''
53352400Sbillffi
53452400Sbillf
53552400SbillfCONFIRMED_UMASK=${NEW_UMASK:-0022}
53652400Sbillf
53767949Sdougb# Warn users who still have ${DESTDIR}/etc/sysconfig
53852400Sbillf#
53967949Sdougbif [ -e "${DESTDIR}/etc/sysconfig" ]; then
54052400Sbillf  echo ''
54167949Sdougb  echo " *** There is a sysconfig file on this system in ${DESTDIR}/etc/."
54267949Sdougb  echo ''
54367949Sdougb  echo '     Starting with FreeBSD version 2.2.2 those settings moved from'
54467949Sdougb  echo '     /etc/sysconfig to /etc/rc.conf.  If you are upgrading an older'
54567949Sdougb  echo '     system make sure that you transfer your settings by hand from'
54667949Sdougb  echo '     sysconfig to rc.conf and install the rc.conf file.  If you'
54767949Sdougb  echo '     have already made this transition, you should consider'
54867949Sdougb  echo '     renaming or deleting the sysconfig file.'
54967949Sdougb  echo ''
55052400Sbillf  case "${AUTO_RUN}" in
55152400Sbillf  '')
55267859Sdougb    echo -n "Continue with the merge process? [yes] "
55367859Sdougb    read CONT_OR_NOT
55467859Sdougb
55552400Sbillf    case "${CONT_OR_NOT}" in
55652400Sbillf    [nN]*)
55752400Sbillf      exit 0
55852400Sbillf      ;;
55952400Sbillf    *)
56052400Sbillf      echo "   *** Continuing"
56152400Sbillf      echo ''
56252400Sbillf      ;;
56352400Sbillf    esac
56452400Sbillf    ;;
56552400Sbillf  *) ;;
56652400Sbillf  esac
56752400Sbillffi
56852400Sbillf
56952400Sbillf# Use the umask/mode information to install the files
57052400Sbillf# Create directories as needed
57152400Sbillf#
57252400Sbillfmm_install () {
57352400Sbillf  local INSTALL_DIR
57452400Sbillf  INSTALL_DIR=${1#.}
57552400Sbillf  INSTALL_DIR=${INSTALL_DIR%/*}
57667949Sdougb
57752400Sbillf  case "${INSTALL_DIR}" in
57852400Sbillf  '')
57952400Sbillf    INSTALL_DIR=/
58052400Sbillf    ;;
58152400Sbillf  esac
58252400Sbillf
58367949Sdougb  if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
58477323Sdougb    DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \
58577323Sdougb      oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"`
58667949Sdougb    install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}"
58752400Sbillf  fi
58852400Sbillf
58977323Sdougb  FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \
59077323Sdougb      oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"`
59152400Sbillf
59252400Sbillf  if [ ! -x "${1}" ]; then
59352400Sbillf    case "${1#.}" in
59464625Sgshapiro    /etc/mail/aliases)
59552400Sbillf      NEED_NEWALIASES=yes
59652400Sbillf      ;;
59752400Sbillf    /etc/login.conf)
59852400Sbillf      NEED_CAP_MKDB=yes
59952400Sbillf      ;;
60052400Sbillf    /etc/master.passwd)
60177478Sdougb      install -m 600 "${1}" "${DESTDIR}${INSTALL_DIR}" &&
60277478Sdougb        [ -f "${1}" ] && rm "${1}"
60352400Sbillf      NEED_PWD_MKDB=yes
60452400Sbillf      DONT_INSTALL=yes
60552400Sbillf      ;;
60652400Sbillf    /.cshrc | /.profile)
60777335Sdougb    case "${AUTO_INSTALL}" in
60877335Sdougb    '')
60952400Sbillf      case "${LINK_EXPLAINED}" in
61052400Sbillf      '')
61167859Sdougb        echo "   *** Historically BSD derived systems have had a"
61267859Sdougb        echo "       hard link from /.cshrc and /.profile to"
61367859Sdougb        echo "       their namesakes in /root.  Please indicate"
61467859Sdougb        echo "       your preference below for bringing your"
61567859Sdougb        echo "       installed files up to date."
61652400Sbillf        echo ''
61752400Sbillf        LINK_EXPLAINED=yes
61852400Sbillf        ;;
61952400Sbillf      esac
62052400Sbillf
62152400Sbillf      echo "   Use 'd' to delete the temporary ${COMPFILE}"
62267949Sdougb      echo "   Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link"
62352400Sbillf      echo ''
62452400Sbillf      echo "   Default is to leave the temporary file to deal with by hand"
62552400Sbillf      echo ''
62667859Sdougb      echo -n "  How should I handle ${COMPFILE}? [Leave it to install later] "
62767859Sdougb      read HANDLE_LINK
62877335Sdougb      ;;
62977335Sdougb    *)  # Part of AUTO_INSTALL
63077335Sdougb      HANDLE_LINK=l
63177335Sdougb      ;;
63277335Sdougb    esac
63367859Sdougb
63452400Sbillf      case "${HANDLE_LINK}" in
63552400Sbillf      [dD]*)
63652400Sbillf        rm "${COMPFILE}"
63752400Sbillf        echo ''
63852400Sbillf        echo "   *** Deleting ${COMPFILE}"
63952400Sbillf        ;;
64052400Sbillf      [lL]*)
64152400Sbillf        echo ''
64267949Sdougb        rm -f "${DESTDIR}${COMPFILE#.}"
64367949Sdougb        if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then
64467949Sdougb          echo "   *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
64552400Sbillf          rm "${COMPFILE}"
64652400Sbillf        else
64767949Sdougb          echo "   *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand"
64852400Sbillf        fi
64952400Sbillf        ;;
65052400Sbillf      *)
65152400Sbillf        echo "   *** ${COMPFILE} will remain for your consideration"
65252400Sbillf        ;;
65352400Sbillf      esac
65452400Sbillf      DONT_INSTALL=yes
65552400Sbillf      ;;
65652400Sbillf    esac
65752400Sbillf
65852400Sbillf    case "${DONT_INSTALL}" in
65952400Sbillf    '')
66077478Sdougb      install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" &&
66177478Sdougb        [ -f "${1}" ] && rm "${1}"
66252400Sbillf      ;;
66352400Sbillf    *)
66452400Sbillf      unset DONT_INSTALL
66552400Sbillf      ;;
66652400Sbillf    esac
66752400Sbillf  else
66867949Sdougb    case "${1#.}" in
66967949Sdougb    /dev/MAKEDEV)
67067949Sdougb      NEED_MAKEDEV=yes
67167949Sdougb      ;;
67267949Sdougb    esac
67377478Sdougb    install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" &&
67477478Sdougb      [ -f "${1}" ] && rm "${1}"
67552400Sbillf  fi
67652400Sbillf  return $?
67752400Sbillf}
67852400Sbillf
67967949Sdougbecho ''
68067949Sdougbecho "*** Beginning comparison"
68167949Sdougbecho ''
68252400Sbillf
68367949Sdougbcd "${TEMPROOT}"
68467949Sdougb
68567949Sdougbif [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
68667949Sdougb  . "${MM_PRE_COMPARE_SCRIPT}"
68767949Sdougbfi
68867949Sdougb
68952400Sbillf# Using -size +0 avoids uselessly checking the empty log files created
69052400Sbillf# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does
69167949Sdougb# check the scripts in ./dev, as we'd like (assuming no devfs of course).
69252400Sbillf#
69352400Sbillffor COMPFILE in `find . -type f -size +0`; do
69467949Sdougb
69567949Sdougb  # First, check to see if the file exists in DESTDIR.  If not, the
69667949Sdougb  # diff_loop function knows how to handle it.
69767949Sdougb  #
69867949Sdougb  if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
69977325Sdougb    case "${AUTO_RUN}" in
70077325Sdougb      '')
70177325Sdougb        diff_loop
70277325Sdougb        ;;
70377325Sdougb      *)
70477325Sdougb        case "${AUTO_INSTALL}" in
70577325Sdougb        '')
70677325Sdougb          # If this is an auto run, make it official
70777325Sdougb          echo "   *** ${COMPFILE} will remain for your consideration"
70877325Sdougb          ;;
70977325Sdougb        *)
71077325Sdougb          diff_loop
71177325Sdougb          ;;
71277325Sdougb        esac
71377325Sdougb        ;;
71477325Sdougb    esac # Auto run test
71567949Sdougb    continue
71667949Sdougb  fi
71767949Sdougb
71852400Sbillf  case "${STRICT}" in
71952400Sbillf  '' | [Nn][Oo])
72052400Sbillf    # Compare CVS $Id's first so if the file hasn't been modified
72152400Sbillf    # local changes will be ignored.
72252400Sbillf    # If the files have the same $Id, delete the one in temproot so the
72352400Sbillf    # user will have less to wade through if files are left to merge by hand.
72452400Sbillf    #
72573651Sdougb    CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
72673651Sdougb    CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null`
72752400Sbillf
72867949Sdougb    case "${CVSID2}" in
72973651Sdougb    "${CVSID1}")
73067949Sdougb      echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting"
73167949Sdougb      rm "${COMPFILE}"
73267949Sdougb      ;;
73367949Sdougb    esac
73452400Sbillf    ;;
73552400Sbillf  esac
73652400Sbillf
73752400Sbillf  # If the file is still here either because the $Ids are different, the
73852400Sbillf  # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
73952400Sbillf  #
74052400Sbillf  if [ -f "${COMPFILE}" ]; then
74152400Sbillf
74252400Sbillf    # Do an absolute diff first to see if the files are actually different.
74352400Sbillf    # If they're not different, delete the one in temproot.
74452400Sbillf    #
74567949Sdougb    if diff -q "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then
74652400Sbillf      echo " *** Temp ${COMPFILE} and installed are the same, deleting"
74752400Sbillf      rm "${COMPFILE}"
74852400Sbillf    else
74977323Sdougb      # Ok, the files are different, so show the user where they differ.
75077323Sdougb      # Use user's choice of diff methods; and user's pager if they have one.
75177323Sdougb      # Use more if not.
75267859Sdougb      # Use unified diffs by default.  Context diffs give me a headache. :)
75352400Sbillf      #
75452400Sbillf      case "${AUTO_RUN}" in
75552400Sbillf      '')
75658910Salfred        # prompt user to install/delete/merge changes
75758910Salfred        diff_loop
75852400Sbillf        ;;
75952400Sbillf      *)
76052400Sbillf        # If this is an auto run, make it official
76152400Sbillf        echo "   *** ${COMPFILE} will remain for your consideration"
76252400Sbillf        ;;
76352400Sbillf      esac # Auto run test
76452400Sbillf    fi # Yes, the files are different
76552400Sbillf  fi # Yes, the file still remains to be checked
76652400Sbillfdone # This is for the do way up there at the beginning of the comparison
76752400Sbillf
76852534Sbillfecho ''
76952400Sbillfecho "*** Comparison complete"
77052400Sbillfecho ''
77152400Sbillf
77252400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
77352400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then
77452400Sbillf  echo "*** Files that remain for you to merge by hand:"
77552400Sbillf  find "${TEMPROOT}" -type f -size +0
77677335Sdougb  echo ''
77752400Sbillffi
77852400Sbillf
77952400Sbillfcase "${AUTO_RUN}" in
78052400Sbillf'')
78167859Sdougb  echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
78267859Sdougb  read DEL_TEMPROOT
78367859Sdougb
78452400Sbillf  case "${DEL_TEMPROOT}" in
78552400Sbillf  [yY]*)
78652400Sbillf    if rm -rf "${TEMPROOT}"; then
78752400Sbillf      echo " *** ${TEMPROOT} has been deleted"
78852400Sbillf    else
78952400Sbillf      echo " *** Unable to delete ${TEMPROOT}"
79052400Sbillf    fi
79152400Sbillf    ;;
79252400Sbillf  *)
79352400Sbillf    echo " *** ${TEMPROOT} will remain"
79452400Sbillf    ;;
79552400Sbillf  esac
79652400Sbillf  ;;
79752400Sbillf*) ;;
79852400Sbillfesac
79952400Sbillf
80068153Sdougbcase "${AUTO_INSTALLED_FILES}" in
80168153Sdougb'') ;;
80268153Sdougb*)
80373651Sdougb  case "${AUTO_RUN}" in
80473651Sdougb  '')
80573651Sdougb    (
80673651Sdougb      echo ''
80777323Sdougb      echo '*** You chose the automatic install option for files that did not'
80877323Sdougb      echo '    exist on your system.  The following were installed for you:'
80973651Sdougb      echo "${AUTO_INSTALLED_FILES}"
81073651Sdougb    ) | ${PAGER}
81173651Sdougb    ;;
81273651Sdougb  *)
81368153Sdougb    echo ''
81477323Sdougb    echo '*** You chose the automatic install option for files that did not'
81577323Sdougb    echo '    exist on your system.  The following were installed for you:'
81668153Sdougb    echo "${AUTO_INSTALLED_FILES}"
81773651Sdougb    ;;
81873651Sdougb  esac
81968153Sdougb  ;;
82068153Sdougbesac
82168153Sdougb
82273651Sdougbrun_it_now () {
82373651Sdougb  case "${AUTO_RUN}" in
82473651Sdougb  '')
82573651Sdougb    unset YES_OR_NO
82673651Sdougb    echo ''
82777335Sdougb    echo -n '    Would you like to run it now? y or n [n] '
82873651Sdougb    read YES_OR_NO
82973651Sdougb
83073651Sdougb    case "${YES_OR_NO}" in
83173651Sdougb    y)
83277335Sdougb      echo "    Running ${1}"
83377335Sdougb      echo ''
83473651Sdougb      eval "${1}"
83573651Sdougb      ;;
83677335Sdougb    ''|n)
83777335Sdougb      echo ''
83877335Sdougb      echo "       *** Cancelled"
83977335Sdougb      echo ''
84077335Sdougb      echo "    Make sure to run ${1} yourself"
84177335Sdougb      ;;
84273651Sdougb    *)
84377335Sdougb      echo ''
84477335Sdougb      echo "       *** Sorry, I do not understand your answer (${YES_OR_NO})"
84577335Sdougb      echo ''
84677335Sdougb      echo "    Make sure to run ${1} yourself"
84773651Sdougb    esac
84873651Sdougb    ;;
84973651Sdougb  *) ;;
85073651Sdougb  esac
85173651Sdougb}
85273651Sdougb
85352400Sbillfcase "${NEED_MAKEDEV}" in
85452400Sbillf'') ;;
85552400Sbillf*)
85652400Sbillf  echo ''
85777335Sdougb  echo "*** You installed a new ${DESTDIR}/dev/MAKEDEV script, so make sure that you run"
85877335Sdougb  echo "    'cd ${DESTDIR}/dev && /bin/sh MAKEDEV all' to rebuild your devices"
85977335Sdougb  run_it_now "cd ${DESTDIR}/dev && /bin/sh MAKEDEV all"
86052400Sbillf  ;;
86152400Sbillfesac
86252400Sbillf
86352400Sbillfcase "${NEED_NEWALIASES}" in
86452400Sbillf'') ;;
86552400Sbillf*)
86652400Sbillf  echo ''
86777335Sdougb  if [ -n "${DESTDIR}" ]; then
86877335Sdougb    echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
86977335Sdougb    echo "    the newaliases command is limited to the directories configured"
87077335Sdougb    echo "    in sendmail.cf.  Make sure to create your aliases database by"
87177335Sdougb    echo "    hand when your sendmail configuration is done."
87277335Sdougb  else
87377335Sdougb    echo "*** You installed a new aliases file, so make sure that you run"
87477335Sdougb    echo "    '/usr/bin/newaliases' to rebuild your aliases database"
87577335Sdougb    run_it_now '/usr/bin/newaliases'
87677335Sdougb  fi
87752400Sbillf  ;;
87852400Sbillfesac
87952400Sbillf
88052400Sbillfcase "${NEED_CAP_MKDB}" in
88152400Sbillf'') ;;
88252400Sbillf*)
88352400Sbillf  echo ''
88452400Sbillf  echo "*** You installed a login.conf file, so make sure that you run"
88577335Sdougb  echo "    '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
88677335Sdougb  echo "     to rebuild your login.conf database"
88777335Sdougb  run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
88852400Sbillf  ;;
88952400Sbillfesac
89052400Sbillf
89152400Sbillfcase "${NEED_PWD_MKDB}" in
89252400Sbillf'') ;;
89352400Sbillf*)
89452400Sbillf  echo ''
89552400Sbillf  echo "*** You installed a new master.passwd file, so make sure that you run"
89677335Sdougb  if [ -n "${DESTDIR}" ]; then
89777335Sdougb    echo "    '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
89877335Sdougb    echo "    to rebuild your password files"
89977335Sdougb    run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
90077335Sdougb  else
90177335Sdougb    echo "    '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
90277335Sdougb    echo "     to rebuild your password files"
90377335Sdougb    run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
90477335Sdougb  fi
90552400Sbillf  ;;
90652400Sbillfesac
90752400Sbillf
90852400Sbillfecho ''
90952400Sbillf
91067949Sdougbif [ -r "${MM_EXIT_SCRIPT}" ]; then
91167949Sdougb  . "${MM_EXIT_SCRIPT}"
91267949Sdougbfi
91367949Sdougb
91452400Sbillfexit 0
91567850Sdougb
916