Print this page
XXX Remove nawk(1)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/scripts/Install.sh
+++ new/usr/src/tools/scripts/Install.sh
1 1 #!/bin/ksh
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22 #
23 23 # Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 #
25 25 # Author: Jeff Bonwick
26 26 #
27 27 # Please report any bugs to bonwick@eng.
28 28 #
29 29 # How Install works:
30 30 #
31 31 # Install performs the following steps:
32 32 #
33 33 # 1. Get the list of modules, configuration files, and links
34 34 # that are desired.
35 35 #
36 36 # 2. Create the requested subset of /kernel in Install's temp space
37 37 # (/tmp/Install.username by default.)
38 38 #
39 39 # 3. Create a tar file (/tmp/Install.username/Install.tar) based on (3).
40 40 #
41 41 # 4. If -n was specified, exit. If a target was specified using -T,
42 42 # rcp the tarfile to the target and exit. If a target was specified
43 43 # using -t, rsh to the target machine and untar the tarfile in the
44 44 # target directory.
45 45 #
46 46 # If any of these steps fail, Install will give you an error message and,
47 47 # in most cases, suggest corrective measures. Then, you can recover the
48 48 # install with "Install -R". (This is not required; it's just faster than
49 49 # starting from scratch.)
50 50 #
51 51 # One final comment: Unfortunately, tar and I disagree on what
52 52 # constitutes a fatal error. (tar -x will exit 0 even if it can't write
53 53 # anything in the current directory.) Thus, I am reduced to grepping stderr
54 54 # for (what I consider) fatal and nonfatal error messages. If you run into
55 55 # a situation where this doesn't behave the way you think it should (either
56 56 # an "Install failed" message after a successful install, or an "Install
57 57 # complete" message after it bombs), please let me know.
58 58
59 59 #
60 60 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
61 61 # under certain circumstances, which can really screw things up; unset it.
62 62 #
63 63 unset CDPATH
64 64
65 65 INSTALL=`basename $0`
66 66 DOT=`pwd`
67 67
68 68 TRAILER="Install.$LOGNAME"
69 69 INSTALL_STATE=${INSTALL_STATE-$HOME/.Install.state}
70 70 export INSTALL_STATE
71 71 INSTALL_DIR=${INSTALL_DIR-/tmp/$TRAILER}
72 72 if [ "`basename $INSTALL_DIR`" != "$TRAILER" ]; then
73 73 INSTALL_DIR="$INSTALL_DIR/$TRAILER"
74 74 fi
75 75 export INSTALL_DIR
76 76 INSTALL_LIB=${INSTALL_LIB-$HOME/LibInstall}
77 77 export INSTALL_LIB
78 78 INSTALL_RC=${INSTALL_RC-$HOME/.Installrc}
79 79 export INSTALL_RC
80 80 INSTALL_CP=${INSTALL_CP-"cp -p"}
81 81 export INSTALL_CP
82 82 INSTALL_RCP=${INSTALL_RCP-"rcp -p"}
83 83 export INSTALL_RCP
84 84
85 85 STATE=0
86 86
87 87 DEFAULT_OPTIONS="-naq"
88 88 GLOM=no
89 89 GLOMNAME=kernel
90 90 IMPL="default"
91 91 WANT32="yes"
92 92 WANT64="yes"
93 93
94 94 modlist=/tmp/modlist$$
95 95 # dummy directory for make state files.
96 96 modstatedir=/tmp/modstate$$
97 97
98 98 trap 'fail "User Interrupt" "You can resume by typing \"$INSTALL -R\""' 1 2 3 15
99 99
100 100 function usage {
101 101 echo ""
102 102 echo $1
103 103 echo '
104 104 Usage: Install [ -w workspace ]
105 105 [ -s srcdir (default: usr/src/uts) ]
106 106 [ -k karch (e.g. sun4u; required if not deducible from pwd) ]
107 107 [ -t target (extract tar file on target, e.g. user@machine:/) ]
108 108 [ -T target (copy tar file to target, e.g. user@machine:/tmp) ]
109 109 [ -n (no target, just create tar file in /tmp (default)) ]
110 110 [ -u (install unix only) ]
111 111 [ -m (install modules only) ]
112 112 [ -a (install everything, i.e. unix + modules (default)) ]
113 113 [ -v (verbose output) ]
114 114 [ -V (REALLY verbose output) ]
115 115 [ -q (quiet (default)) ]
116 116 [ -c (clean up (remove temp files) when done (default) ]
117 117 [ -p (preserve temp files -- useful for debugging) ]
118 118 [ -L (library create: put tarfile in $INSTALL_LIB/env.karch) ]
119 119 [ -l lib (library extract: use $INSTALL_LIB/lib as source) ]
120 120 [ -D libdir (default: $HOME/LibInstall) ]
121 121 [ -d tempdir (Install work area (default: /tmp)) ]
122 122 [ -G glomname (put all files under platform/karch/glomname) ]
123 123 [ -i impl (e.g. sunfire; recommended with -G) ]
124 124 [ -x (update /etc/name_to_major et al) ]
125 125 [ -X (do not update /etc/name_to_major et al (default)) ]
126 126 [ -P (update /etc/path_to_inst -- generally not advisable) ]
127 127 [ -h (help -- prints this message) ]
128 128 [ -R (recover a previous Install) ]
129 129 [ -o objdir (object directory - either obj or debug (the default)) ]
130 130 [ -K (do not copy kmdb) ]
131 131 [ -3 32-bit modules only ]
132 132 [ -6 64-bit modules only ]
133 133 [ list of modules to install ]
134 134
135 135 For full details:
136 136
137 137 man -M /ws/on297-gate/public/docs Install
138 138 '
139 139 exit 1
140 140 }
141 141
142 142 #
143 143 # Save the current state of Install
144 144 #
145 145
146 146 function save_state {
147 147 rm -f $INSTALL_STATE
148 148 (echo "# State of previous Install
149 149 TARGET=$TARGET
150 150 ENV_PATH=$ENV_PATH
151 151 ENV_NAME=$ENV_NAME
152 152 KARCH=$KARCH
153 153 UTS=$UTS
154 154 INSTALL_DIR=$INSTALL_DIR
155 155 INSTALL_LIB=$INSTALL_LIB
156 156 IMODE=$IMODE
157 157 LIBCREATE=$LIBCREATE
158 158 LIBSRC=$LIBSRC
159 159 VERBOSE=$VERBOSE
160 160 CLEANUP=$CLEANUP
161 161 GLOM=$GLOM
162 162 GLOMNAME=$GLOMNAME
163 163 KMDB=$KMDB
164 164 files='$files'
165 165 STATE=$STATE" >$INSTALL_STATE) || verbose "Warning: cannot save state"
166 166 }
167 167
168 168 #
169 169 # Restore the previous state of Install
170 170 #
171 171
172 172 function restore_state {
173 173 test -s $INSTALL_STATE || fail "Can't find $INSTALL_STATE"
174 174 eval "`cat $INSTALL_STATE`"
175 175 }
176 176
177 177 #
178 178 # Install failed -- print error messages and exit 2
179 179 #
180 180
181 181 function fail {
182 182 save_state
183 183 #
184 184 # We might have gotten here via a trap. So wait for any
185 185 # children (especially "make modlist") to exit before giving
186 186 # the error message or cleaning up.
187 187 #
188 188 wait
189 189 while [ $# -gt 0 ]
190 190 do
191 191 echo $1
192 192 shift
193 193 done
194 194 rm -rf $modstatedir
195 195 rm -f $modlist
196 196 echo "Install failed"
197 197 exit 2
198 198 }
199 199
200 200 #
201 201 # Echo a string in verbose mode only
202 202 #
203 203
204 204 function verbose {
205 205 test "$VERBOSE" != "q" && echo $1
206 206 }
207 207
208 208 #
209 209 # hack for tmpfs bug -- remove files gradually
210 210 #
211 211
212 212 function remove_dir {
213 213 test -d $1 || return
214 214 local_dot=`pwd`
215 215 cd $1
216 216 touch foo
217 217 rm -f `find . -type f -print`
218 218 cd $local_dot
219 219 rm -rf $1
220 220 }
221 221
222 222 #
223 223 # Create a directory if it doesn't already exist.
224 224 # mkdir will provide an error message, so don't provide an additional
225 225 # message.
226 226 #
227 227
↓ open down ↓ |
227 lines elided |
↑ open up ↑ |
228 228 function tstmkdir {
229 229 [ -d $1 ] || mkdir -p $1 || fail
230 230 }
231 231
232 232 #
233 233 # Patch up target directories for glommed kernel.
234 234 # usage: fixglom listfile glomname
235 235 #
236 236
237 237 function fixglom {
238 - nawk \
238 + /usr/xpg4/bin/awk \
239 239 -v glomname=$2 \
240 240 -v karch=$KARCH '
241 241 $1 == "MOD" || $1 == "SYMLINK" {
242 242 sub(/^platform.*kernel/, "platform/" karch "/" glomname, $4)
243 243 sub(/^kernel/, "platform/" karch "/" glomname, $4)
244 244 sub(/^usr.kernel/, "platform/" karch "/" glomname, $4)
245 245 print
246 246 }
247 247 $1 == "LINK" {
248 248 sub(/^platform.*kernel/, "platform/" karch "/" glomname, $3)
249 249 sub(/^kernel/, "platform/" karch "/" glomname, $3)
250 250 sub(/^usr.kernel/, "platform/" karch "/" glomname, $3)
251 251 sub(/^platform.*kernel/, "platform/" karch "/" glomname, $5)
252 252 sub(/^kernel/, "platform/" karch "/" glomname, $5)
253 253 sub(/^usr.kernel/, "platform/" karch "/" glomname, $5)
254 254 print
255 255 }
256 256 $1 == "CONF" {
257 257 sub(/^platform.*kernel/, "platform/" karch "/" glomname, $3)
258 258 sub(/^kernel/, "platform/" karch "/" glomname, $3)
259 259 sub(/^usr.kernel/, "platform/" karch "/" glomname, $3)
260 260 print
261 261 }
262 262 ' $1 > $1.new
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
263 263 mv $1.new $1
264 264 }
265 265
266 266 #
267 267 # Filter out implementation-specific modules, unless that
268 268 # implementation was requested by the user.
269 269 # usage: filtimpl listfile implname
270 270 #
271 271
272 272 function filtimpl {
273 - nawk \
273 + /usr/xpg4/bin/awk \
274 274 -v impl=$2 '
275 275 $1 == "MOD" || $1 == "SYMLINK" {
276 276 if ($6 == "all" || $6 == impl)
277 277 print
278 278 }
279 279 $1 == "CONF" {
280 280 if ($5 == "all" || $5 == impl)
281 281 print
282 282 }
283 283 $1 == "LINK" {
284 284 if ($7 == "all" || $7 == impl)
285 285 print
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
286 286 }
287 287 ' $1 > $1.new
288 288 mv $1.new $1
289 289 }
290 290
291 291 #
292 292 # Filter the module list to match the user's request.
293 293 # Usage: filtmod listfile modules
294 294 #
295 295 function filtmod {
296 - nawk -v reqstring="$2" '
296 + /usr/xpg4/bin/awk -v reqstring="$2" '
297 297 function modmatch(modname) {
298 298 if (reqstring == "All") {
299 299 return (1)
300 300 } else if (reqstring == "Modules") {
301 301 if (modname != "unix" && modname != "genunix")
302 302 return (1)
303 303 } else {
304 304 if (modname in reqmods)
305 305 return (1)
306 306 }
307 307 return (0)
308 308 }
309 309 BEGIN {
310 310 #
311 311 # The split call creates indexes 1, 2, 3, ... We want
312 312 # the module names as indexes.
313 313 #
314 314 split(reqstring, tmpmods)
315 315 for (i in tmpmods)
316 316 reqmods[tmpmods[i]] = 1
317 317 }
318 318 $1 == "MOD" {
319 319 if (modmatch($3))
320 320 print
321 321 }
322 322 $1 == "CONF" {
323 323 if (modmatch($6))
324 324 print
325 325 }
326 326 $1 == "SYMLINK" {
327 327 if (modmatch($7))
328 328 print
329 329 }
330 330 $1 == "LINK" {
331 331 if (modmatch($4))
332 332 print
333 333 }
334 334 ' $1 > $1.new
335 335 mv $1.new $1
336 336 }
337 337
338 338 #
339 339 # Unpack the crypto tarball into the given tree, then massage the
340 340 # tree so that the binaries are all in objNN or debugNN directories.
341 341 #
342 342 function unpack_crypto {
343 343 typeset tarfile=$1
344 344 typeset ctop=$2
345 345 [ -d "$ctop" ] || fail "Can't create tree for crypto modules."
346 346
347 347 [ "$VERBOSE" = "V" ] && echo "unpacking crypto tarball into $ctop..."
348 348 bzcat "$tarfile" | (cd "$ctop"; tar xf -)
349 349
350 350 typeset root="$ctop/proto/root_$MACH"
351 351 [ $OBJD = obj ] && root="$ctop/proto/root_$MACH-nd"
352 352 [ -d "$root" ] || fail "Can't unpack crypto tarball."
353 353
354 354 (cd "$root"; for d in platform kernel usr/kernel; do
355 355 [ ! -d $d ] && continue
356 356 find $d -type f -print
357 357 done) | while read file; do
358 358 typeset dir=$(dirname "$file")
359 359 typeset base=$(basename "$file")
360 360 typeset type=$(basename "$dir")
361 361 if [ "$type" = amd64 ]; then
362 362 newdir="$dir/${OBJD}64"
363 363 elif [ "$type" = sparcv9 ]; then
364 364 newdir="$dir/${OBJD}64"
365 365 else
366 366 newdir="$dir/${OBJD}32"
367 367 fi
368 368 mkdir -p "$root/$newdir"
369 369 [ "$VERBOSE" = "V" ] && echo "mv $file $newdir"
370 370 mv "$root/$file" "$root/$newdir"
371 371 done
372 372 }
373 373
374 374 #
375 375 # usage: fixcrypto listfile ctop
376 376 # Massage entries in listfile for crypto modules, so that they point
377 377 # into ctop.
378 378 #
379 379 function fixcrypto {
380 380 typeset listfile=$1
381 381 typeset ctop=$2
382 382
383 383 typeset ccontents=/tmp/crypto-toc$$
384 384 find "$ctop" -type f -print > $ccontents
385 385 typeset root=root_$MACH
386 386 [ "$OBJD" = obj ] && root=root_$MACH-nd
387 387
388 388 grep -v ^MOD $listfile > $listfile.no-mod
389 389 grep ^MOD $listfile | while read tag srcdir module targdir size impl; do
390 390 #
391 391 # We don't just grep for ${OBJD}$size/$module because
392 392 # there can be generic and platform-dependent versions
393 393 # of a module.
394 394 #
395 395 newsrcfile=$(grep -w $root/$targdir/${OBJD}$size/$module $ccontents)
396 396 if [ -n "$newsrcfile" ]; then
397 397 # srcdir doesn't include final objNN or debugNN
398 398 echo $tag $module $targdir $size $impl \
399 399 $(dirname $(dirname "$newsrcfile"))
400 400 else
401 401 echo $tag $module $targdir $size $impl $srcdir
402 402 fi
403 403 done > $listfile.mod
404 404 cat $listfile.mod $listfile.no-mod > $listfile
405 405
406 406 rm -f $listfile.mod
407 407 rm -f $listfile.no-mod
408 408 rm -f $ccontents
409 409 }
410 410
411 411 #
412 412 # Copy a module, or create a link, as needed.
413 413 #
414 414
415 415 function copymod {
416 416 case $1 in
417 417 MOD)
418 418 targdir=$INSTALL_FILES/$4
419 419 tstmkdir $targdir
420 420 target=$targdir/$3
421 421 verbose "$INSTALL_CP $2/${OBJD}$5/$3 $target"
422 422 $INSTALL_CP $2/${OBJD}$5/$3 $target || \
423 423 fail "can't create $target"
424 424 ;;
425 425 SYMLINK)
426 426 targdir=$INSTALL_FILES/$4
427 427 tstmkdir $targdir
428 428 target=$targdir/$5
429 429 rm -f $target
430 430 verbose "ln -s $3 $target"
431 431 ln -s $3 $target || fail "can't create $target"
432 432 ;;
433 433 LINK)
434 434 targdir=$INSTALL_FILES/$5
435 435 tstmkdir $targdir
436 436 target=$targdir/$6
437 437 rm -f $target
438 438 verbose "ln $INSTALL_FILES/$3/$4 $target"
439 439 ln $INSTALL_FILES/$3/$4 $target || fail "can't create $target"
440 440 ;;
441 441 CONF)
442 442 target=$INSTALL_FILES/$3
443 443 tstmkdir `dirname $target`
444 444 conffile=`basename $3`
445 445 verbose "$INSTALL_CP $4/$conffile $target"
↓ open down ↓ |
139 lines elided |
↑ open up ↑ |
446 446 $INSTALL_CP $4/$conffile $target
447 447 ;;
448 448 *)
449 449 fail "unrecognized modlist entry: $*"
450 450 ;;
451 451 esac
452 452 }
453 453
454 454 # Sanity-check the given module list.
455 455 function check_modlist {
456 - nawk '
456 + /usr/xpg4/bin/awk '
457 457 BEGIN {
458 458 nfields["MOD"] = 6
459 459 nfields["CONF"] = 6
460 460 nfields["LINK"] = 7
461 461 nfields["SYMLINK"] = 7
462 462 }
463 463 {
464 464 # This also catches unknown tags.
465 465 if (nfields[$1] != NF) {
466 466 print "error: invalid modlist record:"
467 467 print $0
468 468 print "expected", nfields[$1], "fields, found", NF
469 469 status=1
470 470 }
471 471 }
472 472 END {
473 473 exit status
474 474 }
475 475 ' $1 || fail "Errors in kernel module list"
476 476 }
477 477
478 478 #
479 479 # Copy kernel modules to $INSTALL_DIR
480 480 #
481 481
482 482 function copy_kernel {
483 483
484 484 case $KARCH in
485 485 sun4*) ISA=sparc; MACH=sparc ;;
486 486 i86*) ISA=intel; MACH=i386 ;;
487 487 *) fail "${KARCH}: invalid kernel architecture";;
488 488 esac
489 489 export MACH
490 490
491 491 if [ "$GLOM" = "no" ]; then
492 492 verbose "Source = $UTS, ISA = $ISA, kernel = $KARCH"
493 493 else
494 494 verbose "Source = $UTS, ISA = $ISA, kernel = $KARCH, impl = $IMPL"
495 495 fi
496 496
497 497 test -d $KARCH || fail "${KARCH}: invalid kernel architecture"
498 498 test -d $ISA || fail "${ISA}: invalid instruction set architecture"
499 499
500 500 tstmkdir $INSTALL_FILES
501 501 rm -rf $modstatedir
502 502 tstmkdir $modstatedir
503 503 export MODSTATE=$modstatedir/state
504 504
505 505 #
506 506 # Figure out which "make" to use. dmake is faster than serial
507 507 # make, but dmake 7.3 has a bug that causes it to lose log
508 508 # output, which means the modlist might be incomplete.
509 509 #
510 510 make=dmake
511 511 dmvers=`$make -version`
512 512 if [ $? -ne 0 ]; then
513 513 make=/usr/ccs/bin/make
514 514 elif [[ $dmvers = *Distributed?Make?7.3* ]]; then
515 515 unset make
516 516 searchpath="/ws/onnv-tools/SUNWspro/SOS10/bin
517 517 /opt/SUNWspro/SOS10/bin
518 518 /opt/SUNWspro/bin"
519 519 for dmpath in $searchpath; do
520 520 verbose "Trying $dmpath/dmake"
521 521 if [ -x $dmpath/dmake ]; then
522 522 dmvers=`$dmpath/dmake -version`
523 523 if [[ $dmvers != *Distributed?Make?7.3* ]]; then
524 524 make="$dmpath/dmake"
525 525 break;
526 526 fi
527 527 fi
528 528 done
529 529 if [ -z $make ]; then
530 530 make=/usr/ccs/bin/make
531 531 echo "Warning: dmake 7.3 doesn't work with Install;" \
532 532 "using $make"
533 533 fi
534 534 fi
535 535
536 536 #
537 537 # Get a list of all modules, configuration files, and links
538 538 # that we might want to install.
539 539 #
540 540 verbose "Building module list..."
541 541 (cd $KARCH; MAKEFLAGS=e $make -K $MODSTATE modlist.karch) | \
542 542 egrep "^MOD|^CONF|^LINK|^SYMLINK" > $modlist
543 543 [ "$VERBOSE" = "V" ] && cat $modlist
544 544 check_modlist $modlist
545 545 if [ -n "$ON_CRYPTO_BINS" ]; then
546 546 cryptotar="$ON_CRYPTO_BINS"
547 547 if [ "$OBJD" = obj ]; then
548 548 isa=$(uname -p)
549 549 cryptotar=$(echo "$ON_CRYPTO_BINS" |
550 550 sed -e s/.$isa.tar.bz2/-nd.$isa.tar.bz2/)
551 551 fi
552 552 [ -f "$cryptotar" ] || fail "crypto ($cryptotar) doesn't exist"
553 553 cryptotree=$(mktemp -d /tmp/crypto.XXXXXX)
554 554 [ -n "$cryptotree" ] || fail "can't create tree for crypto"
555 555 unpack_crypto "$cryptotar" "$cryptotree"
556 556 #
557 557 # fixcrypto must come before fixglom, because
558 558 # fixcrypto uses the unglommed path to find things in
559 559 # the unpacked crypto.
560 560 #
561 561 fixcrypto $modlist "$cryptotree"
562 562 fi
563 563 if [ "$GLOM" = "yes" ]; then
564 564 fixglom $modlist $GLOMNAME
565 565 filtimpl $modlist $IMPL
566 566 fi
567 567 if [[ -n "$files" && "$files" != All ]]; then
568 568 filtmod $modlist "$files"
569 569 fi
570 570
571 571 #
572 572 # Copy modules and create links. For architectures with both
573 573 # 32- and 64-bit modules, we'll likely have duplicate
574 574 # configuration files, so do those after filtering out the
575 575 # duplicates.
576 576 #
577 577 verbose "Copying files to ${INSTALL_FILES}..."
578 578
579 579 #
580 580 # The IFS is reset to the newline character so we can buffer the
581 581 # output of grep without piping it directly to copymod, otherwise
582 582 # if fail() is called, then it will deadlock in fail()'s wait call
583 583 #
584 584 OIFS="$IFS"
585 585 IFS="
586 586 "
587 587 set -- `grep -v "^CONF" $modlist`;
588 588 IFS="$OIFS"
589 589 for onemod in "$@"; do
590 590 copymod $onemod
591 591 done
592 592
593 593 OIFS="$IFS"
594 594 IFS="
595 595 "
596 596 set -- `grep "^CONF" $modlist | sort | uniq`;
597 597 IFS="$OIFS"
598 598 for onemod in "$@"; do
599 599 copymod $onemod
600 600 done
601 601
602 602 #
603 603 # Add the glommed kernel name to the root archive
604 604 #
605 605 if [[ $GLOM == "yes" ]];
606 606 then
607 607 filelist="$INSTALL_FILES/etc/boot/solaris/filelist.ramdisk"
608 608 mkdir -p `dirname $filelist`
609 609 echo "platform/$KARCH/$GLOMNAME" >$filelist
610 610 fi
611 611
612 612 STATE=1 # all kernel modules copied correctly
613 613 save_state
614 614 }
615 615
616 616 function kmdb_copy {
617 617 typeset src="$1"
618 618 typeset destdir="$2"
619 619
620 620 if [[ ! -d $dest ]] ; then
621 621 [[ "$VERBOSE" != "q" ]] && echo "mkdir -p $destdir"
622 622
623 623 mkdir -p $destdir || fail "failed to create $destdir"
624 624 fi
625 625
626 626 [[ "$VERBOSE" != "q" ]] && echo "cp $src $destdir"
627 627
628 628 cp $src $destdir || fail "failed to copy $src to $destdir"
629 629 }
630 630
631 631 function kmdb_copy_machkmods {
632 632 typeset modbase="$1"
633 633 typeset destdir="$2"
634 634 typeset dir=
635 635 typeset kmod=
636 636
637 637 [[ ! -d $modbase ]] && return
638 638
639 639 for dir in $(find $modbase -name kmod) ; do
640 640 set -- $(echo $dir |tr '/' ' ')
641 641
642 642 [[ $# -lt 2 ]] && fail "invalid mach kmod dir $dir"
643 643
644 644 shift $(($# - 2))
645 645 kmod=$1
646 646
647 647 [[ ! -f $dir/$kmod ]] && continue
648 648
649 649 kmdb_copy $dir/$kmod $destdir
650 650 done
651 651 }
652 652
653 653 function kmdb_copy_karchkmods {
654 654 typeset modbase="$1"
655 655 typeset destdir="$2"
656 656 typeset bitdir="$3"
657 657 typeset dir=
658 658 typeset kmod=
659 659 typeset karch=
660 660
661 661 [[ ! -d $modbase ]] && return
662 662
663 663 for dir in $(find $modbase -name kmod) ; do
664 664 set -- $(echo $dir | tr '/' ' ')
665 665
666 666 [[ $# -lt 3 ]] && fail "invalid karch kmod dir $dir"
667 667
668 668 shift $(($# - 3))
669 669 kmod=$1
670 670 bdir=$2
671 671
672 672 [[ $bdir != $bitdir ]] && continue
673 673 [[ ! -f $dir/$1 ]] && continue
674 674
675 675 kmdb_copy $dir/$kmod $destdir
676 676 done
677 677 }
678 678
679 679 function kmdb_copy_kmdbmod {
680 680 typeset kmdbpath="$1"
681 681 typeset destdir="$2"
682 682
683 683 [[ ! -f $kmdbpath ]] && return 1
684 684
685 685 kmdb_copy $kmdbpath $destdir
686 686
687 687 return 0
688 688 }
689 689
690 690 function copy_kmdb {
691 691 typeset kmdbtgtdir=$INSTALL_FILES/platform/$KARCH/$GLOMNAME/misc
692 692 typeset bitdirs=
693 693 typeset isadir=
694 694 typeset b64srcdir=
695 695 typeset b64tgtdir=
696 696 typeset b32srcdir=
697 697 typeset b32tgtdir=
698 698 typeset machdir=
699 699 typeset platdir=
700 700
701 701 if [[ $KMDB = "no" || ! -d $SRC/cmd/mdb ]] ; then
702 702 # The kmdb copy was suppressed or the workspace doesn't contain
703 703 # the mdb subtree. Either way, there's nothing to do.
704 704 STATE=2
705 705 save_state
706 706 return
707 707 fi
708 708
709 709 if [[ $(mach) = "i386" ]] ; then
710 710 isadir="intel"
711 711 b64srcdir="amd64"
712 712 b64tgtdir="amd64"
713 713 b32srcdir="ia32"
714 714 b32tgtdir="."
715 715 else
716 716 isadir="sparc"
717 717 b64srcdir="v9"
718 718 b64tgtdir="sparcv9"
719 719 b32srcdir="v7"
720 720 b32tgtdir="."
721 721 fi
722 722
723 723 typeset foundkmdb=no
724 724 typeset kmdbpath=
725 725 typeset destdir=
726 726
727 727 platdir=$INSTALL_FILES/platform/$KARCH/$GLOMNAME
728 728 if [[ $GLOM = "yes" ]] ; then
729 729 machdir=$platdir
730 730 else
731 731 machdir=$INSTALL_FILES/kernel
732 732 fi
733 733
734 734 srctrees=$SRC
735 735 if [[ -d $SRC/../closed && "$CLOSED_IS_PRESENT" != no ]]; then
736 736 srctrees="$srctrees $SRC/../closed"
737 737 else
738 738 if [ -z "$ON_CRYPTO_BINS" ]; then
739 739 echo "Warning: ON_CRYPTO_BINS not set; pre-signed" \
740 740 "crypto not provided."
741 741 fi
742 742 fi
743 743 if [[ $WANT64 = "yes" ]] ; then
744 744 # kmdbmod for sparc and x86 are built and installed
745 745 # in different places
746 746 if [[ $(mach) = "i386" ]] ; then
747 747 kmdbpath=$SRC/cmd/mdb/$isadir/$b64srcdir/kmdb/kmdbmod
748 748 destdir=$machdir/misc/$b64tgtdir
749 749 else
750 750 kmdbpath=$SRC/cmd/mdb/$KARCH/$b64srcdir/kmdb/kmdbmod
751 751 destdir=$platdir/misc/$b64tgtdir
752 752 fi
753 753
754 754 if kmdb_copy_kmdbmod $kmdbpath $destdir ; then
755 755 foundkmdb="yes"
756 756
757 757 for tree in $srctrees; do
758 758 kmdb_copy_machkmods \
759 759 $tree/cmd/mdb/$isadir/$b64srcdir \
760 760 $machdir/kmdb/$b64tgtdir
761 761 kmdb_copy_karchkmods $tree/cmd/mdb/$KARCH \
762 762 $platdir/kmdb/$b64tgtdir $b64srcdir
763 763 done
764 764 fi
765 765 fi
766 766
767 767 if [[ $WANT32 = "yes" ]] ; then
768 768 kmdbpath=$SRC/cmd/mdb/$isadir/$b32srcdir/kmdb/kmdbmod
769 769 destdir=$machdir/misc/$b32tgtdir
770 770
771 771 if kmdb_copy_kmdbmod $kmdbpath $destdir ; then
772 772 foundkmdb="yes"
773 773
774 774 for tree in $srctrees; do
775 775 kmdb_copy_machkmods \
776 776 $tree/cmd/mdb/$isadir/$b32srcdir \
777 777 $machdir/kmdb/$b32tgtdir
778 778 kmdb_copy_karchkmods $tree/cmd/mdb/$KARCH \
779 779 $platdir/kmdb/$b32tgtdir $b32srcdir
780 780 done
781 781 fi
782 782 fi
783 783
784 784 # A kmdb-less workspace isn't fatal, but it is potentially problematic,
785 785 # as the changes made to uts may have altered something upon which kmdb
786 786 # depends. We will therefore remind the user that they haven't built it
787 787 # yet.
788 788 if [[ $foundkmdb != "yes" ]] ; then
789 789 echo "WARNING: kmdb isn't built, and won't be included"
790 790 fi
791 791
792 792 STATE=2
793 793 save_state
794 794 return
795 795 }
796 796
797 797 #
798 798 # Make tarfile
799 799 #
800 800
801 801 function make_tarfile {
802 802 echo "Creating tarfile $TARFILE"
803 803 test -d $INSTALL_FILES || fail "Can't find $INSTALL_FILES"
804 804 cd $INSTALL_FILES
805 805 rm -f $TARFILE files
806 806
807 807 # We don't want to change the permissions or ownership of pre-existing
808 808 # directories on the target machine, so we're going to take care to
809 809 # avoid including directories in the tarfile. On extraction, tar won't
810 810 # modify pre-existing directories, and will create non-existent ones as
811 811 # the user doing the extraction.
812 812 find . ! -type d -print |fgrep -vx './files' >files
813 813 tar cf $TARFILE -I files || fail "Couldn't create tarfile $TARFILE"
814 814 STATE=3
815 815 }
816 816
817 817 #
818 818 # Routines to copy files to the target machine
819 819 #
820 820
821 821 function remote_fail {
822 822 fail "" "$1" "" \
823 823 "Make sure that $TARGET_MACHINE is up." \
824 824 "Check .rhosts in the home directory of user $TARGET_USER on $TARGET_MACHINE." \
825 825 "Check /etc/hosts.equiv, /etc/passwd, and /etc/shadow." \
826 826 "Change permissions on $TARGET_MACHINE as necessary." \
827 827 "Then, use \"$INSTALL -R\" to resume the install." ""
828 828 }
829 829
830 830 function remote_install {
831 831 if [ "$IMODE" = "n" ]; then
832 832 STATE=4
833 833 return 0
834 834 fi
835 835 test -s $TARFILE || fail "$TARFILE missing or empty"
836 836 verbose "Installing system on $TARGET"
837 837 test -d $INSTALL_DIR || fail "Can't find $INSTALL_DIR"
838 838 cd $INSTALL_DIR
839 839 rm -f errors fatal nonfatal
840 840 if [ "$IMODE" = "T" ]; then
841 841 EMESG="Can't rcp to $TARGET"
842 842 touch errors
843 843 sh -e${SHV}c "$INSTALL_RCP $TARFILE $TARGET/Install.tar"
844 844 else
845 845 EMESG="Can't rsh to $TARGET_MACHINE"
846 846 rsh -l $TARGET_USER $TARGET_MACHINE \
847 847 "(cd $TARGET_DIR; /usr/bin/tar x${V}f -)" \
848 848 <$TARFILE 2>errors
849 849 fi
850 850 test $? -ne 0 && remote_fail "$EMESG"
851 851 cd $INSTALL_DIR
852 852 egrep "set time|warning|blocksize" errors >nonfatal
853 853 egrep -v "set time|warning|blocksize" errors >fatal
854 854 if [ -s fatal ]; then
855 855 echo "Fatal errors from rsh:"
856 856 cat fatal
857 857 remote_fail "Can't install on $TARGET_MACHINE"
858 858 fi
859 859 if [ -s nonfatal -a "$VERBOSE" != "q" ]; then
860 860 echo "Non-fatal errors from rsh:"
861 861 cat nonfatal
862 862 fi
863 863 rm -f fatal nonfatal errors
864 864 test "$IMODE" = "T" && echo "Files can be extracted on \
865 865 $TARGET_MACHINE using 'tar xvf $TARGET_DIR/Install.tar'"
866 866 STATE=4
867 867 }
868 868
869 869 function okexit {
870 870 cd /tmp
871 871 test "$CLEANUP" = c && remove_dir $INSTALL_DIR
872 872 save_state
873 873 rm -rf $modstatedir
874 874 rm -f $modlist
875 875 [ -n "$cryptotree" ] && rm -rf "$cryptotree"
876 876 verbose "Install complete"
877 877 exit 0
878 878 }
879 879
880 880 #
881 881 # Process options
882 882 #
883 883
884 884 RCOPTS=""
885 885 LIBCREATE="no"
886 886 LIBSRC=""
887 887 ENV_PATH=$CODEMGR_WS
888 888 OBJD="debug"
889 889 KMDB="yes"
890 890
891 891 test -s $INSTALL_RC && RCOPTS=`cat $INSTALL_RC`
892 892 set $INSTALL $DEFAULT_OPTIONS $RCOPTS $*
893 893 shift
894 894
895 895 while getopts acd:D:G:hi:k:Kl:Lmno:pPqRs:t:T:uvVw:xX36 opt
896 896 do
897 897 case $opt in
898 898 w) ENV_PATH="$OPTARG"; SRC="$ENV_PATH/usr/src";;
899 899 s) UTS="$OPTARG";;
900 900 k) KARCH="$OPTARG";;
901 901 t|T) TARGET="$OPTARG"; IMODE=$opt; CLEANUP="c";;
902 902 n) TARGET=""; IMODE="n"; CLEANUP="p";;
903 903 u) files="unix genunix";;
904 904 m) files="Modules";;
905 905 a) files="All";;
906 906 v|V|q) VERBOSE=$opt;;
907 907 c|p) CLEANUP=$opt;;
908 908 L) LIBCREATE="yes"; CLEANUP="c";;
909 909 l) LIBSRC="$OPTARG";;
910 910 D) INSTALL_LIB="$OPTARG";;
911 911 d) INSTALL_DIR="$OPTARG/$TRAILER";;
912 912 G) GLOM=yes; GLOMNAME="$OPTARG";;
913 913 P|X|x) echo "-$opt is obsolete; ignored";;
914 914 h) usage "${INSTALL}: installs unix and modules";;
915 915 R) x=$OPTIND; restore_state; OPTIND=$x;;
916 916 i) IMPL="$OPTARG";;
917 917 o) OBJD="$OPTARG";;
918 918 K) KMDB="no";;
919 919 3) WANT64="no";;
920 920 6) WANT32="no";;
921 921 \?) usage "Illegal option";;
922 922 esac
923 923 done
924 924 shift `expr $OPTIND - 1`
925 925
926 926 ENV_NAME=`basename $ENV_PATH`
927 927
928 928 #
929 929 # The rest of the command line is a list of individual files to copy.
930 930 # If non-null, this list overrides the -uma options.
931 931 #
932 932
933 933 if [[ $# -gt 0 ]] ; then
934 934 files="$*"
935 935 KMDB="no"
936 936 fi
937 937
938 938 case "$VERBOSE" in
939 939 v) V="v"; SHV="x";;
940 940 V) V="v"; SHV="x"; set -x;;
941 941 q) V=""; SHV="";;
942 942 esac
943 943
944 944 #
945 945 # Create temp directory for Install's files
946 946 #
947 947
948 948 tstmkdir $INSTALL_DIR
↓ open down ↓ |
482 lines elided |
↑ open up ↑ |
949 949
950 950 TARFILE=$INSTALL_DIR/Install.${KARCH}.tar
951 951 INSTALL_FILES=$INSTALL_DIR/$KARCH
952 952
953 953 #
954 954 # Extract the target machine and target directory from a target of the
955 955 # form [user@]machine:/dir .
956 956 #
957 957
958 958 if [ "$IMODE" != "n" ]; then
959 - eval `echo $TARGET | nawk -F':' '{
959 + eval `echo $TARGET | /usr/xpg4/bin/awk -F':' '{
960 960 if (NF != 2 || !length($1) || !length($2))
961 961 print "usage \"Invalid target\""
962 962 m = $1; d = $2
963 963 if ($1 ~ /@/) {
964 964 k = split($1, f, "@");
965 965 if (k != 2 || !length(f[1]) || !length (f[2]))
966 966 print "usage \"Invalid target\""
967 967 u = f[1]; m = f[2]
968 968 }
969 969 print "TARGET_USER=" u ";"
970 970 print "TARGET_MACHINE=" m ";"
971 971 print "TARGET_DIR=" d ";"
972 972 }'`
973 973 if [ -z "$TARGET_USER" ]; then
974 974 TARGET_USER=$LOGNAME
975 975 fi
976 976 fi
977 977
978 978 #
979 979 # Allow the use of library source or target for the install
980 980 #
981 981
982 982 if [ -n "$LIBSRC" ]; then
983 983 LIBSRC="`basename $LIBSRC .tar`.tar"
984 984 TARFILE=$INSTALL_LIB/$LIBSRC
985 985 test -s $TARFILE || fail "Can't find tarfile $TARFILE"
986 986 verbose "Installing from library tarfile $TARFILE"
987 987 STATE=3
988 988 elif [ "$LIBCREATE" = "yes" ]; then
989 989 tstmkdir $INSTALL_LIB
990 990 TARFILE="$INSTALL_LIB/${ENV_NAME}.${KARCH}.tar"
991 991 fi
992 992
993 993 #
994 994 # The next few lines allow recovery and activation with -R,
995 995 # and library installs with -l.
996 996 #
997 997
998 998 [[ $STATE -eq 1 ]] && copy_kmdb
999 999 [[ $STATE -eq 2 ]] && make_tarfile
1000 1000 [[ $STATE -eq 3 ]] && remote_install
1001 1001 [[ $STATE -eq 4 ]] && okexit
1002 1002
1003 1003 save_state
1004 1004
1005 1005 cd $DOT
1006 1006 DOTDOT=`cd ..; pwd`
1007 1007
1008 1008 #
1009 1009 # Try to be smart: if DOTDOT ends in uts, then infer UTS and KARCH from DOT
1010 1010 # Otherwise, if SRC is set, infer UTS = $SRC/uts.
1011 1011 #
1012 1012
1013 1013 if [ "`basename $DOTDOT`" = "uts" ]; then
1014 1014 UTS=$DOTDOT
1015 1015 KARCH=`basename $DOT`
1016 1016 if [ ! -n "$SRC" ]; then
1017 1017 SRC=`dirname $DOTDOT`
1018 1018 verbose "Setting SRC to $SRC"
1019 1019 fi
1020 1020 export SRC
1021 1021 fi
1022 1022
1023 1023 if [ -z "$UTS" -a -n "$SRC" ]; then
1024 1024 UTS="${SRC}/uts"
1025 1025 test -n "$KARCH" || fail "no karch specified (e.g. -k sun4u)"
1026 1026 fi
1027 1027
1028 1028 if [ "$LIBCREATE" = "yes" ]; then
1029 1029 TARFILE=$INSTALL_LIB/${ENV_NAME}.${KARCH}.tar
1030 1030 else
1031 1031 TARFILE=$INSTALL_DIR/Install.${KARCH}.tar
1032 1032 fi
1033 1033 INSTALL_FILES=$INSTALL_DIR/$KARCH
1034 1034 save_state
1035 1035
1036 1036 cd $DOT
1037 1037 test -z "$UTS" && fail 'Cannot find kernel sources -- $SRC not set'
1038 1038 test -d "$UTS" || fail "${UTS}: no such directory"
1039 1039
1040 1040 #
1041 1041 # Convert UTS into an absolute path.
1042 1042 #
1043 1043
1044 1044 cd $UTS
1045 1045 UTS=`pwd`
1046 1046
1047 1047 test "`basename $UTS`" = "uts" || \
1048 1048 verbose "Warning: source path $UTS doesn't end in 'uts'"
1049 1049
1050 1050 remove_dir $INSTALL_DIR/$KARCH
1051 1051 rm -f $TARFILE
1052 1052
1053 1053 copy_kernel # sets STATE=1 if successful
1054 1054 copy_kmdb # sets STATE=2 if successful
1055 1055 make_tarfile # sets STATE=3 if successful
1056 1056 remote_install # sets STATE=4 if successful
1057 1057
1058 1058 okexit
↓ open down ↓ |
89 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX