mergemaster.sh revision 77326
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 873651Sdougb# Copyright 1998-2001 Douglas Barton 973651Sdougb# DougB@FreeBSD.org 1052400Sbillf 1152495Sbillf# $FreeBSD: head/usr.sbin/mergemaster/mergemaster.sh 77326 2001-05-28 09:46:18Z 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}" 1867949Sdougb echo 'Usage: mergemaster [-scrvahi] [-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' 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" 3367949Sdougb echo ' -D /path/directory Specify the destination directory to install files to' 3452400Sbillf echo '' 3552400Sbillf} 3652400Sbillf 3752400Sbillfdisplay_help () { 3852400Sbillf echo "* To specify a directory other than /var/tmp/temproot for the" 3952400Sbillf echo " temporary root environment, use -t /path/to/temp/root" 4052400Sbillf echo "* The -w option takes a number as an argument for the column width" 4167859Sdougb echo " of the screen. The default is 80." 4267949Sdougb echo '* The -a option causes mergemaster to run without prompting.' 4352400Sbillf} 4452400Sbillf 4558910Salfred# Loop allowing the user to use sdiff to merge files and display the merged 4658910Salfred# file. 4758910Salfredmerge_loop () { 4867850Sdougb case "${VERBOSE}" in 4967850Sdougb '') ;; 5067850Sdougb *) 5167850Sdougb echo " *** Type h at the sdiff prompt (%) to get usage help" 5267850Sdougb ;; 5367850Sdougb esac 5467850Sdougb echo '' 5567850Sdougb MERGE_AGAIN=yes 5667850Sdougb while [ "${MERGE_AGAIN}" = "yes" ]; do 5767850Sdougb # Prime file.merged so we don't blat the owner/group id's 5867850Sdougb cp -p "${COMPFILE}" "${COMPFILE}.merged" 5967850Sdougb sdiff -o "${COMPFILE}.merged" --text --suppress-common-lines \ 6067949Sdougb --width=${SCREEN_WIDTH:-80} "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 6167850Sdougb INSTALL_MERGED=V 6267850Sdougb while [ "${INSTALL_MERGED}" = "v" -o "${INSTALL_MERGED}" = "V" ]; do 6367850Sdougb echo '' 6467850Sdougb echo " Use 'i' to install merged file" 6567850Sdougb echo " Use 'r' to re-do the merge" 6667850Sdougb echo " Use 'v' to view the merged file" 6767850Sdougb echo " Default is to leave the temporary file to deal with by hand" 6867850Sdougb echo '' 6967859Sdougb echo -n " *** How should I deal with the merged file? [Leave it for later] " 7067859Sdougb read INSTALL_MERGED 7158910Salfred 7267850Sdougb case "${INSTALL_MERGED}" in 7367850Sdougb [iI]) 7467850Sdougb mv "${COMPFILE}.merged" "${COMPFILE}" 7567850Sdougb echo '' 7667850Sdougb if mm_install "${COMPFILE}"; then 7767850Sdougb echo " *** Merged version of ${COMPFILE} installed successfully" 7867859Sdougb else 7967850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand later" 8067859Sdougb fi 8167850Sdougb unset MERGE_AGAIN 8267850Sdougb ;; 8367850Sdougb [rR]) 8467850Sdougb rm "${COMPFILE}.merged" 8567859Sdougb ;; 8667850Sdougb [vV]) 8767850Sdougb ${PAGER} "${COMPFILE}.merged" 8867850Sdougb ;; 8967850Sdougb '') 9067850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 9167850Sdougb unset MERGE_AGAIN 9267850Sdougb ;; 9367850Sdougb *) 9467850Sdougb echo "invalid choice: ${INSTALL_MERGED}" 9567850Sdougb INSTALL_MERGED=V 9667850Sdougb ;; 9767850Sdougb esac 9867850Sdougb done 9967850Sdougb done 10058910Salfred} 10158910Salfred 10258910Salfred# Loop showing user differences between files, allow merge, skip or install 10358910Salfred# options 10458910Salfreddiff_loop () { 10558910Salfred 10667850Sdougb HANDLE_COMPFILE=v 10758910Salfred 10877323Sdougb while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o \ 10977323Sdougb "${HANDLE_COMPFILE}" = "NOT V" ]; do 11067949Sdougb if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 11167850Sdougb if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 11267850Sdougb ( 11367949Sdougb echo '' 11467850Sdougb echo " *** Displaying differences between ${COMPFILE} and installed version:" 11567850Sdougb echo '' 11667949Sdougb diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 11767850Sdougb ) | ${PAGER} 11867850Sdougb echo '' 11967850Sdougb fi 12067850Sdougb else 12167949Sdougb echo '' 12267850Sdougb echo " *** There is no installed version of ${COMPFILE}" 12367949Sdougb case "${AUTO_INSTALL}" in 12467949Sdougb [Yy][Ee][Ss]) 12567949Sdougb echo '' 12667949Sdougb if mm_install "${COMPFILE}"; then 12767949Sdougb echo " *** ${COMPFILE} installed successfully" 12868507Sdougb echo '' 12967949Sdougb # Make the list print one file per line 13067949Sdougb AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 13167949Sdougb" 13267949Sdougb else 13367949Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 13467949Sdougb fi 13567949Sdougb return 13667949Sdougb ;; 13767949Sdougb *) 13867949Sdougb NO_INSTALLED=yes 13967949Sdougb ;; 14067949Sdougb esac 14167850Sdougb fi 14267859Sdougb 14367850Sdougb echo " Use 'd' to delete the temporary ${COMPFILE}" 14467850Sdougb echo " Use 'i' to install the temporary ${COMPFILE}" 14567850Sdougb case "${NO_INSTALLED}" in 14667850Sdougb '') 14777326Sdougb echo " Use 'm' to merge the temporary and installed versions" 14877326Sdougb echo " Use 'v' to view the diff results again" 14967850Sdougb ;; 15067850Sdougb esac 15167850Sdougb echo '' 15267850Sdougb echo " Default is to leave the temporary file to deal with by hand" 15367850Sdougb echo '' 15467859Sdougb echo -n "How should I deal with this? [Leave it for later] " 15567859Sdougb read HANDLE_COMPFILE 15667859Sdougb 15767850Sdougb case "${HANDLE_COMPFILE}" in 15867850Sdougb [dD]) 15967850Sdougb rm "${COMPFILE}" 16067850Sdougb echo '' 16167850Sdougb echo " *** Deleting ${COMPFILE}" 16267850Sdougb ;; 16367850Sdougb [iI]) 16467850Sdougb echo '' 16567850Sdougb if mm_install "${COMPFILE}"; then 16667850Sdougb echo " *** ${COMPFILE} installed successfully" 16767850Sdougb else 16867850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 16967850Sdougb fi 17067850Sdougb ;; 17167850Sdougb [mM]) 17267850Sdougb case "${NO_INSTALLED}" in 17367850Sdougb '') 17467850Sdougb # interact with user to merge files 17567850Sdougb merge_loop 17667850Sdougb ;; 17767850Sdougb *) 17867850Sdougb echo '' 17967850Sdougb echo " *** There is no installed version of ${COMPFILE}" 18067850Sdougb echo '' 18167850Sdougb HANDLE_COMPFILE="NOT V" 18267850Sdougb ;; 18367850Sdougb esac # End of "No installed version of file but user selected merge" test 18467850Sdougb ;; 18567850Sdougb [vV]) 18667850Sdougb continue 18767850Sdougb ;; 18867850Sdougb '') 18967850Sdougb echo '' 19067850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 19167850Sdougb ;; 19267850Sdougb *) 19367850Sdougb # invalid choice, show menu again. 19467850Sdougb echo "invalid choice: ${HANDLE_COMPFILE}" 19567850Sdougb echo '' 19667850Sdougb HANDLE_COMPFILE="NOT V" 19767850Sdougb continue 19867850Sdougb ;; 19967850Sdougb esac # End of "How to handle files that are different" 20067859Sdougb done 20167850Sdougb unset NO_INSTALLED 20267850Sdougb echo '' 20367850Sdougb case "${VERBOSE}" in 20467850Sdougb '') ;; 20567850Sdougb *) 20667850Sdougb sleep 3 20767850Sdougb ;; 20867850Sdougb esac 20958910Salfred} 21058910Salfred 21152400Sbillf# Set the default path for the temporary root environment 21252400Sbillf# 21352400SbillfTEMPROOT='/var/tmp/temproot' 21452400Sbillf 21573651Sdougb# Read /etc/mergemaster.rc first so the one in $HOME can override 21673651Sdougb# 21773651Sdougbif [ -r /etc/mergemaster.rc ]; then 21873651Sdougb . /etc/mergemaster.rc 21973651Sdougbfi 22073651Sdougb 22152400Sbillf# Read .mergemasterrc before command line so CLI can override 22252400Sbillf# 22367949Sdougbif [ -r "$HOME/.mergemasterrc" ]; then 22452400Sbillf . "$HOME/.mergemasterrc" 22552400Sbillffi 22652400Sbillf 22752400Sbillf# Check the command line options 22852400Sbillf# 22967949Sdougbwhile getopts ":ascrvhim:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do 23052400Sbillf case "${COMMAND_LINE_ARGUMENT}" in 23152400Sbillf s) 23252400Sbillf STRICT=yes 23352400Sbillf ;; 23452400Sbillf c) 23552400Sbillf DIFF_FLAG='-c' 23652400Sbillf ;; 23752400Sbillf r) 23852400Sbillf RERUN=yes 23952400Sbillf ;; 24052400Sbillf v) 24152400Sbillf case "${AUTO_RUN}" in 24252400Sbillf '') VERBOSE=yes ;; 24352400Sbillf esac 24452400Sbillf ;; 24552400Sbillf a) 24652400Sbillf AUTO_RUN=yes 24752400Sbillf unset VERBOSE 24852400Sbillf ;; 24952400Sbillf h) 25052400Sbillf display_usage 25152400Sbillf display_help 25252400Sbillf exit 0 25352400Sbillf ;; 25467949Sdougb i) 25567949Sdougb AUTO_INSTALL=yes 25667949Sdougb ;; 25752400Sbillf m) 25852400Sbillf SOURCEDIR=${OPTARG} 25952400Sbillf ;; 26052400Sbillf t) 26152400Sbillf TEMPROOT=${OPTARG} 26252400Sbillf ;; 26352400Sbillf d) 26452400Sbillf TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 26552400Sbillf ;; 26652400Sbillf u) 26752400Sbillf NEW_UMASK=${OPTARG} 26852400Sbillf ;; 26952400Sbillf w) 27052400Sbillf SCREEN_WIDTH=${OPTARG} 27152400Sbillf ;; 27267949Sdougb D) 27367949Sdougb DESTDIR=${OPTARG} 27467949Sdougb ;; 27552400Sbillf *) 27652400Sbillf display_usage 27752400Sbillf exit 1 27852400Sbillf ;; 27952400Sbillf esac 28052400Sbillfdone 28152400Sbillf 28252400Sbillfecho '' 28352400Sbillf 28452400Sbillf# If the user has a pager defined, make sure we can run it 28552400Sbillf# 28652400Sbillfcase "${DONT_CHECK_PAGER}" in 28752400Sbillf'') 28864467Sbrian while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do 28952400Sbillf echo " *** Your PAGER environment variable specifies '${PAGER}', but" 29064467Sbrian echo " due to the limited PATH that I use for security reasons," 29167859Sdougb echo " I cannot execute it. So, what would you like to do?" 29252400Sbillf echo '' 29352400Sbillf echo " Use 'e' to exit mergemaster and fix your PAGER variable" 29464467Sbrian if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 29564467Sbrian echo " Use 'l' to set PAGER to 'less' for this run" 29652400Sbillf fi 29752400Sbillf echo " Use 'm' to use plain old 'more' as your PAGER for this run" 29852400Sbillf echo '' 29952400Sbillf echo " Default is to use plain old 'more' " 30052400Sbillf echo '' 30167859Sdougb echo -n "What should I do? [Use 'more'] " 30267859Sdougb read FIXPAGER 30367859Sdougb 30452400Sbillf case "${FIXPAGER}" in 30558910Salfred [eE]) 30652400Sbillf exit 0 30752400Sbillf ;; 30858910Salfred [lL]) 30964467Sbrian if [ -x /usr/bin/less ]; then 31064467Sbrian PAGER=/usr/bin/less 31164467Sbrian elif [ -x /usr/local/bin/less ]; then 31258910Salfred PAGER=/usr/local/bin/less 31364467Sbrian else 31464467Sbrian echo '' 31564467Sbrian echo " *** Fatal Error:" 31664467Sbrian echo " You asked to use 'less' as your pager, but I can't" 31764467Sbrian echo " find it in /usr/bin or /usr/local/bin" 31864467Sbrian exit 1 31958910Salfred fi 32052400Sbillf ;; 32160420Sbsd [mM]|'') 32252400Sbillf PAGER=more 32352400Sbillf ;; 32458910Salfred *) 32558910Salfred echo '' 32658910Salfred echo "invalid choice: ${FIXPAGER}" 32752400Sbillf esac 32852400Sbillf echo '' 32958910Salfred done 33052400Sbillf ;; 33152400Sbillfesac 33252400Sbillf 33352400Sbillf# If user has a pager defined, or got assigned one above, use it. 33452400Sbillf# If not, use more. 33552400Sbillf# 33652400SbillfPAGER=${PAGER:-more} 33752400Sbillf 33852400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 33952400Sbillf echo " *** You have ${PAGER} defined as your pager so we will use that" 34052400Sbillf echo '' 34152400Sbillf sleep 3 34252400Sbillffi 34352400Sbillf 34452400Sbillf# Assign the diff flag once so we will not have to keep testing it 34552400Sbillf# 34652400SbillfDIFF_FLAG=${DIFF_FLAG:--u} 34752400Sbillf 34852400Sbillf# Assign the source directory 34952400Sbillf# 35052400SbillfSOURCEDIR=${SOURCEDIR:-/usr/src/etc} 35152400Sbillf 35273651Sdougb# Define what CVS $Id tag to look for to aid portability. 35373651Sdougb# 35473651SdougbCVS_ID_TAG=FreeBSD 35573651Sdougb 35652400Sbillfcase "${RERUN}" in 35752400Sbillf'') 35852400Sbillf # Set up the loop to test for the existence of the 35952400Sbillf # temp root directory. 36052400Sbillf # 36152400Sbillf TEST_TEMP_ROOT=yes 36252400Sbillf while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 36352400Sbillf if [ -d "${TEMPROOT}" ]; then 36452400Sbillf echo "*** The directory specified for the temporary root environment," 36567859Sdougb echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 36652400Sbillf echo " users have access to the system." 36752400Sbillf echo '' 36852400Sbillf case "${AUTO_RUN}" in 36952400Sbillf '') 37052400Sbillf echo " Use 'd' to delete the old ${TEMPROOT} and continue" 37152400Sbillf echo " Use 't' to select a new temporary root directory" 37252400Sbillf echo " Use 'e' to exit mergemaster" 37352400Sbillf echo '' 37452400Sbillf echo " Default is to use ${TEMPROOT} as is" 37552400Sbillf echo '' 37667859Sdougb echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 37767859Sdougb read DELORNOT 37867859Sdougb 37967859Sdougb case "${DELORNOT}" in 38067859Sdougb [dD]) 38167859Sdougb echo '' 38267859Sdougb echo " *** Deleting the old ${TEMPROOT}" 38367859Sdougb echo '' 38467859Sdougb rm -rf "${TEMPROOT}" 38567859Sdougb unset TEST_TEMP_ROOT 38652400Sbillf ;; 38767859Sdougb [tT]) 38867859Sdougb echo " *** Enter new directory name for temporary root environment" 38967859Sdougb read TEMPROOT 39067859Sdougb ;; 39167859Sdougb [eE]) 39267859Sdougb exit 0 39367859Sdougb ;; 39467859Sdougb '') 39567859Sdougb echo '' 39667859Sdougb echo " *** Leaving ${TEMPROOT} intact" 39767859Sdougb echo '' 39867859Sdougb unset TEST_TEMP_ROOT 39967859Sdougb ;; 40067859Sdougb *) 40167859Sdougb echo '' 40267859Sdougb echo "invalid choice: ${DELORNOT}" 40367859Sdougb echo '' 40467859Sdougb ;; 40567859Sdougb esac 40667859Sdougb ;; 40752400Sbillf *) 40877323Sdougb # If this is an auto-run, try a hopefully safe alternative then 40977323Sdougb # re-test anyway. 41052400Sbillf TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 41152400Sbillf ;; 41252400Sbillf esac 41352400Sbillf else 41452400Sbillf unset TEST_TEMP_ROOT 41552400Sbillf fi 41652400Sbillf done 41752400Sbillf 41852400Sbillf echo "*** Creating the temporary root environment in ${TEMPROOT}" 41952400Sbillf 42052400Sbillf if mkdir -p "${TEMPROOT}"; then 42152400Sbillf echo " *** ${TEMPROOT} ready for use" 42252400Sbillf fi 42352400Sbillf 42452400Sbillf if [ ! -d "${TEMPROOT}" ]; then 42552400Sbillf echo '' 42652400Sbillf echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 42752400Sbillf echo '' 42852400Sbillf exit 1 42952400Sbillf fi 43052400Sbillf 43152400Sbillf echo " *** Creating and populating directory structure in ${TEMPROOT}" 43252400Sbillf echo '' 43352400Sbillf 43452400Sbillf case "${VERBOSE}" in 43552400Sbillf '') ;; 43652400Sbillf *) 43752400Sbillf echo " *** Press [Enter] or [Return] key to continue" 43852400Sbillf read ANY_KEY 43952400Sbillf unset ANY_KEY 44052400Sbillf ;; 44152400Sbillf esac 44252400Sbillf 44352400Sbillf { cd ${SOURCEDIR} && 44468507Sdougb case "${DESTDIR}" in 44568507Sdougb '') ;; 44668507Sdougb *) 44768507Sdougb make DESTDIR=${DESTDIR} distrib-dirs 44868507Sdougb ;; 44968507Sdougb esac 45052400Sbillf make DESTDIR=${TEMPROOT} distrib-dirs && 45174992Sasmodai make DESTDIR=${TEMPROOT} -DNO_MAKEDEV_RUN distribution;} || 45252400Sbillf { echo ''; 45377323Sdougb echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to"; 45477323Sdougb echo " the temproot environment"; 45552400Sbillf echo ''; 45652400Sbillf exit 1;} 45752400Sbillf 45877323Sdougb # Doing the inventory and removing files that we don't want to compare only 45977323Sdougb # makes sense if we are not doing a rerun, since we have no way of knowing 46077323Sdougb # what happened to the files during previous incarnations. 46167949Sdougb case "${VERBOSE}" in 46267949Sdougb '') ;; 46367949Sdougb *) 46467949Sdougb echo '' 46567949Sdougb echo ' *** The following files exist only in the installed version of' 46667949Sdougb echo " ${DESTDIR}/etc. In the vast majority of cases these files" 46767949Sdougb echo ' are necessary parts of the system and should not be deleted.' 46867949Sdougb echo ' However because these files are not updated by this process you' 46967949Sdougb echo ' might want to verify their status before rebooting your system.' 47067949Sdougb echo '' 47167949Sdougb echo ' *** Press [Enter] or [Return] key to continue' 47267949Sdougb read ANY_KEY 47367949Sdougb unset ANY_KEY 47467949Sdougb diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER} 47567949Sdougb echo '' 47667949Sdougb echo ' *** Press [Enter] or [Return] key to continue' 47767949Sdougb read ANY_KEY 47867949Sdougb unset ANY_KEY 47967949Sdougb ;; 48067949Sdougb esac 48167949Sdougb 48252400Sbillf # We really don't want to have to deal with these files, since 48352400Sbillf # master.passwd is the real file that should be compared, then 48452400Sbillf # the user should run pwd_mkdb if necessary. 48552400Sbillf # 48652400Sbillf rm ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db 48752400Sbillf 48852534Sbillf # Avoid comparing the motd if the user specifies it in .mergemasterrc 48952534Sbillf case "${IGNORE_MOTD}" in 49052534Sbillf '') ;; 49152534Sbillf *) rm ${TEMPROOT}/etc/motd 49252534Sbillf ;; 49352534Sbillf esac 49452534Sbillf 49565115Sben # Avoid trying to update MAKEDEV if /dev is on a devfs 49668507Sdougb if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 49765115Sben rm ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local 49865115Sben fi 49965115Sben 50052400Sbillf ;; # End of the "RERUN" test 50152400Sbillfesac 50252400Sbillf 50352400Sbillf# Get ready to start comparing files 50452400Sbillf 50552400Sbillf# Check umask if not specified on the command line, 50652400Sbillf# and we are not doing an autorun 50752400Sbillf# 50852400Sbillfif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 50952400Sbillf USER_UMASK=`umask` 51052400Sbillf case "${USER_UMASK}" in 51152400Sbillf 0022) ;; 51252400Sbillf *) 51352400Sbillf echo '' 51467859Sdougb echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 51552400Sbillf echo " installs all files with the same user, group and modes that" 51652400Sbillf echo " they are created with by ${SOURCEDIR}/Makefile, compared to" 51767859Sdougb echo " a umask of 022. This umask allows world read permission when" 51852400Sbillf echo " the file's default permissions have it." 51967859Sdougb echo " No world permissions can sometimes cause problems. A umask of" 52052400Sbillf echo " 022 will restore the default behavior, but is not mandatory." 52167859Sdougb echo " /etc/master.passwd is a special case. Its file permissions" 52252400Sbillf echo " will be 600 (rw-------) if installed." 52352400Sbillf echo '' 52467859Sdougb echo -n "What umask should I use? [${USER_UMASK}] " 52567859Sdougb read NEW_UMASK 52667859Sdougb 52752400Sbillf NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 52852400Sbillf ;; 52952400Sbillf esac 53052400Sbillf echo '' 53152400Sbillffi 53252400Sbillf 53352400SbillfCONFIRMED_UMASK=${NEW_UMASK:-0022} 53452400Sbillf 53567949Sdougb# Warn users who still have ${DESTDIR}/etc/sysconfig 53652400Sbillf# 53767949Sdougbif [ -e "${DESTDIR}/etc/sysconfig" ]; then 53852400Sbillf echo '' 53967949Sdougb echo " *** There is a sysconfig file on this system in ${DESTDIR}/etc/." 54067949Sdougb echo '' 54167949Sdougb echo ' Starting with FreeBSD version 2.2.2 those settings moved from' 54267949Sdougb echo ' /etc/sysconfig to /etc/rc.conf. If you are upgrading an older' 54367949Sdougb echo ' system make sure that you transfer your settings by hand from' 54467949Sdougb echo ' sysconfig to rc.conf and install the rc.conf file. If you' 54567949Sdougb echo ' have already made this transition, you should consider' 54667949Sdougb echo ' renaming or deleting the sysconfig file.' 54767949Sdougb echo '' 54852400Sbillf case "${AUTO_RUN}" in 54952400Sbillf '') 55067859Sdougb echo -n "Continue with the merge process? [yes] " 55167859Sdougb read CONT_OR_NOT 55267859Sdougb 55352400Sbillf case "${CONT_OR_NOT}" in 55452400Sbillf [nN]*) 55552400Sbillf exit 0 55652400Sbillf ;; 55752400Sbillf *) 55852400Sbillf echo " *** Continuing" 55952400Sbillf echo '' 56052400Sbillf ;; 56152400Sbillf esac 56252400Sbillf ;; 56352400Sbillf *) ;; 56452400Sbillf esac 56552400Sbillffi 56652400Sbillf 56752400Sbillf# Use the umask/mode information to install the files 56852400Sbillf# Create directories as needed 56952400Sbillf# 57052400Sbillfmm_install () { 57152400Sbillf local INSTALL_DIR 57252400Sbillf INSTALL_DIR=${1#.} 57352400Sbillf INSTALL_DIR=${INSTALL_DIR%/*} 57467949Sdougb 57552400Sbillf case "${INSTALL_DIR}" in 57652400Sbillf '') 57752400Sbillf INSTALL_DIR=/ 57852400Sbillf ;; 57952400Sbillf esac 58052400Sbillf 58167949Sdougb if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 58277323Sdougb DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \ 58377323Sdougb oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"` 58467949Sdougb install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" 58552400Sbillf fi 58652400Sbillf 58777323Sdougb FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \ 58877323Sdougb oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"` 58952400Sbillf 59052400Sbillf if [ ! -x "${1}" ]; then 59152400Sbillf case "${1#.}" in 59264625Sgshapiro /etc/mail/aliases) 59352400Sbillf NEED_NEWALIASES=yes 59452400Sbillf ;; 59552400Sbillf /etc/login.conf) 59652400Sbillf NEED_CAP_MKDB=yes 59752400Sbillf ;; 59852400Sbillf /etc/master.passwd) 59967949Sdougb install -m 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 60052400Sbillf NEED_PWD_MKDB=yes 60152400Sbillf DONT_INSTALL=yes 60252400Sbillf ;; 60352400Sbillf /.cshrc | /.profile) 60452400Sbillf case "${LINK_EXPLAINED}" in 60552400Sbillf '') 60667859Sdougb echo " *** Historically BSD derived systems have had a" 60767859Sdougb echo " hard link from /.cshrc and /.profile to" 60867859Sdougb echo " their namesakes in /root. Please indicate" 60967859Sdougb echo " your preference below for bringing your" 61067859Sdougb echo " installed files up to date." 61152400Sbillf echo '' 61252400Sbillf LINK_EXPLAINED=yes 61352400Sbillf ;; 61452400Sbillf esac 61552400Sbillf 61652400Sbillf echo " Use 'd' to delete the temporary ${COMPFILE}" 61767949Sdougb echo " Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link" 61852400Sbillf echo '' 61952400Sbillf echo " Default is to leave the temporary file to deal with by hand" 62052400Sbillf echo '' 62167859Sdougb echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 62267859Sdougb read HANDLE_LINK 62367859Sdougb 62452400Sbillf case "${HANDLE_LINK}" in 62552400Sbillf [dD]*) 62652400Sbillf rm "${COMPFILE}" 62752400Sbillf echo '' 62852400Sbillf echo " *** Deleting ${COMPFILE}" 62952400Sbillf ;; 63052400Sbillf [lL]*) 63152400Sbillf echo '' 63267949Sdougb rm -f "${DESTDIR}${COMPFILE#.}" 63367949Sdougb if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then 63467949Sdougb echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 63552400Sbillf rm "${COMPFILE}" 63652400Sbillf else 63767949Sdougb echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand" 63852400Sbillf fi 63952400Sbillf ;; 64052400Sbillf *) 64152400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 64252400Sbillf ;; 64352400Sbillf esac 64452400Sbillf DONT_INSTALL=yes 64552400Sbillf ;; 64652400Sbillf esac 64752400Sbillf 64852400Sbillf case "${DONT_INSTALL}" in 64952400Sbillf '') 65067949Sdougb install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 65152400Sbillf ;; 65252400Sbillf *) 65352400Sbillf unset DONT_INSTALL 65452400Sbillf ;; 65552400Sbillf esac 65652400Sbillf else 65767949Sdougb case "${1#.}" in 65867949Sdougb /dev/MAKEDEV) 65967949Sdougb NEED_MAKEDEV=yes 66067949Sdougb ;; 66167949Sdougb esac 66267949Sdougb install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 66352400Sbillf fi 66452400Sbillf return $? 66552400Sbillf} 66652400Sbillf 66767949Sdougbecho '' 66867949Sdougbecho "*** Beginning comparison" 66967949Sdougbecho '' 67052400Sbillf 67167949Sdougbcd "${TEMPROOT}" 67267949Sdougb 67367949Sdougbif [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 67467949Sdougb . "${MM_PRE_COMPARE_SCRIPT}" 67567949Sdougbfi 67667949Sdougb 67752400Sbillf# Using -size +0 avoids uselessly checking the empty log files created 67852400Sbillf# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does 67967949Sdougb# check the scripts in ./dev, as we'd like (assuming no devfs of course). 68052400Sbillf# 68152400Sbillffor COMPFILE in `find . -type f -size +0`; do 68267949Sdougb 68367949Sdougb # First, check to see if the file exists in DESTDIR. If not, the 68467949Sdougb # diff_loop function knows how to handle it. 68567949Sdougb # 68667949Sdougb if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 68777325Sdougb case "${AUTO_RUN}" in 68877325Sdougb '') 68977325Sdougb diff_loop 69077325Sdougb ;; 69177325Sdougb *) 69277325Sdougb case "${AUTO_INSTALL}" in 69377325Sdougb '') 69477325Sdougb # If this is an auto run, make it official 69577325Sdougb echo " *** ${COMPFILE} will remain for your consideration" 69677325Sdougb ;; 69777325Sdougb *) 69877325Sdougb diff_loop 69977325Sdougb ;; 70077325Sdougb esac 70177325Sdougb ;; 70277325Sdougb esac # Auto run test 70367949Sdougb continue 70467949Sdougb fi 70567949Sdougb 70652400Sbillf case "${STRICT}" in 70752400Sbillf '' | [Nn][Oo]) 70852400Sbillf # Compare CVS $Id's first so if the file hasn't been modified 70952400Sbillf # local changes will be ignored. 71052400Sbillf # If the files have the same $Id, delete the one in temproot so the 71152400Sbillf # user will have less to wade through if files are left to merge by hand. 71252400Sbillf # 71373651Sdougb CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 71473651Sdougb CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` 71552400Sbillf 71667949Sdougb case "${CVSID2}" in 71773651Sdougb "${CVSID1}") 71867949Sdougb echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 71967949Sdougb rm "${COMPFILE}" 72067949Sdougb ;; 72167949Sdougb esac 72252400Sbillf ;; 72352400Sbillf esac 72452400Sbillf 72552400Sbillf # If the file is still here either because the $Ids are different, the 72652400Sbillf # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 72752400Sbillf # 72852400Sbillf if [ -f "${COMPFILE}" ]; then 72952400Sbillf 73052400Sbillf # Do an absolute diff first to see if the files are actually different. 73152400Sbillf # If they're not different, delete the one in temproot. 73252400Sbillf # 73367949Sdougb if diff -q "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then 73452400Sbillf echo " *** Temp ${COMPFILE} and installed are the same, deleting" 73552400Sbillf rm "${COMPFILE}" 73652400Sbillf else 73777323Sdougb # Ok, the files are different, so show the user where they differ. 73877323Sdougb # Use user's choice of diff methods; and user's pager if they have one. 73977323Sdougb # Use more if not. 74067859Sdougb # Use unified diffs by default. Context diffs give me a headache. :) 74152400Sbillf # 74252400Sbillf case "${AUTO_RUN}" in 74352400Sbillf '') 74458910Salfred # prompt user to install/delete/merge changes 74558910Salfred diff_loop 74652400Sbillf ;; 74752400Sbillf *) 74852400Sbillf # If this is an auto run, make it official 74952400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 75052400Sbillf ;; 75152400Sbillf esac # Auto run test 75252400Sbillf fi # Yes, the files are different 75352400Sbillf fi # Yes, the file still remains to be checked 75452400Sbillfdone # This is for the do way up there at the beginning of the comparison 75552400Sbillf 75652534Sbillfecho '' 75752400Sbillfecho "*** Comparison complete" 75852400Sbillfecho '' 75952400Sbillf 76052400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 76152400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then 76252400Sbillf echo "*** Files that remain for you to merge by hand:" 76352400Sbillf find "${TEMPROOT}" -type f -size +0 76452400Sbillffi 76552400Sbillf 76652400Sbillfcase "${AUTO_RUN}" in 76752400Sbillf'') 76852400Sbillf echo '' 76967859Sdougb echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 77067859Sdougb read DEL_TEMPROOT 77167859Sdougb 77252400Sbillf case "${DEL_TEMPROOT}" in 77352400Sbillf [yY]*) 77452400Sbillf if rm -rf "${TEMPROOT}"; then 77552400Sbillf echo " *** ${TEMPROOT} has been deleted" 77652400Sbillf else 77752400Sbillf echo " *** Unable to delete ${TEMPROOT}" 77852400Sbillf fi 77952400Sbillf ;; 78052400Sbillf *) 78152400Sbillf echo " *** ${TEMPROOT} will remain" 78252400Sbillf ;; 78352400Sbillf esac 78452400Sbillf ;; 78552400Sbillf*) ;; 78652400Sbillfesac 78752400Sbillf 78868153Sdougbcase "${AUTO_INSTALLED_FILES}" in 78968153Sdougb'') ;; 79068153Sdougb*) 79173651Sdougb case "${AUTO_RUN}" in 79273651Sdougb '') 79373651Sdougb ( 79473651Sdougb echo '' 79577323Sdougb echo '*** You chose the automatic install option for files that did not' 79677323Sdougb echo ' exist on your system. The following were installed for you:' 79773651Sdougb echo "${AUTO_INSTALLED_FILES}" 79873651Sdougb ) | ${PAGER} 79973651Sdougb ;; 80073651Sdougb *) 80168153Sdougb echo '' 80277323Sdougb echo '*** You chose the automatic install option for files that did not' 80377323Sdougb echo ' exist on your system. The following were installed for you:' 80468153Sdougb echo "${AUTO_INSTALLED_FILES}" 80573651Sdougb ;; 80673651Sdougb esac 80768153Sdougb ;; 80868153Sdougbesac 80968153Sdougb 81073651Sdougbrun_it_now () { 81173651Sdougb case "${AUTO_RUN}" in 81273651Sdougb '') 81373651Sdougb unset YES_OR_NO 81473651Sdougb echo '' 81573651Sdougb echo -n ' Would you like to run it now? [y or n] ' 81673651Sdougb read YES_OR_NO 81773651Sdougb 81873651Sdougb echo '' 81973651Sdougb 82073651Sdougb case "${YES_OR_NO}" in 82173651Sdougb y) 82273651Sdougb echo " Running ${1}" 82373651Sdougb eval "${1}" 82473651Sdougb ;; 82573651Sdougb *) 82673651Sdougb echo " Make sure to run ${1} yourself" 82773651Sdougb ;; 82873651Sdougb esac 82973651Sdougb ;; 83073651Sdougb *) ;; 83173651Sdougb esac 83273651Sdougb} 83373651Sdougb 83452400Sbillfcase "${NEED_MAKEDEV}" in 83552400Sbillf'') ;; 83652400Sbillf*) 83752400Sbillf echo '' 83852400Sbillf echo "*** You installed a new /dev/MAKEDEV script, so make sure that you run" 83952400Sbillf echo " 'cd /dev && /bin/sh MAKEDEV all' to rebuild your devices" 84073651Sdougb run_it_now 'cd /dev && /bin/sh MAKEDEV all' 84152400Sbillf ;; 84252400Sbillfesac 84352400Sbillf 84452400Sbillfcase "${NEED_NEWALIASES}" in 84552400Sbillf'') ;; 84652400Sbillf*) 84752400Sbillf echo '' 84852400Sbillf echo "*** You installed a new aliases file, so make sure that you run" 84973651Sdougb echo " '/usr/bin/newaliases' to rebuild your aliases database" 85073651Sdougb run_it_now '/usr/bin/newaliases' 85152400Sbillf ;; 85252400Sbillfesac 85352400Sbillf 85452400Sbillfcase "${NEED_CAP_MKDB}" in 85552400Sbillf'') ;; 85652400Sbillf*) 85752400Sbillf echo '' 85852400Sbillf echo "*** You installed a login.conf file, so make sure that you run" 85973651Sdougb echo " '/usr/bin/cap_mkdb /etc/login.conf' to rebuild your login.conf database" 86073651Sdougb run_it_now '/usr/bin/cap_mkdb /etc/login.conf' 86152400Sbillf ;; 86252400Sbillfesac 86352400Sbillf 86452400Sbillfcase "${NEED_PWD_MKDB}" in 86552400Sbillf'') ;; 86652400Sbillf*) 86752400Sbillf echo '' 86852400Sbillf echo "*** You installed a new master.passwd file, so make sure that you run" 86973651Sdougb echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd' to rebuild your password files" 87073651Sdougb run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 87152400Sbillf ;; 87252400Sbillfesac 87352400Sbillf 87452400Sbillfecho '' 87552400Sbillf 87667949Sdougbif [ -r "${MM_EXIT_SCRIPT}" ]; then 87767949Sdougb . "${MM_EXIT_SCRIPT}" 87867949Sdougbfi 87967949Sdougb 88052400Sbillfexit 0 88167850Sdougb 882