mergemaster.sh revision 73651
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 73651 2001-03-05 10:13:21Z 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 10867850Sdougb while [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" -o "${HANDLE_COMPFILE}" = "NOT V" ]; do 10967949Sdougb if [ -f "${DESTDIR}${COMPFILE#.}" -a -f "${COMPFILE}" ]; then 11067850Sdougb if [ "${HANDLE_COMPFILE}" = "v" -o "${HANDLE_COMPFILE}" = "V" ]; then 11167850Sdougb ( 11267949Sdougb echo '' 11367850Sdougb echo " *** Displaying differences between ${COMPFILE} and installed version:" 11467850Sdougb echo '' 11567949Sdougb diff "${DIFF_FLAG}" "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" 11667850Sdougb ) | ${PAGER} 11767850Sdougb echo '' 11867850Sdougb fi 11967850Sdougb else 12067949Sdougb echo '' 12167850Sdougb echo " *** There is no installed version of ${COMPFILE}" 12267949Sdougb case "${AUTO_INSTALL}" in 12367949Sdougb [Yy][Ee][Ss]) 12467949Sdougb echo '' 12567949Sdougb if mm_install "${COMPFILE}"; then 12667949Sdougb echo " *** ${COMPFILE} installed successfully" 12768507Sdougb echo '' 12867949Sdougb # Make the list print one file per line 12967949Sdougb AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES} ${DESTDIR}${COMPFILE#.} 13067949Sdougb" 13167949Sdougb else 13267949Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 13367949Sdougb fi 13467949Sdougb return 13567949Sdougb ;; 13667949Sdougb *) 13767949Sdougb NO_INSTALLED=yes 13867949Sdougb ;; 13967949Sdougb esac 14067850Sdougb fi 14167859Sdougb 14267850Sdougb echo " Use 'd' to delete the temporary ${COMPFILE}" 14367850Sdougb echo " Use 'i' to install the temporary ${COMPFILE}" 14467850Sdougb case "${NO_INSTALLED}" in 14567850Sdougb '') 14667850Sdougb echo " Use 'm' to merge the old and new versions" 14767850Sdougb echo " Use 'v' to view to differences between the old and new versions again" 14867850Sdougb ;; 14967850Sdougb esac 15067850Sdougb echo '' 15167850Sdougb echo " Default is to leave the temporary file to deal with by hand" 15267850Sdougb echo '' 15367859Sdougb echo -n "How should I deal with this? [Leave it for later] " 15467859Sdougb read HANDLE_COMPFILE 15567859Sdougb 15667850Sdougb case "${HANDLE_COMPFILE}" in 15767850Sdougb [dD]) 15867850Sdougb rm "${COMPFILE}" 15967850Sdougb echo '' 16067850Sdougb echo " *** Deleting ${COMPFILE}" 16167850Sdougb ;; 16267850Sdougb [iI]) 16367850Sdougb echo '' 16467850Sdougb if mm_install "${COMPFILE}"; then 16567850Sdougb echo " *** ${COMPFILE} installed successfully" 16667850Sdougb else 16767850Sdougb echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" 16867850Sdougb fi 16967850Sdougb ;; 17067850Sdougb [mM]) 17167850Sdougb case "${NO_INSTALLED}" in 17267850Sdougb '') 17367850Sdougb # interact with user to merge files 17467850Sdougb merge_loop 17567850Sdougb ;; 17667850Sdougb *) 17767850Sdougb echo '' 17867850Sdougb echo " *** There is no installed version of ${COMPFILE}" 17967850Sdougb echo '' 18067850Sdougb HANDLE_COMPFILE="NOT V" 18167850Sdougb ;; 18267850Sdougb esac # End of "No installed version of file but user selected merge" test 18367850Sdougb ;; 18467850Sdougb [vV]) 18567850Sdougb continue 18667850Sdougb ;; 18767850Sdougb '') 18867850Sdougb echo '' 18967850Sdougb echo " *** ${COMPFILE} will remain for your consideration" 19067850Sdougb ;; 19167850Sdougb *) 19267850Sdougb # invalid choice, show menu again. 19367850Sdougb echo "invalid choice: ${HANDLE_COMPFILE}" 19467850Sdougb echo '' 19567850Sdougb HANDLE_COMPFILE="NOT V" 19667850Sdougb continue 19767850Sdougb ;; 19867850Sdougb esac # End of "How to handle files that are different" 19967859Sdougb done 20067850Sdougb unset NO_INSTALLED 20167850Sdougb echo '' 20267850Sdougb case "${VERBOSE}" in 20367850Sdougb '') ;; 20467850Sdougb *) 20567850Sdougb sleep 3 20667850Sdougb ;; 20767850Sdougb esac 20858910Salfred} 20958910Salfred 21052400Sbillf# Set the default path for the temporary root environment 21152400Sbillf# 21252400SbillfTEMPROOT='/var/tmp/temproot' 21352400Sbillf 21473651Sdougb# Read /etc/mergemaster.rc first so the one in $HOME can override 21573651Sdougb# 21673651Sdougbif [ -r /etc/mergemaster.rc ]; then 21773651Sdougb . /etc/mergemaster.rc 21873651Sdougbfi 21973651Sdougb 22052400Sbillf# Read .mergemasterrc before command line so CLI can override 22152400Sbillf# 22267949Sdougbif [ -r "$HOME/.mergemasterrc" ]; then 22352400Sbillf . "$HOME/.mergemasterrc" 22452400Sbillffi 22552400Sbillf 22652400Sbillf# Check the command line options 22752400Sbillf# 22867949Sdougbwhile getopts ":ascrvhim:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do 22952400Sbillf case "${COMMAND_LINE_ARGUMENT}" in 23052400Sbillf s) 23152400Sbillf STRICT=yes 23252400Sbillf ;; 23352400Sbillf c) 23452400Sbillf DIFF_FLAG='-c' 23552400Sbillf ;; 23652400Sbillf r) 23752400Sbillf RERUN=yes 23852400Sbillf ;; 23952400Sbillf v) 24052400Sbillf case "${AUTO_RUN}" in 24152400Sbillf '') VERBOSE=yes ;; 24252400Sbillf esac 24352400Sbillf ;; 24452400Sbillf a) 24552400Sbillf AUTO_RUN=yes 24652400Sbillf unset VERBOSE 24752400Sbillf ;; 24852400Sbillf h) 24952400Sbillf display_usage 25052400Sbillf display_help 25152400Sbillf exit 0 25252400Sbillf ;; 25367949Sdougb i) 25467949Sdougb AUTO_INSTALL=yes 25567949Sdougb ;; 25652400Sbillf m) 25752400Sbillf SOURCEDIR=${OPTARG} 25852400Sbillf ;; 25952400Sbillf t) 26052400Sbillf TEMPROOT=${OPTARG} 26152400Sbillf ;; 26252400Sbillf d) 26352400Sbillf TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` 26452400Sbillf ;; 26552400Sbillf u) 26652400Sbillf NEW_UMASK=${OPTARG} 26752400Sbillf ;; 26852400Sbillf w) 26952400Sbillf SCREEN_WIDTH=${OPTARG} 27052400Sbillf ;; 27167949Sdougb D) 27267949Sdougb DESTDIR=${OPTARG} 27367949Sdougb ;; 27452400Sbillf *) 27552400Sbillf display_usage 27652400Sbillf exit 1 27752400Sbillf ;; 27852400Sbillf esac 27952400Sbillfdone 28052400Sbillf 28152400Sbillfecho '' 28252400Sbillf 28352400Sbillf# If the user has a pager defined, make sure we can run it 28452400Sbillf# 28552400Sbillfcase "${DONT_CHECK_PAGER}" in 28652400Sbillf'') 28764467Sbrian while ! type "${PAGER%% *}" >/dev/null && [ -n "${PAGER}" ]; do 28852400Sbillf echo " *** Your PAGER environment variable specifies '${PAGER}', but" 28964467Sbrian echo " due to the limited PATH that I use for security reasons," 29067859Sdougb echo " I cannot execute it. So, what would you like to do?" 29152400Sbillf echo '' 29252400Sbillf echo " Use 'e' to exit mergemaster and fix your PAGER variable" 29364467Sbrian if [ -x /usr/bin/less -o -x /usr/local/bin/less ]; then 29464467Sbrian echo " Use 'l' to set PAGER to 'less' for this run" 29552400Sbillf fi 29652400Sbillf echo " Use 'm' to use plain old 'more' as your PAGER for this run" 29752400Sbillf echo '' 29852400Sbillf echo " Default is to use plain old 'more' " 29952400Sbillf echo '' 30067859Sdougb echo -n "What should I do? [Use 'more'] " 30167859Sdougb read FIXPAGER 30267859Sdougb 30352400Sbillf case "${FIXPAGER}" in 30458910Salfred [eE]) 30552400Sbillf exit 0 30652400Sbillf ;; 30758910Salfred [lL]) 30864467Sbrian if [ -x /usr/bin/less ]; then 30964467Sbrian PAGER=/usr/bin/less 31064467Sbrian elif [ -x /usr/local/bin/less ]; then 31158910Salfred PAGER=/usr/local/bin/less 31264467Sbrian else 31364467Sbrian echo '' 31464467Sbrian echo " *** Fatal Error:" 31564467Sbrian echo " You asked to use 'less' as your pager, but I can't" 31664467Sbrian echo " find it in /usr/bin or /usr/local/bin" 31764467Sbrian exit 1 31858910Salfred fi 31952400Sbillf ;; 32060420Sbsd [mM]|'') 32152400Sbillf PAGER=more 32252400Sbillf ;; 32358910Salfred *) 32458910Salfred echo '' 32558910Salfred echo "invalid choice: ${FIXPAGER}" 32652400Sbillf esac 32752400Sbillf echo '' 32858910Salfred done 32952400Sbillf ;; 33052400Sbillfesac 33152400Sbillf 33252400Sbillf# If user has a pager defined, or got assigned one above, use it. 33352400Sbillf# If not, use more. 33452400Sbillf# 33552400SbillfPAGER=${PAGER:-more} 33652400Sbillf 33752400Sbillfif [ -n "${VERBOSE}" -a ! "${PAGER}" = "more" ]; then 33852400Sbillf echo " *** You have ${PAGER} defined as your pager so we will use that" 33952400Sbillf echo '' 34052400Sbillf sleep 3 34152400Sbillffi 34252400Sbillf 34352400Sbillf# Assign the diff flag once so we will not have to keep testing it 34452400Sbillf# 34552400SbillfDIFF_FLAG=${DIFF_FLAG:--u} 34652400Sbillf 34752400Sbillf# Assign the source directory 34852400Sbillf# 34952400SbillfSOURCEDIR=${SOURCEDIR:-/usr/src/etc} 35052400Sbillf 35173651Sdougb# Define what CVS $Id tag to look for to aid portability. 35273651Sdougb# 35373651SdougbCVS_ID_TAG=FreeBSD 35473651Sdougb 35552400Sbillfcase "${RERUN}" in 35652400Sbillf'') 35752400Sbillf # Set up the loop to test for the existence of the 35852400Sbillf # temp root directory. 35952400Sbillf # 36052400Sbillf TEST_TEMP_ROOT=yes 36152400Sbillf while [ "${TEST_TEMP_ROOT}" = "yes" ]; do 36252400Sbillf if [ -d "${TEMPROOT}" ]; then 36352400Sbillf echo "*** The directory specified for the temporary root environment," 36467859Sdougb echo " ${TEMPROOT}, exists. This can be a security risk if untrusted" 36552400Sbillf echo " users have access to the system." 36652400Sbillf echo '' 36752400Sbillf case "${AUTO_RUN}" in 36852400Sbillf '') 36952400Sbillf echo " Use 'd' to delete the old ${TEMPROOT} and continue" 37052400Sbillf echo " Use 't' to select a new temporary root directory" 37152400Sbillf echo " Use 'e' to exit mergemaster" 37252400Sbillf echo '' 37352400Sbillf echo " Default is to use ${TEMPROOT} as is" 37452400Sbillf echo '' 37567859Sdougb echo -n "How should I deal with this? [Use the existing ${TEMPROOT}] " 37667859Sdougb read DELORNOT 37767859Sdougb 37867859Sdougb case "${DELORNOT}" in 37967859Sdougb [dD]) 38067859Sdougb echo '' 38167859Sdougb echo " *** Deleting the old ${TEMPROOT}" 38267859Sdougb echo '' 38367859Sdougb rm -rf "${TEMPROOT}" 38467859Sdougb unset TEST_TEMP_ROOT 38552400Sbillf ;; 38667859Sdougb [tT]) 38767859Sdougb echo " *** Enter new directory name for temporary root environment" 38867859Sdougb read TEMPROOT 38967859Sdougb ;; 39067859Sdougb [eE]) 39167859Sdougb exit 0 39267859Sdougb ;; 39367859Sdougb '') 39467859Sdougb echo '' 39567859Sdougb echo " *** Leaving ${TEMPROOT} intact" 39667859Sdougb echo '' 39767859Sdougb unset TEST_TEMP_ROOT 39867859Sdougb ;; 39967859Sdougb *) 40067859Sdougb echo '' 40167859Sdougb echo "invalid choice: ${DELORNOT}" 40267859Sdougb echo '' 40367859Sdougb ;; 40467859Sdougb esac 40567859Sdougb ;; 40652400Sbillf *) 40752400Sbillf # If this is an auto-run, try a hopefully safe alternative then re-test anyway 40852400Sbillf TEMPROOT=/var/tmp/temproot.`date +%m%d.%H.%M.%S` 40952400Sbillf ;; 41052400Sbillf esac 41152400Sbillf else 41252400Sbillf unset TEST_TEMP_ROOT 41352400Sbillf fi 41452400Sbillf done 41552400Sbillf 41652400Sbillf echo "*** Creating the temporary root environment in ${TEMPROOT}" 41752400Sbillf 41852400Sbillf if mkdir -p "${TEMPROOT}"; then 41952400Sbillf echo " *** ${TEMPROOT} ready for use" 42052400Sbillf fi 42152400Sbillf 42252400Sbillf if [ ! -d "${TEMPROOT}" ]; then 42352400Sbillf echo '' 42452400Sbillf echo " *** FATAL ERROR: Cannot create ${TEMPROOT}" 42552400Sbillf echo '' 42652400Sbillf exit 1 42752400Sbillf fi 42852400Sbillf 42952400Sbillf echo " *** Creating and populating directory structure in ${TEMPROOT}" 43052400Sbillf echo '' 43152400Sbillf 43252400Sbillf case "${VERBOSE}" in 43352400Sbillf '') ;; 43452400Sbillf *) 43552400Sbillf echo " *** Press [Enter] or [Return] key to continue" 43652400Sbillf read ANY_KEY 43752400Sbillf unset ANY_KEY 43852400Sbillf ;; 43952400Sbillf esac 44052400Sbillf 44152400Sbillf { cd ${SOURCEDIR} && 44268507Sdougb case "${DESTDIR}" in 44368507Sdougb '') ;; 44468507Sdougb *) 44568507Sdougb make DESTDIR=${DESTDIR} distrib-dirs 44668507Sdougb ;; 44768507Sdougb esac 44852400Sbillf make DESTDIR=${TEMPROOT} distrib-dirs && 44957173Sbillf make DESTDIR=${TEMPROOT} -DNO_MAKEDEV distribution;} || 45052400Sbillf { echo ''; 45152400Sbillf echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to the"; 45252400Sbillf echo " temproot environment"; 45352400Sbillf echo ''; 45452400Sbillf exit 1;} 45552400Sbillf 45667949Sdougb # Doing the inventory and removing files that we don't want to compare only makes 45767949Sdougb # sense if we are not doing a rerun, since we have no way of knowing what happened 45867949Sdougb # to the files during previous incarnations. 45967949Sdougb case "${VERBOSE}" in 46067949Sdougb '') ;; 46167949Sdougb *) 46267949Sdougb echo '' 46367949Sdougb echo ' *** The following files exist only in the installed version of' 46467949Sdougb echo " ${DESTDIR}/etc. In the vast majority of cases these files" 46567949Sdougb echo ' are necessary parts of the system and should not be deleted.' 46667949Sdougb echo ' However because these files are not updated by this process you' 46767949Sdougb echo ' might want to verify their status before rebooting your system.' 46867949Sdougb echo '' 46967949Sdougb echo ' *** Press [Enter] or [Return] key to continue' 47067949Sdougb read ANY_KEY 47167949Sdougb unset ANY_KEY 47267949Sdougb diff -qr ${DESTDIR}/etc ${TEMPROOT}/etc | grep "^Only in /etc" | ${PAGER} 47367949Sdougb echo '' 47467949Sdougb echo ' *** Press [Enter] or [Return] key to continue' 47567949Sdougb read ANY_KEY 47667949Sdougb unset ANY_KEY 47767949Sdougb ;; 47867949Sdougb esac 47967949Sdougb 48052400Sbillf # We really don't want to have to deal with these files, since 48152400Sbillf # master.passwd is the real file that should be compared, then 48252400Sbillf # the user should run pwd_mkdb if necessary. 48352400Sbillf # 48452400Sbillf rm ${TEMPROOT}/etc/spwd.db ${TEMPROOT}/etc/passwd ${TEMPROOT}/etc/pwd.db 48552400Sbillf 48652534Sbillf # Avoid comparing the motd if the user specifies it in .mergemasterrc 48752534Sbillf case "${IGNORE_MOTD}" in 48852534Sbillf '') ;; 48952534Sbillf *) rm ${TEMPROOT}/etc/motd 49052534Sbillf ;; 49152534Sbillf esac 49252534Sbillf 49365115Sben # Avoid trying to update MAKEDEV if /dev is on a devfs 49468507Sdougb if /sbin/sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 49565115Sben rm ${TEMPROOT}/dev/MAKEDEV ${TEMPROOT}/dev/MAKEDEV.local 49665115Sben fi 49765115Sben 49852400Sbillf ;; # End of the "RERUN" test 49952400Sbillfesac 50052400Sbillf 50152400Sbillf# Get ready to start comparing files 50252400Sbillf 50352400Sbillf# Check umask if not specified on the command line, 50452400Sbillf# and we are not doing an autorun 50552400Sbillf# 50652400Sbillfif [ -z "${NEW_UMASK}" -a -z "${AUTO_RUN}" ]; then 50752400Sbillf USER_UMASK=`umask` 50852400Sbillf case "${USER_UMASK}" in 50952400Sbillf 0022) ;; 51052400Sbillf *) 51152400Sbillf echo '' 51267859Sdougb echo " *** Your umask is currently set to ${USER_UMASK}. By default, this script" 51352400Sbillf echo " installs all files with the same user, group and modes that" 51452400Sbillf echo " they are created with by ${SOURCEDIR}/Makefile, compared to" 51567859Sdougb echo " a umask of 022. This umask allows world read permission when" 51652400Sbillf echo " the file's default permissions have it." 51767859Sdougb echo " No world permissions can sometimes cause problems. A umask of" 51852400Sbillf echo " 022 will restore the default behavior, but is not mandatory." 51967859Sdougb echo " /etc/master.passwd is a special case. Its file permissions" 52052400Sbillf echo " will be 600 (rw-------) if installed." 52152400Sbillf echo '' 52267859Sdougb echo -n "What umask should I use? [${USER_UMASK}] " 52367859Sdougb read NEW_UMASK 52467859Sdougb 52552400Sbillf NEW_UMASK="${NEW_UMASK:-$USER_UMASK}" 52652400Sbillf ;; 52752400Sbillf esac 52852400Sbillf echo '' 52952400Sbillffi 53052400Sbillf 53152400SbillfCONFIRMED_UMASK=${NEW_UMASK:-0022} 53252400Sbillf 53367949Sdougb# Warn users who still have ${DESTDIR}/etc/sysconfig 53452400Sbillf# 53567949Sdougbif [ -e "${DESTDIR}/etc/sysconfig" ]; then 53652400Sbillf echo '' 53767949Sdougb echo " *** There is a sysconfig file on this system in ${DESTDIR}/etc/." 53867949Sdougb echo '' 53967949Sdougb echo ' Starting with FreeBSD version 2.2.2 those settings moved from' 54067949Sdougb echo ' /etc/sysconfig to /etc/rc.conf. If you are upgrading an older' 54167949Sdougb echo ' system make sure that you transfer your settings by hand from' 54267949Sdougb echo ' sysconfig to rc.conf and install the rc.conf file. If you' 54367949Sdougb echo ' have already made this transition, you should consider' 54467949Sdougb echo ' renaming or deleting the sysconfig file.' 54567949Sdougb echo '' 54652400Sbillf case "${AUTO_RUN}" in 54752400Sbillf '') 54867859Sdougb echo -n "Continue with the merge process? [yes] " 54967859Sdougb read CONT_OR_NOT 55067859Sdougb 55152400Sbillf case "${CONT_OR_NOT}" in 55252400Sbillf [nN]*) 55352400Sbillf exit 0 55452400Sbillf ;; 55552400Sbillf *) 55652400Sbillf echo " *** Continuing" 55752400Sbillf echo '' 55852400Sbillf ;; 55952400Sbillf esac 56052400Sbillf ;; 56152400Sbillf *) ;; 56252400Sbillf esac 56352400Sbillffi 56452400Sbillf 56552400Sbillf# Use the umask/mode information to install the files 56652400Sbillf# Create directories as needed 56752400Sbillf# 56852400Sbillfmm_install () { 56952400Sbillf local INSTALL_DIR 57052400Sbillf INSTALL_DIR=${1#.} 57152400Sbillf INSTALL_DIR=${INSTALL_DIR%/*} 57267949Sdougb 57352400Sbillf case "${INSTALL_DIR}" in 57452400Sbillf '') 57552400Sbillf INSTALL_DIR=/ 57652400Sbillf ;; 57752400Sbillf esac 57852400Sbillf 57967949Sdougb if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then 58052400Sbillf DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"` 58167949Sdougb install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" 58252400Sbillf fi 58352400Sbillf 58452400Sbillf FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"` 58552400Sbillf 58652400Sbillf if [ ! -x "${1}" ]; then 58752400Sbillf case "${1#.}" in 58864625Sgshapiro /etc/mail/aliases) 58952400Sbillf NEED_NEWALIASES=yes 59052400Sbillf ;; 59152400Sbillf /etc/login.conf) 59252400Sbillf NEED_CAP_MKDB=yes 59352400Sbillf ;; 59452400Sbillf /etc/master.passwd) 59567949Sdougb install -m 600 "${1}" "${DESTDIR}${INSTALL_DIR}" 59652400Sbillf NEED_PWD_MKDB=yes 59752400Sbillf DONT_INSTALL=yes 59852400Sbillf ;; 59952400Sbillf /.cshrc | /.profile) 60052400Sbillf case "${LINK_EXPLAINED}" in 60152400Sbillf '') 60267859Sdougb echo " *** Historically BSD derived systems have had a" 60367859Sdougb echo " hard link from /.cshrc and /.profile to" 60467859Sdougb echo " their namesakes in /root. Please indicate" 60567859Sdougb echo " your preference below for bringing your" 60667859Sdougb echo " installed files up to date." 60752400Sbillf echo '' 60852400Sbillf LINK_EXPLAINED=yes 60952400Sbillf ;; 61052400Sbillf esac 61152400Sbillf 61252400Sbillf echo " Use 'd' to delete the temporary ${COMPFILE}" 61367949Sdougb echo " Use 'l' to delete the existing ${DESTDIR}${COMPFILE#.} and create the link" 61452400Sbillf echo '' 61552400Sbillf echo " Default is to leave the temporary file to deal with by hand" 61652400Sbillf echo '' 61767859Sdougb echo -n " How should I handle ${COMPFILE}? [Leave it to install later] " 61867859Sdougb read HANDLE_LINK 61967859Sdougb 62052400Sbillf case "${HANDLE_LINK}" in 62152400Sbillf [dD]*) 62252400Sbillf rm "${COMPFILE}" 62352400Sbillf echo '' 62452400Sbillf echo " *** Deleting ${COMPFILE}" 62552400Sbillf ;; 62652400Sbillf [lL]*) 62752400Sbillf echo '' 62867949Sdougb rm -f "${DESTDIR}${COMPFILE#.}" 62967949Sdougb if ln "${DESTDIR}/root/${COMPFILE##*/}" "${DESTDIR}${COMPFILE#.}"; then 63067949Sdougb echo " *** Link from ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/} installed successfully" 63152400Sbillf rm "${COMPFILE}" 63252400Sbillf else 63367949Sdougb echo " *** Error linking ${DESTDIR}${COMPFILE#.} to ${DESTDIR}/root/${COMPFILE##*/}, ${COMPFILE} will remain to install by hand" 63452400Sbillf fi 63552400Sbillf ;; 63652400Sbillf *) 63752400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 63852400Sbillf ;; 63952400Sbillf esac 64052400Sbillf DONT_INSTALL=yes 64152400Sbillf ;; 64252400Sbillf esac 64352400Sbillf 64452400Sbillf case "${DONT_INSTALL}" in 64552400Sbillf '') 64667949Sdougb install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 64752400Sbillf ;; 64852400Sbillf *) 64952400Sbillf unset DONT_INSTALL 65052400Sbillf ;; 65152400Sbillf esac 65252400Sbillf else 65367949Sdougb case "${1#.}" in 65467949Sdougb /dev/MAKEDEV) 65567949Sdougb NEED_MAKEDEV=yes 65667949Sdougb ;; 65767949Sdougb esac 65867949Sdougb install -m "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" 65952400Sbillf fi 66052400Sbillf return $? 66152400Sbillf} 66252400Sbillf 66367949Sdougbecho '' 66467949Sdougbecho "*** Beginning comparison" 66567949Sdougbecho '' 66652400Sbillf 66767949Sdougbcd "${TEMPROOT}" 66867949Sdougb 66967949Sdougbif [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; then 67067949Sdougb . "${MM_PRE_COMPARE_SCRIPT}" 67167949Sdougbfi 67267949Sdougb 67352400Sbillf# Using -size +0 avoids uselessly checking the empty log files created 67452400Sbillf# by ${SOURCEDIR}/Makefile and the device entries in ./dev, but does 67567949Sdougb# check the scripts in ./dev, as we'd like (assuming no devfs of course). 67652400Sbillf# 67752400Sbillffor COMPFILE in `find . -type f -size +0`; do 67867949Sdougb 67967949Sdougb # First, check to see if the file exists in DESTDIR. If not, the 68067949Sdougb # diff_loop function knows how to handle it. 68167949Sdougb # 68267949Sdougb if [ ! -e "${DESTDIR}${COMPFILE#.}" ]; then 68367949Sdougb diff_loop 68467949Sdougb continue 68567949Sdougb fi 68667949Sdougb 68752400Sbillf case "${STRICT}" in 68852400Sbillf '' | [Nn][Oo]) 68952400Sbillf # Compare CVS $Id's first so if the file hasn't been modified 69052400Sbillf # local changes will be ignored. 69152400Sbillf # If the files have the same $Id, delete the one in temproot so the 69252400Sbillf # user will have less to wade through if files are left to merge by hand. 69352400Sbillf # 69473651Sdougb CVSID1=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null` 69573651Sdougb CVSID2=`grep "[$]${CVS_ID_TAG}:" ${COMPFILE} 2>/dev/null` 69652400Sbillf 69767949Sdougb case "${CVSID2}" in 69873651Sdougb "${CVSID1}") 69967949Sdougb echo " *** Temp ${COMPFILE} and installed have the same CVS Id, deleting" 70067949Sdougb rm "${COMPFILE}" 70167949Sdougb ;; 70267949Sdougb esac 70352400Sbillf ;; 70452400Sbillf esac 70552400Sbillf 70652400Sbillf # If the file is still here either because the $Ids are different, the 70752400Sbillf # file doesn't have an $Id, or we're using STRICT mode; look at the diff. 70852400Sbillf # 70952400Sbillf if [ -f "${COMPFILE}" ]; then 71052400Sbillf 71152400Sbillf # Do an absolute diff first to see if the files are actually different. 71252400Sbillf # If they're not different, delete the one in temproot. 71352400Sbillf # 71467949Sdougb if diff -q "${DESTDIR}${COMPFILE#.}" "${COMPFILE}" > /dev/null 2>&1; then 71552400Sbillf echo " *** Temp ${COMPFILE} and installed are the same, deleting" 71652400Sbillf rm "${COMPFILE}" 71752400Sbillf else 71867859Sdougb # Ok, the files are different, so show the user where they differ. Use user's 71967859Sdougb # choice of diff methods; and user's pager if they have one. Use more if not. 72067859Sdougb # Use unified diffs by default. Context diffs give me a headache. :) 72152400Sbillf # 72252400Sbillf case "${AUTO_RUN}" in 72352400Sbillf '') 72458910Salfred # prompt user to install/delete/merge changes 72558910Salfred diff_loop 72652400Sbillf ;; 72752400Sbillf *) 72852400Sbillf # If this is an auto run, make it official 72952400Sbillf echo " *** ${COMPFILE} will remain for your consideration" 73052400Sbillf ;; 73152400Sbillf esac # Auto run test 73252400Sbillf fi # Yes, the files are different 73352400Sbillf fi # Yes, the file still remains to be checked 73452400Sbillfdone # This is for the do way up there at the beginning of the comparison 73552400Sbillf 73652534Sbillfecho '' 73752400Sbillfecho "*** Comparison complete" 73852400Sbillfecho '' 73952400Sbillf 74052400SbillfTEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null` 74152400Sbillfif [ -n "${TEST_FOR_FILES}" ]; then 74252400Sbillf echo "*** Files that remain for you to merge by hand:" 74352400Sbillf find "${TEMPROOT}" -type f -size +0 74452400Sbillffi 74552400Sbillf 74652400Sbillfcase "${AUTO_RUN}" in 74752400Sbillf'') 74852400Sbillf echo '' 74967859Sdougb echo -n "Do you wish to delete what is left of ${TEMPROOT}? [no] " 75067859Sdougb read DEL_TEMPROOT 75167859Sdougb 75252400Sbillf case "${DEL_TEMPROOT}" in 75352400Sbillf [yY]*) 75452400Sbillf if rm -rf "${TEMPROOT}"; then 75552400Sbillf echo " *** ${TEMPROOT} has been deleted" 75652400Sbillf else 75752400Sbillf echo " *** Unable to delete ${TEMPROOT}" 75852400Sbillf fi 75952400Sbillf ;; 76052400Sbillf *) 76152400Sbillf echo " *** ${TEMPROOT} will remain" 76252400Sbillf ;; 76352400Sbillf esac 76452400Sbillf ;; 76552400Sbillf*) ;; 76652400Sbillfesac 76752400Sbillf 76868153Sdougbcase "${AUTO_INSTALLED_FILES}" in 76968153Sdougb'') ;; 77068153Sdougb*) 77173651Sdougb case "${AUTO_RUN}" in 77273651Sdougb '') 77373651Sdougb ( 77473651Sdougb echo '' 77573651Sdougb echo '*** You chose the automatic install option for files that did not exist' 77673651Sdougb echo ' on your system. The following files were installed for you:' 77773651Sdougb echo "${AUTO_INSTALLED_FILES}" 77873651Sdougb ) | ${PAGER} 77973651Sdougb ;; 78073651Sdougb *) 78168153Sdougb echo '' 78268153Sdougb echo '*** You chose the automatic install option for files that did not exist' 78368153Sdougb echo ' on your system. The following files were installed for you:' 78468153Sdougb echo "${AUTO_INSTALLED_FILES}" 78573651Sdougb ;; 78673651Sdougb esac 78768153Sdougb ;; 78868153Sdougbesac 78968153Sdougb 79073651Sdougbrun_it_now () { 79173651Sdougb case "${AUTO_RUN}" in 79273651Sdougb '') 79373651Sdougb unset YES_OR_NO 79473651Sdougb echo '' 79573651Sdougb echo -n ' Would you like to run it now? [y or n] ' 79673651Sdougb read YES_OR_NO 79773651Sdougb 79873651Sdougb echo '' 79973651Sdougb 80073651Sdougb case "${YES_OR_NO}" in 80173651Sdougb y) 80273651Sdougb echo " Running ${1}" 80373651Sdougb eval "${1}" 80473651Sdougb ;; 80573651Sdougb *) 80673651Sdougb echo " Make sure to run ${1} yourself" 80773651Sdougb ;; 80873651Sdougb esac 80973651Sdougb ;; 81073651Sdougb *) ;; 81173651Sdougb esac 81273651Sdougb} 81373651Sdougb 81452400Sbillfcase "${NEED_MAKEDEV}" in 81552400Sbillf'') ;; 81652400Sbillf*) 81752400Sbillf echo '' 81852400Sbillf echo "*** You installed a new /dev/MAKEDEV script, so make sure that you run" 81952400Sbillf echo " 'cd /dev && /bin/sh MAKEDEV all' to rebuild your devices" 82073651Sdougb run_it_now 'cd /dev && /bin/sh MAKEDEV all' 82152400Sbillf ;; 82252400Sbillfesac 82352400Sbillf 82452400Sbillfcase "${NEED_NEWALIASES}" in 82552400Sbillf'') ;; 82652400Sbillf*) 82752400Sbillf echo '' 82852400Sbillf echo "*** You installed a new aliases file, so make sure that you run" 82973651Sdougb echo " '/usr/bin/newaliases' to rebuild your aliases database" 83073651Sdougb run_it_now '/usr/bin/newaliases' 83152400Sbillf ;; 83252400Sbillfesac 83352400Sbillf 83452400Sbillfcase "${NEED_CAP_MKDB}" in 83552400Sbillf'') ;; 83652400Sbillf*) 83752400Sbillf echo '' 83852400Sbillf echo "*** You installed a login.conf file, so make sure that you run" 83973651Sdougb echo " '/usr/bin/cap_mkdb /etc/login.conf' to rebuild your login.conf database" 84073651Sdougb run_it_now '/usr/bin/cap_mkdb /etc/login.conf' 84152400Sbillf ;; 84252400Sbillfesac 84352400Sbillf 84452400Sbillfcase "${NEED_PWD_MKDB}" in 84552400Sbillf'') ;; 84652400Sbillf*) 84752400Sbillf echo '' 84852400Sbillf echo "*** You installed a new master.passwd file, so make sure that you run" 84973651Sdougb echo " '/usr/sbin/pwd_mkdb -p /etc/master.passwd' to rebuild your password files" 85073651Sdougb run_it_now '/usr/sbin/pwd_mkdb -p /etc/master.passwd' 85152400Sbillf ;; 85252400Sbillfesac 85352400Sbillf 85452400Sbillfecho '' 85552400Sbillf 85667949Sdougbif [ -r "${MM_EXIT_SCRIPT}" ]; then 85767949Sdougb . "${MM_EXIT_SCRIPT}" 85867949Sdougbfi 85967949Sdougb 86052400Sbillfexit 0 86167850Sdougb 862