1#!/bin/sh 2 3# mergemaster 4 5# Compare files created by /usr/src/etc/Makefile (or the directory 6# the user specifies) with the currently installed copies. 7 8# Copyright (c) 1998-2012 Douglas Barton, All rights reserved 9# Please see detailed copyright below 10 11PATH=/bin:/usr/bin:/usr/sbin 12 13display_usage () { 14 VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4` 15 echo "mergemaster version ${VERSION_NUMBER}" 16 echo 'Usage: mergemaster [-scrvhpCP] [-a|[-iFU]] [--run-updates=always|never]' 17 echo ' [-m /path] [-t /path] [-d] [-u N] [-w N] [-A arch] [-D /path]' 18 echo "Options:" 19 echo " -s Strict comparison (diff every pair of files)" 20 echo " -c Use context diff instead of unified diff" 21 echo " -r Re-run on a previously cleaned directory (skip temproot creation)" 22 echo " -v Be more verbose about the process, include additional checks" 23 echo " -a Leave all files that differ to merge by hand" 24 echo " -h Display more complete help" 25 echo ' -i Automatically install files that do not exist in destination directory' 26 echo ' -p Pre-buildworld mode, only compares crucial files' 27 echo ' -F Install files that differ only by revision control Id ($FreeBSD)' 28 echo ' -C Compare local rc.conf variables to the defaults' 29 echo ' -P Preserve files that are overwritten' 30 echo " -U Attempt to auto upgrade files that have not been user modified" 31 echo ' ***DANGEROUS***' 32 echo ' --run-updates= Specify always or never to run newalises, pwd_mkdb, etc.' 33 echo '' 34 echo " -m /path/directory Specify location of source to do the make in" 35 echo " -t /path/directory Specify temp root directory" 36 echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" 37 echo " -u N Specify a numeric umask" 38 echo " -w N Specify a screen width in columns to sdiff" 39 echo " -A architecture Alternative architecture name to pass to make" 40 echo ' -D /path/directory Specify the destination directory to install files to' 41 echo '' 42} 43 44display_help () { 45 echo "* To specify a directory other than /var/tmp/temproot for the" 46 echo " temporary root environment, use -t /path/to/temp/root" 47 echo "* The -w option takes a number as an argument for the column width" 48 echo " of the screen. The default is 80." 49 echo '* The -a option causes mergemaster to run without prompting.' 50} 51 52# Loop allowing the user to use sdiff to merge files and display the merged 53# file. 54merge_loop () { 55 case "${VERBOSE}" in 56 '') ;; 57 *) 58 echo " *** Type h at the sdiff prompt (%) to get usage help" 59 ;; 60 esac 61 echo '' 62 MERGE_AGAIN=yes 63 while [ "${MERGE_AGAIN}" = "yes" ]; do 64 # Prime file.merged so we don't blat the owner/group id's 65 cp -p "${COMPFILE}" "${COMPFILE}.merged" 66 sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 67 --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 68 INSTALL_MERGED=V 69 while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 70 echo '' 71 echo " Use 'i' to install merged file" 72 echo " Use 'r' to re-do the merge" 73 echo " Use 'v' to view the merged file" 74 echo " Default is to leave the temporary file to deal with by hand" 75 echo '' 76 echo -n " *** How should I deal with the merged file? [Leave it for later] " 77 read INSTALL_MERGED 78 79 case "${INSTALL_MERGED}" in 80 [iI]) 81 mv "${COMPFILE}.merged" "${COMPFILE}" 82 echo '' 83 if mm_install "${COMPFILE}"; then 84 echo " *** Merged version of ${COMPFILE} installed successfully" 85 else 86 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 87 fi 88 unset MERGE_AGAIN 89 ;; 90 [rR]) 91 rm "${COMPFILE}.merged" 92 ;; 93 [vV]) 94 ${PAGER} "${COMPFILE}.merged" 95 ;; 96 '') 97 echo " *** ${COMPFILE} will remain for your consideration" 98 unset MERGE_AGAIN 99 ;; 100 *) 101 echo "invalid choice: ${INSTALL_MERGED}" 102 INSTALL_MERGED=V 103 ;; 104 esac 105 done 106 done 107} 108 109# Loop showing user differences between files, allow merge, skip or install 110# options 111diff_loop () { 112 113 HANDLE_COMPFILE=v 114 115 while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \ 116 "${HANDLE_COMPFILE}" = "NOT V" ]; do 117 if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 118 if [ -n "${AUTO_UPGRADE}" -a -n "${CHANGED}" ]; then 119 case "${CHANGED}" in 120 *:${DESTDIR}${COMPFILE#.}:*) ;; # File has been modified 121 *) 122 echo '' 123 echo " *** ${COMPFILE} has not been user modified." 124 echo '' 125 126 if mm_install "${COMPFILE}"; then 127 echo " *** ${COMPFILE} upgraded successfully" 128 echo '' 129 # Make the list print one file per line 130 AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPFILE#.} 131" 132 else 133 echo " *** Problem upgrading ${COMPFILE}, it will remain to merge by hand" 134 fi 135 return 136 ;; 137 esac 138 fi 139 if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 140 echo '' 141 echo ' ====================================================================== ' 142 echo '' 143 ( 144 echo " *** Displaying differences between installed version and ${COMPFILE}:" 145 echo '' 146 diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 147 ) | ${PAGER} 148 echo '' 149 fi 150 else 151 echo '' 152 echo " *** There is no installed version of ${COMPFILE}" 153 echo '' 154 case "${AUTO_INSTALL}" in 155 [Yy][Ee][Ss]) 156 echo '' 157 if mm_install "${COMPFILE}"; then 158 echo " *** ${COMPFILE} installed successfully" 159 echo '' 160 # Make the list print one file per line 161 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 162" 163 else 164 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 165 fi 166 return 167 ;; 168 *) 169 NO_INSTALLED=yes 170 ;; 171 esac 172 fi 173 174 echo " Use 'd' to delete the temporary ${COMPFILE}" 175 echo " Use 'i' to install the temporary ${COMPFILE}" 176 case "${NO_INSTALLED}" in 177 '') 178 echo " Use 'm' to merge the temporary and installed versions" 179 echo " Use 'v' to view the diff results again" 180 ;; 181 esac 182 echo '' 183 echo " Default is to leave the temporary file to deal with by hand" 184 echo '' 185 echo -n "How should I deal with this? [Leave it for later] " 186 read HANDLE_COMPFILE 187 188 case "${HANDLE_COMPFILE}" in 189 [dD]) 190 rm "${COMPFILE}" 191 echo '' 192 echo " *** Deleting ${COMPFILE}" 193 ;; 194 [iI]) 195 echo '' 196 if mm_install "${COMPFILE}"; then 197 echo " *** ${COMPFILE} installed successfully" 198 else 199 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 200 fi 201 ;; 202 [mM]) 203 case "${NO_INSTALLED}" in 204 '') 205 # interact with user to merge files 206 merge_loop 207 ;; 208 *) 209 echo '' 210 echo " *** There is no installed version of ${COMPFILE}" 211 echo '' 212 HANDLE_COMPFILE="NOT V" 213 ;; 214 esac # End of "No installed version of file but user selected merge" test 215 ;; 216 [vV]) 217 continue 218 ;; 219 '') 220 echo '' 221 echo " *** ${COMPFILE} will remain for your consideration" 222 ;; 223 *) 224 # invalid choice, show menu again. 225 echo "invalid choice: ${HANDLE_COMPFILE}" 226 echo '' 227 HANDLE_COMPFILE="NOT V" 228 continue 229 ;; 230 esac # End of "How to handle files that are different" 231 done 232 unset NO_INSTALLED 233 echo '' 234 case "${VERBOSE}" in 235 '') ;; 236 *) 237 sleep 3 238 ;; 239 esac 240} 241 242press_to_continue () { 243 local DISCARD 244 echo -n ' *** Press the [Enter] or [Return] key to continue ' 245 read DISCARD 246} 247 248# Set the default path for the temporary root environment 249# 250TEMPROOT='/var/tmp/temproot' 251 252# Read /etc/mergemaster.rc first so the one in $HOME can override 253# 254if [ -r /etc/mergemaster.rc ]; then 255 . /etc/mergemaster.rc 256fi 257 258# Read .mergemasterrc before command line so CLI can override 259# 260if [ -r "$HOME/.mergemasterrc" ]; then 261 . "$HOME/.mergemasterrc" 262fi 263 264for var in "$@" ; do 265 case "$var" in 266 --run-updates*) 267 RUN_UPDATES=`echo ${var#--run-updates=} | tr [:upper:] [:lower:]` 268 ;; 269 *) 270 newopts="$newopts $var" 271 ;; 272 esac 273done 274 275set -- $newopts 276unset var newopts 277 278# Check the command line options 279# 280while getopts ":ascrvhipCPm:t:du:w:D:A:FU" COMMAND_LINE_ARGUMENT ; do 281 case "${COMMAND_LINE_ARGUMENT}" in 282 A) 283 ARCHSTRING='TARGET_ARCH='${OPTARG} 284 ;; 285 F) 286 FREEBSD_ID=yes 287 ;; 288 U) 289 AUTO_UPGRADE=yes 290 ;; 291 s) 292 STRICT=yes 293 unset DIFF_OPTIONS 294 ;; 295 c) 296 DIFF_FLAG='-c' 297 ;; 298 r) 299 RERUN=yes 300 ;; 301 v) 302 case "${AUTO_RUN}" in 303 '') VERBOSE=yes ;; 304 esac 305 ;; 306 a) 307 AUTO_RUN=yes 308 unset VERBOSE 309 ;; 310 h) 311 display_usage 312 display_help 313 exit 0 314 ;; 315 i) 316 AUTO_INSTALL=yes 317 ;; 318 C) 319 COMP_CONFS=yes 320 ;; 321 P) 322 PRESERVE_FILES=yes 323 ;; 324 p) 325 PRE_WORLD=yes 326 unset COMP_CONFS 327 unset AUTO_RUN 328 ;; 329 m) 330 SOURCEDIR=${OPTARG} 331 ;; 332 t) 333 TEMPROOT=${OPTARG} 334 ;; 335 d) 336 TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 337 ;; 338 u) 339 NEW_UMASK=${OPTARG} 340 ;; 341 w) 342 SCREEN_WIDTH=${OPTARG} 343 ;; 344 D) 345 DESTDIR=${OPTARG} 346 ;; 347 *) 348 display_usage 349 exit 1 350 ;; 351 esac 352done 353 354if [ -n "$AUTO_RUN" ]; then 355 if [ -n "$FREEBSD_ID" -o -n "$AUTO_UPGRADE" -o -n "$AUTO_INSTALL" ]; then 356 echo '' 357 echo "*** You have included the -a option along with one or more options" 358 echo ' that indicate that you wish mergemaster to actually make updates' 359 echo ' (-F, -U, or -i), however these options are not compatible.' 360 echo ' Please read mergemaster(8) for more information.' 361 echo '' 362 exit 1 363 fi 364fi 365 366# Assign the location of the mtree database 367# 368MTREEDB=${MTREEDB:-${DESTDIR}/var/db} 369MTREEFILE="${MTREEDB}/mergemaster.mtree" 370 371# Don't force the user to set this in the mergemaster rc file 372if [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then 373 PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S` 374 mkdir -p ${PRESERVE_FILES_DIR} 375fi 376 377# Check for the mtree database in DESTDIR 378case "${AUTO_UPGRADE}" in 379'') ;; # If the option is not set no need to run the test or warn the user 380*) 381 if [ ! -s "${MTREEFILE}" ]; then 382 echo '' 383 echo "*** Unable to find mtree database (${MTREEFILE})." 384 echo " Skipping auto-upgrade on this run." 385 echo " It will be created for the next run when this one is complete." 386 echo '' 387 case "${AUTO_RUN}" in 388 '') 389 press_to_continue 390 ;; 391 esac 392 unset AUTO_UPGRADE 393 fi 394 ;; 395esac 396 397if [ -e "${DESTDIR}/etc/fstab" ]; then 398 if grep -q nodev ${DESTDIR}/etc/fstab; then 399 echo '' 400 echo "*** You have the deprecated 'nodev' option in ${DESTDIR}/etc/fstab." 401 echo " This can prevent the filesystem from being mounted on reboot." 402 echo " Please update your fstab before continuing." 403 echo " See fstab(5) for more information." 404 echo '' 405 exit 1 406 fi 407fi 408 409echo '' 410 411# If the user has a pager defined, make sure we can run it 412# 413case "${DONT_CHECK_PAGER}" in 414'') 415check_pager () { 416 while ! type "${PAGER%% *}" >/dev/null; do 417 echo " *** Your PAGER environment variable specifies '${PAGER}', but" 418 echo " due to the limited PATH that I use for security reasons," 419 echo " I cannot execute it. So, what would you like to do?" 420 echo '' 421 echo " Use 'e' to exit mergemaster and fix your PAGER variable" 422 echo " Use 'l' to set PAGER to 'less' for this run" 423 echo " Use 'm' to use plain old 'more' as your PAGER for this run" 424 echo '' 425 echo " or you may type an absolute path to PAGER for this run" 426 echo '' 427 echo " Default is to use 'less' " 428 echo '' 429 echo -n "What should I do? [Use 'less'] " 430 read FIXPAGER 431 432 case "${FIXPAGER}" in 433 [eE]) 434 exit 0 435 ;; 436 [lL]|'') 437 PAGER=less 438 ;; 439 [mM]) 440 PAGER=more 441 ;; 442 /*) 443 PAGER="$FIXPAGER" 444 ;; 445 *) 446 echo '' 447 echo "invalid choice: ${FIXPAGER}" 448 esac 449 echo '' 450 done 451} 452 if [ -n "${PAGER}" ]; then 453 check_pager 454 fi 455 ;; 456esac 457 458# If user has a pager defined, or got assigned one above, use it. 459# If not, use less. 460# 461PAGER=${PAGER:-less} 462 463if [ -n "${VERBOSE}" -a ! "${PAGER}" = "less" ]; then 464 echo " *** You have ${PAGER} defined as your pager so we will use that" 465 echo '' 466 sleep 3 467fi 468 469# Assign the diff flag once so we will not have to keep testing it 470# 471DIFF_FLAG=${DIFF_FLAG:--u} 472 473# Assign the source directory 474# 475SOURCEDIR=${SOURCEDIR:-/usr/src} 476if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \ 477 -f ${SOURCEDIR}/../Makefile.inc1 ]; then 478 echo " *** The source directory you specified (${SOURCEDIR})" 479 echo " will be reset to ${SOURCEDIR}/.." 480 echo '' 481 sleep 3 482 SOURCEDIR=${SOURCEDIR}/.. 483fi 484if [ ! -f ${SOURCEDIR}/Makefile.inc1 ]; then 485 echo "*** ${SOURCEDIR} was not found." 486 if [ -f ./Makefile.inc1 ]; then 487 echo " Found Makefile.inc1 in the current directory." 488 echo -n " Would you like to set SOURCEDIR to $(pwd)? [no and exit] " 489 read SRCDOT 490 case "${SRCDOT}" in 491 [yY]*) 492 echo " *** Setting SOURCEDIR to $(pwd)" 493 SOURCEDIR=$(pwd) 494 ;; 495 *) 496 echo " **** No suitable ${SOURCEDIR} found, exiting" 497 exit 1 498 ;; 499 esac 500 else 501 echo " **** No suitable ${SOURCEDIR} found, exiting" 502 exit 1 503 fi 504fi 505SOURCEDIR=$(realpath "$SOURCEDIR") 506 507# Setup make to use system files from SOURCEDIR 508MM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk -DNO_FILEMON" 509MM_MAKE="${MM_MAKE} -j$(/sbin/sysctl -n hw.ncpu)" 510 511# Check DESTDIR against the mergemaster mtree database to see what 512# files the user changed from the reference files. 513# 514if [ -n "${AUTO_UPGRADE}" -a -s "${MTREEFILE}" ]; then 515 # Force FreeBSD 9 compatible output when available. 516 if mtree -F freebsd9 -c -p /var/empty/ > /dev/null 2>&1; then 517 MTREE_FLAVOR="-F freebsd9" 518 else 519 MTREE_FLAVOR= 520 fi 521 CHANGED=: 522 for file in `mtree -eqL ${MTREE_FLAVOR} -f ${MTREEFILE} -p ${DESTDIR}/ \ 523 2>/dev/null | awk '($2 == "changed") {print $1}'`; do 524 if [ -f "${DESTDIR}/$file" ]; then 525 CHANGED="${CHANGED}${DESTDIR}/${file}:" 526 fi 527 done 528 [ "$CHANGED" = ':' ] && unset CHANGED 529fi 530 531# Check the width of the user's terminal 532# 533if [ -t 0 ]; then 534 w=`tput columns` 535 case "${w}" in 536 0|'') ;; # No-op, since the input is not valid 537 *) 538 case "${SCREEN_WIDTH}" in 539 '') SCREEN_WIDTH="${w}" ;; 540 "${w}") ;; # No-op, since they are the same 541 *) 542 echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty " 543 echo "thinks it is ${w}." 544 echo '' 545 echo -n "What would you like to use? [${w}] " 546 read SCREEN_WIDTH 547 case "${SCREEN_WIDTH}" in 548 '') SCREEN_WIDTH="${w}" ;; 549 esac 550 ;; 551 esac 552 esac 553fi 554 555# Define what $Id tag to look for to aid portability. 556# 557ID_TAG=FreeBSD 558 559delete_temproot () { 560 rm -rf "${TEMPROOT}" 2>/dev/null 561 chflags -R 0 "${TEMPROOT}" 2>/dev/null 562 rm -rf "${TEMPROOT}" || { echo "*** Unable to delete ${TEMPROOT}"; exit 1; } 563} 564 565case "${RERUN}" in 566'') 567 # Set up the loop to test for the existence of the 568 # temp root directory. 569 # 570 TEST_TEMP_ROOT=yes 571 while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 572 if [ -d "${TEMPROOT}" ]; then 573 echo "*** The directory specified for the temporary root environment," 574 echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 575 echo " users have access to the system." 576 echo '' 577 case "${AUTO_RUN}" in 578 '') 579 echo " Use 'd' to delete the old ${TEMPROOT} and continue" 580 echo " Use 't' to select a new temporary root directory" 581 echo " Use 'e' to exit mergemaster" 582 echo '' 583 echo " Default is to use ${TEMPROOT} as is" 584 echo '' 585 echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 586 read DELORNOT 587 588 case "${DELORNOT}" in 589 [dD]) 590 echo '' 591 echo " *** Deleting the old ${TEMPROOT}" 592 echo '' 593 delete_temproot 594 unset TEST_TEMP_ROOT 595 ;; 596 [tT]) 597 echo " *** Enter new directory name for temporary root environment" 598 read TEMPROOT 599 ;; 600 [eE]) 601 exit 0 602 ;; 603 '') 604 echo '' 605 echo " *** Leaving ${TEMPROOT} intact" 606 echo '' 607 unset TEST_TEMP_ROOT 608 ;; 609 *) 610 echo '' 611 echo "invalid choice: ${DELORNOT}" 612 echo '' 613 ;; 614 esac 615 ;; 616 *) 617 # If this is an auto-run, try a hopefully safe alternative then 618 # re-test anyway. 619 TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 620 ;; 621 esac 622 else 623 unset TEST_TEMP_ROOT 624 fi 625 done 626 627 echo "*** Creating the temporary root environment in ${TEMPROOT}" 628 629 if mkdir -p "${TEMPROOT}"; then 630 echo " *** ${TEMPROOT} ready for use" 631 fi 632 633 if [ ! -d "${TEMPROOT}" ]; then 634 echo '' 635 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 636 echo '' 637 exit 1 638 fi 639 640 echo " *** Creating and populating directory structure in ${TEMPROOT}" 641 echo '' 642 643 case "${VERBOSE}" in 644 '') ;; 645 *) 646 press_to_continue 647 ;; 648 esac 649 650 case "${PRE_WORLD}" in 651 '') 652 { cd ${SOURCEDIR} && 653 case "${DESTDIR}" in 654 '') ;; 655 *) 656 ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs >/dev/null 657 ;; 658 esac 659 ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs >/dev/null && 660 ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc >/dev/null && 661 ${MM_MAKE} everything SUBDIR_OVERRIDE=etc >/dev/null && 662 ${MM_MAKE} DESTDIR=${TEMPROOT} distribution >/dev/null;} || 663 { echo ''; 664 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 665 echo " the temproot environment"; 666 echo ''; 667 exit 1;} 668 ;; 669 *) 670 # Only set up files that are crucial to {build|install}world 671 { mkdir -p ${TEMPROOT}/etc && 672 cp -p ${SOURCEDIR}/etc/master.passwd ${TEMPROOT}/etc && 673 install -p -o root -g wheel -m 0644 ${SOURCEDIR}/etc/group ${TEMPROOT}/etc;} || 674 { echo ''; 675 echo ' *** FATAL ERROR: Cannot copy files to the temproot environment'; 676 echo ''; 677 exit 1;} 678 ;; 679 esac 680 681 # Doing the inventory and removing files that we don't want to compare only 682 # makes sense if we are not doing a rerun, since we have no way of knowing 683 # what happened to the files during previous incarnations. 684 case "${VERBOSE}" in 685 '') ;; 686 *) 687 echo '' 688 echo ' *** The following files exist only in the installed version of' 689 echo " ${DESTDIR}/etc. In the vast majority of cases these files" 690 echo ' are necessary parts of the system and should not be deleted.' 691 echo ' However because these files are not updated by this process you' 692 echo ' might want to verify their status before rebooting your system.' 693 echo '' 694 press_to_continue 695 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER} 696 echo '' 697 press_to_continue 698 ;; 699 esac 700 701 case "${IGNORE_MOTD}" in 702 '') ;; 703 *) 704 echo '' 705 echo "*** You have the IGNORE_MOTD option set in your mergemaster rc file." 706 echo " This option is deprecated in favor of the IGNORE_FILES option." 707 echo " Please update your rc file accordingly." 708 echo '' 709 exit 1 710 ;; 711 esac 712 713 # Avoid comparing the following user specified files 714 for file in ${IGNORE_FILES}; do 715 test -e ${TEMPROOT}/${file} && unlink ${TEMPROOT}/${file} 716 done 717 718 # We really don't want to have to deal with files like login.conf.db, pwd.db, 719 # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb. 720 # Prompt the user to do so below, as needed. 721 # 722 rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd \ 723 ${TEMPROOT}/var/db/services.db 724 725 # We only need to compare things like freebsd.cf once 726 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null 727 728 # Delete stuff we do not need to keep the mtree database small, 729 # and to make the actual comparison faster. 730 find ${TEMPROOT}/usr -type l -delete 2>/dev/null 731 find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null 732 find -d ${TEMPROOT} -type d -empty -mindepth 1 -delete 2>/dev/null 733 734 # Build the mtree database in a temporary location. 735 case "${PRE_WORLD}" in 736 '') MTREENEW=`mktemp -t mergemaster.mtree` 737 mtree -nci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null 738 ;; 739 *) # We don't want to mess with the mtree database on a pre-world run or 740 # when re-scanning a previously-built tree. 741 ;; 742 esac 743 ;; # End of the "RERUN" test 744esac 745 746# Get ready to start comparing files 747 748# Check umask if not specified on the command line, 749# and we are not doing an autorun 750# 751if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 752 USER_UMASK=`umask` 753 case "${USER_UMASK}" in 754 0022|022) ;; 755 *) 756 echo '' 757 echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 758 echo " installs all files with the same user, group and modes that" 759 echo " they are created with by ${SOURCEDIR}/etc/Makefile, compared to" 760 echo " a umask of 022. This umask allows world read permission when" 761 echo " the file's default permissions have it." 762 echo '' 763 echo " No world permissions can sometimes cause problems. A umask of" 764 echo " 022 will restore the default behavior, but is not mandatory." 765 echo " /etc/master.passwd is a special case. Its file permissions" 766 echo " will be 600 (rw-------) if installed." 767 echo '' 768 echo -n "What umask should I use? [${USER_UMASK}] " 769 read NEW_UMASK 770 771 NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 772 ;; 773 esac 774 echo '' 775fi 776 777CONFIRMED_UMASK=${NEW_UMASK:-0022} 778 779# 780# Warn users who still have old rc files 781# 782for file in atm devfs diskless1 diskless2 network network6 pccard \ 783 serial syscons sysctl alpha amd64 i386; do 784 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 785 OLD_RC_PRESENT=1 786 break 787 fi 788done 789 790case "${OLD_RC_PRESENT}" in 7911) 792 echo '' 793 echo " *** There are elements of the old rc system in ${DESTDIR}/etc/." 794 echo '' 795 echo ' While these scripts will not hurt anything, they are not' 796 echo ' functional on an up to date system, and can be removed.' 797 echo '' 798 799 case "${AUTO_RUN}" in 800 '') 801 echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] ' 802 read MOVE_OLD_RC 803 804 case "${MOVE_OLD_RC}" in 805 [nN]*) ;; 806 *) 807 mkdir -p /var/tmp/mergemaster/old_rc 808 for file in atm devfs diskless1 diskless2 network network6 pccard \ 809 serial syscons sysctl alpha amd64 i386; do 810 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 811 mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/ 812 fi 813 done 814 echo ' The files have been moved' 815 press_to_continue 816 ;; 817 esac 818 ;; 819 *) ;; 820 esac 821esac 822 823# Use the umask/mode information to install the files 824# Create directories as needed 825# 826install_error () { 827 echo "*** FATAL ERROR: Unable to install ${1} to ${2}" 828 echo '' 829 exit 1 830} 831 832do_install_and_rm () { 833 case "${PRESERVE_FILES}" in 834 [Yy][Ee][Ss]) 835 if [ -f "${3}/${2##*/}" ]; then 836 mkdir -p ${PRESERVE_FILES_DIR}/${2%/*} 837 cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*} 838 fi 839 ;; 840 esac 841 842 if [ ! -d "${3}/${2##*/}" ]; then 843 if install -m ${1} ${2} ${3}; then 844 unlink ${2} 845 else 846 install_error ${2} ${3} 847 fi 848 else 849 install_error ${2} ${3} 850 fi 851} 852 853# 4095 = "obase=10;ibase=8;07777" | bc 854find_mode () { 855 local OCTAL 856 OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 & 857 $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) )) 858 printf "%04o\n" ${OCTAL} 859} 860 861mm_install () { 862 local INSTALL_DIR 863 INSTALL_DIR=${1#.} 864 INSTALL_DIR=${INSTALL_DIR%/*} 865 866 case "${INSTALL_DIR}" in 867 '') 868 INSTALL_DIR=/ 869 ;; 870 esac 871 872 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 873 DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"` 874 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" || 875 install_error $1 ${DESTDIR}${INSTALL_DIR} 876 fi 877 878 FILE_MODE=`find_mode "${1}"` 879 880 if [ ! -x "${1}" ]; then 881 case "${1#.}" in 882 /etc/mail/aliases) 883 NEED_NEWALIASES=yes 884 ;; 885 /usr/share/certs/trusted/* | /usr/share/certs/untrusted/*) 886 NEED_CERTCTL=yes 887 ;; 888 /etc/login.conf) 889 NEED_CAP_MKDB=yes 890 ;; 891 /etc/services) 892 NEED_SERVICES_MKDB=yes 893 ;; 894 /etc/master.passwd) 895 do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 896 NEED_PWD_MKDB=yes 897 DONT_INSTALL=yes 898 ;; 899 /.cshrc | /.profile) 900 local st_nlink 901 902 # install will unlink the file before it installs the new one, 903 # so we have to restore/create the link afterwards. 904 # 905 st_nlink=0 # In case the file does not yet exist 906 eval $(stat -s ${DESTDIR}${COMPFILE#.} 2>/dev/null) 907 908 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 909 910 if [ -n "${AUTO_INSTALL}" -a $st_nlink -gt 1 ]; then 911 HANDLE_LINK=l 912 else 913 case "${LINK_EXPLAINED}" in 914 '') 915 echo " *** Historically BSD derived systems have had a" 916 echo " hard link from /.cshrc and /.profile to" 917 echo " their namesakes in /root. Please indicate" 918 echo " your preference below for bringing your" 919 echo " installed files up to date." 920 echo '' 921 LINK_EXPLAINED=yes 922 ;; 923 esac 924 925 echo " Use 'd' to delete the temporary ${COMPFILE}" 926 echo " Use 'l' to delete the existing ${DESTDIR}/root/${COMPFILE##*/} and create the link" 927 echo '' 928 echo " Default is to leave the temporary file to deal with by hand" 929 echo '' 930 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 931 read HANDLE_LINK 932 fi 933 934 case "${HANDLE_LINK}" in 935 [dD]*) 936 rm "${COMPFILE}" 937 echo '' 938 echo " *** Deleting ${COMPFILE}" 939 ;; 940 [lL]*) 941 echo '' 942 unlink ${DESTDIR}/root/${COMPFILE##*/} 943 if ln ${DESTDIR}${COMPFILE#.} ${DESTDIR}/root/${COMPFILE##*/}; then 944 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 945 else 946 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}" 947 echo " *** ${COMPFILE} will remain for your consideration" 948 fi 949 ;; 950 *) 951 echo " *** ${COMPFILE} will remain for your consideration" 952 ;; 953 esac 954 return 955 ;; 956 esac 957 958 case "${DONT_INSTALL}" in 959 '') 960 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 961 ;; 962 *) 963 unset DONT_INSTALL 964 ;; 965 esac 966 else # File matched -x 967 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 968 fi 969 return $? 970} 971 972if [ ! -d "${TEMPROOT}" ]; then 973 echo "*** FATAL ERROR: The temproot directory (${TEMPROOT})" 974 echo ' has disappeared!' 975 echo '' 976 exit 1 977fi 978 979echo '' 980echo "*** Beginning comparison" 981echo '' 982 983# Pre-world does not populate /etc/rc.d. 984# It is very possible that a previous run would have deleted files in 985# ${TEMPROOT}/etc/rc.d, thus creating a lot of false positives. 986if [ -z "${PRE_WORLD}" -a -z "${RERUN}" ]; then 987 echo " *** Checking ${DESTDIR}/etc/rc.d for stale files" 988 echo '' 989 cd "${DESTDIR}/etc/rc.d" && 990 for file in *; do 991 if [ ! -e "${TEMPROOT}/etc/rc.d/${file}" ]; then 992 STALE_RC_FILES="${STALE_RC_FILES} ${file}" 993 fi 994 done 995 case "${STALE_RC_FILES}" in 996 ''|' *') 997 echo ' *** No stale files found' 998 ;; 999 *) 1000 echo " *** The following files exist in ${DESTDIR}/etc/rc.d but not in" 1001 echo " ${TEMPROOT}/etc/rc.d/:" 1002 echo '' 1003 echo "${STALE_RC_FILES}" 1004 echo '' 1005 echo ' The presence of stale files in this directory can cause the' 1006 echo ' dreaded unpredictable results, and therefore it is highly' 1007 echo ' recommended that you delete them.' 1008 case "${AUTO_RUN}" in 1009 '') 1010 echo '' 1011 echo -n ' *** Delete them now? [n] ' 1012 read DELETE_STALE_RC_FILES 1013 case "${DELETE_STALE_RC_FILES}" in 1014 [yY]) 1015 echo ' *** Deleting ... ' 1016 rm ${STALE_RC_FILES} 1017 echo ' done.' 1018 ;; 1019 *) 1020 echo ' *** Files will not be deleted' 1021 ;; 1022 esac 1023 sleep 2 1024 ;; 1025 *) 1026 if [ -n "${DELETE_STALE_RC_FILES}" ]; then 1027 echo ' *** Deleting ... ' 1028 rm ${STALE_RC_FILES} 1029 echo ' done.' 1030 fi 1031 esac 1032 ;; 1033 esac 1034 echo '' 1035fi 1036 1037cd "${TEMPROOT}" 1038 1039if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 1040 . "${MM_PRE_COMPARE_SCRIPT}" 1041fi 1042 1043# Things that were files/directories/links in one version can sometimes 1044# change to something else in a newer version. So we need to explicitly 1045# test for this, and warn the user if what we find does not match. 1046# 1047for COMPFILE in `find . | sort` ; do 1048 if [ -e "${DESTDIR}${COMPFILE#.}" ]; then 1049 INSTALLED_TYPE=`stat -f '%HT' ${DESTDIR}${COMPFILE#.}` 1050 else 1051 continue 1052 fi 1053 TEMPROOT_TYPE=`stat -f '%HT' $COMPFILE` 1054 1055 if [ ! "$TEMPROOT_TYPE" = "$INSTALLED_TYPE" ]; then 1056 [ "$COMPFILE" = '.' ] && continue 1057 TEMPROOT_TYPE=`echo $TEMPROOT_TYPE | tr [:upper:] [:lower:]` 1058 INSTALLED_TYPE=`echo $INSTALLED_TYPE | tr [:upper:] [:lower:]` 1059 1060 echo "*** The installed file ${DESTDIR}${COMPFILE#.} has the type \"$INSTALLED_TYPE\"" 1061 echo " but the new version has the type \"$TEMPROOT_TYPE\"" 1062 echo '' 1063 echo " How would you like to handle this?" 1064 echo '' 1065 echo " Use 'r' to remove ${DESTDIR}${COMPFILE#.}" 1066 case "$TEMPROOT_TYPE" in 1067 'symbolic link') 1068 TARGET=`readlink $COMPFILE` 1069 echo " and create a link to $TARGET in its place" ;; 1070 *) echo " You will be able to install it as a \"$TEMPROOT_TYPE\"" ;; 1071 esac 1072 echo '' 1073 echo " Use 'i' to ignore this" 1074 echo '' 1075 echo -n " How to proceed? [i] " 1076 read ANSWER 1077 case "$ANSWER" in 1078 [rR]) case "${PRESERVE_FILES}" in 1079 [Yy][Ee][Ss]) 1080 mv ${DESTDIR}${COMPFILE#.} ${PRESERVE_FILES_DIR}/ || exit 1 ;; 1081 *) rm -rf ${DESTDIR}${COMPFILE#.} ;; 1082 esac 1083 case "$TEMPROOT_TYPE" in 1084 'symbolic link') ln -sf $TARGET ${DESTDIR}${COMPFILE#.} ;; 1085 esac ;; 1086 *) echo '' 1087 echo "*** See the man page about adding ${COMPFILE#.} to the list of IGNORE_FILES" 1088 press_to_continue ;; 1089 esac 1090 echo '' 1091 fi 1092done 1093 1094# Compare regular files 1095for COMPFILE in `find . -type f | sort`; do 1096 1097 # First, check to see if the file exists in DESTDIR. If not, the 1098 # diff_loop function knows how to handle it. 1099 # 1100 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 1101 case "${AUTO_RUN}" in 1102 '') 1103 diff_loop 1104 ;; 1105 *) 1106 case "${AUTO_INSTALL}" in 1107 '') 1108 # If this is an auto run, make it official 1109 echo " *** ${COMPFILE} will remain for your consideration" 1110 ;; 1111 *) 1112 diff_loop 1113 ;; 1114 esac 1115 ;; 1116 esac # Auto run test 1117 continue 1118 fi 1119 1120 case "${STRICT}" in 1121 '' | [Nn][Oo]) 1122 # Compare $Id's first so if the file hasn't been modified 1123 # local changes will be ignored. 1124 # If the files have the same $Id, delete the one in temproot so the 1125 # user will have less to wade through if files are left to merge by hand. 1126 # 1127 ID1=`grep "[$]${ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 1128 ID2=`grep "[$]${ID_TAG}:" ${COMPFILE} 2>/dev/null` || ID2=none 1129 1130 case "${ID2}" in 1131 "${ID1}") 1132 echo " *** Temp ${COMPFILE} and installed have the same Id, deleting" 1133 rm "${COMPFILE}" 1134 ;; 1135 esac 1136 ;; 1137 esac 1138 1139 # If the file is still here either because the $Ids are different, the 1140 # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 1141 # 1142 if [ -f "${COMPFILE}" ]; then 1143 1144 # Do an absolute diff first to see if the files are actually different. 1145 # If they're not different, delete the one in temproot. 1146 # 1147 if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1148 /dev/null 2>&1; then 1149 echo " *** Temp ${COMPFILE} and installed are the same, deleting" 1150 rm "${COMPFILE}" 1151 else 1152 # Ok, the files are different, so show the user where they differ. 1153 # Use user's choice of diff methods; and user's pager if they have one. 1154 # Use less if not. 1155 # Use unified diffs by default. Context diffs give me a headache. :) 1156 # 1157 # If the user chose the -F option, test for that before proceeding 1158 # 1159 if [ -n "$FREEBSD_ID" ]; then 1160 if diff -q -I'[$]FreeBSD.*[$]' "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 1161 /dev/null 2>&1; then 1162 if mm_install "${COMPFILE}"; then 1163 echo "*** Updated revision control Id for ${DESTDIR}${COMPFILE#.}" 1164 else 1165 echo "*** Problem installing ${COMPFILE}, it will remain to merge by hand later" 1166 fi 1167 continue 1168 fi 1169 fi 1170 case "${AUTO_RUN}" in 1171 '') 1172 # prompt user to install/delete/merge changes 1173 diff_loop 1174 ;; 1175 *) 1176 # If this is an auto run, make it official 1177 echo " *** ${COMPFILE} will remain for your consideration" 1178 ;; 1179 esac # Auto run test 1180 fi # Yes, the files are different 1181 fi # Yes, the file still remains to be checked 1182done # This is for the for way up there at the beginning of the comparison 1183 1184ask_answer_for_symbolic_link () { 1185 HANDLE_COMPSYMLINK='' 1186 while true; do 1187 echo " Use 'd' to delete the temporary ${COMPSYMLINK}" 1188 echo " Use 'i' to install the temporary ${COMPSYMLINK}" 1189 echo '' 1190 echo " Default is to leave the temporary symbolic link to deal with by hand" 1191 echo '' 1192 echo -n "How should I deal with this? [Leave it for later] " 1193 read HANDLE_COMPSYMLINK 1194 case ${HANDLE_COMPSYMLINK} in 1195 ''|[dDiI]) 1196 break 1197 ;; 1198 *) 1199 echo "invalid choice: ${HANDLE_COMPSYMLINK}" 1200 echo '' 1201 HANDLE_COMPSYMLINK='' 1202 ;; 1203 esac 1204 done 1205} 1206 1207install_symbolic_link () { 1208 rm -f ${DESTDIR}${COMPSYMLINK#.} > /dev/null 2>&1 1209 if [ -L ${DESTDIR}${COMPSYMLINK#.} ]; then 1210 return 1 1211 fi 1212 cp -a ${COMPSYMLINK} ${DESTDIR}${COMPSYMLINK#.} > /dev/null 2>&1 1213 if [ ! -L ${DESTDIR}${COMPSYMLINK#.} ]; then 1214 return 1 1215 fi 1216 return 0 1217} 1218 1219handle_symbolic_link () { 1220 case ${HANDLE_COMPSYMLINK} in 1221 [dD]) 1222 rm ${COMPSYMLINK} 1223 echo '' 1224 echo " *** Deleting ${COMPSYMLINK}" 1225 echo '' 1226 return 1 1227 ;; 1228 [iI]) 1229 echo '' 1230 if install_symbolic_link; then 1231 rm ${COMPSYMLINK} 1232 echo " *** ${COMPSYMLINK} installed successfully" 1233 return 2 1234 else 1235 echo " *** Problem installing ${COMPSYMLINK}, it will remain to merge by hand" 1236 return 3 1237 fi 1238 echo '' 1239 ;; 1240 '') 1241 echo '' 1242 echo " *** ${COMPSYMLINK} will remain for your consideration" 1243 echo '' 1244 return 0 1245 ;; 1246 esac 1247} 1248 1249# Compare symbolic links 1250for COMPSYMLINK in `find . -type l | sort`; do 1251 if [ ! -L "${DESTDIR}${COMPSYMLINK#.}" ]; then 1252 if [ -n "${AUTO_RUN}" -a -z "${AUTO_INSTALL}" ]; then 1253 echo " *** ${COMPSYMLINK} will remain for your consideration" 1254 continue 1255 else 1256 echo '' 1257 echo " *** There is no installed version of ${COMPSYMLINK}" 1258 echo '' 1259 if [ -n "${AUTO_INSTALL}" ]; then 1260 HANDLE_COMPSYMLINK="i" 1261 else 1262 ask_answer_for_symbolic_link 1263 fi 1264 handle_symbolic_link 1265 if [ -n "${AUTO_INSTALL}" -a $? -eq 2 ]; then 1266 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPSYMLINK#.} 1267" 1268 fi 1269 fi 1270 elif [ $(readlink ${COMPSYMLINK}) = $(readlink ${DESTDIR}${COMPSYMLINK#.}) ]; then 1271 echo " *** Temp ${COMPSYMLINK} and installed are the same, deleting" 1272 rm ${COMPSYMLINK} 1273 else 1274 if [ -n "${AUTO_RUN}" -a -z "${AUTO_UPGRADE}" ]; then 1275 echo " *** ${COMPSYMLINK} will remain for your consideration" 1276 continue 1277 else 1278 echo '' 1279 echo " *** Target of temp symbolic link is different from that of installed one" 1280 echo " Temp (${COMPSYMLINK}): $(readlink ${COMPSYMLINK})" 1281 echo " Installed (${DESTDIR}${COMPSYMLINK#.})): $(readlink ${DESTDIR}${COMPSYMLINK#.})" 1282 echo '' 1283 if [ -n "${AUTO_UPGRADE}" ]; then 1284 HANDLE_COMPSYMLINK="i" 1285 else 1286 ask_answer_for_symbolic_link 1287 fi 1288 handle_symbolic_link 1289 if [ -n "${AUTO_UPGRADE}" -a $? -eq 2 ]; then 1290 AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES} ${DESTDIR}${COMPSYMLINK#.} 1291" 1292 fi 1293 fi 1294 fi 1295done 1296 1297echo '' 1298echo "*** Comparison complete" 1299 1300if [ -s "${MTREENEW}" ]; then 1301 echo "*** Saving mtree database for future upgrades" 1302 test -e "${MTREEFILE}" && unlink ${MTREEFILE} 1303 mv ${MTREENEW} ${MTREEFILE} 1304fi 1305 1306echo '' 1307 1308TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 -or -type l 2>/dev/null` 1309if [ -n "${TEST_FOR_FILES}" ]; then 1310 echo "*** Files that remain for you to merge by hand:" 1311 find "${TEMPROOT}" -type f -size +0 -or -type l | sort 1312 echo '' 1313 1314 case "${AUTO_RUN}" in 1315 '') 1316 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 1317 read DEL_TEMPROOT 1318 case "${DEL_TEMPROOT}" in 1319 [yY]*) 1320 delete_temproot 1321 ;; 1322 *) 1323 echo " *** ${TEMPROOT} will remain" 1324 ;; 1325 esac 1326 ;; 1327 *) ;; 1328 esac 1329else 1330 echo "*** ${TEMPROOT} is empty, deleting" 1331 delete_temproot 1332fi 1333 1334case "${AUTO_INSTALLED_FILES}" in 1335'') ;; 1336*) 1337 case "${AUTO_RUN}" in 1338 '') 1339 ( 1340 echo '' 1341 echo '*** You chose the automatic install option for files that did not' 1342 echo ' exist on your system. The following were installed for you:' 1343 echo "${AUTO_INSTALLED_FILES}" 1344 ) | ${PAGER} 1345 ;; 1346 *) 1347 echo '' 1348 echo '*** You chose the automatic install option for files that did not' 1349 echo ' exist on your system. The following were installed for you:' 1350 echo "${AUTO_INSTALLED_FILES}" 1351 ;; 1352 esac 1353 ;; 1354esac 1355 1356case "${AUTO_UPGRADED_FILES}" in 1357'') ;; 1358*) 1359 case "${AUTO_RUN}" in 1360 '') 1361 ( 1362 echo '' 1363 echo '*** You chose the automatic upgrade option for files that you did' 1364 echo ' not alter on your system. The following were upgraded for you:' 1365 echo "${AUTO_UPGRADED_FILES}" 1366 ) | ${PAGER} 1367 ;; 1368 *) 1369 echo '' 1370 echo '*** You chose the automatic upgrade option for files that you did' 1371 echo ' not alter on your system. The following were upgraded for you:' 1372 echo "${AUTO_UPGRADED_FILES}" 1373 ;; 1374 esac 1375 ;; 1376esac 1377 1378run_it_now () { 1379 [ -n "$AUTO_RUN" ] && return 1380 1381 local answer 1382 1383 echo '' 1384 while : ; do 1385 if [ "$RUN_UPDATES" = always ]; then 1386 answer=y 1387 elif [ "$RUN_UPDATES" = never ]; then 1388 answer=n 1389 else 1390 echo -n ' Would you like to run it now? y or n [n] ' 1391 read answer 1392 fi 1393 1394 case "$answer" in 1395 y) 1396 echo " Running ${1}" 1397 echo '' 1398 eval "${1}" 1399 return 1400 ;; 1401 ''|n) 1402 if [ ! "$RUN_UPDATES" = never ]; then 1403 echo '' 1404 echo " *** Cancelled" 1405 echo '' 1406 fi 1407 echo " Make sure to run ${1} yourself" 1408 return 1409 ;; 1410 *) 1411 echo '' 1412 echo " *** Sorry, I do not understand your answer (${answer})" 1413 echo '' 1414 esac 1415 done 1416} 1417 1418case "${NEED_NEWALIASES}" in 1419'') ;; 1420*) 1421 echo '' 1422 if [ -n "${DESTDIR}" ]; then 1423 echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but" 1424 echo " the newaliases command is limited to the directories configured" 1425 echo " in sendmail.cf. Make sure to create your aliases database by" 1426 echo " hand when your sendmail configuration is done." 1427 else 1428 echo "*** You installed a new aliases file, so make sure that you run" 1429 echo " '/usr/bin/newaliases' to rebuild your aliases database" 1430 run_it_now '/usr/bin/newaliases' 1431 fi 1432 ;; 1433esac 1434 1435case "${NEED_CAP_MKDB}" in 1436'') ;; 1437*) 1438 echo '' 1439 echo "*** You installed a login.conf file, so make sure that you run" 1440 echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'" 1441 echo " to rebuild your login.conf database" 1442 run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf" 1443 ;; 1444esac 1445 1446case "${NEED_SERVICES_MKDB}" in 1447'') ;; 1448*) 1449 echo '' 1450 echo "*** You installed a services file, so make sure that you run" 1451 echo " '/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services'" 1452 echo " to rebuild your services database" 1453 run_it_now "/usr/sbin/services_mkdb -q -o ${DESTDIR}/var/db/services.db ${DESTDIR}/etc/services" 1454 ;; 1455esac 1456 1457case "${NEED_PWD_MKDB}" in 1458'') ;; 1459*) 1460 echo '' 1461 echo "*** You installed a new master.passwd file, so make sure that you run" 1462 if [ -n "${DESTDIR}" ]; then 1463 echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'" 1464 echo " to rebuild your password files" 1465 run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd" 1466 else 1467 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'" 1468 echo " to rebuild your password files" 1469 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 1470 fi 1471 ;; 1472esac 1473 1474case "${NEED_CERTCTL}" in 1475'') ;; 1476*) 1477 echo '' 1478 echo "*** You installed files in /etc/ssl/certs, so make sure that you run" 1479 if [ -n "${DESTDIR}" ]; then 1480 echo " 'env DESTDIR=${DESTDIR} /usr/sbin/certctl rehash'" 1481 echo " to rebuild your certificate authority database" 1482 run_it_now "env DESTDIR=${DESTDIR} /usr/sbin/certctl rehash" 1483 else 1484 echo " '/usr/sbin/certctl rehash'" 1485 echo " to rebuild your certificate authority database" 1486 run_it_now "/usr/sbin/certctl rehash" 1487 fi 1488 ;; 1489esac 1490 1491if [ -e "${DESTDIR}/etc/localtime" -a ! -L "${DESTDIR}/etc/localtime" -a -z "${PRE_WORLD}" ]; then # Ignore if TZ == UTC 1492 echo '' 1493 [ -n "${DESTDIR}" ] && tzs_args="-C ${DESTDIR}" 1494 if [ -f "${DESTDIR}/var/db/zoneinfo" ]; then 1495 echo "*** Reinstalling `cat ${DESTDIR}/var/db/zoneinfo` as ${DESTDIR}/etc/localtime" 1496 tzsetup $tzs_args -r 1497 else 1498 echo "*** There is no ${DESTDIR}/var/db/zoneinfo file to update ${DESTDIR}/etc/localtime." 1499 echo ' You should run tzsetup' 1500 run_it_now "tzsetup $tzs_args" 1501 fi 1502fi 1503 1504echo '' 1505 1506if [ -r "${MM_EXIT_SCRIPT}" ]; then 1507 . "${MM_EXIT_SCRIPT}" 1508fi 1509 1510case "${COMP_CONFS}" in 1511'') ;; 1512*) 1513 . ${DESTDIR}/etc/defaults/rc.conf 1514 1515 (echo '' 1516 echo "*** Comparing conf files: ${rc_conf_files}" 1517 1518 for CONF_FILE in ${rc_conf_files}; do 1519 if [ -r "${DESTDIR}${CONF_FILE}" ]; then 1520 echo '' 1521 echo "*** From ${DESTDIR}${CONF_FILE}" 1522 echo "*** From ${DESTDIR}/etc/defaults/rc.conf" 1523 1524 for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} | 1525 cut -d '=' -f 1`; do 1526 echo '' 1527 grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE} 1528 grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf || 1529 echo ' * No default variable with this name' 1530 done 1531 fi 1532 done) | ${PAGER} 1533 echo '' 1534 ;; 1535esac 1536 1537if [ -n "${PRESERVE_FILES}" ]; then 1538 find -d $PRESERVE_FILES_DIR -type d -empty -delete 2>/dev/null 1539 rmdir $PRESERVE_FILES_DIR 2>/dev/null 1540fi 1541 1542exit 0 1543 1544#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1545 1546# Copyright (c) 1998-2012 Douglas Barton 1547# All rights reserved. 1548# 1549# Redistribution and use in source and binary forms, with or without 1550# modification, are permitted provided that the following conditions 1551# are met: 1552# 1. Redistributions of source code must retain the above copyright 1553# notice, this list of conditions and the following disclaimer. 1554# 2. Redistributions in binary form must reproduce the above copyright 1555# notice, this list of conditions and the following disclaimer in the 1556# documentation and/or other materials provided with the distribution. 1557# 1558# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1559# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1560# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1561# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1562# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1563# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1564# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1565# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1566# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1567# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1568# SUCH DAMAGE. 1569