5 # Compare files created by /usr/src/etc/Makefile (or the directory
6 # the user specifies) with the currently installed copies.
8 # Copyright (c) 1998-2012 Douglas Barton, All rights reserved
9 # Please see detailed copyright below
13 PATH=/bin:/usr/bin:/usr/sbin
16 VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
17 echo "mergemaster version ${VERSION_NUMBER}"
18 echo 'Usage: mergemaster [-scrvhpCP] [-a|[-iFU]] [--run-updates=always|never]'
19 echo ' [-m /path] [-t /path] [-d] [-u N] [-w N] [-A arch] [-D /path]'
21 echo " -s Strict comparison (diff every pair of files)"
22 echo " -c Use context diff instead of unified diff"
23 echo " -r Re-run on a previously cleaned directory (skip temproot creation)"
24 echo " -v Be more verbose about the process, include additional checks"
25 echo " -a Leave all files that differ to merge by hand"
26 echo " -h Display more complete help"
27 echo ' -i Automatically install files that do not exist in destination directory'
28 echo ' -p Pre-buildworld mode, only compares crucial files'
29 echo ' -F Install files that differ only by revision control Id ($FreeBSD)'
30 echo ' -C Compare local rc.conf variables to the defaults'
31 echo ' -P Preserve files that are overwritten'
32 echo " -U Attempt to auto upgrade files that have not been user modified"
33 echo ' ***DANGEROUS***'
34 echo ' --run-updates= Specify always or never to run newalises, pwd_mkdb, etc.'
36 echo " -m /path/directory Specify location of source to do the make in"
37 echo " -t /path/directory Specify temp root directory"
38 echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)"
39 echo " -u N Specify a numeric umask"
40 echo " -w N Specify a screen width in columns to sdiff"
41 echo " -A architecture Alternative architecture name to pass to make"
42 echo ' -D /path/directory Specify the destination directory to install files to'
47 echo "* To specify a directory other than /var/tmp/temproot for the"
48 echo " temporary root environment, use -t /path/to/temp/root"
49 echo "* The -w option takes a number as an argument for the column width"
50 echo " of the screen. The default is 80."
51 echo '* The -a option causes mergemaster to run without prompting.'
54 # Loop allowing the user to use sdiff to merge files and display the merged
60 echo " *** Type h at the sdiff prompt (%) to get usage help"
65 while [ "${MERGE_AGAIN}" = "yes" ]; do
66 # Prime file.merged so we don't blat the owner/group id's
67 cp -p "${COMPFILE}" "${COMPFILE}.merged"
68 sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \
69 --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
71 while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do
73 echo " Use 'i' to install merged file"
74 echo " Use 'r' to re-do the merge"
75 echo " Use 'v' to view the merged file"
76 echo " Default is to leave the temporary file to deal with by hand"
78 echo -n " *** How should I deal with the merged file? [Leave it for later] "
81 case "${INSTALL_MERGED}" in
83 mv "${COMPFILE}.merged" "${COMPFILE}"
85 if mm_install "${COMPFILE}"; then
86 echo " *** Merged version of ${COMPFILE} installed successfully"
88 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later"
93 rm "${COMPFILE}.merged"
96 ${PAGER} "${COMPFILE}.merged"
99 echo " *** ${COMPFILE} will remain for your consideration"
103 echo "invalid choice: ${INSTALL_MERGED}"
111 # Loop showing user differences between files, allow merge, skip or install
117 while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \
118 "${HANDLE_COMPFILE}" = "NOT V" ]; do
119 if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then
120 if [ -n "${AUTO_UPGRADE}" -a -n "${CHANGED}" ]; then
122 *:${DESTDIR}${COMPFILE#.}:*) ;; # File has been modified
125 echo " *** ${COMPFILE} has not been user modified."
128 if mm_install "${COMPFILE}"; then
129 echo " *** ${COMPFILE} upgraded successfully"
131 # Make the list print one file per line
132 AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPFILE#.}
135 echo " *** Problem upgrading ${COMPFILE}, it will remain to merge by hand"
141 if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then
143 echo ' ====================================================================== '
146 echo " *** Displaying differences between installed version and ${COMPFILE}:"
148 diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}"
154 echo " *** There is no installed version of ${COMPFILE}"
156 case "${AUTO_INSTALL}" in
159 if mm_install "${COMPFILE}"; then
160 echo " *** ${COMPFILE} installed successfully"
162 # Make the list print one file per line
163 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.}
166 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand"
176 echo " Use 'd' to delete the temporary ${COMPFILE}"
177 echo " Use 'i' to install the temporary ${COMPFILE}"
178 case "${NO_INSTALLED}" in
180 echo " Use 'm' to merge the temporary and installed versions"
181 echo " Use 'v' to view the diff results again"
185 echo " Default is to leave the temporary file to deal with by hand"
187 echo -n "How should I deal with this? [Leave it for later] "
190 case "${HANDLE_COMPFILE}" in
194 echo " *** Deleting ${COMPFILE}"
198 if mm_install "${COMPFILE}"; then
199 echo " *** ${COMPFILE} installed successfully"
201 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand"
205 case "${NO_INSTALLED}" in
207 # interact with user to merge files
212 echo " *** There is no installed version of ${COMPFILE}"
214 HANDLE_COMPFILE="NOT V"
216 esac # End of "No installed version of file but user selected merge" test
223 echo " *** ${COMPFILE} will remain for your consideration"
226 # invalid choice, show menu again.
227 echo "invalid choice: ${HANDLE_COMPFILE}"
229 HANDLE_COMPFILE="NOT V"
232 esac # End of "How to handle files that are different"
244 press_to_continue () {
246 echo -n ' *** Press the [Enter] or [Return] key to continue '
250 # Set the default path for the temporary root environment
252 TEMPROOT='/var/tmp/temproot'
254 # Read /etc/mergemaster.rc first so the one in $HOME can override
256 if [ -r /etc/mergemaster.rc ]; then
257 . /etc/mergemaster.rc
260 # Read .mergemasterrc before command line so CLI can override
262 if [ -r "$HOME/.mergemasterrc" ]; then
263 . "$HOME/.mergemasterrc"
269 RUN_UPDATES=`echo ${var#--run-updates=} | tr [:upper:] [:lower:]`
272 newopts="$newopts $var"
280 # Check the command line options
282 while getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do
283 case "${COMMAND_LINE_ARGUMENT}" in
285 ARCHSTRING='TARGET_ARCH='${OPTARG}
304 case "${AUTO_RUN}" in
338 TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M`
344 SCREEN_WIDTH=${OPTARG}
356 if [ -n "$AUTO_RUN" ]; then
357 if [ -n "$FREEBSD_ID" -o -n "$AUTO_UPGRADE" -o -n "$AUTO_INSTALL" ]; then
359 echo "*** You have included the -a option along with one or more options"
360 echo ' that indicate that you wish mergemaster to actually make updates'
361 echo ' (-F, -U, or -i), however these options are not compatible.'
362 echo ' Please read mergemaster(8) for more information.'
368 # Assign the location of the mtree database
370 MTREEDB=${MTREEDB:-${DESTDIR}/var/db}
371 MTREEFILE="${MTREEDB}/mergemaster.mtree"
373 # Don't force the user to set this in the mergemaster rc file
374 if [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then
375 PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S`
376 mkdir -p ${PRESERVE_FILES_DIR}
379 # Check for the mtree database in DESTDIR
380 case "${AUTO_UPGRADE}" in
381 '') ;; # If the option is not set no need to run the test or warn the user
383 if [ ! -s "${MTREEFILE}" ]; then
385 echo "*** Unable to find mtree database (${MTREEFILE})."
386 echo " Skipping auto-upgrade on this run."
387 echo " It will be created for the next run when this one is complete."
389 case "${AUTO_RUN}" in
399 if [ -e "${DESTDIR}/etc/fstab" ]; then
400 if grep -q nodev ${DESTDIR}/etc/fstab; then
402 echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab."
403 echo " This can prevent the filesystem from being mounted on reboot."
404 echo " Please update your fstab before continuing."
405 echo " See fstab(5) for more information."
413 # If the user has a pager defined, make sure we can run it
415 case "${DONT_CHECK_PAGER}" in
418 while ! type "${PAGER%% *}" >/dev/null; do
419 echo " *** Your PAGER environment variable specifies '${PAGER}', but"
420 echo " due to the limited PATH that I use for security reasons,"
421 echo " I cannot execute it. So, what would you like to do?"
423 echo " Use 'e' to exit mergemaster and fix your PAGER variable"
424 echo " Use 'l' to set PAGER to 'less' for this run"
425 echo " Use 'm' to use plain old 'more' as your PAGER for this run"
427 echo " or you may type an absolute path to PAGER for this run"
429 echo " Default is to use 'less' "
431 echo -n "What should I do? [Use 'less'] "
434 case "${FIXPAGER}" in
449 echo "invalid choice: ${FIXPAGER}"
454 if [ -n "${PAGER}" ]; then
460 # If user has a pager defined, or got assigned one above, use it.
465 if [ -n "${VERBOSE}" -a ! "${PAGER}" = "less" ]; then
466 echo " *** You have ${PAGER} defined as your pager so we will use that"
471 # Assign the diff flag once so we will not have to keep testing it
473 DIFF_FLAG=${DIFF_FLAG:--u}
475 # Assign the source directory
477 SOURCEDIR=${SOURCEDIR:-/usr/src}
478 if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
479 -f ${SOURCEDIR}/../Makefile.inc1 ]; then
480 echo " *** The source directory you specified (${SOURCEDIR})"
481 echo " will be reset to ${SOURCEDIR}/.."
484 SOURCEDIR=${SOURCEDIR}/..
486 if [ ! -f ${SOURCEDIR}/Makefile.inc1 ]; then
487 echo "*** ${SOURCEDIR} was not found."
488 if [ -f ./Makefile.inc1 ]; then
489 echo " Found Makefile.inc1 in the current directory."
490 echo -n " Would you like to set SOURCEDIR to $(pwd)? [no and exit] "
494 echo " *** Setting SOURCEDIR to $(pwd)"
498 echo " **** No suitable ${SOURCEDIR} found, exiting"
503 echo " **** No suitable ${SOURCEDIR} found, exiting"
507 SOURCEDIR=$(realpath "$SOURCEDIR")
509 # Setup make to use system files from SOURCEDIR
510 MM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk -DNO_FILEMON"
511 MM_MAKE="${MM_MAKE} -j$(/sbin/sysctl -n hw.ncpu)"
513 # Check DESTDIR against the mergemaster mtree database to see what
514 # files the user changed from the reference files.
516 if [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then
517 # Force FreeBSD 9 compatible output when available.
518 if mtree -F freebsd9 -c -p /var/empty/ > /dev/null 2>&1; then
519 MTREE_FLAVOR="-F freebsd9"
524 for file in `mtree -eqL ${MTREE_FLAVOR} -f ${MTREEFILE} -p ${DESTDIR}/ \
525 2>/dev/null | awk '($2 == "changed") {print $1}'`; do
526 if [ -f "${DESTDIR}/$file" ]; then
527 CHANGED="${CHANGED}${DESTDIR}/${file}:"
530 [ "$CHANGED" = ':' ] && unset CHANGED
533 # Check the width of the user's terminal
538 0|'') ;; # No-op, since the input is not valid
540 case "${SCREEN_WIDTH}" in
541 '') SCREEN_WIDTH="${w}" ;;
542 "${w}") ;; # No-op, since they are the same
544 echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty "
545 echo "thinks it is ${w}."
547 echo -n "What would you like to use? [${w}] "
549 case "${SCREEN_WIDTH}" in
550 '') SCREEN_WIDTH="${w}" ;;
557 # Define what $Id tag to look for to aid portability.
562 rm -rf "${TEMPROOT}" 2>/dev/null
563 chflags -R 0 "${TEMPROOT}" 2>/dev/null
564 rm -rf "${TEMPROOT}" || { echo "*** Unable to delete ${TEMPROOT}"; exit 1; }
569 # Set up the loop to test for the existence of the
570 # temp root directory.
573 while [ "${TEST_TEMP_ROOT}" = "yes" ]; do
574 if [ -d "${TEMPROOT}" ]; then
575 echo "*** The directory specified for the temporary root environment,"
576 echo " ${TEMPROOT}, exists. This can be a security risk if untrusted"
577 echo " users have access to the system."
579 case "${AUTO_RUN}" in
581 echo " Use 'd' to delete the old ${TEMPROOT} and continue"
582 echo " Use 't' to select a new temporary root directory"
583 echo " Use 'e' to exit mergemaster"
585 echo " Default is to use ${TEMPROOT} as is"
587 echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] "
590 case "${DELORNOT}" in
593 echo " *** Deleting the old ${TEMPROOT}"
599 echo " *** Enter new directory name for temporary root environment"
607 echo " *** Leaving ${TEMPROOT} intact"
613 echo "invalid choice: ${DELORNOT}"
619 # If this is an auto-run, try a hopefully safe alternative then
621 TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S`
629 echo "*** Creating the temporary root environment in ${TEMPROOT}"
631 if mkdir -p "${TEMPROOT}"; then
632 echo " *** ${TEMPROOT} ready for use"
635 if [ ! -d "${TEMPROOT}" ]; then
637 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}"
642 echo " *** Creating and populating directory structure in ${TEMPROOT}"
652 case "${PRE_WORLD}" in
658 ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs >/dev/null
661 ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs >/dev/null &&
662 ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc >/dev/null &&
663 ${MM_MAKE} everything SUBDIR_OVERRIDE=etc >/dev/null &&
664 ${MM_MAKE} DESTDIR=${TEMPROOT} distribution >/dev/null;} ||
666 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
667 echo " the temproot environment";
672 # Only set up files that are crucial to {build|install}world
673 { mkdir -p ${TEMPROOT}/etc &&
674 cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc &&
675 install -p -o root -g wheel -m 0644 ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} ||
677 echo ' *** FATAL ERROR: Cannot copy files to the temproot environment';
683 # Doing the inventory and removing files that we don't want to compare only
684 # makes sense if we are not doing a rerun, since we have no way of knowing
685 # what happened to the files during previous incarnations.
690 echo ' *** The following files exist only in the installed version of'
691 echo " ${DESTDIR}/etc. In the vast majority of cases these files"
692 echo ' are necessary parts of the system and should not be deleted.'
693 echo ' However because these files are not updated by this process you'
694 echo ' might want to verify their status before rebooting your system.'
697 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER}
703 case "${IGNORE_MOTD}" in
707 echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file."
708 echo " This option is deprecated in favor of the IGNORE_FILES option."
709 echo " Please update your rc file accordingly."
715 # Avoid comparing the following user specified files
716 for file in ${IGNORE_FILES}; do
717 test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file}
720 # We really don't want to have to deal with files like login.conf.db, pwd.db,
721 # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb.
722 # Prompt the user to do so below, as needed.
724 rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd \
725 ${TEMPROOT}/var/db/services.db
727 # We only need to compare things like freebsd.cf once
728 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
730 # Delete stuff we do not need to keep the mtree database small,
731 # and to make the actual comparison faster.
732 find ${TEMPROOT}/usr -type l -delete 2>/dev/null
733 find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
734 find -d ${TEMPROOT} -type d -empty -mindepth 1 -delete 2>/dev/null
736 # Build the mtree database in a temporary location.
737 case "${PRE_WORLD}" in
738 '') MTREENEW=`mktemp -t mergemaster.mtree`
739 mtree -nci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
741 *) # We don't want to mess with the mtree database on a pre-world run or
742 # when re-scanning a previously-built tree.
745 ;; # End of the "RERUN" test
748 # Get ready to start comparing files
750 # Check umask if not specified on the command line,
751 # and we are not doing an autorun
753 if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then
755 case "${USER_UMASK}" in
759 echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script"
760 echo " installs all files with the same user, group and modes that"
761 echo " they are created with by ${SOURCEDIR}/etc/Makefile, compared to"
762 echo " a umask of 022. This umask allows world read permission when"
763 echo " the file's default permissions have it."
765 echo " No world permissions can sometimes cause problems. A umask of"
766 echo " 022 will restore the default behavior, but is not mandatory."
767 echo " /etc/master.passwd is a special case. Its file permissions"
768 echo " will be 600 (rw-------) if installed."
770 echo -n "What umask should I use? [${USER_UMASK}] "
773 NEW_UMASK="${NEW_UMASK:-$USER_UMASK}"
779 CONFIRMED_UMASK=${NEW_UMASK:-0022}
782 # Warn users who still have old rc files
784 for file in atm devfs diskless1 diskless2 network network6 pccard \
785 serial syscons sysctl alpha amd64 i386 sparc64; do
786 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
792 case "${OLD_RC_PRESENT}" in
795 echo " *** There are elements of the old rc system in ${DESTDIR}/etc/."
797 echo ' While these scripts will not hurt anything, they are not'
798 echo ' functional on an up to date system, and can be removed.'
801 case "${AUTO_RUN}" in
803 echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] '
806 case "${MOVE_OLD_RC}" in
809 mkdir -p /var/tmp/mergemaster/old_rc
810 for file in atm devfs diskless1 diskless2 network network6 pccard \
811 serial syscons sysctl alpha amd64 i386 sparc64; do
812 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then
813 mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/
816 echo ' The files have been moved'
825 # Use the umask/mode information to install the files
826 # Create directories as needed
829 echo "*** FATAL ERROR: Unable to install ${1} to ${2}"
834 do_install_and_rm () {
835 case "${PRESERVE_FILES}" in
837 if [ -f "${3}/${2##*/}" ]; then
838 mkdir -p ${PRESERVE_FILES_DIR}/${2%/*}
839 cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*}
844 if [ ! -d "${3}/${2##*/}" ]; then
845 if install -m ${1} ${2} ${3}; then
848 install_error ${2} ${3}
851 install_error ${2} ${3}
855 # 4095 = "obase=10;ibase=8;07777" | bc
858 OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 &
859 $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) ))
860 printf "%04o\n" ${OCTAL}
866 INSTALL_DIR=${INSTALL_DIR%/*}
868 case "${INSTALL_DIR}" in
874 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then
875 DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"`
876 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" ||
877 install_error $1 ${DESTDIR}${INSTALL_DIR}
880 FILE_MODE=`find_mode "${1}"`
882 if [ ! -x "${1}" ]; then
887 /usr/share/certs/trusted/* | /usr/share/certs/blacklisted/*)
894 NEED_SERVICES_MKDB=yes
897 do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}"
904 # install will unlink the file before it installs the new one,
905 # so we have to restore/create the link afterwards.
907 st_nlink=0 # In case the file does not yet exist
908 eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null)
910 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
912 if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then
915 case "${LINK_EXPLAINED}" in
917 echo " *** Historically BSD derived systems have had a"
918 echo " hard link from /.cshrc and /.profile to"
919 echo " their namesakes in /root. Please indicate"
920 echo " your preference below for bringing your"
921 echo " installed files up to date."
927 echo " Use 'd' to delete the temporary ${COMPFILE}"
928 echo " Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link"
930 echo " Default is to leave the temporary file to deal with by hand"
932 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] "
936 case "${HANDLE_LINK}" in
940 echo " *** Deleting ${COMPFILE}"
944 unlink ${DESTDIR}/root/${COMPFILE##*/}
945 if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then
946 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully"
948 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}"
949 echo " *** ${COMPFILE} will remain for your consideration"
953 echo " *** ${COMPFILE} will remain for your consideration"
960 case "${DONT_INSTALL}" in
962 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
968 else # File matched -x
969 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
974 if [ ! -d "${TEMPROOT}" ]; then
975 echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})"
976 echo ' has disappeared!'
982 echo "*** Beginning comparison"
985 # Pre-world does not populate /etc/rc.d.
986 # It is very possible that a previous run would have deleted files in
987 # ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives.
988 if [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then
989 echo " *** Checking ${DESTDIR}/etc/rc.d for stale files"
991 cd "${DESTDIR}/etc/rc.d" &&
993 if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then
994 STALE_RC_FILES="${STALE_RC_FILES} ${file}"
997 case "${STALE_RC_FILES}" in
999 echo ' *** No stale files found'
1002 echo " *** The following files exist in ${DESTDIR}/etc/rc.d but not in"
1003 echo " ${TEMPROOT}/etc/rc.d/:"
1005 echo "${STALE_RC_FILES}"
1007 echo ' The presence of stale files in this directory can cause the'
1008 echo ' dreaded unpredictable results, and therefore it is highly'
1009 echo ' recommended that you delete them.'
1010 case "${AUTO_RUN}" in
1013 echo -n ' *** Delete them now? [n] '
1014 read DELETE_STALE_RC_FILES
1015 case "${DELETE_STALE_RC_FILES}" in
1017 echo ' *** Deleting ... '
1018 rm ${STALE_RC_FILES}
1022 echo ' *** Files will not be deleted'
1028 if [ -n "${DELETE_STALE_RC_FILES}" ]; then
1029 echo ' *** Deleting ... '
1030 rm ${STALE_RC_FILES}
1041 if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then
1042 . "${MM_PRE_COMPARE_SCRIPT}"
1045 # Things that were files/directories/links in one version can sometimes
1046 # change to something else in a newer version. So we need to explicitly
1047 # test for this, and warn the user if what we find does not match.
1049 for COMPFILE in `find . | sort` ; do
1050 if [ -e "${DESTDIR}${COMPFILE#.}" ]; then
1051 INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}`
1055 TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE`
1057 if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then
1058 [ "$COMPFILE" = '.' ] && continue
1059 TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]`
1060 INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]`
1062 echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\""
1063 echo " but the new version has the type \"$TEMPROOT_TYPE\""
1065 echo " How would you like to handle this?"
1067 echo " Use 'r' to remove ${DESTDIR}${COMPFILE#.}"
1068 case "$TEMPROOT_TYPE" in
1070 TARGET=`readlink $COMPFILE`
1071 echo " and create a link to $TARGET in its place" ;;
1072 *) echo " You will be able to install it as a \"$TEMPROOT_TYPE\"" ;;
1075 echo " Use 'i' to ignore this"
1077 echo -n " How to proceed? [i] "
1080 [rR]) case "${PRESERVE_FILES}" in
1082 mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;;
1083 *) rm -rf ${DESTDIR}${COMPFILE#.} ;;
1085 case "$TEMPROOT_TYPE" in
1086 'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;;
1089 echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES"
1090 press_to_continue ;;
1096 # Compare regular files
1097 for COMPFILE in `find . -type f | sort`; do
1099 # First, check to see if the file exists in DESTDIR. If not, the
1100 # diff_loop function knows how to handle it.
1102 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then
1103 case "${AUTO_RUN}" in
1108 case "${AUTO_INSTALL}" in
1110 # If this is an auto run, make it official
1111 echo " *** ${COMPFILE} will remain for your consideration"
1118 esac # Auto run test
1124 # Compare $Id's first so if the file hasn't been modified
1125 # local changes will be ignored.
1126 # If the files have the same $Id, delete the one in temproot so the
1127 # user will have less to wade through if files are left to merge by hand.
1129 ID1=`grep "[$]${ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
1130 ID2=`grep "[$]${ID_TAG}:" ${COMPFILE} 2>/dev/null` || ID2=none
1134 echo " *** Temp ${COMPFILE} and installed have the same Id, deleting"
1141 # If the file is still here either because the $Ids are different, the
1142 # file doesn't have an $Id, or we're using STRICT mode; look at the diff.
1144 if [ -f "${COMPFILE}" ]; then
1146 # Do an absolute diff first to see if the files are actually different.
1147 # If they're not different, delete the one in temproot.
1149 if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1150 /dev/null 2>&1; then
1151 echo " *** Temp ${COMPFILE} and installed are the same, deleting"
1154 # Ok, the files are different, so show the user where they differ.
1155 # Use user's choice of diff methods; and user's pager if they have one.
1157 # Use unified diffs by default. Context diffs give me a headache. :)
1159 # If the user chose the -F option, test for that before proceeding
1161 if [ -n "$FREEBSD_ID" ]; then
1162 if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \
1163 /dev/null 2>&1; then
1164 if mm_install "${COMPFILE}"; then
1165 echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}"
1167 echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later"
1172 case "${AUTO_RUN}" in
1174 # prompt user to install/delete/merge changes
1178 # If this is an auto run, make it official
1179 echo " *** ${COMPFILE} will remain for your consideration"
1181 esac # Auto run test
1182 fi # Yes, the files are different
1183 fi # Yes, the file still remains to be checked
1184 done # This is for the for way up there at the beginning of the comparison
1186 ask_answer_for_symbolic_link () {
1187 HANDLE_COMPSYMLINK=''
1189 echo " Use 'd' to delete the temporary ${COMPSYMLINK}"
1190 echo " Use 'i' to install the temporary ${COMPSYMLINK}"
1192 echo " Default is to leave the temporary symbolic link to deal with by hand"
1194 echo -n "How should I deal with this? [Leave it for later] "
1195 read HANDLE_COMPSYMLINK
1196 case ${HANDLE_COMPSYMLINK} in
1201 echo "invalid choice: ${HANDLE_COMPSYMLINK}"
1203 HANDLE_COMPSYMLINK=''
1209 install_symbolic_link () {
1210 rm -f ${DESTDIR}${COMPSYMLINK#.} > /dev/null 2>&1
1211 if [ -L ${DESTDIR}${COMPSYMLINK#.} ]; then
1214 cp -a ${COMPSYMLINK} ${DESTDIR}${COMPSYMLINK#.} > /dev/null 2>&1
1215 if [ ! -L ${DESTDIR}${COMPSYMLINK#.} ]; then
1221 handle_symbolic_link () {
1222 case ${HANDLE_COMPSYMLINK} in
1226 echo " *** Deleting ${COMPSYMLINK}"
1232 if install_symbolic_link; then
1234 echo " *** ${COMPSYMLINK} installed successfully"
1237 echo " *** Problem installing ${COMPSYMLINK}, it will remain to merge by hand"
1244 echo " *** ${COMPSYMLINK} will remain for your consideration"
1251 # Compare symblic links
1252 for COMPSYMLINK in `find . -type l | sort`; do
1253 if [ ! -L "${DESTDIR}${COMPSYMLINK#.}" ]; then
1254 if [ -n "${AUTO_RUN}" -a -z "${AUTO_INSTALL}" ]; then
1255 echo " *** ${COMPSYMLINK} will remain for your consideration"
1259 echo " *** There is no installed version of ${COMPSYMLINK}"
1261 if [ -n "${AUTO_INSTALL}" ]; then
1262 HANDLE_COMPSYMLINK="i"
1264 ask_answer_for_symbolic_link
1266 handle_symbolic_link
1267 if [ -n "${AUTO_INSTALL}" -a $? -eq 2 ]; then
1268 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPSYMLINK#.}
1272 elif [ $(readlink ${COMPSYMLINK}) = $(readlink ${DESTDIR}${COMPSYMLINK#.}) ]; then
1273 echo " *** Temp ${COMPSYMLINK} and installed are the same, deleting"
1276 if [ -n "${AUTO_RUN}" -a -z "${AUTO_UPGRADE}" ]; then
1277 echo " *** ${COMPSYMLINK} will remain for your consideration"
1281 echo " *** Target of temp symbolic link is differnt from that of installed one"
1282 echo " Temp (${COMPSYMLINK}): $(readlink ${COMPSYMLINK})"
1283 echo " Installed (${DESTDIR}${COMPSYMLINK#.})): $(readlink ${DESTDIR}${COMPSYMLINK#.})"
1285 if [ -n "${AUTO_UPGRADE}" ]; then
1286 HANDLE_COMPSYMLINK="i"
1288 ask_answer_for_symbolic_link
1290 handle_symbolic_link
1291 if [ -n "${AUTO_UPGRADE}" -a $? -eq 2 ]; then
1292 AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPSYMLINK#.}
1300 echo "*** Comparison complete"
1302 if [ -s "${MTREENEW}" ]; then
1303 echo "*** Saving mtree database for future upgrades"
1304 test -e "${MTREEFILE}" && unlink ${MTREEFILE}
1305 mv ${MTREENEW} ${MTREEFILE}
1310 TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 -or -type l 2>/dev/null`
1311 if [ -n "${TEST_FOR_FILES}" ]; then
1312 echo "*** Files that remain for you to merge by hand:"
1313 find "${TEMPROOT}" -type f -size +0 -or -type l | sort
1316 case "${AUTO_RUN}" in
1318 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] "
1320 case "${DEL_TEMPROOT}" in
1325 echo " *** ${TEMPROOT} will remain"
1332 echo "*** ${TEMPROOT} is empty, deleting"
1336 case "${AUTO_INSTALLED_FILES}" in
1339 case "${AUTO_RUN}" in
1343 echo '*** You chose the automatic install option for files that did not'
1344 echo ' exist on your system. The following were installed for you:'
1345 echo "${AUTO_INSTALLED_FILES}"
1350 echo '*** You chose the automatic install option for files that did not'
1351 echo ' exist on your system. The following were installed for you:'
1352 echo "${AUTO_INSTALLED_FILES}"
1358 case "${AUTO_UPGRADED_FILES}" in
1361 case "${AUTO_RUN}" in
1365 echo '*** You chose the automatic upgrade option for files that you did'
1366 echo ' not alter on your system. The following were upgraded for you:'
1367 echo "${AUTO_UPGRADED_FILES}"
1372 echo '*** You chose the automatic upgrade option for files that you did'
1373 echo ' not alter on your system. The following were upgraded for you:'
1374 echo "${AUTO_UPGRADED_FILES}"
1381 [ -n "$AUTO_RUN" ] && return
1387 if [ "$RUN_UPDATES" = always ]; then
1389 elif [ "$RUN_UPDATES" = never ]; then
1392 echo -n ' Would you like to run it now? y or n [n] '
1398 echo " Running ${1}"
1404 if [ ! "$RUN_UPDATES" = never ]; then
1406 echo " *** Cancelled"
1409 echo " Make sure to run ${1} yourself"
1414 echo " *** Sorry, I do not understand your answer (${answer})"
1420 case "${NEED_NEWALIASES}" in
1424 if [ -n "${DESTDIR}" ]; then
1425 echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but"
1426 echo " the newaliases command is limited to the directories configured"
1427 echo " in sendmail.cf. Make sure to create your aliases database by"
1428 echo " hand when your sendmail configuration is done."
1430 echo "*** You installed a new aliases file, so make sure that you run"
1431 echo " '/usr/bin/newaliases' to rebuild your aliases database"
1432 run_it_now '/usr/bin/newaliases'
1437 case "${NEED_CAP_MKDB}" in
1441 echo "*** You installed a login.conf file, so make sure that you run"
1442 echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'"
1443 echo " to rebuild your login.conf database"
1444 run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf"
1448 case "${NEED_SERVICES_MKDB}" in
1452 echo "*** You installed a services file, so make sure that you run"
1453 echo " '/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services'"
1454 echo " to rebuild your services database"
1455 run_it_now "/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services"
1459 case "${NEED_PWD_MKDB}" in
1463 echo "*** You installed a new master.passwd file, so make sure that you run"
1464 if [ -n "${DESTDIR}" ]; then
1465 echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'"
1466 echo " to rebuild your password files"
1467 run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd"
1469 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'"
1470 echo " to rebuild your password files"
1471 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd'
1476 case "${NEED_CERTCTL}" in
1480 echo "*** You installed files in /etc/ssl/certs, so make sure that you run"
1481 if [ -n "${DESTDIR}" ]; then
1482 echo " 'env DESTDIR=${DESTDIR} /usr/sbin/certctl rehash'"
1483 echo " to rebuild your certificate authority database"
1484 run_it_now "env DESTDIR=${DESTDIR} /usr/sbin/certctl rehash"
1486 echo " '/usr/sbin/certctl rehash'"
1487 echo " to rebuild your certificate authority database"
1488 run_it_now "/usr/sbin/certctl rehash"
1493 if [ -e "${DESTDIR}/etc/localtime" -a ! -L "${DESTDIR}/etc/localtime" -a -z "${PRE_WORLD}" ]; then # Ignore if TZ == UTC
1495 [ -n "${DESTDIR}" ] && tzs_args="-C ${DESTDIR}"
1496 if [ -f "${DESTDIR}/var/db/zoneinfo" ]; then
1497 echo "*** Reinstalling `cat ${DESTDIR}/var/db/zoneinfo` as ${DESTDIR}/etc/localtime"
1498 tzsetup $tzs_args -r
1500 echo "*** There is no ${DESTDIR}/var/db/zoneinfo file to update ${DESTDIR}/etc/localtime."
1501 echo ' You should run tzsetup'
1502 run_it_now "tzsetup $tzs_args"
1508 if [ -r "${MM_EXIT_SCRIPT}" ]; then
1509 . "${MM_EXIT_SCRIPT}"
1512 case "${COMP_CONFS}" in
1515 . ${DESTDIR}/etc/defaults/rc.conf
1518 echo "*** Comparing conf files: ${rc_conf_files}"
1520 for CONF_FILE in ${rc_conf_files}; do
1521 if [ -r "${DESTDIR}${CONF_FILE}" ]; then
1523 echo "*** From ${DESTDIR}${CONF_FILE}"
1524 echo "*** From ${DESTDIR}/etc/defaults/rc.conf"
1526 for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} |
1527 cut -d '=' -f 1`; do
1529 grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE}
1530 grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf ||
1531 echo ' * No default variable with this name'
1539 if [ -n "${PRESERVE_FILES}" ]; then
1540 find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null
1541 rmdir $PRESERVE_FILES_DIR 2>/dev/null
1546 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1548 # Copyright (c) 1998-2012 Douglas Barton
1549 # All rights reserved.
1551 # Redistribution and use in source and binary forms, with or without
1552 # modification, are permitted provided that the following conditions
1554 # 1. Redistributions of source code must retain the above copyright
1555 # notice, this list of conditions and the following disclaimer.
1556 # 2. Redistributions in binary form must reproduce the above copyright
1557 # notice, this list of conditions and the following disclaimer in the
1558 # documentation and/or other materials provided with the distribution.
1560 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1561 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1562 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1563 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1564 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1565 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1566 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1567 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1568 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1569 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF