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