]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - release/scripts/mm-mtree.sh
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / release / scripts / mm-mtree.sh
1 #!/bin/sh
2
3 # mergemaster mtree database generator
4
5 # This script is intended to be used as part of the release building
6 # process to generate the /var/db/mergemaster.mtree file relevant to
7 # the source tree used to create the release so that users can make
8 # use of mergemaster's -U option to update their files after csup'ing
9 # to -stable.
10
11 # Copyright 2009 Douglas Barton
12 # dougb@FreeBSD.org
13
14 # $FreeBSD$
15
16 PATH=/bin:/usr/bin:/usr/sbin
17
18 display_usage () {
19   VERSION_NUMBER=`grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`
20   echo "${0##*/} version ${VERSION_NUMBER}"
21   echo "Usage: ${0##*/} [-m /path] [-t /path] [-A arch] [-F <make args>] [-D /path]"
22   echo "Options:"
23   echo "  -m /path/directory  Specify location of source to do the make in"
24   echo "  -t /path/directory  Specify temp root directory"
25   echo "  -A architecture  Alternative architecture name to pass to make"
26   echo "  -F <arguments for make> Specify what to put on the make command line"
27   echo '  -D /path/directory  Specify the destination directory to install files to'
28   echo ''
29 }
30
31 # Set the default path for the temporary root environment
32 #
33 TEMPROOT='/var/tmp/temproot'
34
35 # Assign the location of the mtree database
36 #
37 MTREEDB=${MTREEDB:-/var/db}
38 MTREEFILE="${MTREEDB}/mergemaster.mtree"
39
40 # Check the command line options
41 #
42 while getopts "m:t:A:F:D:h" COMMAND_LINE_ARGUMENT ; do
43   case "${COMMAND_LINE_ARGUMENT}" in
44   m)
45     SOURCEDIR=${OPTARG}
46     ;;
47   t)
48     TEMPROOT=${OPTARG}
49     ;;
50   A)
51     ARCHSTRING='TARGET_ARCH='${OPTARG}
52     ;;
53   F)
54     MM_MAKE_ARGS="${OPTARG}"
55     ;;
56   D)
57     DESTDIR=${OPTARG}
58     ;;
59   h)
60     display_usage
61     exit 0
62     ;;
63   *)
64     echo ''
65     display_usage
66     exit 1
67     ;;
68   esac
69 done
70
71 # Assign the source directory
72 #
73 SOURCEDIR=${SOURCEDIR:-/usr/src}
74 if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
75    -f ${SOURCEDIR}/../Makefile.inc1 ]; then
76   echo " *** The source directory you specified (${SOURCEDIR})"
77   echo "     will be reset to ${SOURCEDIR}/.."
78   echo ''
79   sleep 3
80   SOURCEDIR=${SOURCEDIR}/..
81 fi
82
83 # Setup make to use system files from SOURCEDIR
84 MM_MAKE="make ${ARCHSTRING} ${MM_MAKE_ARGS} -m ${SOURCEDIR}/share/mk"
85
86 delete_temproot () {
87   rm -rf "${TEMPROOT}" 2>/dev/null
88   chflags -R 0 "${TEMPROOT}" 2>/dev/null
89   rm -rf "${TEMPROOT}" || exit 1
90 }
91
92 [ -d "${TEMPROOT}" ] && delete_temproot
93
94 echo "*** Creating the temporary root environment in ${TEMPROOT}"
95
96 if mkdir -p "${TEMPROOT}"; then
97   echo " *** ${TEMPROOT} ready for use"
98 fi
99
100 if [ ! -d "${TEMPROOT}" ]; then
101   echo ''
102   echo "  *** FATAL ERROR: Cannot create ${TEMPROOT}"
103   echo ''
104   exit 1
105 fi
106
107 echo " *** Creating and populating directory structure in ${TEMPROOT}"
108 echo ''
109
110 { cd ${SOURCEDIR} || { echo "*** Cannot cd to ${SOURCEDIR}" ; exit 1;}
111   case "${DESTDIR}" in
112   '') ;;
113   *)
114     ${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs
115     ;;
116   esac
117   od=${TEMPROOT}/usr/obj
118   ${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs &&
119   MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc &&
120   MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc &&
121   MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution;} ||
122   { echo '';
123     echo "  *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
124     echo "      the temproot environment";
125     echo '';
126     exit 1;}
127
128 # We really don't want to have to deal with files like login.conf.db, pwd.db,
129 # or spwd.db.  Instead, we want to compare the text versions, and run *_mkdb.
130 # Prompt the user to do so below, as needed.
131 #
132 rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/etc/passwd
133
134 # We only need to compare things like freebsd.cf once
135 find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null
136
137 # Delete stuff we do not need to keep the mtree database small,
138 # and to make the actual comparison faster.
139 find ${TEMPROOT}/usr -type l -delete 2>/dev/null
140 find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null
141 find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null
142
143 # Build the mtree database in a temporary location.
144 MTREENEW=`mktemp -t mergemaster.mtree`
145 mtree -ci -p ${TEMPROOT} -k size,md5digest > ${MTREENEW} 2>/dev/null
146
147 if [ -s "${MTREENEW}" ]; then
148   echo "*** Saving mtree database for future upgrades"
149   test -e "${DESTDIR}${MTREEFILE}" && unlink ${DESTDIR}${MTREEFILE}
150   mv ${MTREENEW} ${DESTDIR}${MTREEFILE}
151 fi
152
153 delete_temproot
154
155 exit 0