]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - installworld_newk
This commit was generated by cvs2svn to compensate for changes in r127668,
[FreeBSD/FreeBSD.git] / installworld_newk
1 #!/bin/sh
2 # -------+---------+---------+---------+---------+---------+---------+---------+
3 # Copyright (c) 2004  - Garance Alistair Drosehn <gad@FreeBSD.org>.
4 #
5 # All rights reserved.
6 #
7 #  Redistribution and use in source and binary forms, with or without
8 #  modification, are permitted provided that the following conditions
9 #  are met:
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.
15 #
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
26 #  SUCH DAMAGE.
27 #
28 # -------+---------+---------+---------+---------+---------+---------+---------+
29 # $FreeBSD$
30 # -------+---------+---------+---------+---------+---------+---------+---------+
31 #
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.
37 #
38 #   IMPORTANT: This script does require that you ARE RUNNING ON the
39 # new kernel that matches the 'world' that you want to install.
40 #
41 # -------+---------+---------+---------+---------+---------+---------+---------+
42
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`"
47 else
48     echo "This script must be run from /usr/src!  (or equivalent)"
49     exit 1
50 fi
51
52 DOMAKE=
53 DOMINI=
54 SETMINPATH=
55 SYMLINKS=
56 VERBOSE=
57 BADOPT=
58 while test $# != 0
59 do
60     case "$1" in
61     -M)   SETMINPATH=yes ;;
62     -S)   SYMLINKS=yes ;;
63     -y)   DOMAKE=yes ;;
64     -n)   DOMAKE=no ;;
65     -v)   VERBOSE=yes ;;
66     *)    echo "Invalid option: $1" ; BADOPT=yes ;;
67     esac
68     shift 1
69 done
70 if [ -n "$BADOPT" ] ; then
71     exit 1
72 fi
73
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 "* + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - *"
79 echo ""
80
81 #   Start out with no PATH at all.
82 PATH=
83
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"
90
91 MKTEMPCMD=/usr/bin/mktemp
92 chkfile="${BW_UBIN}/mktemp/mktemp"
93 if [ -f "${chkfile}" -a -x "${chkfile}" ] ; then
94     MKTEMPCMD="${chkfile}"
95 else
96     echo "** Cannot find ${chkfile}?"
97     echo "** Will use ${MKTEMPCMD}"
98 fi
99
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"
105     exit 1
106 fi
107
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
113     PATH=${TMPHOLD}
114 fi
115
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.
119 COPYCMD=/missing/cp
120 for chkexec in "${BW_BIN}/cp/cp" /bin/cp ; do
121     if [ -f "${chkexec}" ] ; then
122         COPYCMD="${chkexec} -p"
123         break
124     fi
125 done
126 LINKCMD=/missing/ln
127 for chkexec in "${BW_BIN}/ln/ln" /bin/ln ; do
128     if [ -f "${chkexec}" ] ; then
129         LINKCMD="${chkexec}"
130         break
131     fi
132 done
133 COPYINFO="Copying"
134
135 copy_exec () {
136     srcdir="$1"
137     cmdname="$2"
138     alsoln="$3"
139     srcfile="${srcdir}/${cmdname}"
140
141     if [ -f "${srcfile}" -a -x "${srcfile}" ] ; then
142         if [ -n "$VERBOSE" ] ; then
143             echo ".. ${COPYINFO} ${srcfile}"
144         fi
145         ${COPYCMD} "${srcfile}" "${TMPHOLD}"
146         if [ $? -ne 0 ] ; then
147             echo "** Error ${COPYINFO} '${srcfile}'"
148             exit 1
149         fi
150     else
151         echo "** Cannot find ${cmdname} in ${srcdir}?"
152         exit 1
153     fi
154
155     if [ -n "${alsoln}" ] ; then
156         if [ -n "$VERBOSE" ] ; then
157             echo ".. Linking '${cmdname}' as '${alsoln}' "
158         fi
159         ${LINKCMD} "${TMPHOLD}/${cmdname}" "${TMPHOLD}/${alsoln}"
160         if [ $? -ne 0 ] ; then
161             echo "** Error Linking '${cmdname}'"
162             exit 1
163         fi
164     fi
165 }
166
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.
175 #
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
178 # second time).
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.
182
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}"
188     fi
189     ${COPYCMD} "${chkfile}" ${TMPHOLD}
190 else
191     echo "** Cannot find ${chkfile}?"
192     exit 1
193 fi
194
195 #   Do the `ln' command as the second one, for similar reasons.
196 copy_exec "${BW_BIN}/ln" ln
197
198 #   Awk is also called 'nawk'
199 copy_exec "${BW_UBIN}/awk" nawk awk
200
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
204
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
213
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"
221     COPYCMD="ln -s"
222     LINKCMD="ln -s"
223 fi
224
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
229 do
230     gotmatch=
231     for chkdir in "${BW_BIN}" "${BW_SBIN}" "${BW_UBIN}" "${BW_GUBIN}" \
232                    "${BW_USBIN}" "${BW_USBIN}/${prog}"
233     do
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
237             gotmatch=yes
238             copy_exec "${chkdir}" "${prog}"
239             if [ $? -ne 0 ] ; then
240                 exit 1
241             fi
242             break
243         fi
244     done
245     if [ -z "$gotmatch" ] ; then
246         echo "** Did not find '${prog}' ?"
247     fi
248 done
249
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 '[' "
254     fi
255     ${LINKCMD} ${TMPHOLD}/test ${TMPHOLD}/[
256 fi
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' "
261     fi
262     ${LINKCMD} ${TMPHOLD}/grep ${TMPHOLD}/egrep
263 fi
264
265 #   Have to duplicate the standard makefile, to make a few changes.
266
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.
273 #    
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...
277 nawk '/^PATH=/ { \
278             print "#   Try to get the make cmd to use an alternate /bin/sh." ; \
279             print ".SHELL : name=sh path=" TDIR "/sh"  ; \
280             print "" ; \
281             if (WANTMIN == "yes") \
282                 sub(/^PATH *=[ \t]*.*/, "PATH=\t" TDIR ); \
283             else \
284                 sub(/^PATH *=[ \t]*/, "PATH=\t" TDIR ":"); \
285             } \
286       /-f Makefile.inc1/ { \
287             sub(/Makefile.inc1/, TDIR "/Makefile.inc1" ); \
288             } \
289       { print $0 }' \
290     "TDIR=${TMPHOLD}" "WANTMIN=${SETMINPATH}" Makefile > ${TMPHOLD}/Makefile
291
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"  ; \
300             print "" ; \
301             } \
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"  ; \
305             print "" ; \
306             } \
307       /-f Makefile.inc1/ { \
308             sub(/Makefile.inc1/, TDIR "/Makefile.inc1" ); \
309             } \
310      { print $0 }' \
311     "TDIR=${TMPHOLD}" Makefile.inc1 > "${TMPHOLD}/Makefile.inc1"
312
313 echo ""
314 echo "The key programs needed by 'make installworld' have been copied."
315 if [ -n "$VERBOSE" ] ; then
316     ls -C ${TMPHOLD}
317     echo ""
318 fi
319
320 #   The sparc64_installcheck will want this in the environment.
321 NEWSPARC_TIMETYPE=__int64_t
322 export NEWSPARC_TIMETYPE
323
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
329     echo " "
330 fi
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"
334     echo "    PATH=${PATH}"
335     echo "and will now execute the command:"
336     echo "    make -f ${TMPHOLD}/Makefile installworld"
337     sleep 4
338     make -f ${TMPHOLD}/Makefile installworld
339 else
340     echo "When you are ready to continue, enter the commands:"
341     echo "    PATH=${PATH}"
342     echo "or:"
343     echo "    PATH=${TMPHOLD}:\${PATH}"
344     echo "and:"
345     echo "    NEWSPARC_TIMETYPE=__int64_t"
346     echo "    export NEWSPARC_TIMETYPE"
347     echo "    make -f ${TMPHOLD}/Makefile installworld"
348 fi