mergemaster.sh revision 58910
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
852400Sbillf# Copyright 1998, 1999 Douglas Barton
952400Sbillf# Doug@gorean.org
1052400Sbillf
1152495Sbillf# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 58910 2000-04-02 02:47:15Z alfred $
1252400Sbillf
1352400SbillfPATH=/bin:/usr/bin:/usr/sbin
1452400Sbillf
1552400Sbillfdisplay_usage () {
1652533Sbillf  VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
1752400Sbillf  echo "mergemaster version ${VERSION_NUMBER}"
1852400Sbillf  echo "Usage: mergemaster [-scrvah] [-m /path] [-t /path] [-d] [-u N] [-w N]"
1952400Sbillf  echo "Options:"
2052400Sbillf  echo "  -s  Strict comparison (diff every pair of files)"
2152400Sbillf  echo "  -c  Use context diff instead of unified diff"
2252400Sbillf  echo "  -r  Re-run on a previously cleaned directory (skip temproot creation)"
2352400Sbillf  echo "  -v  Be more verbose about the process, include additional checks"
2452400Sbillf  echo "  -a  Leave all files that differ to merge by hand"
2552400Sbillf  echo "  -h  Display more complete help"
2652400Sbillf  echo "  -m /path/directory  Specify location of source to do the make in"
2752400Sbillf  echo "  -t /path/directory  Specify temp root directory"
2852400Sbillf  echo "  -d  Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
2952400Sbillf  echo "  -u N  Specify a numeric umask"
3052400Sbillf  echo "  -w N  Specify a screen width in columns to sdiff"
3152400Sbillf  echo ''
3252400Sbillf}
3352400Sbillf
3452400Sbillfdisplay_help () {
3552400Sbillf  echo "* To create a temporary root environment, compare CVS revision \$Ids"
3652400Sbillf  echo "  for files that have them, and compare diffs for files that do not,"
3752400Sbillf  echo "  or have different ones, just type, mergemaster"
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"
4152400Sbillf  echo "  of the screen. The default is 80."
4252400Sbillf  echo "* The -a option causes mergemaster to run without prompting"
4352400Sbillf}
4452400Sbillf
4558910Salfred
4658910Salfred# Loop allowing the user to use sdiff to merge files and display the merged
4758910Salfred# file.
4858910Salfredmerge_loop () {
4958910Salfred	case "${VERBOSE}" in
5058910Salfred   	'') ;;
5158910Salfred	*)
5258910Salfred        echo "   *** Type h at the sdiff prompt (%) to get usage help"
5358910Salfred		;;
5458910Salfred	esac
5558910Salfred	echo ''
5658910Salfred	MERGE_AGAIN=yes
5758910Salfred	while [ "${MERGE_AGAIN}" = "yes" ]; do
5858910Salfred		# Prime file.merged so we don't blat the owner/group id's
5958910Salfred		cp -p "${COMPFILE}" "${COMPFILE}.merged"
6058910Salfred		sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
6158910Salfred			--width=${SCREEN_WIDTH:-80} "${COMPFILE#.}" "${COMPFILE}"
6258910Salfred		INSTALL_MERGED=V
6358910Salfred		while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
6458910Salfred			echo ''
6558910Salfred			echo "  Use 'i' to install merged file"
6658910Salfred			echo "  Use 'r' to re-do the merge"
6758910Salfred			echo "  Use 'v' to view the merged file"
6858910Salfred			echo "  Default is to leave the temporary file to deal with by hand"
6958910Salfred			echo ''
7058910Salfred			read -p "    *** How should I deal with the merged file? [Leave it for later] " INSTALL_MERGED
7158910Salfred
7258910Salfred			case "${INSTALL_MERGED}" in
7358910Salfred			[iI])
7458910Salfred				mv "${COMPFILE}.merged" "${COMPFILE}"
7558910Salfred				echo ''
7658910Salfred				if mm_install "${COMPFILE}"; then
7758910Salfred					echo "     *** Merged version of ${COMPFILE} installed successfully"
7858910Salfred				else 
7958910Salfred					echo "     *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
8058910Salfred				fi 
8158910Salfred				unset MERGE_AGAIN
8258910Salfred				;;
8358910Salfred			[rR])
8458910Salfred				rm "${COMPFILE}.merged"
8558910Salfred				;; 
8658910Salfred			[vV])
8758910Salfred				${PAGER} "${COMPFILE}.merged"
8858910Salfred				;;
8958910Salfred			'')
9058910Salfred				echo "   *** ${COMPFILE} will remain for your consideration"
9158910Salfred				unset MERGE_AGAIN
9258910Salfred				;;
9358910Salfred			*)
9458910Salfred				echo "invalid choice: ${INSTALL_MERGED}"
9558910Salfred				INSTALL_MERGED=V
9658910Salfred				;;
9758910Salfred			esac
9858910Salfred		done
9958910Salfred	done
10058910Salfred}
10158910Salfred
10258910Salfred# Loop showing user differences between files, allow merge, skip or install
10358910Salfred# options
10458910Salfreddiff_loop () {
10558910Salfred
10658910Salfred	HANDLE_COMPFILE=v
10758910Salfred
10858910Salfred	while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o "${HANDLE_COMPFILE}" = "NOT V" ]; do
10958910Salfred		if [ -f "${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
11058910Salfred			if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
11158910Salfred				(
11258910Salfred					echo "  *** Displaying differences between ${COMPFILE} and installed version:"
11358910Salfred					echo ''
11458910Salfred				diff "${DIFF_FLAG}" "${COMPFILE#.}" "${COMPFILE}"
11558910Salfred				) | ${PAGER}
11658910Salfred				echo ''
11758910Salfred			fi
11858910Salfred		else
11958910Salfred			echo "  *** There is no installed version of ${COMPFILE}"
12058910Salfred			NO_INSTALLED=yes
12158910Salfred		fi
12258910Salfred	
12358910Salfred		echo "  Use 'd' to delete the temporary ${COMPFILE}"
12458910Salfred		echo "  Use 'i' to install the temporary ${COMPFILE}"
12558910Salfred		case "${NO_INSTALLED}" in
12658910Salfred		'')
12758910Salfred			echo "  Use 'm' to merge the old and new versions"
12858910Salfred			echo "  Use 'v' to view to differences between the old and new versions again"
12958910Salfred			;;
13058910Salfred		esac
13158910Salfred		echo ''
13258910Salfred		echo "  Default is to leave the temporary file to deal with by hand"
13358910Salfred		echo ''
13458910Salfred		read -p "How should I deal with this? [Leave it for later] " HANDLE_COMPFILE
13558910Salfred		case "${HANDLE_COMPFILE}" in
13658910Salfred		[dD])
13758910Salfred			rm "${COMPFILE}"
13858910Salfred			echo ''
13958910Salfred			echo "   *** Deleting ${COMPFILE}"
14058910Salfred			;;
14158910Salfred		[iI])
14258910Salfred			echo ''
14358910Salfred			if mm_install "${COMPFILE}"; then
14458910Salfred				echo "   *** ${COMPFILE} installed successfully"
14558910Salfred			else
14658910Salfred				echo "   *** Problem installing ${COMPFILE}, it will remain to merge by hand"
14758910Salfred			fi
14858910Salfred			;;
14958910Salfred		[mM])
15058910Salfred			case "${NO_INSTALLED}" in
15158910Salfred			'')
15258910Salfred				# interact with user to merge files
15358910Salfred				merge_loop
15458910Salfred				;;
15558910Salfred			*)
15658910Salfred				echo ''
15758910Salfred				echo "   *** There is no installed version of ${COMPFILE}"
15858910Salfred				echo ''
15958910Salfred				HANDLE_COMPFILE="NOT V"
16058910Salfred				;;
16158910Salfred			esac # End of "No installed version of file but user selected merge" test
16258910Salfred			;;
16358910Salfred		[vV])
16458910Salfred			continue
16558910Salfred			;;
16658910Salfred		'')
16758910Salfred			echo ''
16858910Salfred			echo "   *** ${COMPFILE} will remain for your consideration"
16958910Salfred			;;
17058910Salfred		*)
17158910Salfred			# invalid choice, show menu again.
17258910Salfred			echo "invalid choice: ${HANDLE_COMPFILE}"
17358910Salfred			echo ''
17458910Salfred			HANDLE_COMPFILE="NOT V"
17558910Salfred			continue
17658910Salfred			;;
17758910Salfred		esac  # End of "How to handle files that are different"
17858910Salfred	done	
17958910Salfred	echo ''
18058910Salfred	unset NO_INSTALLED
18158910Salfred	echo ''
18258910Salfred	case "${VERBOSE}" in
18358910Salfred	'') ;;
18458910Salfred	*)
18558910Salfred		sleep 3
18658910Salfred		;;
18758910Salfred	esac
18858910Salfred}
18958910Salfred
19052400Sbillf# Set the default path for the temporary root environment
19152400Sbillf#
19252400SbillfTEMPROOT='/var/tmp/temproot'
19352400Sbillf
19452400Sbillf# Read .mergemasterrc before command line so CLI can override
19552400Sbillf#
19652400Sbillfif [ -f "$HOME/.mergemasterrc" ]; then
19752400Sbillf  . "$HOME/.mergemasterrc"
19852400Sbillffi
19952400Sbillf
20052400Sbillf# Check the command line options
20152400Sbillf#
20252400Sbillfwhile getopts ":ascrvhm:t:du:w:" COMMAND_LINE_ARGUMENT ; do
20352400Sbillf  case "${COMMAND_LINE_ARGUMENT}" in
20452400Sbillf  s)
20552400Sbillf    STRICT=yes
20652400Sbillf    ;;
20752400Sbillf  c)
20852400Sbillf    DIFF_FLAG='-c'
20952400Sbillf    ;;
21052400Sbillf  r)
21152400Sbillf    RERUN=yes
21252400Sbillf    ;;
21352400Sbillf  v)
21452400Sbillf    case "${AUTO_RUN}" in
21552400Sbillf    '') VERBOSE=yes ;;
21652400Sbillf    esac
21752400Sbillf    ;;
21852400Sbillf  a)
21952400Sbillf    AUTO_RUN=yes
22052400Sbillf    unset VERBOSE
22152400Sbillf    ;;
22252400Sbillf  h)
22352400Sbillf    display_usage
22452400Sbillf    display_help
22552400Sbillf    exit 0
22652400Sbillf    ;;
22752400Sbillf  m)
22852400Sbillf    SOURCEDIR=${OPTARG}
22952400Sbillf    ;;
23052400Sbillf  t)
23152400Sbillf    TEMPROOT=${OPTARG}
23252400Sbillf    ;;
23352400Sbillf  d)
23452400Sbillf    TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
23552400Sbillf    ;;
23652400Sbillf  u)
23752400Sbillf    NEW_UMASK=${OPTARG}
23852400Sbillf    ;;
23952400Sbillf  w)
24052400Sbillf    SCREEN_WIDTH=${OPTARG}
24152400Sbillf    ;;
24252400Sbillf  *)
24352400Sbillf    display_usage
24452400Sbillf    exit 1
24552400Sbillf    ;;
24652400Sbillf  esac
24752400Sbillfdone
24852400Sbillf
24952400Sbillfecho ''
25052400Sbillf
25152400Sbillf# If the user has a pager defined, make sure we can run it
25252400Sbillf#
25352400Sbillfcase "${DONT_CHECK_PAGER}" in
25452400Sbillf'')
25558910Salfred  while [ "${PAGER}" != "more" -a -n "${PAGER}" -a ! -x "${PAGER%% *}" ]; do
25652400Sbillf    echo " *** Your PAGER environment variable specifies '${PAGER}', but"
25752400Sbillf    echo "     I cannot execute it. In general it is good practice to"
25852400Sbillf    echo "     specify the full path for environment variables like"
25952400Sbillf    echo "     PAGER and EDITOR. Meanwhile, what would you like to do?"
26052400Sbillf    echo ''
26152400Sbillf    echo "  Use 'e' to exit mergemaster and fix your PAGER variable"
26252400Sbillf    if [ -x /usr/local/bin/less ]; then
26352400Sbillf    echo "  Use 'l' to set PAGER to /usr/local/bin/less for this run"
26452400Sbillf    fi
26552400Sbillf    echo "  Use 'm' to use plain old 'more' as your PAGER for this run"
26652400Sbillf    echo ''
26752400Sbillf    echo "  Default is to use plain old 'more' "
26852400Sbillf    echo ''
26952400Sbillf    read -p "What should I do? [Use 'more'] " FIXPAGER
27052400Sbillf    case "${FIXPAGER}" in
27158910Salfred    [eE])
27252400Sbillf       exit 0
27352400Sbillf       ;;
27458910Salfred    [lL])
27558910Salfred       if [ -x /usr/local/bin/less ]; then
27658910Salfred         PAGER=/usr/local/bin/less
27758910Salfred       fi
27852400Sbillf       ;;
27958910Salfred    '')
28052400Sbillf       PAGER=more
28152400Sbillf       ;;
28258910Salfred    *)
28358910Salfred       echo ''
28458910Salfred       echo "invalid choice: ${FIXPAGER}"
28552400Sbillf    esac
28652400Sbillf    echo ''
28758910Salfred  done
28852400Sbillf  ;;
28952400Sbillfesac
29052400Sbillf
29152400Sbillf# If user has a pager defined, or got assigned one above, use it.
29252400Sbillf# If not, use more.
29352400Sbillf#
29452400SbillfPAGER=${PAGER:-more}
29552400Sbillf
29652400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then
29752400Sbillf  echo " *** You have ${PAGER} defined as your pager so we will use that"
29852400Sbillf  echo ''
29952400Sbillf  sleep 3
30052400Sbillffi
30152400Sbillf
30252400Sbillf# Assign the diff flag once so we will not have to keep testing it
30352400Sbillf#
30452400SbillfDIFF_FLAG=${DIFF_FLAG:--u}
30552400Sbillf
30652400Sbillf# Assign the source directory
30752400Sbillf#
30852400SbillfSOURCEDIR=${SOURCEDIR:-/usr/src/etc}
30952400Sbillf
31052400Sbillfcase "${RERUN}" in
31152400Sbillf'')
31252400Sbillf  # Set up the loop to test for the existence of the
31352400Sbillf  # temp root directory.
31452400Sbillf  #
31552400Sbillf  TEST_TEMP_ROOT=yes
31652400Sbillf  while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
31752400Sbillf    if [ -d "${TEMPROOT}" ]; then
31852400Sbillf      echo "*** The directory specified for the temporary root environment,"
31952400Sbillf      echo "    ${TEMPROOT}, exists. This can be a security risk if untrusted"
32052400Sbillf      echo "    users have access to the system."
32152400Sbillf      echo ''
32252400Sbillf      case "${AUTO_RUN}" in
32352400Sbillf      '')
32452400Sbillf        echo "  Use 'd' to delete the old ${TEMPROOT} and continue"
32552400Sbillf        echo "  Use 't' to select a new temporary root directory"
32652400Sbillf        echo "  Use 'e' to exit mergemaster"
32752400Sbillf        echo ''
32852400Sbillf        echo "  Default is to use ${TEMPROOT} as is"
32952400Sbillf        echo ''
33052400Sbillf        read -p "How should I deal with this? [Use the existing ${TEMPROOT}] " DELORNOT
33152400Sbillf          case "${DELORNOT}" in
33258910Salfred          [dD])
33352400Sbillf            echo ''
33452400Sbillf            echo "   *** Deleting the old ${TEMPROOT}"
33552400Sbillf            echo ''
33652400Sbillf            rm -rf "${TEMPROOT}"
33752400Sbillf            unset TEST_TEMP_ROOT
33852400Sbillf            ;;
33958910Salfred          [tT])
34052400Sbillf            echo "   *** Enter new directory name for temporary root environment"
34152400Sbillf            read TEMPROOT
34252400Sbillf            ;;
34358910Salfred          [eE])
34452400Sbillf            exit 0
34552400Sbillf            ;;
34658910Salfred          '')
34752400Sbillf            echo ''
34852400Sbillf            echo "   *** Leaving ${TEMPROOT} intact"
34952400Sbillf            echo ''
35052400Sbillf            unset TEST_TEMP_ROOT
35152400Sbillf            ;;
35258910Salfred          *)
35358910Salfred            echo ''
35458910Salfred            echo "invalid choice: ${DELORNOT}"
35558910Salfred            echo ''
35658910Salfred            ;;
35752400Sbillf          esac
35852400Sbillf          ;;
35952400Sbillf      *)
36052400Sbillf        # If this is an auto-run, try a hopefully safe alternative then re-test anyway
36152400Sbillf        TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
36252400Sbillf        ;;
36352400Sbillf      esac
36452400Sbillf    else
36552400Sbillf      unset TEST_TEMP_ROOT
36652400Sbillf    fi
36752400Sbillf  done
36852400Sbillf
36952400Sbillf  echo "*** Creating the temporary root environment in ${TEMPROOT}"
37052400Sbillf
37152400Sbillf  if mkdir -p "${TEMPROOT}"; then
37252400Sbillf    echo " *** ${TEMPROOT} ready for use"
37352400Sbillf  fi
37452400Sbillf
37552400Sbillf  if [ ! -d "${TEMPROOT}" ]; then
37652400Sbillf    echo ''
37752400Sbillf    echo "  *** FATAL ERROR: Cannot create ${TEMPROOT}"
37852400Sbillf    echo ''
37952400Sbillf    exit 1
38052400Sbillf  fi
38152400Sbillf
38252400Sbillf  echo " *** Creating and populating directory structure in ${TEMPROOT}"
38352400Sbillf  echo ''
38452400Sbillf
38552400Sbillf  case "${VERBOSE}" in
38652400Sbillf  '') ;;
38752400Sbillf  *)
38852400Sbillf    echo " *** Press [Enter] or [Return] key to continue"
38952400Sbillf    read ANY_KEY
39052400Sbillf    unset ANY_KEY
39152400Sbillf    ;;
39252400Sbillf  esac
39352400Sbillf
39452400Sbillf  { cd ${SOURCEDIR} &&
39552400Sbillf    make DESTDIR=${TEMPROOT} distrib-dirs &&
39657173Sbillf    make DESTDIR=${TEMPROOT} -DNO_MAKEDEV distribution;} ||
39752400Sbillf  { echo '';
39852400Sbillf    echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to the";
39952400Sbillf    echo "      temproot environment";
40052400Sbillf    echo '';
40152400Sbillf    exit 1;}
40252400Sbillf
40352400Sbillf  # We really don't want to have to deal with these files, since
40452400Sbillf  # master.passwd is the real file that should be compared, then
40552400Sbillf  # the user should run pwd_mkdb if necessary.
40652400Sbillf  # Only do this if we are not rerun'ing, since if we are the
40752400Sbillf  # files will not be there.
40852400Sbillf  #
40952400Sbillf  rm ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db
41052400Sbillf
41152534Sbillf  # Avoid comparing the motd if the user specifies it in .mergemasterrc
41252534Sbillf  case "${IGNORE_MOTD}" in
41352534Sbillf  '') ;;
41452534Sbillf  *) rm ${TEMPROOT}/etc/motd
41552534Sbillf     ;;
41652534Sbillf  esac
41752534Sbillf
41852400Sbillf  ;; # End of the "RERUN" test
41952400Sbillfesac
42052400Sbillf
42152400Sbillf# Get ready to start comparing files
42252400Sbillf
42352400Sbillfcase "${VERBOSE}" in
42452400Sbillf'') ;;
42552400Sbillf*)
42652400Sbillf  echo ''
42752400Sbillf  echo " *** The following files exist only in the installed version"
42852400Sbillf  echo "     of /etc. In the far majority of cases these files are"
42952400Sbillf  echo "     necessary parts of the system and should not be deleted,"
43052400Sbillf  echo "     however because these files are not updated by this process"
43152400Sbillf  echo "     you might want to verify their status before rebooting your system."
43252400Sbillf  echo ''
43352400Sbillf  echo " *** Press [Enter] or [Return] key to continue"
43452400Sbillf  read ANY_KEY
43552400Sbillf  unset ANY_KEY
43652400Sbillf  diff -qr /etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER}
43752400Sbillf  echo ''
43852400Sbillf  echo " *** Press [Enter] or [Return] key to continue"
43952400Sbillf  read ANY_KEY
44052400Sbillf  unset ANY_KEY
44152400Sbillf  ;;
44252400Sbillfesac
44352400Sbillf
44452400Sbillf# Check umask if not specified on the command line,
44552400Sbillf# and we are not doing an autorun
44652400Sbillf#
44752400Sbillfif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
44852400Sbillf  USER_UMASK=`umask`
44952400Sbillf  case "${USER_UMASK}" in
45052400Sbillf  0022) ;;
45152400Sbillf  *)
45252400Sbillf    echo ''
45352400Sbillf    echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script"
45452400Sbillf    echo "     installs all files with the same user, group and modes that"
45552400Sbillf    echo "     they are created with by ${SOURCEDIR}/Makefile, compared to"
45652400Sbillf    echo "     a umask of 022. This umask allows world read permission when"
45752400Sbillf    echo "     the file's default permissions have it."
45852400Sbillf    echo "     No world permissions can sometimes cause problems. A umask of"
45952400Sbillf    echo "     022 will restore the default behavior, but is not mandatory."
46052400Sbillf    echo "     /etc/master.passwd is a special case. Its file permissions"
46152400Sbillf    echo "     will be 600 (rw-------) if installed."
46252400Sbillf    echo ''
46352400Sbillf    read -p "What umask should I use? [${USER_UMASK}] " NEW_UMASK
46452400Sbillf    NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
46552400Sbillf    ;;
46652400Sbillf  esac
46752400Sbillf  echo ''
46852400Sbillffi
46952400Sbillf
47052400SbillfCONFIRMED_UMASK=${NEW_UMASK:-0022}
47152400Sbillf
47252400Sbillf# Warn users who have an /etc/sysconfig file
47352400Sbillf#
47452400Sbillfif [ -f /etc/sysconfig ]; then
47552400Sbillf  echo " *** There is an /etc/sysconfig file on this system. Starting with"
47652400Sbillf  echo "     FreeBSD version 2.2.2 those settings have moved from /etc/sysconfig"
47752400Sbillf  echo "     to /etc/rc.conf. If you are upgrading an older system make sure"
47852400Sbillf  echo "     that you transfer your settings by hand from sysconfig to rc.conf and"
47952400Sbillf  echo "     install the rc.conf file. If you have already made this transition,"
48052400Sbillf  echo "     you should consider renaming or deleting the /etc/sysconfig file."
48152400Sbillf  echo ''
48252400Sbillf  case "${AUTO_RUN}" in
48352400Sbillf  '')
48452400Sbillf    read -p "Continue with the merge process? [yes] " CONT_OR_NOT
48552400Sbillf    case "${CONT_OR_NOT}" in
48652400Sbillf    [nN]*)
48752400Sbillf      exit 0
48852400Sbillf      ;;
48952400Sbillf    *)
49052400Sbillf      echo "   *** Continuing"
49152400Sbillf      echo ''
49252400Sbillf      ;;
49352400Sbillf    esac
49452400Sbillf    ;;
49552400Sbillf  *) ;;
49652400Sbillf  esac
49752400Sbillffi
49852400Sbillf
49952400Sbillfecho ''
50052400Sbillfecho "*** Beginning comparison"
50152400Sbillfecho ''
50252400Sbillf
50352400Sbillfcd "${TEMPROOT}"
50452400Sbillf
50552400Sbillf# Use the umask/mode information to install the files
50652400Sbillf# Create directories as needed
50752400Sbillf#
50852400Sbillfmm_install () {
50952400Sbillf  local INSTALL_DIR
51052400Sbillf  INSTALL_DIR=${1#.}
51152400Sbillf  INSTALL_DIR=${INSTALL_DIR%/*}
51252400Sbillf  case "${INSTALL_DIR}" in
51352400Sbillf  '')
51452400Sbillf    INSTALL_DIR=/
51552400Sbillf    ;;
51652400Sbillf  esac
51752400Sbillf
51852400Sbillf  if [ -n "${INSTALL_DIR}" -a ! -d "${INSTALL_DIR}" ]; then
51952400Sbillf    DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"`
52052400Sbillf    install -d -o root -g wheel -m "${DIR_MODE}" "${INSTALL_DIR}"
52152400Sbillf  fi
52252400Sbillf
52352400Sbillf  FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"`
52452400Sbillf
52552400Sbillf  if [ ! -x "${1}" ]; then
52652400Sbillf    case "${1#.}" in
52752400Sbillf    /dev/MAKEDEV)
52852400Sbillf      NEED_MAKEDEV=yes
52952400Sbillf      ;;
53052400Sbillf    /etc/aliases)
53152400Sbillf      NEED_NEWALIASES=yes
53252400Sbillf      ;;
53352400Sbillf    /etc/login.conf)
53452400Sbillf      NEED_CAP_MKDB=yes
53552400Sbillf      ;;
53652400Sbillf    /etc/master.passwd)
53752400Sbillf      install -m 600 "${1}" "${INSTALL_DIR}"
53852400Sbillf      NEED_PWD_MKDB=yes
53952400Sbillf      DONT_INSTALL=yes
54052400Sbillf      ;;
54152400Sbillf    /.cshrc | /.profile)
54252400Sbillf      case "${LINK_EXPLAINED}" in
54352400Sbillf      '')
54452400Sbillf        echo "   *** Historically FreeBSD has had a hard link from"
54552400Sbillf        echo "       /.cshrc and /.profile to their namesakes in"
54652400Sbillf        echo "       /root. Please indicate your preference below"
54752400Sbillf        echo "       for bringing your installed files up to date."
54852400Sbillf        echo ''
54952400Sbillf        LINK_EXPLAINED=yes
55052400Sbillf        ;;
55152400Sbillf      esac
55252400Sbillf
55352400Sbillf      echo "   Use 'd' to delete the temporary ${COMPFILE}"
55452400Sbillf      echo "   Use 'l' to delete the existing ${COMPFILE#.} and create the link"
55552400Sbillf      echo ''
55652400Sbillf      echo "   Default is to leave the temporary file to deal with by hand"
55752400Sbillf      echo ''
55852400Sbillf      read -p "  How should I handle ${COMPFILE}? [Leave it to install later] " HANDLE_LINK
55952400Sbillf      case "${HANDLE_LINK}" in
56052400Sbillf      [dD]*)
56152400Sbillf        rm "${COMPFILE}"
56252400Sbillf        echo ''
56352400Sbillf        echo "   *** Deleting ${COMPFILE}"
56452400Sbillf        ;;
56552400Sbillf      [lL]*)
56652400Sbillf        echo ''
56752400Sbillf        if [ -e "${COMPFILE#.}" ]; then
56852400Sbillf          rm "${COMPFILE#.}"
56952400Sbillf        fi
57052400Sbillf        if ln "/root/${COMPFILE##*/}" "${COMPFILE#.}"; then
57152400Sbillf          echo "   *** Link from ${COMPFILE#.} to /root/${COMPFILE##*/} installed successfully"
57252400Sbillf          rm "${COMPFILE}"
57352400Sbillf        else
57452400Sbillf          echo "   *** Error linking ${COMPFILE#.} to /root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand"
57552400Sbillf        fi
57652400Sbillf        ;;
57752400Sbillf      *)
57852400Sbillf        echo "   *** ${COMPFILE} will remain for your consideration"
57952400Sbillf        ;;
58052400Sbillf      esac
58152400Sbillf      DONT_INSTALL=yes
58252400Sbillf      ;;
58352400Sbillf    esac
58452400Sbillf
58552400Sbillf    case "${DONT_INSTALL}" in
58652400Sbillf    '')
58752400Sbillf      install -m "${FILE_MODE}" "${1}" "${INSTALL_DIR}"
58852400Sbillf      ;;
58952400Sbillf    *)
59052400Sbillf      unset DONT_INSTALL
59152400Sbillf      ;;
59252400Sbillf    esac
59352400Sbillf
59452400Sbillf  else
59552400Sbillf    install -m "${FILE_MODE}" "${1}" "${INSTALL_DIR}"
59652400Sbillf  fi
59752400Sbillf  return $?
59852400Sbillf}
59952400Sbillf
60052400Sbillfcompare_ids () {
60152400Sbillf  case "${1}" in
60252400Sbillf "${2}")
60352400Sbillf    echo " *** Temp ${COMPFILE} and installed have the same ${IDTAG}, deleting"
60452400Sbillf    rm "${COMPFILE}"
60552400Sbillf    ;;
60652400Sbillf  esac
60752400Sbillf}
60852400Sbillf
60952400Sbillf# Using -size +0 avoids uselessly checking the empty log files created
61052400Sbillf# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does
61152400Sbillf# check the scripts in ./dev, as we'd like.
61252400Sbillf#
61352400Sbillffor COMPFILE in `find . -type f -size +0`; do
61452400Sbillf  case "${STRICT}" in
61552400Sbillf  '' | [Nn][Oo])
61652400Sbillf    # Compare CVS $Id's first so if the file hasn't been modified
61752400Sbillf    # local changes will be ignored.
61852400Sbillf    # If the files have the same $Id, delete the one in temproot so the
61952400Sbillf    # user will have less to wade through if files are left to merge by hand.
62052400Sbillf    # Take the $Id -> $FreeBSD tag change into account
62152400Sbillf    #
62252400Sbillf    FREEBSDID1=`grep "[$]FreeBSD:" ${COMPFILE#.} 2>/dev/null`
62352400Sbillf    FREEBSDID2=`grep "[$]FreeBSD:" ${COMPFILE} 2>/dev/null`
62452400Sbillf
62552400Sbillf    if [ -n "${FREEBSDID1}" -a -n "${FREEBSDID2}" ]; then
62652400Sbillf      IDTAG='$FreeBSD'
62752400Sbillf      compare_ids "${FREEBSDID1}" "${FREEBSDID2}"
62852400Sbillf    else
62952400Sbillf      CVSID1=`grep "[$]Id:" ${COMPFILE#.} 2>/dev/null`
63052400Sbillf      CVSID2=`grep "[$]Id:" ${COMPFILE} 2>/dev/null`
63152400Sbillf
63252400Sbillf      if [ -n "${CVSID1}" -a -n "${CVSID2}" ]; then
63352400Sbillf        IDTAG='$Id'
63452400Sbillf        compare_ids "${CVSID1}" "${CVSID2}"
63552400Sbillf      fi
63652400Sbillf    fi
63752400Sbillf    ;;
63852400Sbillf  esac
63952400Sbillf
64052400Sbillf  # If the file is still here either because the $Ids are different, the
64152400Sbillf  # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
64252400Sbillf  #
64352400Sbillf  if [ -f "${COMPFILE}" ]; then
64452400Sbillf
64552400Sbillf    # Do an absolute diff first to see if the files are actually different.
64652400Sbillf    # If they're not different, delete the one in temproot.
64752400Sbillf    #
64852400Sbillf    if diff -q "${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then
64952400Sbillf      echo " *** Temp ${COMPFILE} and installed are the same, deleting"
65052400Sbillf      rm "${COMPFILE}"
65152400Sbillf    else
65252400Sbillf      # Ok, the files are different, so show the user where they differ. Use user's
65352400Sbillf      # choice of diff methods; and user's pager if they have one. Use more if not.
65452400Sbillf      # Use unified diffs by default. Context diffs give me a headache. :)
65552400Sbillf      #
65652400Sbillf      case "${AUTO_RUN}" in
65752400Sbillf      '')
65858910Salfred        # prompt user to install/delete/merge changes
65958910Salfred        diff_loop
66052400Sbillf        ;;
66152400Sbillf      *)
66252400Sbillf        # If this is an auto run, make it official
66352400Sbillf        echo "   *** ${COMPFILE} will remain for your consideration"
66452400Sbillf        ;;
66552400Sbillf      esac # Auto run test
66652400Sbillf    fi # Yes, the files are different
66752400Sbillf  fi # Yes, the file still remains to be checked
66852400Sbillfdone # This is for the do way up there at the beginning of the comparison
66952400Sbillf
67052534Sbillfecho ''
67152400Sbillfecho "*** Comparison complete"
67252400Sbillfecho ''
67352400Sbillf
67452400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
67552400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then
67652400Sbillf  echo "*** Files that remain for you to merge by hand:"
67752400Sbillf  find "${TEMPROOT}" -type f -size +0
67852400Sbillffi
67952400Sbillf
68052400Sbillfcase "${AUTO_RUN}" in
68152400Sbillf'')
68252400Sbillf  echo ''
68352400Sbillf  read -p "Do you wish to delete what is left of ${TEMPROOT}? [no] " DEL_TEMPROOT
68452400Sbillf  case "${DEL_TEMPROOT}" in
68552400Sbillf  [yY]*)
68652400Sbillf    if rm -rf "${TEMPROOT}"; then
68752400Sbillf      echo " *** ${TEMPROOT} has been deleted"
68852400Sbillf    else
68952400Sbillf      echo " *** Unable to delete ${TEMPROOT}"
69052400Sbillf    fi
69152400Sbillf    ;;
69252400Sbillf  *)
69352400Sbillf    echo " *** ${TEMPROOT} will remain"
69452400Sbillf    ;;
69552400Sbillf  esac
69652400Sbillf  ;;
69752400Sbillf*) ;;
69852400Sbillfesac
69952400Sbillf
70052400Sbillfcase "${NEED_MAKEDEV}" in
70152400Sbillf'') ;;
70252400Sbillf*)
70352400Sbillf  echo ''
70452400Sbillf  echo "*** You installed a new /dev/MAKEDEV script, so make sure that you run"
70552400Sbillf  echo "    'cd /dev && /bin/sh MAKEDEV all' to rebuild your devices"
70652400Sbillf  ;;
70752400Sbillfesac
70852400Sbillf
70952400Sbillfcase "${NEED_NEWALIASES}" in
71052400Sbillf'') ;;
71152400Sbillf*)
71252400Sbillf  echo ''
71352400Sbillf  echo "*** You installed a new aliases file, so make sure that you run"
71452400Sbillf  echo "    'newaliases' to rebuild your aliases database"
71552400Sbillf  ;;
71652400Sbillfesac
71752400Sbillf
71852400Sbillfcase "${NEED_CAP_MKDB}" in
71952400Sbillf'') ;;
72052400Sbillf*)
72152400Sbillf  echo ''
72252400Sbillf  echo "*** You installed a login.conf file, so make sure that you run"
72352400Sbillf  echo "    'cap_mkdb /etc/login.conf' to rebuild your login.conf database"
72452400Sbillf  ;;
72552400Sbillfesac
72652400Sbillf
72752400Sbillfcase "${NEED_PWD_MKDB}" in
72852400Sbillf'') ;;
72952400Sbillf*)
73052400Sbillf  echo ''
73152400Sbillf  echo "*** You installed a new master.passwd file, so make sure that you run"
73252400Sbillf  echo "    'pwd_mkdb -p /etc/master.passwd' to rebuild your password files"
73352400Sbillf  ;;
73452400Sbillfesac
73552400Sbillf
73652400Sbillfecho ''
73752400Sbillf
73852400Sbillfexit 0
739