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]
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.
32 # Install performs the following steps:
34 # 1. Get the list of modules, configuration files, and links
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
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.
69 TRAILER
="Install.$LOGNAME"
70 INSTALL_STATE
=${INSTALL_STATE-$HOME/.Install.state}
72 INSTALL_DIR
=${INSTALL_DIR-/tmp/$TRAILER}
73 if [ "`basename $INSTALL_DIR`" != "$TRAILER" ]; then
74 INSTALL_DIR
="$INSTALL_DIR/$TRAILER"
77 INSTALL_LIB
=${INSTALL_LIB-$HOME/LibInstall}
79 INSTALL_RC
=${INSTALL_RC-$HOME/.Installrc}
81 INSTALL_CP
=${INSTALL_CP-"cp -p"}
83 INSTALL_RCP
=${INSTALL_RCP-"rcp -p"}
88 DEFAULT_OPTIONS
="-naq"
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
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 ]
138 man -M /ws/on297-gate/public/docs Install
144 # Save the current state of Install
149 (echo "# State of previous Install
155 INSTALL_DIR=$INSTALL_DIR
156 INSTALL_LIB=$INSTALL_LIB
166 STATE=$STATE" >$INSTALL_STATE) || verbose
"Warning: cannot save state"
170 # Restore the previous state of Install
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
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.
197 echo "Install failed"
202 # Echo a string in verbose mode only
206 test "$VERBOSE" != "q" && echo $1
210 # hack for tmpfs bug -- remove files gradually
218 rm -f `find . -type f -print`
224 # Create a directory if it doesn't already exist.
225 # mkdir will provide an error message, so don't provide an additional
230 [ -d $1 ] || mkdir
-p $1 || fail
234 # Patch up target directories for glommed kernel.
235 # usage: fixglom listfile glomname
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)
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)
258 sub(/^platform.*kernel/, "platform/" karch "/" glomname, $2)
259 sub(/^kernel/, "platform/" karch "/" glomname, $2)
260 sub(/^usr.kernel/, "platform/" karch "/" glomname, $2)
268 # Remove entries from
269 # usage: filtimpl listfile implname
275 $1 == "MOD" || $1 == "SYMLINK" {
276 if ($5 == "all" || $5 == impl)
280 if ($4 == "all" || $4 == impl)
284 if ($6 == "all" || $6 == impl)
292 # Filter the module list to match the user's request.
293 # Usage: filtmod listfile modules
296 nawk
-v reqstring
="$2" '
297 function modmatch(modname) {
298 if (reqstring == "All") {
300 } else if (reqstring == "Modules") {
301 if (modname != "unix" && modname != "genunix")
304 if (modname in reqmods)
311 # The split call creates indexes 1, 2, 3, ... We want
312 # the module names as indexes.
314 split(reqstring, tmpmods)
316 reqmods[tmpmods[i]] = 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.
347 targdir
=$INSTALL_FILES/$3
350 verbose
"$INSTALL_CP $6/${OBJD}$4/$2 $target"
351 $INSTALL_CP $6/${OBJD}$4/$2 $target || \
352 fail
"can't create $target"
355 targdir
=$INSTALL_FILES/$3
359 verbose
"ln -s $2 $target"
360 ln -s $2 $target || fail
"can't create $target"
363 targdir
=$INSTALL_FILES/$4
367 verbose
"ln $INSTALL_FILES/$2/$3 $target"
368 ln $INSTALL_FILES/$2/$3 $target || fail
"can't create $target"
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: $*"
384 # Copy kernel modules to $INSTALL_DIR
390 sun4
*) ISA
=sparc
; MACH
=sparc
;;
391 i86
*) ISA
=intel
; MACH
=i386
;;
392 *) fail
"${KARCH}: invalid kernel architecture";;
396 if [ "$GLOM" = "no" ]; then
397 verbose
"Source = $UTS, ISA = $ISA, kernel = $KARCH"
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
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.
416 dmvers
=`$make -version`
417 if [ $?
-ne 0 ]; then
418 make=/usr
/ccs
/bin
/make
419 elif [[ $dmvers = *Distributed?Make?
7.3* ]]; then
421 searchpath
="/ws/onnv-tools/SUNWspro/SOS10/bin
422 /opt/SUNWspro/SOS10/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
434 if [ -z $make ]; then
435 make=/usr
/ccs
/bin
/make
436 echo "Warning: dmake 7.3 doesn't work with Install;" \
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
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
473 set -- `grep -v "^CONF" $modlist`;
475 for onemod
in "$@"; do
482 set -- `grep "^CONF" $modlist | sort | uniq`;
484 for onemod
in "$@"; do
489 # Add the glommed kernel name to the root archive
491 if [[ $GLOM == "yes" ]];
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
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
() {
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"
533 [[ ! -f $dir/$kmod ]] && continue
535 kmdb_copy
$dir/$kmod $destdir
539 kmdb_copy_karchkmods
() {
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"
558 [[ $bdir != $bitdir ]] && continue
559 [[ ! -f $dir/$1 ]] && continue
561 kmdb_copy
$dir/$kmod $destdir
565 kmdb_copy_kmdbmod
() {
566 typeset kmdbpath
="$1"
569 [[ ! -f $kmdbpath ]] && return 1
571 kmdb_copy
$kmdbpath $destdir
577 typeset kmdbtgtdir
=$INSTALL_FILES/platform
/$KARCH/$GLOMNAME/misc
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.
595 if [[ $
(mach
) = "i386" ]] ; then
613 platdir
=$INSTALL_FILES/platform
/$KARCH/$GLOMNAME
614 if [[ $GLOM = "yes" ]] ; then
617 machdir
=$INSTALL_FILES/kernel
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
631 kmdbpath
=$SRC/cmd
/mdb
/$KARCH/$b64srcdir/kmdb
/kmdbmod
632 destdir
=$platdir/misc
/$b64tgtdir
635 if kmdb_copy_kmdbmod
$kmdbpath $destdir ; then
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
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
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
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
669 if [[ $foundkmdb != "yes" ]] ; then
670 echo "WARNING: kmdb isn't built, and won't be included"
683 echo "Creating tarfile $TARFILE"
684 test -d $INSTALL_FILES || fail
"Can't find $INSTALL_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"
699 # Routines to copy files to the target machine
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." ""
712 if [ "$IMODE" = "n" ]; then
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"
720 rm -f errors fatal nonfatal
721 if [ "$IMODE" = "T" ]; then
722 EMESG
="Can't rcp to $TARGET"
724 sh
-e${SHV}c
"$INSTALL_RCP $TARFILE $TARGET/Install.tar"
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 -)" \
731 test $?
-ne 0 && remote_fail
"$EMESG"
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:"
738 remote_fail
"Can't install on $TARGET_MACHINE"
740 if [ -s nonfatal
-a "$VERBOSE" != "q" ]; then
741 echo "Non-fatal errors from rsh:"
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'"
752 test "$CLEANUP" = c
&& remove_dir
$INSTALL_DIR
756 verbose
"Install complete"
771 test -s $INSTALL_RC && RCOPTS
=`cat $INSTALL_RC`
772 set $INSTALL $DEFAULT_OPTIONS $RCOPTS $
*
775 while getopts acd
:D
:G
:hi
:k
:Kl
:Lmno
:pPqRs
:t
:T
:uvVw
:xX36 opt
778 w
) ENV_PATH
="$OPTARG"; SRC
="$ENV_PATH/usr/src";;
781 t|T
) TARGET
="$OPTARG"; IMODE
=$opt; CLEANUP
="c";;
782 n
) TARGET
=""; IMODE
="n"; CLEANUP
="p";;
783 u
) files
="unix genunix";;
786 v|V|q
) VERBOSE
=$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;;
801 \?) usage
"Illegal option";;
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
820 V
) V
="v"; SHV
="x"; set -x;;
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\""
844 k = split($1, f, "@");
845 if (k != 2 || !length(f[1]) || !length (f[2]))
846 print "usage \"Invalid target\""
849 print "TARGET_USER=" u ";"
850 print "TARGET_MACHINE=" m ";"
851 print "TARGET_DIR=" d ";"
853 if [ -z "$TARGET_USER" ]; then
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"
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
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
895 KARCH
=`basename $DOT`
896 if [ ! -n "$SRC" ]; then
897 SRC
=`dirname $DOTDOT`
898 verbose
"Setting SRC to $SRC"
903 if [ -z "$UTS" -a -n "$SRC" ]; then
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
911 TARFILE
=$INSTALL_DIR/Install.
${KARCH}.
tar
913 INSTALL_FILES
=$INSTALL_DIR/$KARCH
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.
927 test "`basename $UTS`" = "uts" || \
928 verbose
"Warning: source path $UTS doesn't end in 'uts'"
930 remove_dir
$INSTALL_DIR/$KARCH
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