mergemaster.sh revision 52495
152400Sbillf#!/bin/sh 252400Sbillf 352400Sbillf# mergemaster 452400Sbillf 552400Sbillf# Compare files created by /usr/src/etc/Makefile (or the directory 652400Sbillf# the user specifies) with the currently installed copies. 752400Sbillf 852400Sbillf# Copyright 1998, 1999 Douglas Barton 952400Sbillf# Doug@gorean.org 1052400Sbillf 1152495Sbillf# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 52495 1999-10-25 21:51:04Z billf $ 1252400Sbillf# $Revision: 1.36 $ 1352400Sbillf# $Date: 1999/09/10 20:56:33 $ 1452400Sbillf 1552400SbillfPATH=/bin:/usr/bin:/usr/sbin 1652400Sbillf 1752400Sbillfdisplay_usage () { 1852400Sbillf VERSION_NUMBER=`grep "[$]Revision:" $0 | cut -d ' ' -f 3` 1952400Sbillf echo "mergemaster version ${VERSION_NUMBER}" 2052400Sbillf echo "Usage: mergemaster [-scrvah] [-m /path] [-t /path] [-d] [-u N] [-w N]" 2152400Sbillf echo "Options:" 2252400Sbillf echo " -s Strict comparison (diff every pair of files)" 2352400Sbillf echo " -c Use context diff instead of unified diff" 2452400Sbillf echo " -r Re-run on a previously cleaned directory (skip temproot creation)" 2552400Sbillf echo " -v Be more verbose about the process, include additional checks" 2652400Sbillf echo " -a Leave all files that differ to merge by hand" 2752400Sbillf echo " -h Display more complete help" 2852400Sbillf echo " -m /path/directory Specify location of source to do the make in" 2952400Sbillf echo " -t /path/directory Specify temp root directory" 3052400Sbillf echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" 3152400Sbillf echo " -u N Specify a numeric umask" 3252400Sbillf echo " -w N Specify a screen width in columns to sdiff" 3352400Sbillf echo '' 3452400Sbillf} 3552400Sbillf 3652400Sbillfdisplay_help () { 3752400Sbillf echo "* To create a temporary root environment, compare CVS revision \$Ids" 3852400Sbillf echo " for files that have them, and compare diffs for files that do not," 3952400Sbillf echo " or have different ones, just type, mergemaster" 4052400Sbillf echo "* To specify a directory other than /var/tmp/temproot for the" 4152400Sbillf echo " temporary root environment, use -t /path/to/temp/root" 4252400Sbillf echo "* The -w option takes a number as an argument for the column width" 4352400Sbillf echo " of the screen. The default is 80." 4452400Sbillf echo "* The -a option causes mergemaster to run without prompting" 4552400Sbillf} 4652400Sbillf 4752400Sbillf# Set the default path for the temporary root environment 4852400Sbillf# 4952400SbillfTEMPROOT='/var/tmp/temproot' 5052400Sbillf 5152400Sbillf# Read .mergemasterrc before command line so CLI can override 5252400Sbillf# 5352400Sbillfif [ -f "$HOME/.mergemasterrc" ]; then 5452400Sbillf . "$HOME/.mergemasterrc" 5552400Sbillffi 5652400Sbillf 5752400Sbillf# Check the command line options 5852400Sbillf# 5952400Sbillfwhile getopts ":ascrvhm:t:du:w:" COMMAND_LINE_ARGUMENT ; do 6052400Sbillf case "${COMMAND_LINE_ARGUMENT}" in 6152400Sbillf s) 6252400Sbillf STRICT=yes 6352400Sbillf ;; 6452400Sbillf c) 6552400Sbillf DIFF_FLAG='-c' 6652400Sbillf ;; 6752400Sbillf r) 6852400Sbillf RERUN=yes 6952400Sbillf ;; 7052400Sbillf v) 7152400Sbillf case "${AUTO_RUN}" in 7252400Sbillf '') VERBOSE=yes ;; 7352400Sbillf esac 7452400Sbillf ;; 7552400Sbillf a) 7652400Sbillf AUTO_RUN=yes 7752400Sbillf unset VERBOSE 7852400Sbillf ;; 7952400Sbillf h) 8052400Sbillf display_usage 8152400Sbillf display_help 8252400Sbillf exit 0 8352400Sbillf ;; 8452400Sbillf m) 8552400Sbillf SOURCEDIR=${OPTARG} 8652400Sbillf ;; 8752400Sbillf t) 8852400Sbillf TEMPROOT=${OPTARG} 8952400Sbillf ;; 9052400Sbillf d) 9152400Sbillf TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 9252400Sbillf ;; 9352400Sbillf u) 9452400Sbillf NEW_UMASK=${OPTARG} 9552400Sbillf ;; 9652400Sbillf w) 9752400Sbillf SCREEN_WIDTH=${OPTARG} 9852400Sbillf ;; 9952400Sbillf *) 10052400Sbillf display_usage 10152400Sbillf exit 1 10252400Sbillf ;; 10352400Sbillf esac 10452400Sbillfdone 10552400Sbillf 10652400Sbillfecho '' 10752400Sbillf 10852400Sbillf# If the user has a pager defined, make sure we can run it 10952400Sbillf# 11052400Sbillfcase "${DONT_CHECK_PAGER}" in 11152400Sbillf'') 11252400Sbillf if [ -n "${PAGER}" -a ! -x "${PAGER}" ]; then 11352400Sbillf echo " *** Your PAGER environment variable specifies '${PAGER}', but" 11452400Sbillf echo " I cannot execute it. In general it is good practice to" 11552400Sbillf echo " specify the full path for environment variables like" 11652400Sbillf echo " PAGER and EDITOR. Meanwhile, what would you like to do?" 11752400Sbillf echo '' 11852400Sbillf echo " Use 'e' to exit mergemaster and fix your PAGER variable" 11952400Sbillf if [ -x /usr/local/bin/less ]; then 12052400Sbillf echo " Use 'l' to set PAGER to /usr/local/bin/less for this run" 12152400Sbillf fi 12252400Sbillf echo " Use 'm' to use plain old 'more' as your PAGER for this run" 12352400Sbillf echo '' 12452400Sbillf echo " Default is to use plain old 'more' " 12552400Sbillf echo '' 12652400Sbillf read -p "What should I do? [Use 'more'] " FIXPAGER 12752400Sbillf case "${FIXPAGER}" in 12852400Sbillf [eE]*) 12952400Sbillf exit 0 13052400Sbillf ;; 13152400Sbillf [lL]*) 13252400Sbillf PAGER=/usr/local/bin/less 13352400Sbillf ;; 13452400Sbillf *) 13552400Sbillf PAGER=more 13652400Sbillf ;; 13752400Sbillf esac 13852400Sbillf echo '' 13952400Sbillf fi 14052400Sbillf ;; 14152400Sbillfesac 14252400Sbillf 14352400Sbillf# If user has a pager defined, or got assigned one above, use it. 14452400Sbillf# If not, use more. 14552400Sbillf# 14652400SbillfPAGER=${PAGER:-more} 14752400Sbillf 14852400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 14952400Sbillf echo " *** You have ${PAGER} defined as your pager so we will use that" 15052400Sbillf echo '' 15152400Sbillf sleep 3 15252400Sbillffi 15352400Sbillf 15452400Sbillf# Assign the diff flag once so we will not have to keep testing it 15552400Sbillf# 15652400SbillfDIFF_FLAG=${DIFF_FLAG:--u} 15752400Sbillf 15852400Sbillf# Assign the source directory 15952400Sbillf# 16052400SbillfSOURCEDIR=${SOURCEDIR:-/usr/src/etc} 16152400Sbillf 16252400Sbillfcase "${RERUN}" in 16352400Sbillf'') 16452400Sbillf # Set up the loop to test for the existence of the 16552400Sbillf # temp root directory. 16652400Sbillf # 16752400Sbillf TEST_TEMP_ROOT=yes 16852400Sbillf while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 16952400Sbillf if [ -d "${TEMPROOT}" ]; then 17052400Sbillf echo "*** The directory specified for the temporary root environment," 17152400Sbillf echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 17252400Sbillf echo " users have access to the system." 17352400Sbillf echo '' 17452400Sbillf case "${AUTO_RUN}" in 17552400Sbillf '') 17652400Sbillf echo " Use 'd' to delete the old ${TEMPROOT} and continue" 17752400Sbillf echo " Use 't' to select a new temporary root directory" 17852400Sbillf echo " Use 'e' to exit mergemaster" 17952400Sbillf echo '' 18052400Sbillf echo " Default is to use ${TEMPROOT} as is" 18152400Sbillf echo '' 18252400Sbillf read -p "How should I deal with this? [Use the existing ${TEMPROOT}] " DELORNOT 18352400Sbillf case "${DELORNOT}" in 18452400Sbillf [dD]*) 18552400Sbillf echo '' 18652400Sbillf echo " *** Deleting the old ${TEMPROOT}" 18752400Sbillf echo '' 18852400Sbillf rm -rf "${TEMPROOT}" 18952400Sbillf unset TEST_TEMP_ROOT 19052400Sbillf ;; 19152400Sbillf [tT]*) 19252400Sbillf echo " *** Enter new directory name for temporary root environment" 19352400Sbillf read TEMPROOT 19452400Sbillf ;; 19552400Sbillf [eE]*) 19652400Sbillf exit 0 19752400Sbillf ;; 19852400Sbillf *) 19952400Sbillf echo '' 20052400Sbillf echo " *** Leaving ${TEMPROOT} intact" 20152400Sbillf echo '' 20252400Sbillf unset TEST_TEMP_ROOT 20352400Sbillf ;; 20452400Sbillf esac 20552400Sbillf ;; 20652400Sbillf *) 20752400Sbillf # If this is an auto-run, try a hopefully safe alternative then re-test anyway 20852400Sbillf TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 20952400Sbillf ;; 21052400Sbillf esac 21152400Sbillf else 21252400Sbillf unset TEST_TEMP_ROOT 21352400Sbillf fi 21452400Sbillf done 21552400Sbillf 21652400Sbillf echo "*** Creating the temporary root environment in ${TEMPROOT}" 21752400Sbillf 21852400Sbillf if mkdir -p "${TEMPROOT}"; then 21952400Sbillf echo " *** ${TEMPROOT} ready for use" 22052400Sbillf fi 22152400Sbillf 22252400Sbillf if [ ! -d "${TEMPROOT}" ]; then 22352400Sbillf echo '' 22452400Sbillf echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 22552400Sbillf echo '' 22652400Sbillf exit 1 22752400Sbillf fi 22852400Sbillf 22952400Sbillf echo " *** Creating and populating directory structure in ${TEMPROOT}" 23052400Sbillf echo '' 23152400Sbillf 23252400Sbillf case "${VERBOSE}" in 23352400Sbillf '') ;; 23452400Sbillf *) 23552400Sbillf echo " *** Press [Enter] or [Return] key to continue" 23652400Sbillf read ANY_KEY 23752400Sbillf unset ANY_KEY 23852400Sbillf ;; 23952400Sbillf esac 24052400Sbillf 24152400Sbillf { cd ${SOURCEDIR} && 24252400Sbillf make DESTDIR=${TEMPROOT} distrib-dirs && 24352400Sbillf make DESTDIR=${TEMPROOT} distribution;} || 24452400Sbillf { echo ''; 24552400Sbillf echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to the"; 24652400Sbillf echo " temproot environment"; 24752400Sbillf echo ''; 24852400Sbillf exit 1;} 24952400Sbillf 25052400Sbillf # We really don't want to have to deal with these files, since 25152400Sbillf # master.passwd is the real file that should be compared, then 25252400Sbillf # the user should run pwd_mkdb if necessary. 25352400Sbillf # Only do this if we are not rerun'ing, since if we are the 25452400Sbillf # files will not be there. 25552400Sbillf # 25652400Sbillf rm ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db 25752400Sbillf 25852400Sbillf ;; # End of the "RERUN" test 25952400Sbillfesac 26052400Sbillf 26152400Sbillf# Get ready to start comparing files 26252400Sbillf 26352400Sbillfcase "${VERBOSE}" in 26452400Sbillf'') ;; 26552400Sbillf*) 26652400Sbillf echo '' 26752400Sbillf echo " *** The following files exist only in the installed version" 26852400Sbillf echo " of /etc. In the far majority of cases these files are" 26952400Sbillf echo " necessary parts of the system and should not be deleted," 27052400Sbillf echo " however because these files are not updated by this process" 27152400Sbillf echo " you might want to verify their status before rebooting your system." 27252400Sbillf echo '' 27352400Sbillf echo " *** Press [Enter] or [Return] key to continue" 27452400Sbillf read ANY_KEY 27552400Sbillf unset ANY_KEY 27652400Sbillf diff -qr /etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER} 27752400Sbillf echo '' 27852400Sbillf echo " *** Press [Enter] or [Return] key to continue" 27952400Sbillf read ANY_KEY 28052400Sbillf unset ANY_KEY 28152400Sbillf ;; 28252400Sbillfesac 28352400Sbillf 28452400Sbillf# Check umask if not specified on the command line, 28552400Sbillf# and we are not doing an autorun 28652400Sbillf# 28752400Sbillfif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 28852400Sbillf USER_UMASK=`umask` 28952400Sbillf case "${USER_UMASK}" in 29052400Sbillf 0022) ;; 29152400Sbillf *) 29252400Sbillf echo '' 29352400Sbillf echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 29452400Sbillf echo " installs all files with the same user, group and modes that" 29552400Sbillf echo " they are created with by ${SOURCEDIR}/Makefile, compared to" 29652400Sbillf echo " a umask of 022. This umask allows world read permission when" 29752400Sbillf echo " the file's default permissions have it." 29852400Sbillf echo " No world permissions can sometimes cause problems. A umask of" 29952400Sbillf echo " 022 will restore the default behavior, but is not mandatory." 30052400Sbillf echo " /etc/master.passwd is a special case. Its file permissions" 30152400Sbillf echo " will be 600 (rw-------) if installed." 30252400Sbillf echo '' 30352400Sbillf read -p "What umask should I use? [${USER_UMASK}] " NEW_UMASK 30452400Sbillf NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 30552400Sbillf ;; 30652400Sbillf esac 30752400Sbillf echo '' 30852400Sbillffi 30952400Sbillf 31052400SbillfCONFIRMED_UMASK=${NEW_UMASK:-0022} 31152400Sbillf 31252400Sbillf# Warn users who have an /etc/sysconfig file 31352400Sbillf# 31452400Sbillfif [ -f /etc/sysconfig ]; then 31552400Sbillf echo " *** There is an /etc/sysconfig file on this system. Starting with" 31652400Sbillf echo " FreeBSD version 2.2.2 those settings have moved from /etc/sysconfig" 31752400Sbillf echo " to /etc/rc.conf. If you are upgrading an older system make sure" 31852400Sbillf echo " that you transfer your settings by hand from sysconfig to rc.conf and" 31952400Sbillf echo " install the rc.conf file. If you have already made this transition," 32052400Sbillf echo " you should consider renaming or deleting the /etc/sysconfig file." 32152400Sbillf echo '' 32252400Sbillf case "${AUTO_RUN}" in 32352400Sbillf '') 32452400Sbillf read -p "Continue with the merge process? [yes] " CONT_OR_NOT 32552400Sbillf case "${CONT_OR_NOT}" in 32652400Sbillf [nN]*) 32752400Sbillf exit 0 32852400Sbillf ;; 32952400Sbillf *) 33052400Sbillf echo " *** Continuing" 33152400Sbillf echo '' 33252400Sbillf ;; 33352400Sbillf esac 33452400Sbillf ;; 33552400Sbillf *) ;; 33652400Sbillf esac 33752400Sbillffi 33852400Sbillf 33952400Sbillfecho '' 34052400Sbillfecho "*** Beginning comparison" 34152400Sbillfecho '' 34252400Sbillf 34352400Sbillfcd "${TEMPROOT}" 34452400Sbillf 34552400Sbillf# Use the umask/mode information to install the files 34652400Sbillf# Create directories as needed 34752400Sbillf# 34852400Sbillfmm_install () { 34952400Sbillf local INSTALL_DIR 35052400Sbillf INSTALL_DIR=${1#.} 35152400Sbillf INSTALL_DIR=${INSTALL_DIR%/*} 35252400Sbillf case "${INSTALL_DIR}" in 35352400Sbillf '') 35452400Sbillf INSTALL_DIR=/ 35552400Sbillf ;; 35652400Sbillf esac 35752400Sbillf 35852400Sbillf if [ -n "${INSTALL_DIR}" -a ! -d "${INSTALL_DIR}" ]; then 35952400Sbillf DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"` 36052400Sbillf install -d -o root -g wheel -m "${DIR_MODE}" "${INSTALL_DIR}" 36152400Sbillf fi 36252400Sbillf 36352400Sbillf FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"` 36452400Sbillf 36552400Sbillf if [ ! -x "${1}" ]; then 36652400Sbillf case "${1#.}" in 36752400Sbillf /dev/MAKEDEV) 36852400Sbillf NEED_MAKEDEV=yes 36952400Sbillf ;; 37052400Sbillf /etc/aliases) 37152400Sbillf NEED_NEWALIASES=yes 37252400Sbillf ;; 37352400Sbillf /etc/login.conf) 37452400Sbillf NEED_CAP_MKDB=yes 37552400Sbillf ;; 37652400Sbillf /etc/master.passwd) 37752400Sbillf install -m 600 "${1}" "${INSTALL_DIR}" 37852400Sbillf NEED_PWD_MKDB=yes 37952400Sbillf DONT_INSTALL=yes 38052400Sbillf ;; 38152400Sbillf /.cshrc | /.profile) 38252400Sbillf case "${LINK_EXPLAINED}" in 38352400Sbillf '') 38452400Sbillf echo " *** Historically FreeBSD has had a hard link from" 38552400Sbillf echo " /.cshrc and /.profile to their namesakes in" 38652400Sbillf echo " /root. Please indicate your preference below" 38752400Sbillf echo " for bringing your installed files up to date." 38852400Sbillf echo '' 38952400Sbillf LINK_EXPLAINED=yes 39052400Sbillf ;; 39152400Sbillf esac 39252400Sbillf 39352400Sbillf echo " Use 'd' to delete the temporary ${COMPFILE}" 39452400Sbillf echo " Use 'l' to delete the existing ${COMPFILE#.} and create the link" 39552400Sbillf echo '' 39652400Sbillf echo " Default is to leave the temporary file to deal with by hand" 39752400Sbillf echo '' 39852400Sbillf read -p " How should I handle ${COMPFILE}? [Leave it to install later] " HANDLE_LINK 39952400Sbillf case "${HANDLE_LINK}" in 40052400Sbillf [dD]*) 40152400Sbillf rm "${COMPFILE}" 40252400Sbillf echo '' 40352400Sbillf echo " *** Deleting ${COMPFILE}" 40452400Sbillf ;; 40552400Sbillf [lL]*) 40652400Sbillf echo '' 40752400Sbillf if [ -e "${COMPFILE#.}" ]; then 40852400Sbillf rm "${COMPFILE#.}" 40952400Sbillf fi 41052400Sbillf if ln "/root/${COMPFILE##*/}" "${COMPFILE#.}"; then 41152400Sbillf echo " *** Link from ${COMPFILE#.} to /root/${COMPFILE##*/} installed successfully" 41252400Sbillf rm "${COMPFILE}" 41352400Sbillf else 41452400Sbillf echo " *** Error linking ${COMPFILE#.} to /root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand" 41552400Sbillf fi 41652400Sbillf ;; 41752400Sbillf *) 41852400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 41952400Sbillf ;; 42052400Sbillf esac 42152400Sbillf DONT_INSTALL=yes 42252400Sbillf ;; 42352400Sbillf esac 42452400Sbillf 42552400Sbillf case "${DONT_INSTALL}" in 42652400Sbillf '') 42752400Sbillf install -m "${FILE_MODE}" "${1}" "${INSTALL_DIR}" 42852400Sbillf ;; 42952400Sbillf *) 43052400Sbillf unset DONT_INSTALL 43152400Sbillf ;; 43252400Sbillf esac 43352400Sbillf 43452400Sbillf else 43552400Sbillf install -m "${FILE_MODE}" "${1}" "${INSTALL_DIR}" 43652400Sbillf fi 43752400Sbillf return $? 43852400Sbillf} 43952400Sbillf 44052400Sbillfcompare_ids () { 44152400Sbillf case "${1}" in 44252400Sbillf "${2}") 44352400Sbillf echo " *** Temp ${COMPFILE} and installed have the same ${IDTAG}, deleting" 44452400Sbillf rm "${COMPFILE}" 44552400Sbillf ;; 44652400Sbillf esac 44752400Sbillf} 44852400Sbillf 44952400Sbillf# Using -size +0 avoids uselessly checking the empty log files created 45052400Sbillf# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does 45152400Sbillf# check the scripts in ./dev, as we'd like. 45252400Sbillf# 45352400Sbillffor COMPFILE in `find . -type f -size +0`; do 45452400Sbillf case "${STRICT}" in 45552400Sbillf '' | [Nn][Oo]) 45652400Sbillf # Compare CVS $Id's first so if the file hasn't been modified 45752400Sbillf # local changes will be ignored. 45852400Sbillf # If the files have the same $Id, delete the one in temproot so the 45952400Sbillf # user will have less to wade through if files are left to merge by hand. 46052400Sbillf # Take the $Id -> $FreeBSD tag change into account 46152400Sbillf # 46252400Sbillf FREEBSDID1=`grep "[$]FreeBSD:" ${COMPFILE#.} 2>/dev/null` 46352400Sbillf FREEBSDID2=`grep "[$]FreeBSD:" ${COMPFILE} 2>/dev/null` 46452400Sbillf 46552400Sbillf if [ -n "${FREEBSDID1}" -a -n "${FREEBSDID2}" ]; then 46652400Sbillf IDTAG='$FreeBSD' 46752400Sbillf compare_ids "${FREEBSDID1}" "${FREEBSDID2}" 46852400Sbillf else 46952400Sbillf CVSID1=`grep "[$]Id:" ${COMPFILE#.} 2>/dev/null` 47052400Sbillf CVSID2=`grep "[$]Id:" ${COMPFILE} 2>/dev/null` 47152400Sbillf 47252400Sbillf if [ -n "${CVSID1}" -a -n "${CVSID2}" ]; then 47352400Sbillf IDTAG='$Id' 47452400Sbillf compare_ids "${CVSID1}" "${CVSID2}" 47552400Sbillf fi 47652400Sbillf fi 47752400Sbillf ;; 47852400Sbillf esac 47952400Sbillf 48052400Sbillf # If the file is still here either because the $Ids are different, the 48152400Sbillf # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 48252400Sbillf # 48352400Sbillf if [ -f "${COMPFILE}" ]; then 48452400Sbillf 48552400Sbillf # Do an absolute diff first to see if the files are actually different. 48652400Sbillf # If they're not different, delete the one in temproot. 48752400Sbillf # 48852400Sbillf if diff -q "${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then 48952400Sbillf echo " *** Temp ${COMPFILE} and installed are the same, deleting" 49052400Sbillf rm "${COMPFILE}" 49152400Sbillf else 49252400Sbillf # Ok, the files are different, so show the user where they differ. Use user's 49352400Sbillf # choice of diff methods; and user's pager if they have one. Use more if not. 49452400Sbillf # Use unified diffs by default. Context diffs give me a headache. :) 49552400Sbillf # 49652400Sbillf case "${AUTO_RUN}" in 49752400Sbillf '') 49852400Sbillf echo '' 49952400Sbillf if [ -f "${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 50052400Sbillf echo " *** Displaying differences between ${COMPFILE} and installed version" 50152400Sbillf echo '' 50252400Sbillf diff "${DIFF_FLAG}" "${COMPFILE#.}" "${COMPFILE}" | ${PAGER} 50352400Sbillf echo '' 50452400Sbillf else 50552400Sbillf echo " *** There is no installed version of ${COMPFILE}" 50652400Sbillf NO_INSTALLED=yes 50752400Sbillf fi 50852400Sbillf echo " Use 'd' to delete the temporary ${COMPFILE}" 50952400Sbillf echo " Use 'i' to install the temporary ${COMPFILE}" 51052400Sbillf case "${NO_INSTALLED}" in 51152400Sbillf '') 51252400Sbillf echo " Use 'm' to merge the old and new versions" 51352400Sbillf ;; 51452400Sbillf esac 51552400Sbillf echo '' 51652400Sbillf echo " Default is to leave the temporary file to deal with by hand" 51752400Sbillf echo '' 51852400Sbillf read -p "How should I deal with this? [Leave it for later] " HANDLE_COMPFILE 51952400Sbillf case "${HANDLE_COMPFILE}" in 52052400Sbillf [dD]*) 52152400Sbillf rm "${COMPFILE}" 52252400Sbillf echo '' 52352400Sbillf echo " *** Deleting ${COMPFILE}" 52452400Sbillf ;; 52552400Sbillf [iI]*) 52652400Sbillf echo '' 52752400Sbillf if mm_install "${COMPFILE}"; then 52852400Sbillf echo " *** ${COMPFILE} installed successfully" 52952400Sbillf else 53052400Sbillf echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 53152400Sbillf fi 53252400Sbillf ;; 53352400Sbillf [mM]*) 53452400Sbillf case "${NO_INSTALLED}" in 53552400Sbillf '') 53652400Sbillf case "${VERBOSE}" in 53752400Sbillf '') ;; 53852400Sbillf *) 53952400Sbillf echo " *** Type h at the sdiff prompt (%) to get usage help" 54052400Sbillf ;; 54152400Sbillf esac 54252400Sbillf echo '' 54352400Sbillf MERGE_AGAIN=yes 54452400Sbillf while [ "${MERGE_AGAIN}" = "yes" ]; do 54552400Sbillf # Prime file.merged so we don't blat the owner/group id's 54652400Sbillf cp -p "${COMPFILE}" "${COMPFILE}.merged" 54752400Sbillf sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 54852400Sbillf --width=${SCREEN_WIDTH:-80} "${COMPFILE#.}" "${COMPFILE}" 54952400Sbillf 55052400Sbillf echo '' 55152400Sbillf echo " Use 'i' to install merged file" 55252400Sbillf echo " Use 'r' to re-do the merge" 55352400Sbillf echo " Default is to leave the temporary file to deal with by hand" 55452400Sbillf echo '' 55552400Sbillf read -p " *** How should I deal with the merged file? [Leave it for later] " INSTALL_MERGED 55652400Sbillf 55752400Sbillf case "${INSTALL_MERGED}" in 55852400Sbillf [iI]*) 55952400Sbillf mv "${COMPFILE}.merged" "${COMPFILE}" 56052400Sbillf echo '' 56152400Sbillf if mm_install "${COMPFILE}"; then 56252400Sbillf echo " *** Merged version of ${COMPFILE} installed successfully" 56352400Sbillf else 56452400Sbillf echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 56552400Sbillf fi 56652400Sbillf unset MERGE_AGAIN 56752400Sbillf ;; 56852400Sbillf [rR]*) 56952400Sbillf rm "${COMPFILE}.merged" 57052400Sbillf ;; 57152400Sbillf *) 57252400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 57352400Sbillf unset MERGE_AGAIN 57452400Sbillf ;; 57552400Sbillf esac 57652400Sbillf done 57752400Sbillf ;; 57852400Sbillf *) 57952400Sbillf echo '' 58052400Sbillf echo " *** There is no installed version of ${COMPFILE}" 58152400Sbillf echo " to merge so it will remain to install by hand later" 58252400Sbillf echo '' 58352400Sbillf echo " *** Press [Enter] or [Return] key to continue" 58452400Sbillf read ANY_KEY 58552400Sbillf unset ANY_KEY 58652400Sbillf ;; 58752400Sbillf esac # End of "No installed version of file but user selected merge" test 58852400Sbillf ;; 58952400Sbillf *) 59052400Sbillf echo '' 59152400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 59252400Sbillf ;; 59352400Sbillf esac # End of "How to handle files that are different" 59452400Sbillf unset NO_INSTALLED 59552400Sbillf echo '' 59652400Sbillf case "${VERBOSE}" in 59752400Sbillf '') ;; 59852400Sbillf *) 59952400Sbillf sleep 3 60052400Sbillf ;; 60152400Sbillf esac 60252400Sbillf ;; 60352400Sbillf *) 60452400Sbillf # If this is an auto run, make it official 60552400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 60652400Sbillf ;; 60752400Sbillf esac # Auto run test 60852400Sbillf fi # Yes, the files are different 60952400Sbillf fi # Yes, the file still remains to be checked 61052400Sbillfdone # This is for the do way up there at the beginning of the comparison 61152400Sbillf 61252400Sbillfecho "*** Comparison complete" 61352400Sbillfecho '' 61452400Sbillf 61552400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 61652400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then 61752400Sbillf echo "*** Files that remain for you to merge by hand:" 61852400Sbillf find "${TEMPROOT}" -type f -size +0 61952400Sbillffi 62052400Sbillf 62152400Sbillfcase "${AUTO_RUN}" in 62252400Sbillf'') 62352400Sbillf echo '' 62452400Sbillf read -p "Do you wish to delete what is left of ${TEMPROOT}? [no] " DEL_TEMPROOT 62552400Sbillf case "${DEL_TEMPROOT}" in 62652400Sbillf [yY]*) 62752400Sbillf if rm -rf "${TEMPROOT}"; then 62852400Sbillf echo " *** ${TEMPROOT} has been deleted" 62952400Sbillf else 63052400Sbillf echo " *** Unable to delete ${TEMPROOT}" 63152400Sbillf fi 63252400Sbillf ;; 63352400Sbillf *) 63452400Sbillf echo " *** ${TEMPROOT} will remain" 63552400Sbillf ;; 63652400Sbillf esac 63752400Sbillf ;; 63852400Sbillf*) ;; 63952400Sbillfesac 64052400Sbillf 64152400Sbillfcase "${NEED_MAKEDEV}" in 64252400Sbillf'') ;; 64352400Sbillf*) 64452400Sbillf echo '' 64552400Sbillf echo "*** You installed a new /dev/MAKEDEV script, so make sure that you run" 64652400Sbillf echo " 'cd /dev && /bin/sh MAKEDEV all' to rebuild your devices" 64752400Sbillf ;; 64852400Sbillfesac 64952400Sbillf 65052400Sbillfcase "${NEED_NEWALIASES}" in 65152400Sbillf'') ;; 65252400Sbillf*) 65352400Sbillf echo '' 65452400Sbillf echo "*** You installed a new aliases file, so make sure that you run" 65552400Sbillf echo " 'newaliases' to rebuild your aliases database" 65652400Sbillf ;; 65752400Sbillfesac 65852400Sbillf 65952400Sbillfcase "${NEED_CAP_MKDB}" in 66052400Sbillf'') ;; 66152400Sbillf*) 66252400Sbillf echo '' 66352400Sbillf echo "*** You installed a login.conf file, so make sure that you run" 66452400Sbillf echo " 'cap_mkdb /etc/login.conf' to rebuild your login.conf database" 66552400Sbillf ;; 66652400Sbillfesac 66752400Sbillf 66852400Sbillfcase "${NEED_PWD_MKDB}" in 66952400Sbillf'') ;; 67052400Sbillf*) 67152400Sbillf echo '' 67252400Sbillf echo "*** You installed a new master.passwd file, so make sure that you run" 67352400Sbillf echo " 'pwd_mkdb -p /etc/master.passwd' to rebuild your password files" 67452400Sbillf ;; 67552400Sbillfesac 67652400Sbillf 67752400Sbillfecho '' 67852400Sbillf 67952400Sbillfexit 0 680