2 # -------+---------+---------+---------+---------+---------+---------+---------+
3 # Copyright (c) 2004 - Garance Alistair Drosehn <gad@FreeBSD.org>.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # -------+---------+---------+---------+---------+---------+---------+---------+
30 # -------+---------+---------+---------+---------+---------+---------+---------+
32 # This script does a 'make installworld' using the *new* versions of all
33 # commands to do the work. This is important when a major incompatible
34 # change is made, a change such that the old-binaries won't work when
35 # running on the new-kernel. This script was written for the change to
36 # 64-bit time_t on FreeBSD/Sparc64, but it is not specific to that.
38 # IMPORTANT: This script does require that you ARE RUNNING ON the
39 # new kernel that matches the 'world' that you want to install.
41 # -------+---------+---------+---------+---------+---------+---------+---------+
43 # This script expects that it will be run from /usr/src, or an
44 # equivalent (perhaps NFS-mounted) directory.
45 if [ -f MAINTAINERS -a -f UPDATING -a -f Makefile -a -f Makefile.inc1 ] ; then
46 SOURCE_BWDIR="`make -V .OBJDIR`"
48 echo "This script must be run from /usr/src! (or equivalent)"
66 *) echo "Invalid option: $1" ; BADOPT=yes ;;
70 if [ -n "$BADOPT" ] ; then
74 echo "* + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - *"
75 echo "* This script expects that a 'make installkernel' has already"
76 echo "* been done, and that you HAVE rebooted, and you ARE running"
77 echo "* on that new kernel."
78 echo "* + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - *"
81 # Start out with no PATH at all.
84 # Where all the binaries should be coming from.
85 BW_BIN="${SOURCE_BWDIR}/bin"
86 BW_SBIN="${SOURCE_BWDIR}/sbin"
87 BW_UBIN="${SOURCE_BWDIR}/usr.bin"
88 BW_USBIN="${SOURCE_BWDIR}/usr.sbin"
89 BW_GUBIN="${SOURCE_BWDIR}/gnu/usr.bin"
91 MKTEMPCMD=/usr/bin/mktemp
92 chkfile="${BW_UBIN}/mktemp/mktemp"
93 if [ -f "${chkfile}" -a -x "${chkfile}" ] ; then
94 MKTEMPCMD="${chkfile}"
96 echo "** Cannot find ${chkfile}?"
97 echo "** Will use ${MKTEMPCMD}"
100 # I intentionally prefer to have a shorter name here... We just need a
101 # unique name, we're not likely to be under attack during installworld!
102 TMPHOLD=`"${MKTEMPCMD}" -q -d ${TMPDIR:-/tmp}/install-newk.XXX`
103 if [ $? -ne 0 ] ; then
104 echo "** Unable to create temp program-holding directory"
108 # Set the most-restrictive value for PATH that the user is willing to
109 # shoot for. The more restrictive we are here, the more likely we
110 # will catch all references to "old version" executables.
111 PATH=${TMPHOLD}:/sbin:/bin:/usr/sbin:/usr/bin
112 if [ -n "$SETMINPATH" ] ; then
116 # Find the most-appropriate version of key commands for this script.
117 # XXX - It would be nice if we could reliably find the exact kernel that
118 # we booted up with, and check for the optional mini-/bin in it.
120 for chkexec in "${BW_BIN}/cp/cp" /bin/cp ; do
121 if [ -f "${chkexec}" ] ; then
122 COPYCMD="${chkexec} -p"
127 for chkexec in "${BW_BIN}/ln/ln" /bin/ln ; do
128 if [ -f "${chkexec}" ] ; then
139 srcfile="${srcdir}/${cmdname}"
141 if [ -f "${srcfile}" -a -x "${srcfile}" ] ; then
142 if [ -n "$VERBOSE" ] ; then
143 echo ".. ${COPYINFO} ${srcfile}"
145 ${COPYCMD} "${srcfile}" "${TMPHOLD}"
146 if [ $? -ne 0 ] ; then
147 echo "** Error ${COPYINFO} '${srcfile}'"
151 echo "** Cannot find ${cmdname} in ${srcdir}?"
155 if [ -n "${alsoln}" ] ; then
156 if [ -n "$VERBOSE" ] ; then
157 echo ".. Linking '${cmdname}' as '${alsoln}' "
159 ${LINKCMD} "${TMPHOLD}/${cmdname}" "${TMPHOLD}/${alsoln}"
160 if [ $? -ne 0 ] ; then
161 echo "** Error Linking '${cmdname}'"
167 # The programs listed in the following `do' loop are all the same programs
168 # that the standard 'installworld' target wants to make copies of, except
169 # that this has special-cases for `awk', `[', and `egrep'. This script
170 # also adds the commands `cp', `install', `id' and `which', because those
171 # are also *used* by the standard `make installworld' target, although
172 # that target doesn't bother to make copies of those programs. The `sleep'
173 # command is also added, but only because it is used in this script. And
174 # `script' is included just because it can be useful when testing this script.
176 # Note that this means there will be two copies made of these files
177 # (because the 'make installworld' target is still going to copy them a
179 # XXX - also remember that these are dynamically-linked, so this is not
180 # necessarily a perfect solution for the 'general case', but it
181 # does seem to work correctly for the switch to 64-bit time_t.
183 # Do the `cp' command first, because this script does so much with it.
184 chkfile="${BW_BIN}/cp/cp"
185 if [ -f "${chkfile}" -a -x "${chkfile}" ] ; then
186 if [ -n "$VERBOSE" ] ; then
187 echo ".. Copying ${chkfile}"
189 ${COPYCMD} "${chkfile}" ${TMPHOLD}
191 echo "** Cannot find ${chkfile}?"
195 # Do the `ln' command as the second one, for similar reasons.
196 copy_exec "${BW_BIN}/ln" ln
198 # Awk is also called 'nawk'
199 copy_exec "${BW_UBIN}/awk" nawk awk
201 # The `install' comand is also is a special case, because
202 # the program is actually built under the name 'xinstall'.
203 copy_exec "${BW_UBIN}/xinstall" xinstall install
205 # Mergemaster is another special case, because it's a script which is
206 # pulled from the /usr/src directory (not from /usr/obj/usr/src/...).
207 # Strictly speaking we shouldn't need to pull this in, but I do in
208 # case someone says 'no' to the automatic-installworld at the end
209 # if this script. If they also specified -M, then they end up with
210 # a PATH which will have only our TMPHOLD directory when they get
211 # to the mergemaster step.
212 copy_exec "`pwd`/usr.sbin/mergemaster" mergemaster.sh mergemaster
214 # Worried about the extra disk space that this script uses up in /tmp? Well,
215 # just specify the -S option, and this script will create symlinks instead of
216 # copying the files. Note that the original files might be NFS-mounted, and
217 # /tmp might be a memory-based file system, so the `installworld' might go
218 # much faster when copies are done here instead of symlinks.
219 if [ -n "$SYMLINKS" ] ; then
220 COPYINFO="Linking to"
225 for prog in cap_mkdb cat chflags chmod chown date \
226 echo find grep make mkdir mtree mv \
227 pwd_mkdb rm sed sh sysctl test true uname wc zic \
228 hostname id ls sleep script umount which xargs
231 for chkdir in "${BW_BIN}" "${BW_SBIN}" "${BW_UBIN}" "${BW_GUBIN}" \
232 "${BW_USBIN}" "${BW_USBIN}/${prog}"
234 # (the above extra-${prog} case is only needed for 'zic')
235 chkdir="${chkdir}/${prog}"
236 if [ -f "${chkdir}/${prog}" -a -x "${chkdir}/${prog}" ] ; then
238 copy_exec "${chkdir}" "${prog}"
239 if [ $? -ne 0 ] ; then
245 if [ -z "$gotmatch" ] ; then
246 echo "** Did not find '${prog}' ?"
250 # Special case to handle '[', which we know is the same as 'test'
251 if [ -x ${TMPHOLD}/test ] ; then
252 if [ -n "$VERBOSE" ] ; then
253 echo ".. Linking 'test' as '[' "
255 ${LINKCMD} ${TMPHOLD}/test ${TMPHOLD}/[
257 # Special case for 'egrep', which is the same as 'grep'
258 if [ -x ${TMPHOLD}/grep ] ; then
259 if [ -n "$VERBOSE" ] ; then
260 echo ".. Linking 'grep' as 'egrep' "
262 ${LINKCMD} ${TMPHOLD}/grep ${TMPHOLD}/egrep
265 # Have to duplicate the standard makefile, to make a few changes.
267 # First find the setting of PATH. Insert a line in front of that
268 # which uses the (undocumented) .SHELL feature to get 'make' to
269 # use the newer version of /bin/sh that we just made a copy of.
270 # Then alter the PATH setting so that all make targets check our
271 # directory of copied files first. If '-M' was given, then have
272 # a PATH setting that looks ONLY at our copied files.
274 # XXX - the .SHELL feature did NOT seem to work the way that I
275 # wanted it to, but that is not a problem for now. It can
276 # be looked into at some later date...
278 print "# Try to get the make cmd to use an alternate /bin/sh." ; \
279 print ".SHELL : name=sh path=" TDIR "/sh" ; \
281 if (WANTMIN == "yes") \
282 sub(/^PATH *=[ \t]*.*/, "PATH=\t" TDIR ); \
284 sub(/^PATH *=[ \t]*/, "PATH=\t" TDIR ":"); \
286 /-f Makefile.inc1/ { \
287 sub(/Makefile.inc1/, TDIR "/Makefile.inc1" ); \
290 "TDIR=${TMPHOLD}" "WANTMIN=${SETMINPATH}" Makefile > ${TMPHOLD}/Makefile
292 # In the case of this script, we also change Makefile.inc1, just to
293 # set the .SHELL target, and to make it (Makefile.inc1) reference
294 # the modified version in 'make -f' references. Someone recently
295 # committed a total restructuring of Makefile.inc1, so the following
296 # has to be setup such that it works with both formats.
297 nawk '/^# Put initial settings/ { \
298 print "# Try to get the make cmd to use an alternate /bin/sh." ; \
299 print ".SHELL : name=sh path=" TDIR "/sh" ; \
302 /^SUBDIR=[\t ]*share\/info .*bin/ { \
303 print "# Try to get the make cmd to use an alternate /bin/sh." ; \
304 print ".SHELL : name=sh path=" TDIR "/sh" ; \
307 /-f Makefile.inc1/ { \
308 sub(/Makefile.inc1/, TDIR "/Makefile.inc1" ); \
311 "TDIR=${TMPHOLD}" Makefile.inc1 > "${TMPHOLD}/Makefile.inc1"
314 echo "The key programs needed by 'make installworld' have been copied."
315 if [ -n "$VERBOSE" ] ; then
320 # The sparc64_installcheck will want this in the environment.
321 NEWSPARC_TIMETYPE=__int64_t
322 export NEWSPARC_TIMETYPE
324 # See if the user wants us to go ahead with 'installworld',
325 # or just tell them what steps they need to do.
326 if [ -z "${DOMAKE}" ] ; then
327 echo "Do you want to proceed with 'installworld'? "
328 read -p "(y/n) ? " DOMAKE remline
331 if [ -n "`echo /y/yes/okay/ok/ | grep -i \"/${DOMAKE}/\"`" ] ; then
332 echo "Okay then, this script has set:"
333 echo " NEWSPARC_TIMETYPE=__int64_t"
335 echo "and will now execute the command:"
336 echo " make -f ${TMPHOLD}/Makefile installworld"
338 make -f ${TMPHOLD}/Makefile installworld
340 echo "When you are ready to continue, enter the commands:"
343 echo " PATH=${TMPHOLD}:\${PATH}"
345 echo " NEWSPARC_TIMETYPE=__int64_t"
346 echo " export NEWSPARC_TIMETYPE"
347 echo " make -f ${TMPHOLD}/Makefile installworld"