#!/bin/sh # mergemaster mtree database generator # This script is intended to be used as part of the release building # process to generate the /var/db/mergemaster.mtree file relevant to # the source tree used to create the release so that users can make # use of mergemaster's -U option to update their files after updating # to -stable. # Copyright 2009 Douglas Barton # dougb@FreeBSD.org # $FreeBSD: stable/11/release/scripts/mm-mtree.sh 301584 2016-06-08 06:33:55Z delphij $ setglobal PATH = '/bin:/usr/bin:/usr/sbin' proc display_usage { setglobal VERSION_NUMBER = $[grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4] echo "$(0##*/) version $(VERSION_NUMBER)" echo "Usage: $(0##*/) [-m /path] [-t /path] [-A arch] [-F ] [-D /path]" echo "Options:" echo " -m /path/directory Specify location of source to do the make in" echo " -t /path/directory Specify temp root directory" echo " -A architecture Alternative architecture name to pass to make" echo " -F Specify what to put on the make command line" echo ' -D /path/directory Specify the destination directory to install files to' echo '' } # Set the default path for the temporary root environment # setglobal TEMPROOT = $[env TMPDIR=/var/tmp mktemp -d -t temproot] # Assign the location of the mtree database # setglobal MTREEDB = $(MTREEDB:-/var/db) setglobal MTREEFILE = ""$(MTREEDB)/mergemaster.mtree"" # Check the command line options # while getopts "m:t:A:F:D:h" COMMAND_LINE_ARGUMENT { match $(COMMAND_LINE_ARGUMENT) { with m setglobal SOURCEDIR = $(OPTARG) with t setglobal TEMPROOT = $(OPTARG) with A setglobal ARCHSTRING = "'TARGET_ARCH='$(OPTARG)" with F setglobal MM_MAKE_ARGS = $(OPTARG) with D setglobal DESTDIR = $(OPTARG) with h display_usage exit 0 with * echo '' display_usage exit 1 } } # Assign the source directory # setglobal SOURCEDIR = $(SOURCEDIR:-/usr/src) if test ! -f $(SOURCEDIR)/Makefile.inc1 -a \ -f $(SOURCEDIR)/../Makefile.inc1 { echo " *** The source directory you specified ($(SOURCEDIR))" echo " will be reset to $(SOURCEDIR)/.." echo '' sleep 3 setglobal SOURCEDIR = "$(SOURCEDIR)/.." } # Setup make to use system files from SOURCEDIR setglobal objp = $(MAKEOBJDIRPREFIX) test -z $(objp) && setglobal objp = '/usr/obj' setglobal legacydir = "$(objp)$(SOURCEDIR)/tmp/legacy" setglobal legacypath = "$(legacydir)/usr/sbin:$(legacydir)/usr/bin:$(legacydir)/bin" setglobal MM_MAKE_ARGS = ""$(MM_MAKE_ARGS) PATH=$(legacypath):$(PATH)"" setglobal MM_MAKE = ""make $(ARCHSTRING) $(MM_MAKE_ARGS) -m $(SOURCEDIR)/share/mk"" proc delete_temproot { rm -rf $(TEMPROOT) !2 >/dev/null chflags -R 0 $(TEMPROOT) !2 >/dev/null rm -rf $(TEMPROOT) || exit 1 } test -d $(TEMPROOT) && delete_temproot echo "*** Creating the temporary root environment in $(TEMPROOT)" if mkdir -p $(TEMPROOT) { echo " *** $(TEMPROOT) ready for use" } if test ! -d $(TEMPROOT) { echo '' echo " *** FATAL ERROR: Cannot create $(TEMPROOT)" echo '' exit 1 } echo " *** Creating and populating directory structure in $(TEMPROOT)" echo '' do { cd $(SOURCEDIR) || do { echo "*** Cannot cd to $(SOURCEDIR)" ; exit 1;} match $(DESTDIR) { with '' with * $(MM_MAKE) DESTDIR=$(DESTDIR) distrib-dirs } setglobal od = "$(TEMPROOT)/usr/obj" $(MM_MAKE) DESTDIR=$(TEMPROOT) distrib-dirs && env MAKEOBJDIRPREFIX=$od $(MM_MAKE) _obj SUBDIR_OVERRIDE=etc && env MAKEOBJDIRPREFIX=$od $(MM_MAKE) everything SUBDIR_OVERRIDE=etc && env MAKEOBJDIRPREFIX=$od $(MM_MAKE) DESTDIR=$(TEMPROOT) distribution;} || do { echo ''; echo " *** FATAL ERROR: Cannot 'cd' to $(SOURCEDIR) and install files to"; echo " the temproot environment"; echo ''; exit 1;} # We really don't want to have to deal with files like login.conf.db, pwd.db, # or spwd.db. Instead, we want to compare the text versions, and run *_mkdb. # Prompt the user to do so below, as needed. # rm -f $(TEMPROOT)/etc/*.db $(TEMPROOT)/etc/passwd # We only need to compare things like freebsd.cf once find $(TEMPROOT)/usr/obj -type f -delete !2 >/dev/null # Delete stuff we do not need to keep the mtree database small, # and to make the actual comparison faster. find $(TEMPROOT)/usr -type l -delete !2 >/dev/null find $(TEMPROOT) -type f -size 0 -delete !2 >/dev/null find -d $(TEMPROOT) -type d -empty -delete !2 >/dev/null # Build the mtree database in a temporary location. setglobal MTREENEW = $[mktemp -t mergemaster.mtree] mtree -nci -p $(TEMPROOT) -k size,md5digest > $(MTREENEW) !2 >/dev/null if test -s $(MTREENEW) { echo "*** Saving mtree database for future upgrades" test -e "$(DESTDIR)$(MTREEFILE)" && unlink $(DESTDIR)$(MTREEFILE) mv $(MTREENEW) $(DESTDIR)$(MTREEFILE) } delete_temproot exit 0