mergemaster.sh revision 114565
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 1998-2003 Douglas Barton 9# DougB@FreeBSD.org 10 11# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 114565 2003-05-03 06:35:19Z dougb $ 12 13PATH=/bin:/usr/bin:/usr/sbin 14 15display_usage () { 16 VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4` 17 echo "mergemaster version ${VERSION_NUMBER}" 18 echo 'Usage: mergemaster [-scrvahipCP] [-m /path]' 19 echo ' [-t /path] [-d] [-u N] [-w N] [-D /path]' 20 echo "Options:" 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 ' -C Compare local rc.conf variables to the defaults' 30 echo ' -P Preserve files that are overwritten' 31 echo " -m /path/directory Specify location of source to do the make in" 32 echo " -t /path/directory Specify temp root directory" 33 echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" 34 echo " -u N Specify a numeric umask" 35 echo " -w N Specify a screen width in columns to sdiff" 36 echo ' -D /path/directory Specify the destination directory to install files to' 37 echo '' 38} 39 40display_help () { 41 echo "* To specify a directory other than /var/tmp/temproot for the" 42 echo " temporary root environment, use -t /path/to/temp/root" 43 echo "* The -w option takes a number as an argument for the column width" 44 echo " of the screen. The default is 80." 45 echo '* The -a option causes mergemaster to run without prompting.' 46} 47 48# Loop allowing the user to use sdiff to merge files and display the merged 49# file. 50merge_loop () { 51 case "${VERBOSE}" in 52 '') ;; 53 *) 54 echo " *** Type h at the sdiff prompt (%) to get usage help" 55 ;; 56 esac 57 echo '' 58 MERGE_AGAIN=yes 59 while [ "${MERGE_AGAIN}" = "yes" ]; do 60 # Prime file.merged so we don't blat the owner/group id's 61 cp -p "${COMPFILE}" "${COMPFILE}.merged" 62 sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 63 --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 64 INSTALL_MERGED=V 65 while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 66 echo '' 67 echo " Use 'i' to install merged file" 68 echo " Use 'r' to re-do the merge" 69 echo " Use 'v' to view the merged file" 70 echo " Default is to leave the temporary file to deal with by hand" 71 echo '' 72 echo -n " *** How should I deal with the merged file? [Leave it for later] " 73 read INSTALL_MERGED 74 75 case "${INSTALL_MERGED}" in 76 [iI]) 77 mv "${COMPFILE}.merged" "${COMPFILE}" 78 echo '' 79 if mm_install "${COMPFILE}"; then 80 echo " *** Merged version of ${COMPFILE} installed successfully" 81 else 82 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 83 fi 84 unset MERGE_AGAIN 85 ;; 86 [rR]) 87 rm "${COMPFILE}.merged" 88 ;; 89 [vV]) 90 ${PAGER} "${COMPFILE}.merged" 91 ;; 92 '') 93 echo " *** ${COMPFILE} will remain for your consideration" 94 unset MERGE_AGAIN 95 ;; 96 *) 97 echo "invalid choice: ${INSTALL_MERGED}" 98 INSTALL_MERGED=V 99 ;; 100 esac 101 done 102 done 103} 104 105# Loop showing user differences between files, allow merge, skip or install 106# options 107diff_loop () { 108 109 HANDLE_COMPFILE=v 110 111 while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \ 112 "${HANDLE_COMPFILE}" = "NOT V" ]; do 113 if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 114 if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 115 echo '' 116 echo ' ====================================================================== ' 117 echo '' 118 ( 119 echo " *** Displaying differences between ${COMPFILE} and installed version:" 120 echo '' 121 diff ${DIFF_FLAG} ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 122 ) | ${PAGER} 123 echo '' 124 fi 125 else 126 echo '' 127 echo " *** There is no installed version of ${COMPFILE}" 128 echo '' 129 case "${AUTO_INSTALL}" in 130 [Yy][Ee][Ss]) 131 echo '' 132 if mm_install "${COMPFILE}"; then 133 echo " *** ${COMPFILE} installed successfully" 134 echo '' 135 # Make the list print one file per line 136 AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 137" 138 else 139 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 140 fi 141 return 142 ;; 143 *) 144 NO_INSTALLED=yes 145 ;; 146 esac 147 fi 148 149 echo " Use 'd' to delete the temporary ${COMPFILE}" 150 echo " Use 'i' to install the temporary ${COMPFILE}" 151 case "${NO_INSTALLED}" in 152 '') 153 echo " Use 'm' to merge the temporary and installed versions" 154 echo " Use 'v' to view the diff results again" 155 ;; 156 esac 157 echo '' 158 echo " Default is to leave the temporary file to deal with by hand" 159 echo '' 160 echo -n "How should I deal with this? [Leave it for later] " 161 read HANDLE_COMPFILE 162 163 case "${HANDLE_COMPFILE}" in 164 [dD]) 165 rm "${COMPFILE}" 166 echo '' 167 echo " *** Deleting ${COMPFILE}" 168 ;; 169 [iI]) 170 echo '' 171 if mm_install "${COMPFILE}"; then 172 echo " *** ${COMPFILE} installed successfully" 173 else 174 echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 175 fi 176 ;; 177 [mM]) 178 case "${NO_INSTALLED}" in 179 '') 180 # interact with user to merge files 181 merge_loop 182 ;; 183 *) 184 echo '' 185 echo " *** There is no installed version of ${COMPFILE}" 186 echo '' 187 HANDLE_COMPFILE="NOT V" 188 ;; 189 esac # End of "No installed version of file but user selected merge" test 190 ;; 191 [vV]) 192 continue 193 ;; 194 '') 195 echo '' 196 echo " *** ${COMPFILE} will remain for your consideration" 197 ;; 198 *) 199 # invalid choice, show menu again. 200 echo "invalid choice: ${HANDLE_COMPFILE}" 201 echo '' 202 HANDLE_COMPFILE="NOT V" 203 continue 204 ;; 205 esac # End of "How to handle files that are different" 206 done 207 unset NO_INSTALLED 208 echo '' 209 case "${VERBOSE}" in 210 '') ;; 211 *) 212 sleep 3 213 ;; 214 esac 215} 216 217press_to_continue () { 218 local DISCARD 219 echo -n ' *** Press the [Enter] or [Return] key to continue ' 220 read DISCARD 221} 222 223# Set the default path for the temporary root environment 224# 225TEMPROOT='/var/tmp/temproot' 226 227# Read /etc/mergemaster.rc first so the one in $HOME can override 228# 229if [ -r /etc/mergemaster.rc ]; then 230 . /etc/mergemaster.rc 231fi 232 233# Read .mergemasterrc before command line so CLI can override 234# 235if [ -r "$HOME/.mergemasterrc" ]; then 236 . "$HOME/.mergemasterrc" 237fi 238 239# Check the command line options 240# 241while getopts ":ascrvhipCPm:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do 242 case "${COMMAND_LINE_ARGUMENT}" in 243 s) 244 STRICT=yes 245 unset DIFF_OPTIONS 246 ;; 247 c) 248 DIFF_FLAG='-c' 249 ;; 250 r) 251 RERUN=yes 252 ;; 253 v) 254 case "${AUTO_RUN}" in 255 '') VERBOSE=yes ;; 256 esac 257 ;; 258 a) 259 AUTO_RUN=yes 260 unset VERBOSE 261 ;; 262 h) 263 display_usage 264 display_help 265 exit 0 266 ;; 267 i) 268 AUTO_INSTALL=yes 269 ;; 270 C) 271 COMP_CONFS=yes 272 ;; 273 P) 274 PRESERVE_FILES=yes 275 ;; 276 p) 277 PRE_WORLD=yes 278 unset COMP_CONFS 279 unset AUTO_RUN 280 ;; 281 m) 282 SOURCEDIR=${OPTARG} 283 ;; 284 t) 285 TEMPROOT=${OPTARG} 286 ;; 287 d) 288 TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 289 ;; 290 u) 291 NEW_UMASK=${OPTARG} 292 ;; 293 w) 294 SCREEN_WIDTH=${OPTARG} 295 ;; 296 D) 297 DESTDIR=${OPTARG} 298 ;; 299 *) 300 display_usage 301 exit 1 302 ;; 303 esac 304done 305 306# Don't force the user to set this in the mergemaster rc file 307if [ -n "${PRESERVE_FILES}" -a -z "${PRESERVE_FILES_DIR}" ]; then 308 PRESERVE_FILES_DIR=/var/tmp/mergemaster/preserved-files-`date +%y%m%d-%H%M%S` 309fi 310 311echo '' 312 313# If the user has a pager defined, make sure we can run it 314# 315case "${DONT_CHECK_PAGER}" in 316'') 317 while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do 318 echo " *** Your PAGER environment variable specifies '${PAGER}', but" 319 echo " due to the limited PATH that I use for security reasons," 320 echo " I cannot execute it. So, what would you like to do?" 321 echo '' 322 echo " Use 'e' to exit mergemaster and fix your PAGER variable" 323 if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 324 echo " Use 'l' to set PAGER to 'less' for this run" 325 fi 326 echo " Use 'm' to use plain old 'more' as your PAGER for this run" 327 echo '' 328 echo " Default is to use plain old 'more' " 329 echo '' 330 echo -n "What should I do? [Use 'more'] " 331 read FIXPAGER 332 333 case "${FIXPAGER}" in 334 [eE]) 335 exit 0 336 ;; 337 [lL]) 338 if [ -x /usr/bin/less ]; then 339 PAGER=/usr/bin/less 340 elif [ -x /usr/local/bin/less ]; then 341 PAGER=/usr/local/bin/less 342 else 343 echo '' 344 echo " *** Fatal Error:" 345 echo " You asked to use 'less' as your pager, but I can't" 346 echo " find it in /usr/bin or /usr/local/bin" 347 exit 1 348 fi 349 ;; 350 [mM]|'') 351 PAGER=more 352 ;; 353 *) 354 echo '' 355 echo "invalid choice: ${FIXPAGER}" 356 esac 357 echo '' 358 done 359 ;; 360esac 361 362# If user has a pager defined, or got assigned one above, use it. 363# If not, use more. 364# 365PAGER=${PAGER:-more} 366 367if [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 368 echo " *** You have ${PAGER} defined as your pager so we will use that" 369 echo '' 370 sleep 3 371fi 372 373# Assign the diff flag once so we will not have to keep testing it 374# 375DIFF_FLAG=${DIFF_FLAG:--u} 376 377# Assign the source directory 378# 379SOURCEDIR=${SOURCEDIR:-/usr/src/etc} 380 381# Check the width of the user's terminal 382# 383if [ -t 0 ]; then 384 w=`tput columns` 385 case "${w}" in 386 0|'') ;; # No-op, since the input is not valid 387 *) 388 case "${SCREEN_WIDTH}" in 389 '') SCREEN_WIDTH="${w}" ;; 390 "${w}") ;; # No-op, since they are the same 391 *) 392 echo -n "*** You entered ${SCREEN_WIDTH} as your screen width, but stty " 393 echo "thinks it is ${w}." 394 echo '' 395 echo -n "What would you like to use? [${w}] " 396 read SCREEN_WIDTH 397 case "${SCREEN_WIDTH}" in 398 '') SCREEN_WIDTH="${w}" ;; 399 esac 400 ;; 401 esac 402 esac 403fi 404 405# Define what CVS $Id tag to look for to aid portability. 406# 407CVS_ID_TAG=FreeBSD 408 409delete_temproot () { 410 rm -rf "${TEMPROOT}" 2>/dev/null 411 chflags -R 0 "${TEMPROOT}" 2>/dev/null 412 rm -rf "${TEMPROOT}" || exit 1 413} 414 415case "${RERUN}" in 416'') 417 # Set up the loop to test for the existence of the 418 # temp root directory. 419 # 420 TEST_TEMP_ROOT=yes 421 while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 422 if [ -d "${TEMPROOT}" ]; then 423 echo "*** The directory specified for the temporary root environment," 424 echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 425 echo " users have access to the system." 426 echo '' 427 case "${AUTO_RUN}" in 428 '') 429 echo " Use 'd' to delete the old ${TEMPROOT} and continue" 430 echo " Use 't' to select a new temporary root directory" 431 echo " Use 'e' to exit mergemaster" 432 echo '' 433 echo " Default is to use ${TEMPROOT} as is" 434 echo '' 435 echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 436 read DELORNOT 437 438 case "${DELORNOT}" in 439 [dD]) 440 echo '' 441 echo " *** Deleting the old ${TEMPROOT}" 442 echo '' 443 delete_temproot || exit 1 444 unset TEST_TEMP_ROOT 445 ;; 446 [tT]) 447 echo " *** Enter new directory name for temporary root environment" 448 read TEMPROOT 449 ;; 450 [eE]) 451 exit 0 452 ;; 453 '') 454 echo '' 455 echo " *** Leaving ${TEMPROOT} intact" 456 echo '' 457 unset TEST_TEMP_ROOT 458 ;; 459 *) 460 echo '' 461 echo "invalid choice: ${DELORNOT}" 462 echo '' 463 ;; 464 esac 465 ;; 466 *) 467 # If this is an auto-run, try a hopefully safe alternative then 468 # re-test anyway. 469 TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 470 ;; 471 esac 472 else 473 unset TEST_TEMP_ROOT 474 fi 475 done 476 477 echo "*** Creating the temporary root environment in ${TEMPROOT}" 478 479 if mkdir -p "${TEMPROOT}"; then 480 echo " *** ${TEMPROOT} ready for use" 481 fi 482 483 if [ ! -d "${TEMPROOT}" ]; then 484 echo '' 485 echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 486 echo '' 487 exit 1 488 fi 489 490 echo " *** Creating and populating directory structure in ${TEMPROOT}" 491 echo '' 492 493 case "${VERBOSE}" in 494 '') ;; 495 *) 496 press_to_continue 497 ;; 498 esac 499 500 case "${PRE_WORLD}" in 501 '') 502 { cd ${SOURCEDIR} && 503 case "${DESTDIR}" in 504 '') ;; 505 *) 506 make DESTDIR=${DESTDIR} distrib-dirs 507 ;; 508 esac 509 make DESTDIR=${TEMPROOT} distrib-dirs && 510 make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj obj && 511 make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj DESTDIR=${TEMPROOT} \ 512 distribution;} || 513 { echo ''; 514 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 515 echo " the temproot environment"; 516 echo ''; 517 exit 1;} 518 ;; 519 *) 520 # Only set up files that are crucial to {build|install}world 521 { mkdir -p ${TEMPROOT}/etc && 522 cp -p ${SOURCEDIR}/master.passwd ${TEMPROOT}/etc && 523 cp -p ${SOURCEDIR}/group ${TEMPROOT}/etc;} || 524 { echo ''; 525 echo ' *** FATAL ERROR: Cannot copy files to the temproot environment'; 526 echo ''; 527 exit 1;} 528 ;; 529 esac 530 531 # Doing the inventory and removing files that we don't want to compare only 532 # makes sense if we are not doing a rerun, since we have no way of knowing 533 # what happened to the files during previous incarnations. 534 case "${VERBOSE}" in 535 '') ;; 536 *) 537 echo '' 538 echo ' *** The following files exist only in the installed version of' 539 echo " ${DESTDIR}/etc. In the vast majority of cases these files" 540 echo ' are necessary parts of the system and should not be deleted.' 541 echo ' However because these files are not updated by this process you' 542 echo ' might want to verify their status before rebooting your system.' 543 echo '' 544 press_to_continue 545 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in ${DESTDIR}/etc" | ${PAGER} 546 echo '' 547 press_to_continue 548 ;; 549 esac 550 551 # Avoid comparing the motd if the user specifies it in .mergemasterrc 552 case "${IGNORE_MOTD}" in 553 '') ;; 554 *) rm -f ${TEMPROOT}/etc/motd 555 ;; 556 esac 557 558 # Avoid trying to update MAKEDEV if /dev is on a devfs 559 if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 560 rm -f ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local 561 fi 562 563 ;; # End of the "RERUN" test 564esac 565 566# We really don't want to have to deal with files like login.conf.db, pwd.db, 567# or spwd.db. Instead, we want to compare the text versions, and run *_mkdb. 568# Prompt the user to do so below, as needed. 569# 570rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd 571 572# We only need to compare things like freebsd.cf once 573find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null 574 575# Get ready to start comparing files 576 577# Check umask if not specified on the command line, 578# and we are not doing an autorun 579# 580if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 581 USER_UMASK=`umask` 582 case "${USER_UMASK}" in 583 0022|022) ;; 584 *) 585 echo '' 586 echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 587 echo " installs all files with the same user, group and modes that" 588 echo " they are created with by ${SOURCEDIR}/Makefile, compared to" 589 echo " a umask of 022. This umask allows world read permission when" 590 echo " the file's default permissions have it." 591 echo '' 592 echo " No world permissions can sometimes cause problems. A umask of" 593 echo " 022 will restore the default behavior, but is not mandatory." 594 echo " /etc/master.passwd is a special case. Its file permissions" 595 echo " will be 600 (rw-------) if installed." 596 echo '' 597 echo -n "What umask should I use? [${USER_UMASK}] " 598 read NEW_UMASK 599 600 NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 601 ;; 602 esac 603 echo '' 604fi 605 606CONFIRMED_UMASK=${NEW_UMASK:-0022} 607 608# 609# Warn users who still have old rc files 610# 611for file in atm devfs diskless1 diskless2 isdn network network6 pccard \ 612 serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 613 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 614 OLD_RC_PRESENT=1 615 break 616 fi 617done 618 619case "${OLD_RC_PRESENT}" in 6201) 621 echo '' 622 echo " *** There are elements of the old rc system in ${DESTDIR}/etc/." 623 echo '' 624 echo ' While these scripts will not hurt anything, they are not' 625 echo ' functional on an up to date system, and can be removed.' 626 echo '' 627 628 case "${AUTO_RUN}" in 629 '') 630 echo -n 'Move these files to /var/tmp/mergemaster/old_rc? [yes] ' 631 read MOVE_OLD_RC 632 633 case "${MOVE_OLD_RC}" in 634 [nN]*) ;; 635 *) 636 mkdir -p /var/tmp/mergemaster/old_rc 637 for file in atm devfs diskless1 diskless2 isdn network network6 pccard \ 638 serial syscons sysctl alpha amd64 i386 ia64 sparc64; do 639 if [ -f "${DESTDIR}/etc/rc.${file}" ]; then 640 mv ${DESTDIR}/etc/rc.${file} /var/tmp/mergemaster/old_rc/ 641 fi 642 done 643 echo ' The files have been moved' 644 press_to_continue 645 ;; 646 esac 647 ;; 648 *) ;; 649 esac 650esac 651 652# Use the umask/mode information to install the files 653# Create directories as needed 654# 655do_install_and_rm () { 656 case "${PRESERVE_FILES}" in 657 [Yy][Ee][Ss]) 658 if [ -f "${3}/${2##*/}" ]; then 659 mkdir -p ${PRESERVE_FILES_DIR}/${2%/*} 660 cp ${3}/${2##*/} ${PRESERVE_FILES_DIR}/${2%/*} 661 fi 662 ;; 663 esac 664 665 install -m "${1}" "${2}" "${3}" && 666 rm -f "${2}" 667} 668 669# 4095 = "obase=10;ibase=8;07777" | bc 670find_mode () { 671 local OCTAL 672 OCTAL=$(( ~$(echo "obase=10; ibase=8; ${CONFIRMED_UMASK}" | bc) & 4095 & 673 $(echo "obase=10; ibase=8; $(stat -f "%OMp%OLp" ${1})" | bc) )) 674 printf "%04o\n" ${OCTAL} 675} 676 677mm_install () { 678 local INSTALL_DIR 679 INSTALL_DIR=${1#.} 680 INSTALL_DIR=${INSTALL_DIR%/*} 681 682 case "${INSTALL_DIR}" in 683 '') 684 INSTALL_DIR=/ 685 ;; 686 esac 687 688 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 689 DIR_MODE=`find_mode "${TEMPROOT}/${INSTALL_DIR}"` 690 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" 691 fi 692 693 FILE_MODE=`find_mode "${1}"` 694 695 if [ ! -x "${1}" ]; then 696 case "${1#.}" in 697 /etc/mail/aliases) 698 NEED_NEWALIASES=yes 699 ;; 700 /etc/login.conf) 701 NEED_CAP_MKDB=yes 702 ;; 703 /etc/master.passwd) 704 do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 705 NEED_PWD_MKDB=yes 706 DONT_INSTALL=yes 707 ;; 708 /.cshrc | /.profile) 709 case "${AUTO_INSTALL}" in 710 '') 711 case "${LINK_EXPLAINED}" in 712 '') 713 echo " *** Historically BSD derived systems have had a" 714 echo " hard link from /.cshrc and /.profile to" 715 echo " their namesakes in /root. Please indicate" 716 echo " your preference below for bringing your" 717 echo " installed files up to date." 718 echo '' 719 LINK_EXPLAINED=yes 720 ;; 721 esac 722 723 echo " Use 'd' to delete the temporary ${COMPFILE}" 724 echo " Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link" 725 echo '' 726 echo " Default is to leave the temporary file to deal with by hand" 727 echo '' 728 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 729 read HANDLE_LINK 730 ;; 731 *) # Part of AUTO_INSTALL 732 HANDLE_LINK=l 733 ;; 734 esac 735 736 case "${HANDLE_LINK}" in 737 [dD]*) 738 rm "${COMPFILE}" 739 echo '' 740 echo " *** Deleting ${COMPFILE}" 741 ;; 742 [lL]*) 743 echo '' 744 rm -f "${DESTDIR}${COMPFILE#.}" 745 if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then 746 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 747 rm "${COMPFILE}" 748 else 749 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand" 750 fi 751 ;; 752 *) 753 echo " *** ${COMPFILE} will remain for your consideration" 754 ;; 755 esac 756 DONT_INSTALL=yes 757 ;; 758 esac 759 760 case "${DONT_INSTALL}" in 761 '') 762 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 763 ;; 764 *) 765 unset DONT_INSTALL 766 ;; 767 esac 768 else # File matched -x 769 case "${1#.}" in 770 /dev/MAKEDEV) 771 NEED_MAKEDEV=yes 772 ;; 773 esac 774 do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 775 fi 776 return $? 777} 778 779echo '' 780echo "*** Beginning comparison" 781echo '' 782 783cd "${TEMPROOT}" 784 785if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 786 . "${MM_PRE_COMPARE_SCRIPT}" 787fi 788 789# Using -size +0 avoids uselessly checking the empty log files created 790# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does 791# check the scripts in ./dev, as we'd like (assuming no devfs of course). 792# 793for COMPFILE in `find . -type f -size +0`; do 794 795 # First, check to see if the file exists in DESTDIR. If not, the 796 # diff_loop function knows how to handle it. 797 # 798 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 799 case "${AUTO_RUN}" in 800 '') 801 diff_loop 802 ;; 803 *) 804 case "${AUTO_INSTALL}" in 805 '') 806 # If this is an auto run, make it official 807 echo " *** ${COMPFILE} will remain for your consideration" 808 ;; 809 *) 810 diff_loop 811 ;; 812 esac 813 ;; 814 esac # Auto run test 815 continue 816 fi 817 818 case "${STRICT}" in 819 '' | [Nn][Oo]) 820 # Compare CVS $Id's first so if the file hasn't been modified 821 # local changes will be ignored. 822 # If the files have the same $Id, delete the one in temproot so the 823 # user will have less to wade through if files are left to merge by hand. 824 # 825 CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 826 CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none 827 828 case "${CVSID2}" in 829 "${CVSID1}") 830 echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 831 rm "${COMPFILE}" 832 ;; 833 esac 834 ;; 835 esac 836 837 # If the file is still here either because the $Ids are different, the 838 # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 839 # 840 if [ -f "${COMPFILE}" ]; then 841 842 # Do an absolute diff first to see if the files are actually different. 843 # If they're not different, delete the one in temproot. 844 # 845 if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > \ 846 /dev/null 2>&1; then 847 echo " *** Temp ${COMPFILE} and installed are the same, deleting" 848 rm "${COMPFILE}" 849 else 850 # Ok, the files are different, so show the user where they differ. 851 # Use user's choice of diff methods; and user's pager if they have one. 852 # Use more if not. 853 # Use unified diffs by default. Context diffs give me a headache. :) 854 # 855 case "${AUTO_RUN}" in 856 '') 857 # prompt user to install/delete/merge changes 858 diff_loop 859 ;; 860 *) 861 # If this is an auto run, make it official 862 echo " *** ${COMPFILE} will remain for your consideration" 863 ;; 864 esac # Auto run test 865 fi # Yes, the files are different 866 fi # Yes, the file still remains to be checked 867done # This is for the do way up there at the beginning of the comparison 868 869echo '' 870echo "*** Comparison complete" 871echo '' 872 873TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 874if [ -n "${TEST_FOR_FILES}" ]; then 875 echo "*** Files that remain for you to merge by hand:" 876 find "${TEMPROOT}" -type f -size +0 877 echo '' 878fi 879 880case "${AUTO_RUN}" in 881'') 882 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 883 read DEL_TEMPROOT 884 885 case "${DEL_TEMPROOT}" in 886 [yY]*) 887 if delete_temproot; then 888 echo " *** ${TEMPROOT} has been deleted" 889 else 890 echo " *** Unable to delete ${TEMPROOT}" 891 fi 892 ;; 893 *) 894 echo " *** ${TEMPROOT} will remain" 895 ;; 896 esac 897 ;; 898*) ;; 899esac 900 901case "${AUTO_INSTALLED_FILES}" in 902'') ;; 903*) 904 case "${AUTO_RUN}" in 905 '') 906 ( 907 echo '' 908 echo '*** You chose the automatic install option for files that did not' 909 echo ' exist on your system. The following were installed for you:' 910 echo "${AUTO_INSTALLED_FILES}" 911 ) | ${PAGER} 912 ;; 913 *) 914 echo '' 915 echo '*** You chose the automatic install option for files that did not' 916 echo ' exist on your system. The following were installed for you:' 917 echo "${AUTO_INSTALLED_FILES}" 918 ;; 919 esac 920 ;; 921esac 922 923run_it_now () { 924 case "${AUTO_RUN}" in 925 '') 926 unset YES_OR_NO 927 echo '' 928 echo -n ' Would you like to run it now? y or n [n] ' 929 read YES_OR_NO 930 931 case "${YES_OR_NO}" in 932 y) 933 echo " Running ${1}" 934 echo '' 935 eval "${1}" 936 ;; 937 ''|n) 938 echo '' 939 echo " *** Cancelled" 940 echo '' 941 echo " Make sure to run ${1} yourself" 942 ;; 943 *) 944 echo '' 945 echo " *** Sorry, I do not understand your answer (${YES_OR_NO})" 946 echo '' 947 echo " Make sure to run ${1} yourself" 948 esac 949 ;; 950 *) ;; 951 esac 952} 953 954case "${NEED_MAKEDEV}" in 955'') ;; 956*) 957 echo '' 958 echo "*** You installed a new ${DESTDIR}/dev/MAKEDEV script, so make sure that you run" 959 echo " 'cd ${DESTDIR}/dev && /bin/sh MAKEDEV all' to rebuild your devices" 960 run_it_now "cd ${DESTDIR}/dev && /bin/sh MAKEDEV all" 961 ;; 962esac 963 964case "${NEED_NEWALIASES}" in 965'') ;; 966*) 967 echo '' 968 if [ -n "${DESTDIR}" ]; then 969 echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but" 970 echo " the newaliases command is limited to the directories configured" 971 echo " in sendmail.cf. Make sure to create your aliases database by" 972 echo " hand when your sendmail configuration is done." 973 else 974 echo "*** You installed a new aliases file, so make sure that you run" 975 echo " '/usr/bin/newaliases' to rebuild your aliases database" 976 run_it_now '/usr/bin/newaliases' 977 fi 978 ;; 979esac 980 981case "${NEED_CAP_MKDB}" in 982'') ;; 983*) 984 echo '' 985 echo "*** You installed a login.conf file, so make sure that you run" 986 echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'" 987 echo " to rebuild your login.conf database" 988 run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf" 989 ;; 990esac 991 992case "${NEED_PWD_MKDB}" in 993'') ;; 994*) 995 echo '' 996 echo "*** You installed a new master.passwd file, so make sure that you run" 997 if [ -n "${DESTDIR}" ]; then 998 echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'" 999 echo " to rebuild your password files" 1000 run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd" 1001 else 1002 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'" 1003 echo " to rebuild your password files" 1004 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 1005 fi 1006 ;; 1007esac 1008 1009echo '' 1010 1011if [ -r "${MM_EXIT_SCRIPT}" ]; then 1012 . "${MM_EXIT_SCRIPT}" 1013fi 1014 1015case "${COMP_CONFS}" in 1016'') ;; 1017*) 1018 . ${DESTDIR}/etc/defaults/rc.conf 1019 1020 (echo '' 1021 echo "*** Comparing conf files: ${rc_conf_files}" 1022 1023 for CONF_FILE in ${rc_conf_files}; do 1024 if [ -r "${DESTDIR}${CONF_FILE}" ]; then 1025 echo '' 1026 echo "*** From ${DESTDIR}${CONF_FILE}" 1027 echo "*** From ${DESTDIR}/etc/defaults/rc.conf" 1028 1029 for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} | 1030 cut -d '=' -f 1`; do 1031 echo '' 1032 grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE} 1033 grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf || 1034 echo ' * No default variable with this name' 1035 done 1036 fi 1037 done) | ${PAGER} 1038 echo '' 1039 ;; 1040esac 1041 1042case "${PRE_WORLD}" in 1043'') ;; 1044*) 1045 MAKE_CONF="${SOURCEDIR%etc}share/examples/etc/make.conf" 1046 1047 (echo '' 1048 echo '*** Comparing make variables' 1049 echo '' 1050 echo "*** From ${DESTDIR}/etc/make.conf" 1051 echo "*** From ${MAKE_CONF}" 1052 1053 for MAKE_VAR in `grep -i ^[a-z] ${DESTDIR}/etc/make.conf | cut -d '=' -f 1`; do 1054 echo '' 1055 grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf 1056 grep -w ^#${MAKE_VAR} ${MAKE_CONF} || 1057 echo ' * No example variable with this name' 1058 done) | ${PAGER} 1059 ;; 1060esac 1061 1062exit 0 1063 1064