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