6785229 Install -P is dead code
[illumos-gate.git] / usr / src / tools / scripts / Install.sh
blobc491f0ccf54cc7346b6d4683098fa2e90622a6d5
1 #!/bin/ksh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 # Author: Jeff Bonwick
28 # Please report any bugs to bonwick@eng.
30 # How Install works:
32 # Install performs the following steps:
34 # 1. Get the list of modules, configuration files, and links
35 # that are desired.
37 # 2. Create the requested subset of /kernel in Install's temp space
38 # (/tmp/Install.username by default.)
40 # 3. Create a tar file (/tmp/Install.username/Install.tar) based on (3).
42 # 4. If -n was specified, exit. If a target was specified using -T,
43 # rcp the tarfile to the target and exit. If a target was specified
44 # using -t, rsh to the target machine and untar the tarfile in the
45 # target directory.
47 # If any of these steps fail, Install will give you an error message and,
48 # in most cases, suggest corrective measures. Then, you can recover the
49 # install with "Install -R". (This is not required; it's just faster than
50 # starting from scratch.)
52 # One final comment: Unfortunately, tar and I disagree on what
53 # constitutes a fatal error. (tar -x will exit 0 even if it can't write
54 # anything in the current directory.) Thus, I am reduced to grepping stderr
55 # for (what I consider) fatal and nonfatal error messages. If you run into
56 # a situation where this doesn't behave the way you think it should (either
57 # an "Install failed" message after a successful install, or an "Install
58 # complete" message after it bombs), please let me know.
61 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
62 # under certain circumstances, which can really screw things up; unset it.
64 unset CDPATH
66 INSTALL=`basename $0`
67 DOT=`pwd`
69 TRAILER="Install.$LOGNAME"
70 INSTALL_STATE=${INSTALL_STATE-$HOME/.Install.state}
71 export INSTALL_STATE
72 INSTALL_DIR=${INSTALL_DIR-/tmp/$TRAILER}
73 if [ "`basename $INSTALL_DIR`" != "$TRAILER" ]; then
74 INSTALL_DIR="$INSTALL_DIR/$TRAILER"
76 export INSTALL_DIR
77 INSTALL_LIB=${INSTALL_LIB-$HOME/LibInstall}
78 export INSTALL_LIB
79 INSTALL_RC=${INSTALL_RC-$HOME/.Installrc}
80 export INSTALL_RC
81 INSTALL_CP=${INSTALL_CP-"cp -p"}
82 export INSTALL_CP
83 INSTALL_RCP=${INSTALL_RCP-"rcp -p"}
84 export INSTALL_RCP
86 STATE=0
88 DEFAULT_OPTIONS="-naq"
89 GLOM=no
90 GLOMNAME=kernel
91 IMPL="default"
92 WANT32="yes"
93 WANT64="yes"
95 modlist=/tmp/modlist$$
96 # dummy directory for make state files.
97 modstatedir=/tmp/modstate$$
99 trap 'fail "User Interrupt" "You can resume by typing \"$INSTALL -R\""' 1 2 3 15
101 usage() {
102 echo ""
103 echo $1
104 echo '
105 Usage: Install [ -w workspace ]
106 [ -s srcdir (default: usr/src/uts) ]
107 [ -k karch (e.g. sun4u; required if not deducible from pwd) ]
108 [ -t target (extract tar file on target, e.g. user@machine:/) ]
109 [ -T target (copy tar file to target, e.g. user@machine:/tmp) ]
110 [ -n (no target, just create tar file in /tmp (default)) ]
111 [ -u (install unix only) ]
112 [ -m (install modules only) ]
113 [ -a (install everything, i.e. unix + modules (default)) ]
114 [ -v (verbose output) ]
115 [ -V (REALLY verbose output) ]
116 [ -q (quiet (default)) ]
117 [ -c (clean up (remove temp files) when done (default) ]
118 [ -p (preserve temp files -- useful for debugging) ]
119 [ -L (library create: put tarfile in $INSTALL_LIB/env.karch) ]
120 [ -l lib (library extract: use $INSTALL_LIB/lib as source) ]
121 [ -D libdir (default: $HOME/LibInstall) ]
122 [ -d tempdir (Install work area (default: /tmp)) ]
123 [ -G glomname (put all files under platform/karch/glomname) ]
124 [ -i impl (e.g. sunfire; recommended with -G) ]
125 [ -x (update /etc/name_to_major et al) ]
126 [ -X (do not update /etc/name_to_major et al (default)) ]
127 [ -P (update /etc/path_to_inst -- generally not advisable) ]
128 [ -h (help -- prints this message) ]
129 [ -R (recover a previous Install) ]
130 [ -o objdir (object directory - either obj or debug (the default)) ]
131 [ -K (do not copy kmdb) ]
132 [ -3 32-bit modules only ]
133 [ -6 64-bit modules only ]
134 [ list of modules to install ]
136 For full details:
138 man -M /ws/on297-gate/public/docs Install
140 exit 1
144 # Save the current state of Install
147 save_state() {
148 rm -f $INSTALL_STATE
149 (echo "# State of previous Install
150 TARGET=$TARGET
151 ENV_PATH=$ENV_PATH
152 ENV_NAME=$ENV_NAME
153 KARCH=$KARCH
154 UTS=$UTS
155 INSTALL_DIR=$INSTALL_DIR
156 INSTALL_LIB=$INSTALL_LIB
157 IMODE=$IMODE
158 LIBCREATE=$LIBCREATE
159 LIBSRC=$LIBSRC
160 VERBOSE=$VERBOSE
161 CLEANUP=$CLEANUP
162 GLOM=$GLOM
163 GLOMNAME=$GLOMNAME
164 KMDB=$KMDB
165 files='$files'
166 STATE=$STATE" >$INSTALL_STATE) || verbose "Warning: cannot save state"
170 # Restore the previous state of Install
173 restore_state() {
174 test -s $INSTALL_STATE || fail "Can't find $INSTALL_STATE"
175 eval "`cat $INSTALL_STATE`"
179 # Install failed -- print error messages and exit 2
182 fail() {
183 save_state
185 # We might have gotten here via a trap. So wait for any
186 # children (especially "make modlist") to exit before giving
187 # the error message or cleaning up.
189 wait
190 while [ $# -gt 0 ]
192 echo $1
193 shift
194 done
195 rm -rf $modstatedir
196 rm -f $modlist
197 echo "Install failed"
198 exit 2
202 # Echo a string in verbose mode only
205 verbose() {
206 test "$VERBOSE" != "q" && echo $1
210 # hack for tmpfs bug -- remove files gradually
213 remove_dir() {
214 test -d $1 || return
215 local_dot=`pwd`
216 cd $1
217 touch foo
218 rm -f `find . -type f -print`
219 cd $local_dot
220 rm -rf $1
224 # Create a directory if it doesn't already exist.
225 # mkdir will provide an error message, so don't provide an additional
226 # message.
229 tstmkdir() {
230 [ -d $1 ] || mkdir -p $1 || fail
234 # Patch up target directories for glommed kernel.
235 # usage: fixglom listfile glomname
238 fixglom() {
239 nawk \
240 -v glomname=$2 \
241 -v karch=$KARCH '
242 $1 == "MOD" || $1 == "SYMLINK" {
243 sub(/^platform.*kernel/, "platform/" karch "/" glomname, $3)
244 sub(/^kernel/, "platform/" karch "/" glomname, $3)
245 sub(/^usr.kernel/, "platform/" karch "/" glomname, $3)
246 print
248 $1 == "LINK" {
249 sub(/^platform.*kernel/, "platform/" karch "/" glomname, $2)
250 sub(/^kernel/, "platform/" karch "/" glomname, $2)
251 sub(/^usr.kernel/, "platform/" karch "/" glomname, $2)
252 sub(/^platform.*kernel/, "platform/" karch "/" glomname, $4)
253 sub(/^kernel/, "platform/" karch "/" glomname, $4)
254 sub(/^usr.kernel/, "platform/" karch "/" glomname, $4)
255 print
257 $1 == "CONF" {
258 sub(/^platform.*kernel/, "platform/" karch "/" glomname, $2)
259 sub(/^kernel/, "platform/" karch "/" glomname, $2)
260 sub(/^usr.kernel/, "platform/" karch "/" glomname, $2)
261 print
263 ' $1 > $1.new
264 mv $1.new $1
268 # Remove entries from
269 # usage: filtimpl listfile implname
272 filtimpl() {
273 nawk \
274 -v impl=$2 '
275 $1 == "MOD" || $1 == "SYMLINK" {
276 if ($5 == "all" || $5 == impl)
277 print
279 $1 == "CONF" {
280 if ($4 == "all" || $4 == impl)
281 print
283 $1 == "LINK" {
284 if ($6 == "all" || $6 == impl)
285 print
287 ' $1 > $1.new
288 mv $1.new $1
292 # Filter the module list to match the user's request.
293 # Usage: filtmod listfile modules
295 filtmod() {
296 nawk -v reqstring="$2" '
297 function modmatch(modname) {
298 if (reqstring == "All") {
299 return (1)
300 } else if (reqstring == "Modules") {
301 if (modname != "unix" && modname != "genunix")
302 return (1)
303 } else {
304 if (modname in reqmods)
305 return (1)
307 return (0)
309 BEGIN {
311 # The split call creates indexes 1, 2, 3, ... We want
312 # the module names as indexes.
314 split(reqstring, tmpmods)
315 for (i in tmpmods)
316 reqmods[tmpmods[i]] = 1
318 $1 == "MOD" {
319 if (modmatch($2))
320 print
322 $1 == "CONF" {
323 if (modmatch($5))
324 print
326 $1 == "SYMLINK" {
327 if (modmatch($6))
328 print
330 $1 == "LINK" {
331 if (modmatch($3))
332 print
334 ' $1 > $1.new
335 mv $1.new $1
339 # Copy a module, or create a link, as needed.
340 # See $SRC/uts/Makefile.targ ($(MODLIST_DEPS) target) for the format
341 # of the different input lines.
344 copymod() {
345 case $1 in
346 MOD)
347 targdir=$INSTALL_FILES/$3
348 tstmkdir $targdir
349 target=$targdir/$2
350 verbose "$INSTALL_CP $6/${OBJD}$4/$2 $target"
351 $INSTALL_CP $6/${OBJD}$4/$2 $target || \
352 fail "can't create $target"
354 SYMLINK)
355 targdir=$INSTALL_FILES/$3
356 tstmkdir $targdir
357 target=$targdir/$4
358 rm -f $target
359 verbose "ln -s $2 $target"
360 ln -s $2 $target || fail "can't create $target"
362 LINK)
363 targdir=$INSTALL_FILES/$4
364 tstmkdir $targdir
365 target=$targdir/$5
366 rm -f $target
367 verbose "ln $INSTALL_FILES/$2/$3 $target"
368 ln $INSTALL_FILES/$2/$3 $target || fail "can't create $target"
370 CONF)
371 target=$INSTALL_FILES/$2
372 tstmkdir `dirname $target`
373 conffile=`basename $2`
374 verbose "$INSTALL_CP $3/$conffile $target"
375 $INSTALL_CP $3/$conffile $target
378 fail "unrecognized modlist entry: $*"
380 esac
384 # Copy kernel modules to $INSTALL_DIR
387 copy_kernel() {
389 case $KARCH in
390 sun4*) ISA=sparc; MACH=sparc ;;
391 i86*) ISA=intel; MACH=i386 ;;
392 *) fail "${KARCH}: invalid kernel architecture";;
393 esac
394 export MACH
396 if [ "$GLOM" = "no" ]; then
397 verbose "Source = $UTS, ISA = $ISA, kernel = $KARCH"
398 else
399 verbose "Source = $UTS, ISA = $ISA, kernel = $KARCH, impl = $IMPL"
402 test -d $KARCH || fail "${KARCH}: invalid kernel architecture"
403 test -d $ISA || fail "${ISA}: invalid instruction set architecture"
405 tstmkdir $INSTALL_FILES
406 rm -rf $modstatedir
407 tstmkdir $modstatedir
408 export MODSTATE=$modstatedir/state
411 # Figure out which "make" to use. dmake is faster than serial
412 # make, but dmake 7.3 has a bug that causes it to lose log
413 # output, which means the modlist might be incomplete.
415 make=dmake
416 dmvers=`$make -version`
417 if [ $? -ne 0 ]; then
418 make=/usr/ccs/bin/make
419 elif [[ $dmvers = *Distributed?Make?7.3* ]]; then
420 unset make
421 searchpath="/ws/onnv-tools/SUNWspro/SOS10/bin
422 /opt/SUNWspro/SOS10/bin
423 /opt/SUNWspro/bin"
424 for dmpath in $searchpath; do
425 verbose "Trying $dmpath/dmake"
426 if [ -x $dmpath/dmake ]; then
427 dmvers=`$dmpath/dmake -version`
428 if [[ $dmvers != *Distributed?Make?7.3* ]]; then
429 make="$dmpath/dmake"
430 break;
433 done
434 if [ -z $make ]; then
435 make=/usr/ccs/bin/make
436 echo "Warning: dmake 7.3 doesn't work with Install;" \
437 "using $make"
442 # Get a list of all modules, configuration files, and links
443 # that we might want to install.
445 verbose "Building module list..."
446 (cd $KARCH; MAKEFLAGS=e $make -K $MODSTATE modlist.karch) | \
447 egrep "^MOD|^CONF|^LINK|^SYMLINK" > $modlist
448 [ $VERBOSE = "V" ] && cat $modlist
449 if [ "$GLOM" = "yes" ]; then
450 fixglom $modlist $GLOMNAME
451 filtimpl $modlist $IMPL
453 if [[ -n "$files" && "$files" != All ]]; then
454 filtmod $modlist "$files"
458 # Copy modules and create links. For architectures with both
459 # 32- and 64-bit modules, we'll likely have duplicate
460 # configuration files, so do those after filtering out the
461 # duplicates.
463 verbose "Copying files to ${INSTALL_FILES}..."
466 # The IFS is reset to the newline character so we can buffer the
467 # output of grep without piping it directly to copymod, otherwise
468 # if fail() is called, then it will deadlock in fail()'s wait call
470 OIFS="$IFS"
471 IFS="
473 set -- `grep -v "^CONF" $modlist`;
474 IFS="$OIFS"
475 for onemod in "$@"; do
476 copymod $onemod
477 done
479 OIFS="$IFS"
480 IFS="
482 set -- `grep "^CONF" $modlist | sort | uniq`;
483 IFS="$OIFS"
484 for onemod in "$@"; do
485 copymod $onemod
486 done
489 # Add the glommed kernel name to the root archive
491 if [[ $GLOM == "yes" ]];
492 then
493 filelist="$INSTALL_FILES/etc/boot/solaris/filelist.ramdisk"
494 mkdir -p `dirname $filelist`
495 echo "platform/$KARCH/$GLOMNAME" >$filelist
498 STATE=1 # all kernel modules copied correctly
499 save_state
502 kmdb_copy() {
503 typeset src="$1"
504 typeset destdir="$2"
506 if [[ ! -d $dest ]] ; then
507 [[ $VERBOSE != "q" ]] && echo "mkdir -p $destdir"
509 mkdir -p $destdir || fail "failed to create $destdir"
512 [[ $VERBOSE != "q" ]] && echo "cp $src $destdir"
514 cp $src $destdir || fail "failed to copy $src to $destdir"
517 kmdb_copy_machkmods() {
518 typeset modbase="$1"
519 typeset destdir="$2"
520 typeset dir=
521 typeset kmod=
523 [[ ! -d $modbase ]] && return
525 for dir in $(find $modbase -name kmod) ; do
526 set -- $(echo $dir |tr '/' ' ')
528 [[ $# -lt 2 ]] && fail "invalid mach kmod dir $dir"
530 shift $(($# - 2))
531 kmod=$1
533 [[ ! -f $dir/$kmod ]] && continue
535 kmdb_copy $dir/$kmod $destdir
536 done
539 kmdb_copy_karchkmods() {
540 typeset modbase="$1"
541 typeset destdir="$2"
542 typeset bitdir="$3"
543 typeset dir=
544 typeset kmod=
545 typeset karch=
547 [[ ! -d $modbase ]] && return
549 for dir in $(find $modbase -name kmod) ; do
550 set -- $(echo $dir | tr '/' ' ')
552 [[ $# -lt 3 ]] && fail "invalid karch kmod dir $dir"
554 shift $(($# - 3))
555 kmod=$1
556 bdir=$2
558 [[ $bdir != $bitdir ]] && continue
559 [[ ! -f $dir/$1 ]] && continue
561 kmdb_copy $dir/$kmod $destdir
562 done
565 kmdb_copy_kmdbmod() {
566 typeset kmdbpath="$1"
567 typeset destdir="$2"
569 [[ ! -f $kmdbpath ]] && return 1
571 kmdb_copy $kmdbpath $destdir
573 return 0
576 copy_kmdb() {
577 typeset kmdbtgtdir=$INSTALL_FILES/platform/$KARCH/$GLOMNAME/misc
578 typeset bitdirs=
579 typeset isadir=
580 typeset b64srcdir=
581 typeset b64tgtdir=
582 typeset b32srcdir=
583 typeset b32tgtdir=
584 typeset machdir=
585 typeset platdir=
587 if [[ $KMDB = "no" || ! -d $SRC/cmd/mdb ]] ; then
588 # The kmdb copy was suppressed or the workspace doesn't contain
589 # the mdb subtree. Either way, there's nothing to do.
590 STATE=2
591 save_state
592 return
595 if [[ $(mach) = "i386" ]] ; then
596 isadir="intel"
597 b64srcdir="amd64"
598 b64tgtdir="amd64"
599 b32srcdir="ia32"
600 b32tgtdir="."
601 else
602 isadir="sparc"
603 b64srcdir="v9"
604 b64tgtdir="sparcv9"
605 b32srcdir="v7"
606 b32tgtdir="."
609 typeset foundkmdb=no
610 typeset kmdbpath=
611 typeset destdir=
613 platdir=$INSTALL_FILES/platform/$KARCH/$GLOMNAME
614 if [[ $GLOM = "yes" ]] ; then
615 machdir=$platdir
616 else
617 machdir=$INSTALL_FILES/kernel
620 srctrees=$SRC
621 if [[ -d $SRC/../closed && "$CLOSED_IS_PRESENT" != no ]]; then
622 srctrees="$srctrees $SRC/../closed"
624 if [[ $WANT64 = "yes" ]] ; then
625 # kmdbmod for sparc and x86 are built and installed
626 # in different places
627 if [[ $(mach) = "i386" ]] ; then
628 kmdbpath=$SRC/cmd/mdb/$isadir/$b64srcdir/kmdb/kmdbmod
629 destdir=$machdir/misc/$b64tgtdir
630 else
631 kmdbpath=$SRC/cmd/mdb/$KARCH/$b64srcdir/kmdb/kmdbmod
632 destdir=$platdir/misc/$b64tgtdir
635 if kmdb_copy_kmdbmod $kmdbpath $destdir ; then
636 foundkmdb="yes"
638 for tree in $srctrees; do
639 kmdb_copy_machkmods \
640 $tree/cmd/mdb/$isadir/$b64srcdir \
641 $machdir/kmdb/$b64tgtdir
642 kmdb_copy_karchkmods $tree/cmd/mdb/$KARCH \
643 $platdir/kmdb/$b64tgtdir $b64srcdir
644 done
648 if [[ $WANT32 = "yes" ]] ; then
649 kmdbpath=$SRC/cmd/mdb/$isadir/$b32srcdir/kmdb/kmdbmod
650 destdir=$machdir/misc/$b32tgtdir
652 if kmdb_copy_kmdbmod $kmdbpath $destdir ; then
653 foundkmdb="yes"
655 for tree in $srctrees; do
656 kmdb_copy_machkmods \
657 $tree/cmd/mdb/$isadir/$b32srcdir \
658 $machdir/kmdb/$b32tgtdir
659 kmdb_copy_karchkmods $tree/cmd/mdb/$KARCH \
660 $platdir/kmdb/$b32tgtdir $b32srcdir
661 done
665 # A kmdb-less workspace isn't fatal, but it is potentially problematic,
666 # as the changes made to uts may have altered something upon which kmdb
667 # depends. We will therefore remind the user that they haven't built it
668 # yet.
669 if [[ $foundkmdb != "yes" ]] ; then
670 echo "WARNING: kmdb isn't built, and won't be included"
673 STATE=2
674 save_state
675 return
679 # Make tarfile
682 make_tarfile() {
683 echo "Creating tarfile $TARFILE"
684 test -d $INSTALL_FILES || fail "Can't find $INSTALL_FILES"
685 cd $INSTALL_FILES
686 rm -f $TARFILE files
688 # We don't want to change the permissions or ownership of pre-existing
689 # directories on the target machine, so we're going to take care to
690 # avoid including directories in the tarfile. On extraction, tar won't
691 # modify pre-existing directories, and will create non-existent ones as
692 # the user doing the extraction.
693 find . ! -type d -print |fgrep -vx './files' >files
694 tar cf $TARFILE -I files || fail "Couldn't create tarfile $TARFILE"
695 STATE=3
699 # Routines to copy files to the target machine
702 remote_fail() {
703 fail "" "$1" "" \
704 "Make sure that $TARGET_MACHINE is up." \
705 "Check .rhosts in the home directory of user $TARGET_USER on $TARGET_MACHINE." \
706 "Check /etc/hosts.equiv, /etc/passwd, and /etc/shadow." \
707 "Change permissions on $TARGET_MACHINE as necessary." \
708 "Then, use \"$INSTALL -R\" to resume the install." ""
711 remote_install() {
712 if [ "$IMODE" = "n" ]; then
713 STATE=4
714 return 0
716 test -s $TARFILE || fail "$TARFILE missing or empty"
717 verbose "Installing system on $TARGET"
718 test -d $INSTALL_DIR || fail "Can't find $INSTALL_DIR"
719 cd $INSTALL_DIR
720 rm -f errors fatal nonfatal
721 if [ "$IMODE" = "T" ]; then
722 EMESG="Can't rcp to $TARGET"
723 touch errors
724 sh -e${SHV}c "$INSTALL_RCP $TARFILE $TARGET/Install.tar"
725 else
726 EMESG="Can't rsh to $TARGET_MACHINE"
727 rsh -l $TARGET_USER $TARGET_MACHINE \
728 "(cd $TARGET_DIR; /usr/bin/tar x${V}f -)" \
729 <$TARFILE 2>errors
731 test $? -ne 0 && remote_fail "$EMESG"
732 cd $INSTALL_DIR
733 egrep "set time|warning|blocksize" errors >nonfatal
734 egrep -v "set time|warning|blocksize" errors >fatal
735 if [ -s fatal ]; then
736 echo "Fatal errors from rsh:"
737 cat fatal
738 remote_fail "Can't install on $TARGET_MACHINE"
740 if [ -s nonfatal -a "$VERBOSE" != "q" ]; then
741 echo "Non-fatal errors from rsh:"
742 cat nonfatal
744 rm -f fatal nonfatal errors
745 test "$IMODE" = "T" && echo "Files can be extracted on \
746 $TARGET_MACHINE using 'tar xvf $TARGET_DIR/Install.tar'"
747 STATE=4
750 okexit() {
751 cd /tmp
752 test "$CLEANUP" = c && remove_dir $INSTALL_DIR
753 save_state
754 rm -rf $modstatedir
755 rm -f $modlist
756 verbose "Install complete"
757 exit 0
761 # Process options
764 RCOPTS=""
765 LIBCREATE="no"
766 LIBSRC=""
767 ENV_PATH=$CODEMGR_WS
768 OBJD="debug"
769 KMDB="yes"
771 test -s $INSTALL_RC && RCOPTS=`cat $INSTALL_RC`
772 set $INSTALL $DEFAULT_OPTIONS $RCOPTS $*
773 shift
775 while getopts acd:D:G:hi:k:Kl:Lmno:pPqRs:t:T:uvVw:xX36 opt
777 case $opt in
778 w) ENV_PATH="$OPTARG"; SRC="$ENV_PATH/usr/src";;
779 s) UTS="$OPTARG";;
780 k) KARCH="$OPTARG";;
781 t|T) TARGET="$OPTARG"; IMODE=$opt; CLEANUP="c";;
782 n) TARGET=""; IMODE="n"; CLEANUP="p";;
783 u) files="unix genunix";;
784 m) files="Modules";;
785 a) files="All";;
786 v|V|q) VERBOSE=$opt;;
787 c|p) CLEANUP=$opt;;
788 L) LIBCREATE="yes"; CLEANUP="c";;
789 l) LIBSRC="$OPTARG";;
790 D) INSTALL_LIB="$OPTARG";;
791 d) INSTALL_DIR="$OPTARG/$TRAILER";;
792 G) GLOM=yes; GLOMNAME="$OPTARG";;
793 P|X|x) echo "-$opt is obsolete; ignored";;
794 h) usage "${INSTALL}: installs unix and modules";;
795 R) x=$OPTIND; restore_state; OPTIND=$x;;
796 i) IMPL="$OPTARG";;
797 o) OBJD="$OPTARG";;
798 K) KMDB="no";;
799 3) WANT64="no";;
800 6) WANT32="no";;
801 \?) usage "Illegal option";;
802 esac
803 done
804 shift `expr $OPTIND - 1`
806 ENV_NAME=`basename $ENV_PATH`
809 # The rest of the command line is a list of individual files to copy.
810 # If non-null, this list overrides the -uma options.
813 if [[ $# -gt 0 ]] ; then
814 files="$*"
815 KMDB="no"
818 case $VERBOSE in
819 v) V="v"; SHV="x";;
820 V) V="v"; SHV="x"; set -x;;
821 q) V=""; SHV="";;
822 esac
825 # Create temp directory for Install's files
828 tstmkdir $INSTALL_DIR
830 TARFILE=$INSTALL_DIR/Install.${KARCH}.tar
831 INSTALL_FILES=$INSTALL_DIR/$KARCH
834 # Extract the target machine and target directory from a target of the
835 # form [user@]machine:/dir .
838 if [ "$IMODE" != "n" ]; then
839 eval `echo $TARGET | nawk -F':' '{
840 if (NF != 2 || !length($1) || !length($2))
841 print "usage \"Invalid target\""
842 m = $1; d = $2
843 if ($1 ~ /@/) {
844 k = split($1, f, "@");
845 if (k != 2 || !length(f[1]) || !length (f[2]))
846 print "usage \"Invalid target\""
847 u = f[1]; m = f[2]
849 print "TARGET_USER=" u ";"
850 print "TARGET_MACHINE=" m ";"
851 print "TARGET_DIR=" d ";"
853 if [ -z "$TARGET_USER" ]; then
854 TARGET_USER=$LOGNAME
859 # Allow the use of library source or target for the install
862 if [ -n "$LIBSRC" ]; then
863 LIBSRC="`basename $LIBSRC .tar`.tar"
864 TARFILE=$INSTALL_LIB/$LIBSRC
865 test -s $TARFILE || fail "Can't find tarfile $TARFILE"
866 verbose "Installing from library tarfile $TARFILE"
867 STATE=3
868 elif [ "$LIBCREATE" = "yes" ]; then
869 tstmkdir $INSTALL_LIB
870 TARFILE="$INSTALL_LIB/${ENV_NAME}.${KARCH}.tar"
874 # The next few lines allow recovery and activation with -R,
875 # and library installs with -l.
878 [[ $STATE -eq 1 ]] && copy_kmdb
879 [[ $STATE -eq 2 ]] && make_tarfile
880 [[ $STATE -eq 3 ]] && remote_install
881 [[ $STATE -eq 4 ]] && okexit
883 save_state
885 cd $DOT
886 DOTDOT=`cd ..; pwd`
889 # Try to be smart: if DOTDOT ends in uts, then infer UTS and KARCH from DOT
890 # Otherwise, if SRC is set, infer UTS = $SRC/uts.
893 if [ "`basename $DOTDOT`" = "uts" ]; then
894 UTS=$DOTDOT
895 KARCH=`basename $DOT`
896 if [ ! -n "$SRC" ]; then
897 SRC=`dirname $DOTDOT`
898 verbose "Setting SRC to $SRC"
900 export SRC
903 if [ -z "$UTS" -a -n "$SRC" ]; then
904 UTS="${SRC}/uts"
905 test -n "$KARCH" || fail "no karch specified (e.g. -k sun4u)"
908 if [ "$LIBCREATE" = "yes" ]; then
909 TARFILE=$INSTALL_LIB/${ENV_NAME}.${KARCH}.tar
910 else
911 TARFILE=$INSTALL_DIR/Install.${KARCH}.tar
913 INSTALL_FILES=$INSTALL_DIR/$KARCH
914 save_state
916 cd $DOT
917 test -z "$UTS" && fail 'Cannot find kernel sources -- $SRC not set'
918 test -d "$UTS" || fail "${UTS}: no such directory"
921 # Convert UTS into an absolute path.
924 cd $UTS
925 UTS=`pwd`
927 test "`basename $UTS`" = "uts" || \
928 verbose "Warning: source path $UTS doesn't end in 'uts'"
930 remove_dir $INSTALL_DIR/$KARCH
931 rm -f $TARFILE
933 copy_kernel # sets STATE=1 if successful
934 copy_kmdb # sets STATE=2 if successful
935 make_tarfile # sets STATE=3 if successful
936 remote_install # sets STATE=4 if successful
938 okexit