mergemaster.sh revision 91223
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 890564Sdougb# Copyright 1998-2002 Douglas Barton 973651Sdougb# DougB@FreeBSD.org 1052400Sbillf 1152495Sbillf# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 91223 2002-02-25 04:52:56Z dougb $ 1252400Sbillf 1368507SdougbPATH=/bin:/usr/bin:/usr/sbin 1452400Sbillf 1552400Sbillfdisplay_usage () { 1652533Sbillf VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4` 1752400Sbillf echo "mergemaster version ${VERSION_NUMBER}" 1891193Sdougb echo 'Usage: mergemaster [-scrvahipC] [-m /path]' 1967949Sdougb echo ' [-t /path] [-d] [-u N] [-w N] [-D /path]' 2052400Sbillf echo "Options:" 2152400Sbillf echo " -s Strict comparison (diff every pair of files)" 2252400Sbillf echo " -c Use context diff instead of unified diff" 2352400Sbillf echo " -r Re-run on a previously cleaned directory (skip temproot creation)" 2452400Sbillf echo " -v Be more verbose about the process, include additional checks" 2552400Sbillf echo " -a Leave all files that differ to merge by hand" 2652400Sbillf echo " -h Display more complete help" 2767949Sdougb echo ' -i Automatically install files that do not exist in destination directory' 2891193Sdougb echo ' -p Pre-buildworld mode, only compares crucial files' 2991193Sdougb echo ' -C Compare local rc.conf variables to the defaults' 3052400Sbillf echo " -m /path/directory Specify location of source to do the make in" 3152400Sbillf echo " -t /path/directory Specify temp root directory" 3252400Sbillf echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" 3352400Sbillf echo " -u N Specify a numeric umask" 3452400Sbillf echo " -w N Specify a screen width in columns to sdiff" 3567949Sdougb echo ' -D /path/directory Specify the destination directory to install files to' 3652400Sbillf echo '' 3752400Sbillf} 3852400Sbillf 3952400Sbillfdisplay_help () { 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" 4367859Sdougb echo " of the screen. The default is 80." 4467949Sdougb echo '* The -a option causes mergemaster to run without prompting.' 4552400Sbillf} 4652400Sbillf 4758910Salfred# Loop allowing the user to use sdiff to merge files and display the merged 4858910Salfred# file. 4958910Salfredmerge_loop () { 5067850Sdougb case "${VERBOSE}" in 5167850Sdougb '') ;; 5267850Sdougb *) 5367850Sdougb echo " *** Type h at the sdiff prompt (%) to get usage help" 5467850Sdougb ;; 5567850Sdougb esac 5667850Sdougb echo '' 5767850Sdougb MERGE_AGAIN=yes 5867850Sdougb while [ "${MERGE_AGAIN}" = "yes" ]; do 5967850Sdougb # Prime file.merged so we don't blat the owner/group id's 6067850Sdougb cp -p "${COMPFILE}" "${COMPFILE}.merged" 6167850Sdougb sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 6267949Sdougb --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 6367850Sdougb INSTALL_MERGED=V 6467850Sdougb while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 6567850Sdougb echo '' 6667850Sdougb echo " Use 'i' to install merged file" 6767850Sdougb echo " Use 'r' to re-do the merge" 6867850Sdougb echo " Use 'v' to view the merged file" 6967850Sdougb echo " Default is to leave the temporary file to deal with by hand" 7067850Sdougb echo '' 7167859Sdougb echo -n " *** How should I deal with the merged file? [Leave it for later] " 7267859Sdougb read INSTALL_MERGED 7358910Salfred 7467850Sdougb case "${INSTALL_MERGED}" in 7567850Sdougb [iI]) 7667850Sdougb mv "${COMPFILE}.merged" "${COMPFILE}" 7767850Sdougb echo '' 7867850Sdougb if mm_install "${COMPFILE}"; then 7967850Sdougb echo " *** Merged version of ${COMPFILE} installed successfully" 8067859Sdougb else 8167850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 8267859Sdougb fi 8367850Sdougb unset MERGE_AGAIN 8467850Sdougb ;; 8567850Sdougb [rR]) 8667850Sdougb rm "${COMPFILE}.merged" 8767859Sdougb ;; 8867850Sdougb [vV]) 8967850Sdougb ${PAGER} "${COMPFILE}.merged" 9067850Sdougb ;; 9167850Sdougb '') 9267850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 9367850Sdougb unset MERGE_AGAIN 9467850Sdougb ;; 9567850Sdougb *) 9667850Sdougb echo "invalid choice: ${INSTALL_MERGED}" 9767850Sdougb INSTALL_MERGED=V 9867850Sdougb ;; 9967850Sdougb esac 10067850Sdougb done 10167850Sdougb done 10258910Salfred} 10358910Salfred 10458910Salfred# Loop showing user differences between files, allow merge, skip or install 10558910Salfred# options 10658910Salfreddiff_loop () { 10758910Salfred 10867850Sdougb HANDLE_COMPFILE=v 10958910Salfred 11077323Sdougb while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \ 11177323Sdougb "${HANDLE_COMPFILE}" = "NOT V" ]; do 11267949Sdougb if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 11367850Sdougb if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 11490564Sdougb echo '' 11590564Sdougb echo ' ====================================================================== ' 11690564Sdougb echo '' 11767850Sdougb ( 11867949Sdougb echo '' 11967850Sdougb echo " *** Displaying differences between ${COMPFILE} and installed version:" 12067850Sdougb echo '' 12167949Sdougb diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 12267850Sdougb ) | ${PAGER} 12367850Sdougb echo '' 12467850Sdougb fi 12567850Sdougb else 12667949Sdougb echo '' 12767850Sdougb echo " *** There is no installed version of ${COMPFILE}" 12891193Sdougb echo '' 12967949Sdougb case "${AUTO_INSTALL}" in 13067949Sdougb [Yy][Ee][Ss]) 13167949Sdougb echo '' 13267949Sdougb if mm_install "${COMPFILE}"; then 13367949Sdougb echo " *** ${COMPFILE} installed successfully" 13468507Sdougb echo '' 13567949Sdougb # Make the list print one file per line 13667949Sdougb AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 13767949Sdougb" 13867949Sdougb else 13967949Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 14067949Sdougb fi 14167949Sdougb return 14267949Sdougb ;; 14367949Sdougb *) 14467949Sdougb NO_INSTALLED=yes 14567949Sdougb ;; 14667949Sdougb esac 14767850Sdougb fi 14867859Sdougb 14967850Sdougb echo " Use 'd' to delete the temporary ${COMPFILE}" 15067850Sdougb echo " Use 'i' to install the temporary ${COMPFILE}" 15167850Sdougb case "${NO_INSTALLED}" in 15267850Sdougb '') 15377326Sdougb echo " Use 'm' to merge the temporary and installed versions" 15477326Sdougb echo " Use 'v' to view the diff results again" 15567850Sdougb ;; 15667850Sdougb esac 15767850Sdougb echo '' 15867850Sdougb echo " Default is to leave the temporary file to deal with by hand" 15967850Sdougb echo '' 16067859Sdougb echo -n "How should I deal with this? [Leave it for later] " 16167859Sdougb read HANDLE_COMPFILE 16267859Sdougb 16367850Sdougb case "${HANDLE_COMPFILE}" in 16467850Sdougb [dD]) 16567850Sdougb rm "${COMPFILE}" 16667850Sdougb echo '' 16767850Sdougb echo " *** Deleting ${COMPFILE}" 16867850Sdougb ;; 16967850Sdougb [iI]) 17067850Sdougb echo '' 17167850Sdougb if mm_install "${COMPFILE}"; then 17267850Sdougb echo " *** ${COMPFILE} installed successfully" 17367850Sdougb else 17467850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 17567850Sdougb fi 17667850Sdougb ;; 17767850Sdougb [mM]) 17867850Sdougb case "${NO_INSTALLED}" in 17967850Sdougb '') 18067850Sdougb # interact with user to merge files 18167850Sdougb merge_loop 18267850Sdougb ;; 18367850Sdougb *) 18467850Sdougb echo '' 18567850Sdougb echo " *** There is no installed version of ${COMPFILE}" 18667850Sdougb echo '' 18767850Sdougb HANDLE_COMPFILE="NOT V" 18867850Sdougb ;; 18967850Sdougb esac # End of "No installed version of file but user selected merge" test 19067850Sdougb ;; 19167850Sdougb [vV]) 19267850Sdougb continue 19367850Sdougb ;; 19467850Sdougb '') 19567850Sdougb echo '' 19667850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 19767850Sdougb ;; 19867850Sdougb *) 19967850Sdougb # invalid choice, show menu again. 20067850Sdougb echo "invalid choice: ${HANDLE_COMPFILE}" 20167850Sdougb echo '' 20267850Sdougb HANDLE_COMPFILE="NOT V" 20367850Sdougb continue 20467850Sdougb ;; 20567850Sdougb esac # End of "How to handle files that are different" 20667859Sdougb done 20767850Sdougb unset NO_INSTALLED 20867850Sdougb echo '' 20967850Sdougb case "${VERBOSE}" in 21067850Sdougb '') ;; 21167850Sdougb *) 21267850Sdougb sleep 3 21367850Sdougb ;; 21467850Sdougb esac 21558910Salfred} 21658910Salfred 21752400Sbillf# Set the default path for the temporary root environment 21852400Sbillf# 21952400SbillfTEMPROOT='/var/tmp/temproot' 22052400Sbillf 22173651Sdougb# Read /etc/mergemaster.rc first so the one in $HOME can override 22273651Sdougb# 22373651Sdougbif [ -r /etc/mergemaster.rc ]; then 22473651Sdougb . /etc/mergemaster.rc 22573651Sdougbfi 22673651Sdougb 22752400Sbillf# Read .mergemasterrc before command line so CLI can override 22852400Sbillf# 22967949Sdougbif [ -r "$HOME/.mergemasterrc" ]; then 23052400Sbillf . "$HOME/.mergemasterrc" 23152400Sbillffi 23252400Sbillf 23352400Sbillf# Check the command line options 23452400Sbillf# 23591193Sdougbwhile getopts ":ascrvhipCm:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do 23652400Sbillf case "${COMMAND_LINE_ARGUMENT}" in 23752400Sbillf s) 23852400Sbillf STRICT=yes 23952400Sbillf ;; 24052400Sbillf c) 24152400Sbillf DIFF_FLAG='-c' 24252400Sbillf ;; 24352400Sbillf r) 24452400Sbillf RERUN=yes 24552400Sbillf ;; 24652400Sbillf v) 24752400Sbillf case "${AUTO_RUN}" in 24852400Sbillf '') VERBOSE=yes ;; 24952400Sbillf esac 25052400Sbillf ;; 25152400Sbillf a) 25252400Sbillf AUTO_RUN=yes 25352400Sbillf unset VERBOSE 25452400Sbillf ;; 25552400Sbillf h) 25652400Sbillf display_usage 25752400Sbillf display_help 25852400Sbillf exit 0 25952400Sbillf ;; 26067949Sdougb i) 26167949Sdougb AUTO_INSTALL=yes 26267949Sdougb ;; 26391193Sdougb p) 26491193Sdougb PRE_WORLD=yes 26591193Sdougb ;; 26691193Sdougb C) 26791193Sdougb COMP_CONFS=yes 26891193Sdougb ;; 26952400Sbillf m) 27052400Sbillf SOURCEDIR=${OPTARG} 27152400Sbillf ;; 27252400Sbillf t) 27352400Sbillf TEMPROOT=${OPTARG} 27452400Sbillf ;; 27552400Sbillf d) 27652400Sbillf TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 27752400Sbillf ;; 27852400Sbillf u) 27952400Sbillf NEW_UMASK=${OPTARG} 28052400Sbillf ;; 28152400Sbillf w) 28252400Sbillf SCREEN_WIDTH=${OPTARG} 28352400Sbillf ;; 28467949Sdougb D) 28567949Sdougb DESTDIR=${OPTARG} 28667949Sdougb ;; 28752400Sbillf *) 28852400Sbillf display_usage 28952400Sbillf exit 1 29052400Sbillf ;; 29152400Sbillf esac 29252400Sbillfdone 29352400Sbillf 29452400Sbillfecho '' 29552400Sbillf 29652400Sbillf# If the user has a pager defined, make sure we can run it 29752400Sbillf# 29852400Sbillfcase "${DONT_CHECK_PAGER}" in 29952400Sbillf'') 30064467Sbrian while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do 30152400Sbillf echo " *** Your PAGER environment variable specifies '${PAGER}', but" 30264467Sbrian echo " due to the limited PATH that I use for security reasons," 30367859Sdougb echo " I cannot execute it. So, what would you like to do?" 30452400Sbillf echo '' 30552400Sbillf echo " Use 'e' to exit mergemaster and fix your PAGER variable" 30664467Sbrian if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 30764467Sbrian echo " Use 'l' to set PAGER to 'less' for this run" 30852400Sbillf fi 30952400Sbillf echo " Use 'm' to use plain old 'more' as your PAGER for this run" 31052400Sbillf echo '' 31152400Sbillf echo " Default is to use plain old 'more' " 31252400Sbillf echo '' 31367859Sdougb echo -n "What should I do? [Use 'more'] " 31467859Sdougb read FIXPAGER 31567859Sdougb 31652400Sbillf case "${FIXPAGER}" in 31758910Salfred [eE]) 31852400Sbillf exit 0 31952400Sbillf ;; 32058910Salfred [lL]) 32164467Sbrian if [ -x /usr/bin/less ]; then 32264467Sbrian PAGER=/usr/bin/less 32364467Sbrian elif [ -x /usr/local/bin/less ]; then 32458910Salfred PAGER=/usr/local/bin/less 32564467Sbrian else 32664467Sbrian echo '' 32764467Sbrian echo " *** Fatal Error:" 32864467Sbrian echo " You asked to use 'less' as your pager, but I can't" 32964467Sbrian echo " find it in /usr/bin or /usr/local/bin" 33064467Sbrian exit 1 33158910Salfred fi 33252400Sbillf ;; 33360420Sbsd [mM]|'') 33452400Sbillf PAGER=more 33552400Sbillf ;; 33658910Salfred *) 33758910Salfred echo '' 33858910Salfred echo "invalid choice: ${FIXPAGER}" 33952400Sbillf esac 34052400Sbillf echo '' 34158910Salfred done 34252400Sbillf ;; 34352400Sbillfesac 34452400Sbillf 34552400Sbillf# If user has a pager defined, or got assigned one above, use it. 34652400Sbillf# If not, use more. 34752400Sbillf# 34852400SbillfPAGER=${PAGER:-more} 34952400Sbillf 35052400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 35152400Sbillf echo " *** You have ${PAGER} defined as your pager so we will use that" 35252400Sbillf echo '' 35352400Sbillf sleep 3 35452400Sbillffi 35552400Sbillf 35652400Sbillf# Assign the diff flag once so we will not have to keep testing it 35752400Sbillf# 35852400SbillfDIFF_FLAG=${DIFF_FLAG:--u} 35952400Sbillf 36052400Sbillf# Assign the source directory 36152400Sbillf# 36252400SbillfSOURCEDIR=${SOURCEDIR:-/usr/src/etc} 36352400Sbillf 36473651Sdougb# Define what CVS $Id tag to look for to aid portability. 36573651Sdougb# 36673651SdougbCVS_ID_TAG=FreeBSD 36773651Sdougb 36852400Sbillfcase "${RERUN}" in 36952400Sbillf'') 37052400Sbillf # Set up the loop to test for the existence of the 37152400Sbillf # temp root directory. 37252400Sbillf # 37352400Sbillf TEST_TEMP_ROOT=yes 37452400Sbillf while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 37552400Sbillf if [ -d "${TEMPROOT}" ]; then 37652400Sbillf echo "*** The directory specified for the temporary root environment," 37767859Sdougb echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 37852400Sbillf echo " users have access to the system." 37952400Sbillf echo '' 38052400Sbillf case "${AUTO_RUN}" in 38152400Sbillf '') 38252400Sbillf echo " Use 'd' to delete the old ${TEMPROOT} and continue" 38352400Sbillf echo " Use 't' to select a new temporary root directory" 38452400Sbillf echo " Use 'e' to exit mergemaster" 38552400Sbillf echo '' 38652400Sbillf echo " Default is to use ${TEMPROOT} as is" 38752400Sbillf echo '' 38867859Sdougb echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 38967859Sdougb read DELORNOT 39067859Sdougb 39167859Sdougb case "${DELORNOT}" in 39267859Sdougb [dD]) 39367859Sdougb echo '' 39467859Sdougb echo " *** Deleting the old ${TEMPROOT}" 39567859Sdougb echo '' 39667859Sdougb rm -rf "${TEMPROOT}" 39767859Sdougb unset TEST_TEMP_ROOT 39852400Sbillf ;; 39967859Sdougb [tT]) 40067859Sdougb echo " *** Enter new directory name for temporary root environment" 40167859Sdougb read TEMPROOT 40267859Sdougb ;; 40367859Sdougb [eE]) 40467859Sdougb exit 0 40567859Sdougb ;; 40667859Sdougb '') 40767859Sdougb echo '' 40867859Sdougb echo " *** Leaving ${TEMPROOT} intact" 40967859Sdougb echo '' 41067859Sdougb unset TEST_TEMP_ROOT 41167859Sdougb ;; 41267859Sdougb *) 41367859Sdougb echo '' 41467859Sdougb echo "invalid choice: ${DELORNOT}" 41567859Sdougb echo '' 41667859Sdougb ;; 41767859Sdougb esac 41867859Sdougb ;; 41952400Sbillf *) 42077323Sdougb # If this is an auto-run, try a hopefully safe alternative then 42177323Sdougb # re-test anyway. 42252400Sbillf TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 42352400Sbillf ;; 42452400Sbillf esac 42552400Sbillf else 42652400Sbillf unset TEST_TEMP_ROOT 42752400Sbillf fi 42852400Sbillf done 42952400Sbillf 43052400Sbillf echo "*** Creating the temporary root environment in ${TEMPROOT}" 43152400Sbillf 43252400Sbillf if mkdir -p "${TEMPROOT}"; then 43352400Sbillf echo " *** ${TEMPROOT} ready for use" 43452400Sbillf fi 43552400Sbillf 43652400Sbillf if [ ! -d "${TEMPROOT}" ]; then 43752400Sbillf echo '' 43852400Sbillf echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 43952400Sbillf echo '' 44052400Sbillf exit 1 44152400Sbillf fi 44252400Sbillf 44352400Sbillf echo " *** Creating and populating directory structure in ${TEMPROOT}" 44452400Sbillf echo '' 44552400Sbillf 44652400Sbillf case "${VERBOSE}" in 44752400Sbillf '') ;; 44852400Sbillf *) 44952400Sbillf echo " *** Press [Enter] or [Return] key to continue" 45052400Sbillf read ANY_KEY 45152400Sbillf unset ANY_KEY 45252400Sbillf ;; 45352400Sbillf esac 45452400Sbillf 45591193Sdougb case "${PRE_WORLD}" in 45691193Sdougb '') 45791193Sdougb { cd ${SOURCEDIR} && 45891193Sdougb case "${DESTDIR}" in 45991193Sdougb '') ;; 46091193Sdougb *) 46168507Sdougb make DESTDIR=${DESTDIR} distrib-dirs 46291193Sdougb ;; 46391193Sdougb esac 46491193Sdougb make DESTDIR=${TEMPROOT} distrib-dirs && 46591193Sdougb make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj obj && 46691193Sdougb make MAKEOBJDIRPREFIX=${TEMPROOT}/usr/obj DESTDIR=${TEMPROOT} \ 46791193Sdougb -DNO_MAKEDEV_RUN distribution;} || 46891193Sdougb { echo ''; 46991193Sdougb echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 47091193Sdougb echo " the temproot environment"; 47191193Sdougb echo ''; 47291193Sdougb exit 1;} 47391193Sdougb ;; 47491193Sdougb *) 47591193Sdougb # Only set up files that are crucial to {build|install}world 47691193Sdougb { mkdir -p ${TEMPROOT}/etc && 47791193Sdougb cp -p ${SOURCEDIR}/master.passwd ${TEMPROOT}/etc && 47891193Sdougb cp -p ${SOURCEDIR}/group ${TEMPROOT}/etc;} || 47991193Sdougb { echo ''; 48091193Sdougb echo ' *** FATAL ERROR: Cannot copy files to the temproot environment'; 48191193Sdougb echo ''; 48291193Sdougb exit 1;} 48391193Sdougb ;; 48491193Sdougb esac 48552400Sbillf 48677323Sdougb # Doing the inventory and removing files that we don't want to compare only 48777323Sdougb # makes sense if we are not doing a rerun, since we have no way of knowing 48877323Sdougb # what happened to the files during previous incarnations. 48967949Sdougb case "${VERBOSE}" in 49067949Sdougb '') ;; 49167949Sdougb *) 49267949Sdougb echo '' 49367949Sdougb echo ' *** The following files exist only in the installed version of' 49467949Sdougb echo " ${DESTDIR}/etc. In the vast majority of cases these files" 49567949Sdougb echo ' are necessary parts of the system and should not be deleted.' 49667949Sdougb echo ' However because these files are not updated by this process you' 49767949Sdougb echo ' might want to verify their status before rebooting your system.' 49867949Sdougb echo '' 49967949Sdougb echo ' *** Press [Enter] or [Return] key to continue' 50067949Sdougb read ANY_KEY 50167949Sdougb unset ANY_KEY 50267949Sdougb diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER} 50367949Sdougb echo '' 50467949Sdougb echo ' *** Press [Enter] or [Return] key to continue' 50567949Sdougb read ANY_KEY 50667949Sdougb unset ANY_KEY 50767949Sdougb ;; 50867949Sdougb esac 50967949Sdougb 51052534Sbillf # Avoid comparing the motd if the user specifies it in .mergemasterrc 51152534Sbillf case "${IGNORE_MOTD}" in 51252534Sbillf '') ;; 51352534Sbillf *) rm ${TEMPROOT}/etc/motd 51452534Sbillf ;; 51552534Sbillf esac 51652534Sbillf 51765115Sben # Avoid trying to update MAKEDEV if /dev is on a devfs 51868507Sdougb if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 51991193Sdougb rm -f ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local 52065115Sben fi 52165115Sben 52252400Sbillf ;; # End of the "RERUN" test 52352400Sbillfesac 52452400Sbillf 52577478Sdougb# We really don't want to have to deal with these files, since 52677478Sdougb# master.passwd is the real file that should be compared, then 52777478Sdougb# the user should run pwd_mkdb if necessary. 52877478Sdougb# 52991193Sdougbrm -f ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db 53077478Sdougb 53152400Sbillf# Get ready to start comparing files 53252400Sbillf 53352400Sbillf# Check umask if not specified on the command line, 53452400Sbillf# and we are not doing an autorun 53552400Sbillf# 53652400Sbillfif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 53752400Sbillf USER_UMASK=`umask` 53852400Sbillf case "${USER_UMASK}" in 53977335Sdougb 0022|022) ;; 54052400Sbillf *) 54152400Sbillf echo '' 54267859Sdougb echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 54352400Sbillf echo " installs all files with the same user, group and modes that" 54452400Sbillf echo " they are created with by ${SOURCEDIR}/Makefile, compared to" 54567859Sdougb echo " a umask of 022. This umask allows world read permission when" 54652400Sbillf echo " the file's default permissions have it." 54767859Sdougb echo " No world permissions can sometimes cause problems. A umask of" 54852400Sbillf echo " 022 will restore the default behavior, but is not mandatory." 54967859Sdougb echo " /etc/master.passwd is a special case. Its file permissions" 55052400Sbillf echo " will be 600 (rw-------) if installed." 55152400Sbillf echo '' 55267859Sdougb echo -n "What umask should I use? [${USER_UMASK}] " 55367859Sdougb read NEW_UMASK 55467859Sdougb 55552400Sbillf NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 55652400Sbillf ;; 55752400Sbillf esac 55852400Sbillf echo '' 55952400Sbillffi 56052400Sbillf 56152400SbillfCONFIRMED_UMASK=${NEW_UMASK:-0022} 56252400Sbillf 56367949Sdougb# Warn users who still have ${DESTDIR}/etc/sysconfig 56452400Sbillf# 56567949Sdougbif [ -e "${DESTDIR}/etc/sysconfig" ]; then 56652400Sbillf echo '' 56767949Sdougb echo " *** There is a sysconfig file on this system in ${DESTDIR}/etc/." 56867949Sdougb echo '' 56967949Sdougb echo ' Starting with FreeBSD version 2.2.2 those settings moved from' 57067949Sdougb echo ' /etc/sysconfig to /etc/rc.conf. If you are upgrading an older' 57167949Sdougb echo ' system make sure that you transfer your settings by hand from' 57267949Sdougb echo ' sysconfig to rc.conf and install the rc.conf file. If you' 57367949Sdougb echo ' have already made this transition, you should consider' 57467949Sdougb echo ' renaming or deleting the sysconfig file.' 57567949Sdougb echo '' 57652400Sbillf case "${AUTO_RUN}" in 57752400Sbillf '') 57867859Sdougb echo -n "Continue with the merge process? [yes] " 57967859Sdougb read CONT_OR_NOT 58067859Sdougb 58152400Sbillf case "${CONT_OR_NOT}" in 58252400Sbillf [nN]*) 58352400Sbillf exit 0 58452400Sbillf ;; 58552400Sbillf *) 58652400Sbillf echo " *** Continuing" 58752400Sbillf echo '' 58852400Sbillf ;; 58952400Sbillf esac 59052400Sbillf ;; 59152400Sbillf *) ;; 59252400Sbillf esac 59352400Sbillffi 59452400Sbillf 59552400Sbillf# Use the umask/mode information to install the files 59652400Sbillf# Create directories as needed 59752400Sbillf# 59878490Sdougbdo_install_and_rm () { 59978490Sdougb install -m "${1}" "${2}" "${3}" && 60091193Sdougb rm -f "${2}" 60178490Sdougb} 60278490Sdougb 60352400Sbillfmm_install () { 60452400Sbillf local INSTALL_DIR 60552400Sbillf INSTALL_DIR=${1#.} 60652400Sbillf INSTALL_DIR=${INSTALL_DIR%/*} 60767949Sdougb 60852400Sbillf case "${INSTALL_DIR}" in 60952400Sbillf '') 61052400Sbillf INSTALL_DIR=/ 61152400Sbillf ;; 61252400Sbillf esac 61352400Sbillf 61467949Sdougb if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 61577323Sdougb DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \ 61677323Sdougb oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"` 61767949Sdougb install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" 61852400Sbillf fi 61952400Sbillf 62077323Sdougb FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \ 62177323Sdougb oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"` 62252400Sbillf 62352400Sbillf if [ ! -x "${1}" ]; then 62452400Sbillf case "${1#.}" in 62564625Sgshapiro /etc/mail/aliases) 62652400Sbillf NEED_NEWALIASES=yes 62752400Sbillf ;; 62852400Sbillf /etc/login.conf) 62952400Sbillf NEED_CAP_MKDB=yes 63052400Sbillf ;; 63152400Sbillf /etc/master.passwd) 63278490Sdougb do_install_and_rm 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 63352400Sbillf NEED_PWD_MKDB=yes 63452400Sbillf DONT_INSTALL=yes 63552400Sbillf ;; 63652400Sbillf /.cshrc | /.profile) 63777335Sdougb case "${AUTO_INSTALL}" in 63877335Sdougb '') 63952400Sbillf case "${LINK_EXPLAINED}" in 64052400Sbillf '') 64167859Sdougb echo " *** Historically BSD derived systems have had a" 64267859Sdougb echo " hard link from /.cshrc and /.profile to" 64367859Sdougb echo " their namesakes in /root. Please indicate" 64467859Sdougb echo " your preference below for bringing your" 64567859Sdougb echo " installed files up to date." 64652400Sbillf echo '' 64752400Sbillf LINK_EXPLAINED=yes 64852400Sbillf ;; 64952400Sbillf esac 65052400Sbillf 65152400Sbillf echo " Use 'd' to delete the temporary ${COMPFILE}" 65267949Sdougb echo " Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link" 65352400Sbillf echo '' 65452400Sbillf echo " Default is to leave the temporary file to deal with by hand" 65552400Sbillf echo '' 65667859Sdougb echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 65767859Sdougb read HANDLE_LINK 65877335Sdougb ;; 65977335Sdougb *) # Part of AUTO_INSTALL 66077335Sdougb HANDLE_LINK=l 66177335Sdougb ;; 66277335Sdougb esac 66367859Sdougb 66452400Sbillf case "${HANDLE_LINK}" in 66552400Sbillf [dD]*) 66652400Sbillf rm "${COMPFILE}" 66752400Sbillf echo '' 66852400Sbillf echo " *** Deleting ${COMPFILE}" 66952400Sbillf ;; 67052400Sbillf [lL]*) 67152400Sbillf echo '' 67267949Sdougb rm -f "${DESTDIR}${COMPFILE#.}" 67367949Sdougb if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then 67467949Sdougb echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 67552400Sbillf rm "${COMPFILE}" 67652400Sbillf else 67767949Sdougb echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand" 67852400Sbillf fi 67952400Sbillf ;; 68052400Sbillf *) 68152400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 68252400Sbillf ;; 68352400Sbillf esac 68452400Sbillf DONT_INSTALL=yes 68552400Sbillf ;; 68652400Sbillf esac 68752400Sbillf 68852400Sbillf case "${DONT_INSTALL}" in 68952400Sbillf '') 69078490Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 69152400Sbillf ;; 69252400Sbillf *) 69352400Sbillf unset DONT_INSTALL 69452400Sbillf ;; 69552400Sbillf esac 69678490Sdougb else # File matched -x 69767949Sdougb case "${1#.}" in 69867949Sdougb /dev/MAKEDEV) 69967949Sdougb NEED_MAKEDEV=yes 70067949Sdougb ;; 70167949Sdougb esac 70278490Sdougb do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 70352400Sbillf fi 70452400Sbillf return $? 70552400Sbillf} 70652400Sbillf 70767949Sdougbecho '' 70867949Sdougbecho "*** Beginning comparison" 70967949Sdougbecho '' 71052400Sbillf 71167949Sdougbcd "${TEMPROOT}" 71267949Sdougb 71367949Sdougbif [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 71467949Sdougb . "${MM_PRE_COMPARE_SCRIPT}" 71567949Sdougbfi 71667949Sdougb 71752400Sbillf# Using -size +0 avoids uselessly checking the empty log files created 71852400Sbillf# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does 71967949Sdougb# check the scripts in ./dev, as we'd like (assuming no devfs of course). 72052400Sbillf# 72152400Sbillffor COMPFILE in `find . -type f -size +0`; do 72267949Sdougb 72367949Sdougb # First, check to see if the file exists in DESTDIR. If not, the 72467949Sdougb # diff_loop function knows how to handle it. 72567949Sdougb # 72667949Sdougb if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 72777325Sdougb case "${AUTO_RUN}" in 72877325Sdougb '') 72977325Sdougb diff_loop 73077325Sdougb ;; 73177325Sdougb *) 73277325Sdougb case "${AUTO_INSTALL}" in 73377325Sdougb '') 73477325Sdougb # If this is an auto run, make it official 73577325Sdougb echo " *** ${COMPFILE} will remain for your consideration" 73677325Sdougb ;; 73777325Sdougb *) 73877325Sdougb diff_loop 73977325Sdougb ;; 74077325Sdougb esac 74177325Sdougb ;; 74277325Sdougb esac # Auto run test 74367949Sdougb continue 74467949Sdougb fi 74567949Sdougb 74652400Sbillf case "${STRICT}" in 74752400Sbillf '' | [Nn][Oo]) 74852400Sbillf # Compare CVS $Id's first so if the file hasn't been modified 74952400Sbillf # local changes will be ignored. 75052400Sbillf # If the files have the same $Id, delete the one in temproot so the 75152400Sbillf # user will have less to wade through if files are left to merge by hand. 75252400Sbillf # 75373651Sdougb CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 75490564Sdougb CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` || CVSID2=none 75552400Sbillf 75667949Sdougb case "${CVSID2}" in 75773651Sdougb "${CVSID1}") 75867949Sdougb echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 75967949Sdougb rm "${COMPFILE}" 76067949Sdougb ;; 76167949Sdougb esac 76252400Sbillf ;; 76352400Sbillf esac 76452400Sbillf 76552400Sbillf # If the file is still here either because the $Ids are different, the 76652400Sbillf # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 76752400Sbillf # 76852400Sbillf if [ -f "${COMPFILE}" ]; then 76952400Sbillf 77052400Sbillf # Do an absolute diff first to see if the files are actually different. 77152400Sbillf # If they're not different, delete the one in temproot. 77252400Sbillf # 77367949Sdougb if diff -q "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then 77452400Sbillf echo " *** Temp ${COMPFILE} and installed are the same, deleting" 77552400Sbillf rm "${COMPFILE}" 77652400Sbillf else 77777323Sdougb # Ok, the files are different, so show the user where they differ. 77877323Sdougb # Use user's choice of diff methods; and user's pager if they have one. 77977323Sdougb # Use more if not. 78067859Sdougb # Use unified diffs by default. Context diffs give me a headache. :) 78152400Sbillf # 78252400Sbillf case "${AUTO_RUN}" in 78352400Sbillf '') 78458910Salfred # prompt user to install/delete/merge changes 78558910Salfred diff_loop 78652400Sbillf ;; 78752400Sbillf *) 78852400Sbillf # If this is an auto run, make it official 78952400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 79052400Sbillf ;; 79152400Sbillf esac # Auto run test 79252400Sbillf fi # Yes, the files are different 79352400Sbillf fi # Yes, the file still remains to be checked 79452400Sbillfdone # This is for the do way up there at the beginning of the comparison 79552400Sbillf 79652534Sbillfecho '' 79752400Sbillfecho "*** Comparison complete" 79852400Sbillfecho '' 79952400Sbillf 80052400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 80152400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then 80252400Sbillf echo "*** Files that remain for you to merge by hand:" 80352400Sbillf find "${TEMPROOT}" -type f -size +0 80477335Sdougb echo '' 80552400Sbillffi 80652400Sbillf 80752400Sbillfcase "${AUTO_RUN}" in 80852400Sbillf'') 80967859Sdougb echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 81067859Sdougb read DEL_TEMPROOT 81167859Sdougb 81252400Sbillf case "${DEL_TEMPROOT}" in 81352400Sbillf [yY]*) 81452400Sbillf if rm -rf "${TEMPROOT}"; then 81552400Sbillf echo " *** ${TEMPROOT} has been deleted" 81652400Sbillf else 81752400Sbillf echo " *** Unable to delete ${TEMPROOT}" 81852400Sbillf fi 81952400Sbillf ;; 82052400Sbillf *) 82152400Sbillf echo " *** ${TEMPROOT} will remain" 82252400Sbillf ;; 82352400Sbillf esac 82452400Sbillf ;; 82552400Sbillf*) ;; 82652400Sbillfesac 82752400Sbillf 82868153Sdougbcase "${AUTO_INSTALLED_FILES}" in 82968153Sdougb'') ;; 83068153Sdougb*) 83173651Sdougb case "${AUTO_RUN}" in 83273651Sdougb '') 83373651Sdougb ( 83473651Sdougb echo '' 83577323Sdougb echo '*** You chose the automatic install option for files that did not' 83677323Sdougb echo ' exist on your system. The following were installed for you:' 83773651Sdougb echo "${AUTO_INSTALLED_FILES}" 83873651Sdougb ) | ${PAGER} 83973651Sdougb ;; 84073651Sdougb *) 84168153Sdougb echo '' 84277323Sdougb echo '*** You chose the automatic install option for files that did not' 84377323Sdougb echo ' exist on your system. The following were installed for you:' 84468153Sdougb echo "${AUTO_INSTALLED_FILES}" 84573651Sdougb ;; 84673651Sdougb esac 84768153Sdougb ;; 84868153Sdougbesac 84968153Sdougb 85073651Sdougbrun_it_now () { 85173651Sdougb case "${AUTO_RUN}" in 85273651Sdougb '') 85373651Sdougb unset YES_OR_NO 85473651Sdougb echo '' 85577335Sdougb echo -n ' Would you like to run it now? y or n [n] ' 85673651Sdougb read YES_OR_NO 85773651Sdougb 85873651Sdougb case "${YES_OR_NO}" in 85973651Sdougb y) 86077335Sdougb echo " Running ${1}" 86177335Sdougb echo '' 86273651Sdougb eval "${1}" 86373651Sdougb ;; 86477335Sdougb ''|n) 86577335Sdougb echo '' 86677335Sdougb echo " *** Cancelled" 86777335Sdougb echo '' 86877335Sdougb echo " Make sure to run ${1} yourself" 86977335Sdougb ;; 87073651Sdougb *) 87177335Sdougb echo '' 87277335Sdougb echo " *** Sorry, I do not understand your answer (${YES_OR_NO})" 87377335Sdougb echo '' 87477335Sdougb echo " Make sure to run ${1} yourself" 87573651Sdougb esac 87673651Sdougb ;; 87773651Sdougb *) ;; 87873651Sdougb esac 87973651Sdougb} 88073651Sdougb 88152400Sbillfcase "${NEED_MAKEDEV}" in 88252400Sbillf'') ;; 88352400Sbillf*) 88452400Sbillf echo '' 88577335Sdougb echo "*** You installed a new ${DESTDIR}/dev/MAKEDEV script, so make sure that you run" 88677335Sdougb echo " 'cd ${DESTDIR}/dev && /bin/sh MAKEDEV all' to rebuild your devices" 88777335Sdougb run_it_now "cd ${DESTDIR}/dev && /bin/sh MAKEDEV all" 88852400Sbillf ;; 88952400Sbillfesac 89052400Sbillf 89152400Sbillfcase "${NEED_NEWALIASES}" in 89252400Sbillf'') ;; 89352400Sbillf*) 89452400Sbillf echo '' 89577335Sdougb if [ -n "${DESTDIR}" ]; then 89677335Sdougb echo "*** You installed a new aliases file into ${DESTDIR}/etc/mail, but" 89777335Sdougb echo " the newaliases command is limited to the directories configured" 89877335Sdougb echo " in sendmail.cf. Make sure to create your aliases database by" 89977335Sdougb echo " hand when your sendmail configuration is done." 90077335Sdougb else 90177335Sdougb echo "*** You installed a new aliases file, so make sure that you run" 90277335Sdougb echo " '/usr/bin/newaliases' to rebuild your aliases database" 90377335Sdougb run_it_now '/usr/bin/newaliases' 90477335Sdougb fi 90552400Sbillf ;; 90652400Sbillfesac 90752400Sbillf 90852400Sbillfcase "${NEED_CAP_MKDB}" in 90952400Sbillf'') ;; 91052400Sbillf*) 91152400Sbillf echo '' 91252400Sbillf echo "*** You installed a login.conf file, so make sure that you run" 91377335Sdougb echo " '/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf'" 91477335Sdougb echo " to rebuild your login.conf database" 91577335Sdougb run_it_now "/usr/bin/cap_mkdb ${DESTDIR}/etc/login.conf" 91652400Sbillf ;; 91752400Sbillfesac 91852400Sbillf 91952400Sbillfcase "${NEED_PWD_MKDB}" in 92052400Sbillf'') ;; 92152400Sbillf*) 92252400Sbillf echo '' 92352400Sbillf echo "*** You installed a new master.passwd file, so make sure that you run" 92477335Sdougb if [ -n "${DESTDIR}" ]; then 92577335Sdougb echo " '/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd'" 92677335Sdougb echo " to rebuild your password files" 92777335Sdougb run_it_now "/usr/sbin/pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd" 92877335Sdougb else 92977335Sdougb echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd'" 93077335Sdougb echo " to rebuild your password files" 93177335Sdougb run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 93277335Sdougb fi 93352400Sbillf ;; 93452400Sbillfesac 93552400Sbillf 93652400Sbillfecho '' 93752400Sbillf 93867949Sdougbif [ -r "${MM_EXIT_SCRIPT}" ]; then 93967949Sdougb . "${MM_EXIT_SCRIPT}" 94067949Sdougbfi 94167949Sdougb 94291193Sdougbcase "${COMP_CONFS}" in 94391193Sdougb'') ;; 94491193Sdougb*) 94591193Sdougb . ${DESTDIR}/etc/defaults/rc.conf 94691193Sdougb 94791193Sdougb (echo '' 94891193Sdougb echo "*** Comparing conf files: ${rc_conf_files}" 94991193Sdougb 95091193Sdougb for CONF_FILE in ${rc_conf_files}; do 95191193Sdougb if [ -r "${DESTDIR}${CONF_FILE}" ]; then 95291193Sdougb echo '' 95391193Sdougb echo "*** From ${DESTDIR}${CONF_FILE}" 95491193Sdougb echo "*** From ${DESTDIR}/etc/defaults/rc.conf" 95591193Sdougb 95691193Sdougb for RC_CONF_VAR in `grep -i ^[a-z] ${DESTDIR}${CONF_FILE} | 95791193Sdougb cut -d '=' -f 1`; do 95891193Sdougb echo '' 95991223Sdougb grep -w ^${RC_CONF_VAR} ${DESTDIR}${CONF_FILE} 96091223Sdougb grep -w ^${RC_CONF_VAR} ${DESTDIR}/etc/defaults/rc.conf || 96191193Sdougb echo ' * No default variable with this name' 96291193Sdougb done 96391193Sdougb fi 96491193Sdougb done) | ${PAGER} 96591193Sdougb echo '' 96691193Sdougb ;; 96791193Sdougbesac 96891193Sdougb 96991193Sdougbcase "${PRE_WORLD}" in 97091193Sdougb'') ;; 97191193Sdougb*) 97291193Sdougb MAKE_CONF="${SOURCEDIR%etc}share/examples/etc/make.conf" 97391193Sdougb 97491193Sdougb (echo '' 97591193Sdougb echo '*** Comparing make variables' 97691193Sdougb echo '' 97791193Sdougb echo "*** From ${DESTDIR}/etc/make.conf" 97891193Sdougb echo "*** From ${MAKE_CONF}" 97991193Sdougb 98091193Sdougb for MAKE_VAR in `grep -i ^[a-z] /etc/make.conf | cut -d '=' -f 1`; do 98191193Sdougb echo '' 98291223Sdougb grep -w ^${MAKE_VAR} ${DESTDIR}/etc/make.conf 98391223Sdougb grep -w ^#${MAKE_VAR} ${MAKE_CONF} || 98491193Sdougb echo ' * No example variable with this name' 98591193Sdougb done) | ${PAGER} 98691193Sdougb ;; 98791193Sdougbesac 98891193Sdougb 98952400Sbillfexit 0 99067850Sdougb 991