mergemaster.sh revision 77325
159769Sgrog#!/bin/sh 259769Sgrog 324424Swosch# mergemaster 424424Swosch 524424Swosch# Compare files created by /usr/src/etc/Makefile (or the directory 624424Swosch# the user specifies) with the currently installed copies. 724424Swosch 824424Swosch# Copyright 1998-2001 Douglas Barton 924424Swosch# DougB@FreeBSD.org 1024424Swosch 1124424Swosch# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 77325 2001-05-28 09:35:30Z dougb $ 1224424Swosch 1324424SwoschPATH=/bin:/usr/bin:/usr/sbin 1424424Swosch 1542704Swoschdisplay_usage () { 1642704Swosch VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4` 1742704Swosch echo "mergemaster version ${VERSION_NUMBER}" 1824424Swosch echo 'Usage: mergemaster [-scrvahi] [-m /path]' 1942704Swosch echo ' [-t /path] [-d] [-u N] [-w N] [-D /path]' 2042704Swosch echo "Options:" 2142704Swosch echo " -s Strict comparison (diff every pair of files)" 2242704Swosch echo " -c Use context diff instead of unified diff" 2342704Swosch echo " -r Re-run on a previously cleaned directory (skip temproot creation)" 2442704Swosch echo " -v Be more verbose about the process, include additional checks" 2542704Swosch echo " -a Leave all files that differ to merge by hand" 2642704Swosch echo " -h Display more complete help" 2742704Swosch echo ' -i Automatically install files that do not exist in destination directory' 2842704Swosch echo " -m /path/directory Specify location of source to do the make in" 2942704Swosch echo " -t /path/directory Specify temp root directory" 3059769Sgrog echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" 3159769Sgrog echo " -u N Specify a numeric umask" 3259769Sgrog echo " -w N Specify a screen width in columns to sdiff" 3359769Sgrog echo ' -D /path/directory Specify the destination directory to install files to' 3459769Sgrog echo '' 3559769Sgrog} 3659769Sgrog 3759769Sgrogdisplay_help () { 3859769Sgrog echo "* To specify a directory other than /var/tmp/temproot for the" 3924424Swosch echo " temporary root environment, use -t /path/to/temp/root" 4042704Swosch echo "* The -w option takes a number as an argument for the column width" 4124424Swosch echo " of the screen. The default is 80." 4242704Swosch echo '* The -a option causes mergemaster to run without prompting.' 4324424Swosch} 4442704Swosch 4524424Swosch# Loop allowing the user to use sdiff to merge files and display the merged 4624424Swosch# file. 4724424Swoschmerge_loop () { 4842704Swosch case "${VERBOSE}" in 4925031Swosch '') ;; 5059156Swosch *) 5125031Swosch echo " *** Type h at the sdiff prompt (%) to get usage help" 5225031Swosch ;; 5324424Swosch esac 5424424Swosch echo '' 5524424Swosch MERGE_AGAIN=yes 5624424Swosch while [ "${MERGE_AGAIN}" = "yes" ]; do 5771231Sitojun # Prime file.merged so we don't blat the owner/group id's 5824424Swosch cp -p "${COMPFILE}" "${COMPFILE}.merged" 5971231Sitojun sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 6025031Swosch --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 6171231Sitojun INSTALL_MERGED=V 6224424Swosch while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 6325031Swosch echo '' 6425031Swosch echo " Use 'i' to install merged file" 6571231Sitojun echo " Use 'r' to re-do the merge" 6625031Swosch echo " Use 'v' to view the merged file" 6771231Sitojun echo " Default is to leave the temporary file to deal with by hand" 6870110Swosch echo '' 6970110Swosch echo -n " *** How should I deal with the merged file? [Leave it for later] " 7070110Swosch read INSTALL_MERGED 7170110Swosch 7270110Swosch case "${INSTALL_MERGED}" in 7370110Swosch [iI]) 7470110Swosch mv "${COMPFILE}.merged" "${COMPFILE}" 7570110Swosch echo '' 7670110Swosch if mm_install "${COMPFILE}"; then 7770110Swosch echo " *** Merged version of ${COMPFILE} installed successfully" 7870110Swosch else 7980675Sasmodai echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 8080675Sasmodai fi 8180675Sasmodai unset MERGE_AGAIN 8280675Sasmodai ;; 8380675Sasmodai [rR]) 8480675Sasmodai rm "${COMPFILE}.merged" 8580675Sasmodai ;; 8680675Sasmodai [vV]) 8780675Sasmodai ${PAGER} "${COMPFILE}.merged" 8880675Sasmodai ;; 8980675Sasmodai '') 9080675Sasmodai echo " *** ${COMPFILE} will remain for your consideration" 9180675Sasmodai unset MERGE_AGAIN 9280675Sasmodai ;; 9380675Sasmodai *) 9480675Sasmodai echo "invalid choice: ${INSTALL_MERGED}" 9580675Sasmodai INSTALL_MERGED=V 9680675Sasmodai ;; 9780675Sasmodai esac 9880675Sasmodai done 9980675Sasmodai done 10080675Sasmodai} 10180675Sasmodai 10280675Sasmodai# Loop showing user differences between files, allow merge, skip or install 10380675Sasmodai# options 10480675Sasmodaidiff_loop () { 10580675Sasmodai 10680675Sasmodai HANDLE_COMPFILE=v 10780675Sasmodai 10880675Sasmodai while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \ 10980675Sasmodai "${HANDLE_COMPFILE}" = "NOT V" ]; do 11080675Sasmodai if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 11180675Sasmodai if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 11280675Sasmodai ( 11380675Sasmodai echo '' 11480675Sasmodai echo " *** Displaying differences between ${COMPFILE} and installed version:" 11580675Sasmodai echo '' 11680675Sasmodai diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 11780675Sasmodai ) | ${PAGER} 11880675Sasmodai echo '' 11980675Sasmodai fi 12080675Sasmodai else 12180675Sasmodai echo '' 12280675Sasmodai echo " *** There is no installed version of ${COMPFILE}" 12380675Sasmodai case "${AUTO_INSTALL}" in 12480675Sasmodai [Yy][Ee][Ss]) 12580675Sasmodai echo '' 12680675Sasmodai if mm_install "${COMPFILE}"; then 12780675Sasmodai echo " *** ${COMPFILE} installed successfully" 12880675Sasmodai echo '' 12980675Sasmodai # Make the list print one file per line 13080675Sasmodai AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 13180675Sasmodai" 13280675Sasmodai else 13380675Sasmodai echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 13480675Sasmodai fi 13580675Sasmodai return 13680675Sasmodai ;; 13780675Sasmodai *) 138101401Swosch NO_INSTALLED=yes 13980675Sasmodai ;; 14087200Swosch esac 14187200Swosch fi 14287200Swosch 14380675Sasmodai echo " Use 'd' to delete the temporary ${COMPFILE}" 144104772Smaxim echo " Use 'i' to install the temporary ${COMPFILE}" 145104772Smaxim case "${NO_INSTALLED}" in 146104772Smaxim '') 147104772Smaxim echo " Use 'm' to merge the old and new versions" 148104781Sjhb echo " Use 'v' to view to differences between the old and new versions again" 149104781Sjhb ;; 150104781Sjhb esac 151104781Sjhb echo '' 152104781Sjhb echo " Default is to leave the temporary file to deal with by hand" 153104781Sjhb echo '' 154104781Sjhb echo -n "How should I deal with this? [Leave it for later] " 155113054Smurray read HANDLE_COMPFILE 156113054Smurray 157113054Smurray case "${HANDLE_COMPFILE}" in 158114211Swosch [dD]) 159114211Swosch rm "${COMPFILE}" 160114211Swosch echo '' 161114572Swosch echo " *** Deleting ${COMPFILE}" 162114211Swosch ;; 163111949Swosch [iI]) 164111949Swosch echo '' 16580675Sasmodai if mm_install "${COMPFILE}"; then 16680675Sasmodai echo " *** ${COMPFILE} installed successfully" 167104781Sjhb else 16824424Swosch echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 16924424Swosch fi 17024424Swosch ;; 17124424Swosch [mM]) 17269277Sasmodai case "${NO_INSTALLED}" in 17369277Sasmodai '') 17424424Swosch # interact with user to merge files 17525031Swosch merge_loop 17625031Swosch ;; 17725031Swosch *) 17880675Sasmodai echo '' 179104782Sjhb echo " *** There is no installed version of ${COMPFILE}" 18025031Swosch echo '' 181104782Sjhb HANDLE_COMPFILE="NOT V" 182104782Sjhb ;; 183104782Sjhb esac # End of "No installed version of file but user selected merge" test 184104797Sjhb ;; 185104797Sjhb [vV]) 18625031Swosch continue 18725031Swosch ;; 18825031Swosch '') 18945349Swosch echo '' 19045349Swosch echo " *** ${COMPFILE} will remain for your consideration" 191104782Sjhb ;; 192104782Sjhb *) 193104782Sjhb # invalid choice, show menu again. 194104782Sjhb echo "invalid choice: ${HANDLE_COMPFILE}" 19542704Swosch echo '' 19625031Swosch HANDLE_COMPFILE="NOT V" 19724424Swosch continue 19859769Sgrog ;; 19925031Swosch esac # End of "How to handle files that are different" 20025031Swosch done 20125031Swosch unset NO_INSTALLED 20225031Swosch echo '' 20359769Sgrog case "${VERBOSE}" in 20425031Swosch '') ;; 20525031Swosch *) 20625031Swosch sleep 3 20725031Swosch ;; 20824424Swosch esac 20925031Swosch} 21025031Swosch 21125031Swosch# Set the default path for the temporary root environment 21225031Swosch# 21325031SwoschTEMPROOT='/var/tmp/temproot' 21459769Sgrog 21559769Sgrog# Read /etc/mergemaster.rc first so the one in $HOME can override 21642704Swosch# 21742704Swoschif [ -r /etc/mergemaster.rc ]; then 21842704Swosch . /etc/mergemaster.rc 21970110Swoschfi 22042704Swosch 22142704Swosch# Read .mergemasterrc before command line so CLI can override 22225031Swosch# 22325031Swoschif [ -r "$HOME/.mergemasterrc" ]; then 22424424Swosch . "$HOME/.mergemasterrc" 22525031Swoschfi 22625031Swosch 22725031Swosch# Check the command line options 22825031Swosch# 22925031Swoschwhile getopts ":ascrvhim:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do 23025031Swosch case "${COMMAND_LINE_ARGUMENT}" in 23125031Swosch s) 23225031Swosch STRICT=yes 23325031Swosch ;; 23424424Swosch c) 23525031Swosch DIFF_FLAG='-c' 23625031Swosch ;; 23725031Swosch r) 23825031Swosch RERUN=yes 23925031Swosch ;; 24025031Swosch v) 24125031Swosch case "${AUTO_RUN}" in 24225031Swosch '') VERBOSE=yes ;; 24359156Swosch esac 24425031Swosch ;; 24525031Swosch a) 24625031Swosch AUTO_RUN=yes 24725031Swosch unset VERBOSE 24825031Swosch ;; 24925031Swosch h) 25089981Sjoe display_usage 25125031Swosch display_help 25225031Swosch exit 0 25325031Swosch ;; 25424424Swosch i) 25525031Swosch AUTO_INSTALL=yes 25625031Swosch ;; 25789981Sjoe m) 25825031Swosch SOURCEDIR=${OPTARG} 25989981Sjoe ;; 26089981Sjoe t) 26125031Swosch TEMPROOT=${OPTARG} 26289981Sjoe ;; 26389981Sjoe d) 26489981Sjoe TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 26570110Swosch ;; 26671231Sitojun u) 26770110Swosch NEW_UMASK=${OPTARG} 26825031Swosch ;; 26971231Sitojun w) 27071231Sitojun SCREEN_WIDTH=${OPTARG} 27169278Sasmodai ;; 27225031Swosch D) 27371231Sitojun DESTDIR=${OPTARG} 27470110Swosch ;; 27571231Sitojun *) 27670110Swosch display_usage 27770110Swosch exit 1 27871231Sitojun ;; 27970110Swosch esac 28057000Swoschdone 28125031Swosch 28245349Swoschecho '' 28378270Snik 28471231Sitojun# If the user has a pager defined, make sure we can run it 28525031Swosch# 28638440Sjkhcase "${DONT_CHECK_PAGER}" in 28738440Sjkh'') 28849392Swosch while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do 28957000Swosch echo " *** Your PAGER environment variable specifies '${PAGER}', but" 29038440Sjkh echo " due to the limited PATH that I use for security reasons," 29138440Sjkh echo " I cannot execute it. So, what would you like to do?" 29270110Swosch echo '' 29369278Sasmodai echo " Use 'e' to exit mergemaster and fix your PAGER variable" 29470110Swosch if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 29525031Swosch echo " Use 'l' to set PAGER to 'less' for this run" 29625031Swosch fi 29769278Sasmodai echo " Use 'm' to use plain old 'more' as your PAGER for this run" 29845349Swosch echo '' 29970110Swosch echo " Default is to use plain old 'more' " 30069278Sasmodai echo '' 30145349Swosch echo -n "What should I do? [Use 'more'] " 30245349Swosch read FIXPAGER 30369278Sasmodai 30469278Sasmodai case "${FIXPAGER}" in 30580675Sasmodai [eE]) 30669278Sasmodai exit 0 30770110Swosch ;; 30869278Sasmodai [lL]) 30969278Sasmodai if [ -x /usr/bin/less ]; then 31069278Sasmodai PAGER=/usr/bin/less 31157000Swosch elif [ -x /usr/local/bin/less ]; then 31245349Swosch PAGER=/usr/local/bin/less 31369277Sasmodai else 31445349Swosch echo '' 31566542Sitojun echo " *** Fatal Error:" 31669277Sasmodai echo " You asked to use 'less' as your pager, but I can't" 31757000Swosch echo " find it in /usr/bin or /usr/local/bin" 31870110Swosch exit 1 31945349Swosch fi 32057000Swosch ;; 32169277Sasmodai [mM]|'') 32270110Swosch PAGER=more 32370110Swosch ;; 32442589Swosch *) 32570110Swosch echo '' 32670110Swosch echo "invalid choice: ${FIXPAGER}" 32746321Swosch esac 32845349Swosch echo '' 32945349Swosch done 33057000Swosch ;; 33146318Swoschesac 33270110Swosch 33356406Swosch# If user has a pager defined, or got assigned one above, use it. 33455389Sbillf# If not, use more. 33555389Sbillf# 33657000SwoschPAGER=${PAGER:-more} 33755389Sbillf 33855389Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 33955389Sbillf echo " *** You have ${PAGER} defined as your pager so we will use that" 34070110Swosch echo '' 34158448Swosch sleep 3 34258448Swoschfi 34365412Swosch 34464612Salex# Assign the diff flag once so we will not have to keep testing it 34564612Salex# 34665411SwoschDIFF_FLAG=${DIFF_FLAG:--u} 34765974Swosch 34869277Sasmodai# Assign the source directory 34969277Sasmodai# 35070119SwoschSOURCEDIR=${SOURCEDIR:-/usr/src/etc} 35169277Sasmodai 35270111Swosch# Define what CVS $Id tag to look for to aid portability. 35380675Sasmodai# 35475833SwoschCVS_ID_TAG=FreeBSD 35578867Sitojun 35679603Sitojuncase "${RERUN}" in 35784087Swosch'') 35883686Sobrien # Set up the loop to test for the existence of the 359104797Sjhb # temp root directory. 36087201Swosch # 36192013Swosch TEST_TEMP_ROOT=yes 362104772Smaxim while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 363101331Swosch if [ -d "${TEMPROOT}" ]; then 364101331Swosch echo "*** The directory specified for the temporary root environment," 365104797Sjhb echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 366104781Sjhb echo " users have access to the system." 367104781Sjhb echo '' 368104781Sjhb case "${AUTO_RUN}" in 369104659Smurray '') 370106406Smaxim echo " Use 'd' to delete the old ${TEMPROOT} and continue" 371111949Swosch echo " Use 't' to select a new temporary root directory" 372111949Swosch echo " Use 'e' to exit mergemaster" 373111949Swosch echo '' 374113054Smurray echo " Default is to use ${TEMPROOT} as is" 375114211Swosch echo '' 376114572Swosch echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 37724424Swosch read DELORNOT 378111949Swosch 37924424Swosch case "${DELORNOT}" in 38024424Swosch [dD]) 38124424Swosch echo '' 38224424Swosch echo " *** Deleting the old ${TEMPROOT}" 38324424Swosch echo '' 38424424Swosch rm -rf "${TEMPROOT}" 38524424Swosch unset TEST_TEMP_ROOT 38624424Swosch ;; 38724424Swosch [tT]) 38824424Swosch echo " *** Enter new directory name for temporary root environment" 38924424Swosch read TEMPROOT 39024424Swosch ;; 39124424Swosch [eE]) 39224424Swosch exit 0 39325031Swosch ;; 39425031Swosch '') 39524424Swosch echo '' 39624424Swosch echo " *** Leaving ${TEMPROOT} intact" 39724424Swosch echo '' 39824424Swosch unset TEST_TEMP_ROOT 39959769Sgrog ;; 40079514Sitojun *) 40124424Swosch echo '' 40225031Swosch echo "invalid choice: ${DELORNOT}" 40325031Swosch echo '' 40425031Swosch ;; 40525031Swosch esac 40659769Sgrog ;; 40725031Swosch *) 40831658Swosch # If this is an auto-run, try a hopefully safe alternative then 40979514Sitojun # re-test anyway. 41031658Swosch TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 41159769Sgrog ;; 41279514Sitojun esac 41359769Sgrog else 41465415Swosch unset TEST_TEMP_ROOT 415104786Sjhb fi 41665415Swosch done 41775834Swosch 41879514Sitojun echo "*** Creating the temporary root environment in ${TEMPROOT}" 41975834Swosch 42075834Swosch if mkdir -p "${TEMPROOT}"; then 42175834Swosch echo " *** ${TEMPROOT} ready for use" 42225031Swosch fi 42325031Swosch 42425031Swosch if [ ! -d "${TEMPROOT}" ]; then 42559769Sgrog echo '' 42625031Swosch echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 42725031Swosch echo '' 42831658Swosch exit 1 42925031Swosch fi 43024424Swosch 43172877Swosch echo " *** Creating and populating directory structure in ${TEMPROOT}" 43267388Swosch echo '' 43342589Swosch 43450970Speter case "${VERBOSE}" in 435 '') ;; 436 *) 437 echo " *** Press [Enter] or [Return] key to continue" 438 read ANY_KEY 439 unset ANY_KEY 440 ;; 441 esac 442 443 { cd ${SOURCEDIR} && 444 case "${DESTDIR}" in 445 '') ;; 446 *) 447 make DESTDIR=${DESTDIR} distrib-dirs 448 ;; 449 esac 450 make DESTDIR=${TEMPROOT} distrib-dirs && 451 make DESTDIR=${TEMPROOT} -DNO_MAKEDEV_RUN distribution;} || 452 { echo ''; 453 echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 454 echo " the temproot environment"; 455 echo ''; 456 exit 1;} 457 458 # Doing the inventory and removing files that we don't want to compare only 459 # makes sense if we are not doing a rerun, since we have no way of knowing 460 # what happened to the files during previous incarnations. 461 case "${VERBOSE}" in 462 '') ;; 463 *) 464 echo '' 465 echo ' *** The following files exist only in the installed version of' 466 echo " ${DESTDIR}/etc. In the vast majority of cases these files" 467 echo ' are necessary parts of the system and should not be deleted.' 468 echo ' However because these files are not updated by this process you' 469 echo ' might want to verify their status before rebooting your system.' 470 echo '' 471 echo ' *** Press [Enter] or [Return] key to continue' 472 read ANY_KEY 473 unset ANY_KEY 474 diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER} 475 echo '' 476 echo ' *** Press [Enter] or [Return] key to continue' 477 read ANY_KEY 478 unset ANY_KEY 479 ;; 480 esac 481 482 # We really don't want to have to deal with these files, since 483 # master.passwd is the real file that should be compared, then 484 # the user should run pwd_mkdb if necessary. 485 # 486 rm ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db 487 488 # Avoid comparing the motd if the user specifies it in .mergemasterrc 489 case "${IGNORE_MOTD}" in 490 '') ;; 491 *) rm ${TEMPROOT}/etc/motd 492 ;; 493 esac 494 495 # Avoid trying to update MAKEDEV if /dev is on a devfs 496 if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 497 rm ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local 498 fi 499 500 ;; # End of the "RERUN" test 501esac 502 503# Get ready to start comparing files 504 505# Check umask if not specified on the command line, 506# and we are not doing an autorun 507# 508if [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 509 USER_UMASK=`umask` 510 case "${USER_UMASK}" in 511 0022) ;; 512 *) 513 echo '' 514 echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 515 echo " installs all files with the same user, group and modes that" 516 echo " they are created with by ${SOURCEDIR}/Makefile, compared to" 517 echo " a umask of 022. This umask allows world read permission when" 518 echo " the file's default permissions have it." 519 echo " No world permissions can sometimes cause problems. A umask of" 520 echo " 022 will restore the default behavior, but is not mandatory." 521 echo " /etc/master.passwd is a special case. Its file permissions" 522 echo " will be 600 (rw-------) if installed." 523 echo '' 524 echo -n "What umask should I use? [${USER_UMASK}] " 525 read NEW_UMASK 526 527 NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 528 ;; 529 esac 530 echo '' 531fi 532 533CONFIRMED_UMASK=${NEW_UMASK:-0022} 534 535# Warn users who still have ${DESTDIR}/etc/sysconfig 536# 537if [ -e "${DESTDIR}/etc/sysconfig" ]; then 538 echo '' 539 echo " *** There is a sysconfig file on this system in ${DESTDIR}/etc/." 540 echo '' 541 echo ' Starting with FreeBSD version 2.2.2 those settings moved from' 542 echo ' /etc/sysconfig to /etc/rc.conf. If you are upgrading an older' 543 echo ' system make sure that you transfer your settings by hand from' 544 echo ' sysconfig to rc.conf and install the rc.conf file. If you' 545 echo ' have already made this transition, you should consider' 546 echo ' renaming or deleting the sysconfig file.' 547 echo '' 548 case "${AUTO_RUN}" in 549 '') 550 echo -n "Continue with the merge process? [yes] " 551 read CONT_OR_NOT 552 553 case "${CONT_OR_NOT}" in 554 [nN]*) 555 exit 0 556 ;; 557 *) 558 echo " *** Continuing" 559 echo '' 560 ;; 561 esac 562 ;; 563 *) ;; 564 esac 565fi 566 567# Use the umask/mode information to install the files 568# Create directories as needed 569# 570mm_install () { 571 local INSTALL_DIR 572 INSTALL_DIR=${1#.} 573 INSTALL_DIR=${INSTALL_DIR%/*} 574 575 case "${INSTALL_DIR}" in 576 '') 577 INSTALL_DIR=/ 578 ;; 579 esac 580 581 if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 582 DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \ 583 oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"` 584 install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" 585 fi 586 587 FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \ 588 oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"` 589 590 if [ ! -x "${1}" ]; then 591 case "${1#.}" in 592 /etc/mail/aliases) 593 NEED_NEWALIASES=yes 594 ;; 595 /etc/login.conf) 596 NEED_CAP_MKDB=yes 597 ;; 598 /etc/master.passwd) 599 install -m 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 600 NEED_PWD_MKDB=yes 601 DONT_INSTALL=yes 602 ;; 603 /.cshrc | /.profile) 604 case "${LINK_EXPLAINED}" in 605 '') 606 echo " *** Historically BSD derived systems have had a" 607 echo " hard link from /.cshrc and /.profile to" 608 echo " their namesakes in /root. Please indicate" 609 echo " your preference below for bringing your" 610 echo " installed files up to date." 611 echo '' 612 LINK_EXPLAINED=yes 613 ;; 614 esac 615 616 echo " Use 'd' to delete the temporary ${COMPFILE}" 617 echo " Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link" 618 echo '' 619 echo " Default is to leave the temporary file to deal with by hand" 620 echo '' 621 echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 622 read HANDLE_LINK 623 624 case "${HANDLE_LINK}" in 625 [dD]*) 626 rm "${COMPFILE}" 627 echo '' 628 echo " *** Deleting ${COMPFILE}" 629 ;; 630 [lL]*) 631 echo '' 632 rm -f "${DESTDIR}${COMPFILE#.}" 633 if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then 634 echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 635 rm "${COMPFILE}" 636 else 637 echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand" 638 fi 639 ;; 640 *) 641 echo " *** ${COMPFILE} will remain for your consideration" 642 ;; 643 esac 644 DONT_INSTALL=yes 645 ;; 646 esac 647 648 case "${DONT_INSTALL}" in 649 '') 650 install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 651 ;; 652 *) 653 unset DONT_INSTALL 654 ;; 655 esac 656 else 657 case "${1#.}" in 658 /dev/MAKEDEV) 659 NEED_MAKEDEV=yes 660 ;; 661 esac 662 install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 663 fi 664 return $? 665} 666 667echo '' 668echo "*** Beginning comparison" 669echo '' 670 671cd "${TEMPROOT}" 672 673if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 674 . "${MM_PRE_COMPARE_SCRIPT}" 675fi 676 677# Using -size +0 avoids uselessly checking the empty log files created 678# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does 679# check the scripts in ./dev, as we'd like (assuming no devfs of course). 680# 681for COMPFILE in `find . -type f -size +0`; do 682 683 # First, check to see if the file exists in DESTDIR. If not, the 684 # diff_loop function knows how to handle it. 685 # 686 if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 687 case "${AUTO_RUN}" in 688 '') 689 diff_loop 690 ;; 691 *) 692 case "${AUTO_INSTALL}" in 693 '') 694 # If this is an auto run, make it official 695 echo " *** ${COMPFILE} will remain for your consideration" 696 ;; 697 *) 698 diff_loop 699 ;; 700 esac 701 ;; 702 esac # Auto run test 703 continue 704 fi 705 706 case "${STRICT}" in 707 '' | [Nn][Oo]) 708 # Compare CVS $Id's first so if the file hasn't been modified 709 # local changes will be ignored. 710 # If the files have the same $Id, delete the one in temproot so the 711 # user will have less to wade through if files are left to merge by hand. 712 # 713 CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 714 CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` 715 716 case "${CVSID2}" in 717 "${CVSID1}") 718 echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 719 rm "${COMPFILE}" 720 ;; 721 esac 722 ;; 723 esac 724 725 # If the file is still here either because the $Ids are different, the 726 # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 727 # 728 if [ -f "${COMPFILE}" ]; then 729 730 # Do an absolute diff first to see if the files are actually different. 731 # If they're not different, delete the one in temproot. 732 # 733 if diff -q "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then 734 echo " *** Temp ${COMPFILE} and installed are the same, deleting" 735 rm "${COMPFILE}" 736 else 737 # Ok, the files are different, so show the user where they differ. 738 # Use user's choice of diff methods; and user's pager if they have one. 739 # Use more if not. 740 # Use unified diffs by default. Context diffs give me a headache. :) 741 # 742 case "${AUTO_RUN}" in 743 '') 744 # prompt user to install/delete/merge changes 745 diff_loop 746 ;; 747 *) 748 # If this is an auto run, make it official 749 echo " *** ${COMPFILE} will remain for your consideration" 750 ;; 751 esac # Auto run test 752 fi # Yes, the files are different 753 fi # Yes, the file still remains to be checked 754done # This is for the do way up there at the beginning of the comparison 755 756echo '' 757echo "*** Comparison complete" 758echo '' 759 760TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 761if [ -n "${TEST_FOR_FILES}" ]; then 762 echo "*** Files that remain for you to merge by hand:" 763 find "${TEMPROOT}" -type f -size +0 764fi 765 766case "${AUTO_RUN}" in 767'') 768 echo '' 769 echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 770 read DEL_TEMPROOT 771 772 case "${DEL_TEMPROOT}" in 773 [yY]*) 774 if rm -rf "${TEMPROOT}"; then 775 echo " *** ${TEMPROOT} has been deleted" 776 else 777 echo " *** Unable to delete ${TEMPROOT}" 778 fi 779 ;; 780 *) 781 echo " *** ${TEMPROOT} will remain" 782 ;; 783 esac 784 ;; 785*) ;; 786esac 787 788case "${AUTO_INSTALLED_FILES}" in 789'') ;; 790*) 791 case "${AUTO_RUN}" in 792 '') 793 ( 794 echo '' 795 echo '*** You chose the automatic install option for files that did not' 796 echo ' exist on your system. The following were installed for you:' 797 echo "${AUTO_INSTALLED_FILES}" 798 ) | ${PAGER} 799 ;; 800 *) 801 echo '' 802 echo '*** You chose the automatic install option for files that did not' 803 echo ' exist on your system. The following were installed for you:' 804 echo "${AUTO_INSTALLED_FILES}" 805 ;; 806 esac 807 ;; 808esac 809 810run_it_now () { 811 case "${AUTO_RUN}" in 812 '') 813 unset YES_OR_NO 814 echo '' 815 echo -n ' Would you like to run it now? [y or n] ' 816 read YES_OR_NO 817 818 echo '' 819 820 case "${YES_OR_NO}" in 821 y) 822 echo " Running ${1}" 823 eval "${1}" 824 ;; 825 *) 826 echo " Make sure to run ${1} yourself" 827 ;; 828 esac 829 ;; 830 *) ;; 831 esac 832} 833 834case "${NEED_MAKEDEV}" in 835'') ;; 836*) 837 echo '' 838 echo "*** You installed a new /dev/MAKEDEV script, so make sure that you run" 839 echo " 'cd /dev && /bin/sh MAKEDEV all' to rebuild your devices" 840 run_it_now 'cd /dev && /bin/sh MAKEDEV all' 841 ;; 842esac 843 844case "${NEED_NEWALIASES}" in 845'') ;; 846*) 847 echo '' 848 echo "*** You installed a new aliases file, so make sure that you run" 849 echo " '/usr/bin/newaliases' to rebuild your aliases database" 850 run_it_now '/usr/bin/newaliases' 851 ;; 852esac 853 854case "${NEED_CAP_MKDB}" in 855'') ;; 856*) 857 echo '' 858 echo "*** You installed a login.conf file, so make sure that you run" 859 echo " '/usr/bin/cap_mkdb /etc/login.conf' to rebuild your login.conf database" 860 run_it_now '/usr/bin/cap_mkdb /etc/login.conf' 861 ;; 862esac 863 864case "${NEED_PWD_MKDB}" in 865'') ;; 866*) 867 echo '' 868 echo "*** You installed a new master.passwd file, so make sure that you run" 869 echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd' to rebuild your password files" 870 run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 871 ;; 872esac 873 874echo '' 875 876if [ -r "${MM_EXIT_SCRIPT}" ]; then 877 . "${MM_EXIT_SCRIPT}" 878fi 879 880exit 0 881 882