xref: /titanic_50/usr/src/tools/scripts/Install.sh (revision c3e6cb59e6ec7e289cc296c8f5f6e77651afe0a2)
17c478bd9Sstevel@tonic-gate#!/bin/ksh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6fb9f9b97Skupfer# Common Development and Distribution License (the "License").
7fb9f9b97Skupfer# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
23*84d8c05bSMike Kupfer# Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate# Author:  Jeff Bonwick
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate#	Please report any bugs to bonwick@eng.
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate# How Install works:
307c478bd9Sstevel@tonic-gate#
317c478bd9Sstevel@tonic-gate#	Install performs the following steps:
327c478bd9Sstevel@tonic-gate#
33fb9f9b97Skupfer#	1. Get the list of modules, configuration files, and links
34fb9f9b97Skupfer#	   that are desired.
357c478bd9Sstevel@tonic-gate#
367c478bd9Sstevel@tonic-gate#	2. Create the requested subset of /kernel in Install's temp space
377c478bd9Sstevel@tonic-gate#	   (/tmp/Install.username by default.)
387c478bd9Sstevel@tonic-gate#
397c478bd9Sstevel@tonic-gate#	3. Create a tar file (/tmp/Install.username/Install.tar) based on (3).
407c478bd9Sstevel@tonic-gate#
417c478bd9Sstevel@tonic-gate#	4. If -n was specified, exit.  If a target was specified using -T,
427c478bd9Sstevel@tonic-gate#	   rcp the tarfile to the target and exit.  If a target was specified
437c478bd9Sstevel@tonic-gate#	   using -t, rsh to the target machine and untar the tarfile in the
447c478bd9Sstevel@tonic-gate#	   target directory.
457c478bd9Sstevel@tonic-gate#
467c478bd9Sstevel@tonic-gate# If any of these steps fail, Install will give you an error message and,
477c478bd9Sstevel@tonic-gate# in most cases, suggest corrective measures.  Then, you can recover the
487c478bd9Sstevel@tonic-gate# install with "Install -R". (This is not required; it's just faster than
497c478bd9Sstevel@tonic-gate# starting from scratch.)
507c478bd9Sstevel@tonic-gate#
517c478bd9Sstevel@tonic-gate# One final comment:  Unfortunately, tar and I disagree on what
527c478bd9Sstevel@tonic-gate# constitutes a fatal error.  (tar -x will exit 0 even if it can't write
537c478bd9Sstevel@tonic-gate# anything in the current directory.)  Thus, I am reduced to grepping stderr
547c478bd9Sstevel@tonic-gate# for (what I consider) fatal and nonfatal error messages.  If you run into
557c478bd9Sstevel@tonic-gate# a situation where this doesn't behave the way you think it should (either
567c478bd9Sstevel@tonic-gate# an "Install failed" message after a successful install, or an "Install
577c478bd9Sstevel@tonic-gate# complete" message after it bombs), please let me know.
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate#
607c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
617c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
627c478bd9Sstevel@tonic-gate#
637c478bd9Sstevel@tonic-gateunset CDPATH
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gateINSTALL=`basename $0`
667c478bd9Sstevel@tonic-gateDOT=`pwd`
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gateTRAILER="Install.$LOGNAME"
697c478bd9Sstevel@tonic-gateINSTALL_STATE=${INSTALL_STATE-$HOME/.Install.state}
707c478bd9Sstevel@tonic-gateexport INSTALL_STATE
717c478bd9Sstevel@tonic-gateINSTALL_DIR=${INSTALL_DIR-/tmp/$TRAILER}
727c478bd9Sstevel@tonic-gateif [ "`basename $INSTALL_DIR`" != "$TRAILER" ]; then
737c478bd9Sstevel@tonic-gate	INSTALL_DIR="$INSTALL_DIR/$TRAILER"
747c478bd9Sstevel@tonic-gatefi
757c478bd9Sstevel@tonic-gateexport INSTALL_DIR
767c478bd9Sstevel@tonic-gateINSTALL_LIB=${INSTALL_LIB-$HOME/LibInstall}
777c478bd9Sstevel@tonic-gateexport INSTALL_LIB
787c478bd9Sstevel@tonic-gateINSTALL_RC=${INSTALL_RC-$HOME/.Installrc}
797c478bd9Sstevel@tonic-gateexport INSTALL_RC
807c478bd9Sstevel@tonic-gateINSTALL_CP=${INSTALL_CP-"cp -p"}
817c478bd9Sstevel@tonic-gateexport INSTALL_CP
827c478bd9Sstevel@tonic-gateINSTALL_RCP=${INSTALL_RCP-"rcp -p"}
837c478bd9Sstevel@tonic-gateexport INSTALL_RCP
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gateSTATE=0
867c478bd9Sstevel@tonic-gate
87fb9f9b97SkupferDEFAULT_OPTIONS="-naq"
887c478bd9Sstevel@tonic-gateGLOM=no
897c478bd9Sstevel@tonic-gateGLOMNAME=kernel
907c478bd9Sstevel@tonic-gateIMPL="default"
917c478bd9Sstevel@tonic-gateWANT32="yes"
927c478bd9Sstevel@tonic-gateWANT64="yes"
937c478bd9Sstevel@tonic-gate
94fb9f9b97Skupfermodlist=/tmp/modlist$$
95fb9f9b97Skupfer# dummy directory for make state files.
96fb9f9b97Skupfermodstatedir=/tmp/modstate$$
97fb9f9b97Skupfer
987c478bd9Sstevel@tonic-gatetrap 'fail "User Interrupt" "You can resume by typing \"$INSTALL -R\""' 1 2 3 15
997c478bd9Sstevel@tonic-gate
100597bd30bSMike Kupferfunction usage {
1017c478bd9Sstevel@tonic-gate	echo ""
1027c478bd9Sstevel@tonic-gate	echo $1
1037c478bd9Sstevel@tonic-gate	echo '
1047c478bd9Sstevel@tonic-gateUsage: Install	[ -w workspace ]
1057c478bd9Sstevel@tonic-gate		[ -s srcdir (default: usr/src/uts) ]
1067c478bd9Sstevel@tonic-gate		[ -k karch (e.g. sun4u; required if not deducible from pwd) ]
1077c478bd9Sstevel@tonic-gate		[ -t target (extract tar file on target, e.g. user@machine:/) ]
1087c478bd9Sstevel@tonic-gate		[ -T target (copy tar file to target, e.g. user@machine:/tmp) ]
1097c478bd9Sstevel@tonic-gate		[ -n (no target, just create tar file in /tmp (default)) ]
1107c478bd9Sstevel@tonic-gate		[ -u (install unix only) ]
1117c478bd9Sstevel@tonic-gate		[ -m (install modules only) ]
1127c478bd9Sstevel@tonic-gate		[ -a (install everything, i.e. unix + modules (default)) ]
1137c478bd9Sstevel@tonic-gate		[ -v (verbose output) ]
1147c478bd9Sstevel@tonic-gate		[ -V (REALLY verbose output) ]
1157c478bd9Sstevel@tonic-gate		[ -q (quiet (default)) ]
1167c478bd9Sstevel@tonic-gate		[ -c (clean up (remove temp files) when done (default) ]
1177c478bd9Sstevel@tonic-gate		[ -p (preserve temp files -- useful for debugging) ]
1187c478bd9Sstevel@tonic-gate		[ -L (library create: put tarfile in $INSTALL_LIB/env.karch) ]
1197c478bd9Sstevel@tonic-gate		[ -l lib (library extract: use $INSTALL_LIB/lib as source) ]
1207c478bd9Sstevel@tonic-gate		[ -D libdir (default: $HOME/LibInstall) ]
1217c478bd9Sstevel@tonic-gate		[ -d tempdir (Install work area (default: /tmp)) ]
1227c478bd9Sstevel@tonic-gate		[ -G glomname (put all files under platform/karch/glomname) ]
1237c478bd9Sstevel@tonic-gate		[ -i impl (e.g. sunfire; recommended with -G) ]
1247c478bd9Sstevel@tonic-gate		[ -x (update /etc/name_to_major et al) ]
1257c478bd9Sstevel@tonic-gate		[ -X (do not update /etc/name_to_major et al (default)) ]
1267c478bd9Sstevel@tonic-gate		[ -P (update /etc/path_to_inst -- generally not advisable) ]
1277c478bd9Sstevel@tonic-gate		[ -h (help -- prints this message) ]
1287c478bd9Sstevel@tonic-gate		[ -R (recover a previous Install) ]
1297c478bd9Sstevel@tonic-gate		[ -o objdir (object directory - either obj or debug (the default)) ]
1307c478bd9Sstevel@tonic-gate		[ -K (do not copy kmdb) ]
1317c478bd9Sstevel@tonic-gate		[ -3 32-bit modules only ]
1327c478bd9Sstevel@tonic-gate		[ -6 64-bit modules only ]
1337c478bd9Sstevel@tonic-gate		[ list of modules to install ]
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gateFor full details:
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate	man -M /ws/on297-gate/public/docs Install
1387c478bd9Sstevel@tonic-gate'
1397c478bd9Sstevel@tonic-gate	exit 1
1407c478bd9Sstevel@tonic-gate}
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate#
1437c478bd9Sstevel@tonic-gate# Save the current state of Install
1447c478bd9Sstevel@tonic-gate#
1457c478bd9Sstevel@tonic-gate
146597bd30bSMike Kupferfunction save_state {
1477c478bd9Sstevel@tonic-gate	rm -f $INSTALL_STATE
1487c478bd9Sstevel@tonic-gate	(echo "# State of previous Install
1497c478bd9Sstevel@tonic-gateTARGET=$TARGET
1507c478bd9Sstevel@tonic-gateENV_PATH=$ENV_PATH
1517c478bd9Sstevel@tonic-gateENV_NAME=$ENV_NAME
1527c478bd9Sstevel@tonic-gateKARCH=$KARCH
1537c478bd9Sstevel@tonic-gateUTS=$UTS
1547c478bd9Sstevel@tonic-gateINSTALL_DIR=$INSTALL_DIR
1557c478bd9Sstevel@tonic-gateINSTALL_LIB=$INSTALL_LIB
1567c478bd9Sstevel@tonic-gateIMODE=$IMODE
1577c478bd9Sstevel@tonic-gateLIBCREATE=$LIBCREATE
1587c478bd9Sstevel@tonic-gateLIBSRC=$LIBSRC
1597c478bd9Sstevel@tonic-gateVERBOSE=$VERBOSE
1607c478bd9Sstevel@tonic-gateCLEANUP=$CLEANUP
1617c478bd9Sstevel@tonic-gateGLOM=$GLOM
1627c478bd9Sstevel@tonic-gateGLOMNAME=$GLOMNAME
1637c478bd9Sstevel@tonic-gateKMDB=$KMDB
1647c478bd9Sstevel@tonic-gatefiles='$files'
1657c478bd9Sstevel@tonic-gateSTATE=$STATE" >$INSTALL_STATE) || verbose "Warning: cannot save state"
1667c478bd9Sstevel@tonic-gate}
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate#
1697c478bd9Sstevel@tonic-gate# Restore the previous state of Install
1707c478bd9Sstevel@tonic-gate#
1717c478bd9Sstevel@tonic-gate
172597bd30bSMike Kupferfunction restore_state {
1737c478bd9Sstevel@tonic-gate	test -s $INSTALL_STATE || fail "Can't find $INSTALL_STATE"
1747c478bd9Sstevel@tonic-gate	eval "`cat $INSTALL_STATE`"
1757c478bd9Sstevel@tonic-gate}
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate#
1787c478bd9Sstevel@tonic-gate# Install failed -- print error messages and exit 2
1797c478bd9Sstevel@tonic-gate#
1807c478bd9Sstevel@tonic-gate
181597bd30bSMike Kupferfunction fail {
1827c478bd9Sstevel@tonic-gate	save_state
183fb9f9b97Skupfer	#
184fb9f9b97Skupfer	# We might have gotten here via a trap.  So wait for any
185fb9f9b97Skupfer	# children (especially "make modlist") to exit before giving
186fb9f9b97Skupfer	# the error message or cleaning up.
187fb9f9b97Skupfer	#
188fb9f9b97Skupfer	wait
1897c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]
1907c478bd9Sstevel@tonic-gate	do
1917c478bd9Sstevel@tonic-gate		echo $1
1927c478bd9Sstevel@tonic-gate		shift
1937c478bd9Sstevel@tonic-gate	done
194fb9f9b97Skupfer	rm -rf $modstatedir
195fb9f9b97Skupfer	rm -f $modlist
1967c478bd9Sstevel@tonic-gate	echo "Install failed"
1977c478bd9Sstevel@tonic-gate	exit 2
1987c478bd9Sstevel@tonic-gate}
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate#
2017c478bd9Sstevel@tonic-gate# Echo a string in verbose mode only
2027c478bd9Sstevel@tonic-gate#
2037c478bd9Sstevel@tonic-gate
204597bd30bSMike Kupferfunction verbose {
2057c478bd9Sstevel@tonic-gate	test "$VERBOSE" != "q" && echo $1
2067c478bd9Sstevel@tonic-gate}
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate#
2097c478bd9Sstevel@tonic-gate# hack for tmpfs bug -- remove files gradually
2107c478bd9Sstevel@tonic-gate#
2117c478bd9Sstevel@tonic-gate
212597bd30bSMike Kupferfunction remove_dir {
2137c478bd9Sstevel@tonic-gate	test -d $1 || return
2147c478bd9Sstevel@tonic-gate	local_dot=`pwd`
2157c478bd9Sstevel@tonic-gate	cd $1
2167c478bd9Sstevel@tonic-gate	touch foo
2177c478bd9Sstevel@tonic-gate	rm -f `find . -type f -print`
2187c478bd9Sstevel@tonic-gate	cd $local_dot
2197c478bd9Sstevel@tonic-gate	rm -rf $1
2207c478bd9Sstevel@tonic-gate}
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate#
223fb9f9b97Skupfer# Create a directory if it doesn't already exist.
224fb9f9b97Skupfer# mkdir will provide an error message, so don't provide an additional
225fb9f9b97Skupfer# message.
226fb9f9b97Skupfer#
227fb9f9b97Skupfer
228597bd30bSMike Kupferfunction tstmkdir {
229fb9f9b97Skupfer	[ -d $1 ] || mkdir -p $1 || fail
230fb9f9b97Skupfer}
231fb9f9b97Skupfer
232fb9f9b97Skupfer#
233fb9f9b97Skupfer# Patch up target directories for glommed kernel.
234fb9f9b97Skupfer# usage: fixglom listfile glomname
235fb9f9b97Skupfer#
236fb9f9b97Skupfer
237597bd30bSMike Kupferfunction fixglom {
238fb9f9b97Skupfer	nawk \
239fb9f9b97Skupfer	    -v glomname=$2 \
240fb9f9b97Skupfer	    -v karch=$KARCH '
241fb9f9b97Skupfer	$1 == "MOD" || $1 == "SYMLINK" {
242fb9f9b97Skupfer		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $4)
243fb9f9b97Skupfer		sub(/^kernel/, "platform/" karch "/" glomname, $4)
244fb9f9b97Skupfer		sub(/^usr.kernel/, "platform/" karch "/" glomname, $4)
245fb9f9b97Skupfer		print
246fb9f9b97Skupfer	}
247*84d8c05bSMike Kupfer	$1 == "LINK" {
248*84d8c05bSMike Kupfer		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $3)
249*84d8c05bSMike Kupfer		sub(/^kernel/, "platform/" karch "/" glomname, $3)
250*84d8c05bSMike Kupfer		sub(/^usr.kernel/, "platform/" karch "/" glomname, $3)
251*84d8c05bSMike Kupfer		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $5)
252*84d8c05bSMike Kupfer		sub(/^kernel/, "platform/" karch "/" glomname, $5)
253*84d8c05bSMike Kupfer		sub(/^usr.kernel/, "platform/" karch "/" glomname, $5)
254*84d8c05bSMike Kupfer		print
255*84d8c05bSMike Kupfer	}
256fb9f9b97Skupfer	$1 == "CONF" {
257*84d8c05bSMike Kupfer		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $3)
258*84d8c05bSMike Kupfer		sub(/^kernel/, "platform/" karch "/" glomname, $3)
259*84d8c05bSMike Kupfer		sub(/^usr.kernel/, "platform/" karch "/" glomname, $3)
260fb9f9b97Skupfer		print
261fb9f9b97Skupfer	}
262fb9f9b97Skupfer	' $1 > $1.new
263fb9f9b97Skupfer	mv $1.new $1
264fb9f9b97Skupfer}
265fb9f9b97Skupfer
266fb9f9b97Skupfer#
267*84d8c05bSMike Kupfer# Filter out implementation-specific modules, unless that
268*84d8c05bSMike Kupfer# implementation was requested by the user.
269fb9f9b97Skupfer# usage: filtimpl listfile implname
270fb9f9b97Skupfer#
271fb9f9b97Skupfer
272597bd30bSMike Kupferfunction filtimpl {
273fb9f9b97Skupfer	nawk \
274fb9f9b97Skupfer	    -v impl=$2 '
275fb9f9b97Skupfer	$1 == "MOD" || $1 == "SYMLINK" {
276*84d8c05bSMike Kupfer		if ($6 == "all" || $6 == impl)
277fb9f9b97Skupfer			print
278fb9f9b97Skupfer	}
279fb9f9b97Skupfer	$1 == "CONF" {
280*84d8c05bSMike Kupfer		if ($5 == "all" || $5 == impl)
281fb9f9b97Skupfer			print
282fb9f9b97Skupfer	}
283fb9f9b97Skupfer	$1 == "LINK" {
284*84d8c05bSMike Kupfer		if ($7 == "all" || $7 == impl)
285fb9f9b97Skupfer			print
286fb9f9b97Skupfer	}
287fb9f9b97Skupfer	' $1 > $1.new
288fb9f9b97Skupfer	mv $1.new $1
289fb9f9b97Skupfer}
290fb9f9b97Skupfer
291fb9f9b97Skupfer#
292fb9f9b97Skupfer# Filter the module list to match the user's request.
293fb9f9b97Skupfer# Usage: filtmod listfile modules
294fb9f9b97Skupfer#
295597bd30bSMike Kupferfunction filtmod {
296fb9f9b97Skupfer	nawk -v reqstring="$2" '
297fb9f9b97Skupfer	function modmatch(modname) {
298fb9f9b97Skupfer		if (reqstring == "All") {
299fb9f9b97Skupfer			return (1)
300fb9f9b97Skupfer		} else if (reqstring == "Modules") {
301fb9f9b97Skupfer			if (modname != "unix" && modname != "genunix")
302fb9f9b97Skupfer				return (1)
303fb9f9b97Skupfer		} else {
304fb9f9b97Skupfer			if (modname in reqmods)
305fb9f9b97Skupfer				return (1)
306fb9f9b97Skupfer		}
307fb9f9b97Skupfer		return (0)
308fb9f9b97Skupfer	}
309fb9f9b97Skupfer	BEGIN {
310fb9f9b97Skupfer		#
311fb9f9b97Skupfer		# The split call creates indexes 1, 2, 3, ...  We want
312fb9f9b97Skupfer		# the module names as indexes.
313fb9f9b97Skupfer		#
314fb9f9b97Skupfer		split(reqstring, tmpmods)
315fb9f9b97Skupfer		for (i in tmpmods)
316fb9f9b97Skupfer			reqmods[tmpmods[i]] = 1
317fb9f9b97Skupfer	}
318fb9f9b97Skupfer	$1 == "MOD" {
319*84d8c05bSMike Kupfer		if (modmatch($3))
320fb9f9b97Skupfer			print
321fb9f9b97Skupfer	}
322fb9f9b97Skupfer	$1 == "CONF" {
323fb9f9b97Skupfer		if (modmatch($6))
324fb9f9b97Skupfer			print
325fb9f9b97Skupfer	}
326*84d8c05bSMike Kupfer	$1 == "SYMLINK" {
327*84d8c05bSMike Kupfer		if (modmatch($7))
328*84d8c05bSMike Kupfer			print
329*84d8c05bSMike Kupfer	}
330fb9f9b97Skupfer	$1 == "LINK" {
331*84d8c05bSMike Kupfer		if (modmatch($4))
332fb9f9b97Skupfer			print
333fb9f9b97Skupfer	}
334fb9f9b97Skupfer	' $1 > $1.new
335fb9f9b97Skupfer	mv $1.new $1
336fb9f9b97Skupfer}
337fb9f9b97Skupfer
338fb9f9b97Skupfer#
339597bd30bSMike Kupfer# Unpack the crypto tarball into the given tree, then massage the
340597bd30bSMike Kupfer# tree so that the binaries are all in objNN or debugNN directories.
341597bd30bSMike Kupfer#
342597bd30bSMike Kupferfunction unpack_crypto {
343597bd30bSMike Kupfer	typeset tarfile=$1
344597bd30bSMike Kupfer	typeset ctop=$2
345597bd30bSMike Kupfer	[ -d "$ctop" ] || fail "Can't create tree for crypto modules."
346597bd30bSMike Kupfer
347597bd30bSMike Kupfer	[ "$VERBOSE" = "V" ] && echo "unpacking crypto tarball into $ctop..."
348597bd30bSMike Kupfer	bzcat "$tarfile" | (cd "$ctop"; tar xf -)
349597bd30bSMike Kupfer
350597bd30bSMike Kupfer	typeset root="$ctop/proto/root_$MACH"
351597bd30bSMike Kupfer	[ $OBJD = obj ] && root="$ctop/proto/root_$MACH-nd"
352597bd30bSMike Kupfer	[ -d "$root" ] || fail "Can't unpack crypto tarball."
353597bd30bSMike Kupfer
354597bd30bSMike Kupfer	(cd "$root"; for d in platform kernel usr/kernel; do
355597bd30bSMike Kupfer		[ ! -d $d ] && continue
356597bd30bSMike Kupfer		find $d -type f -print
357597bd30bSMike Kupfer	done) | while read file; do
358597bd30bSMike Kupfer		typeset dir=$(dirname "$file")
359597bd30bSMike Kupfer		typeset base=$(basename "$file")
360597bd30bSMike Kupfer		typeset type=$(basename "$dir")
361597bd30bSMike Kupfer		if [ "$type" = amd64 ]; then
362597bd30bSMike Kupfer			newdir="$dir/${OBJD}64"
363597bd30bSMike Kupfer		elif [ "$type" = sparcv9 ]; then
364597bd30bSMike Kupfer			newdir="$dir/${OBJD}64"
365597bd30bSMike Kupfer		else
366597bd30bSMike Kupfer			newdir="$dir/${OBJD}32"
367597bd30bSMike Kupfer		fi
368597bd30bSMike Kupfer		mkdir -p "$root/$newdir"
369597bd30bSMike Kupfer		[ "$VERBOSE" = "V" ] && echo "mv $file $newdir"
370597bd30bSMike Kupfer		mv "$root/$file" "$root/$newdir"
371597bd30bSMike Kupfer	done
372597bd30bSMike Kupfer}
373597bd30bSMike Kupfer
374597bd30bSMike Kupfer#
375fb9f9b97Skupfer# Copy a module, or create a link, as needed.
376fb9f9b97Skupfer#
377597bd30bSMike Kupferfunction copymod {
378fb9f9b97Skupfer	case $1 in
379fb9f9b97Skupfer	MOD)
380*84d8c05bSMike Kupfer		targdir=$INSTALL_FILES/$4
381fb9f9b97Skupfer		tstmkdir $targdir
382*84d8c05bSMike Kupfer		target=$targdir/$3
383*84d8c05bSMike Kupfer		verbose "$INSTALL_CP $2/${OBJD}$5/$3 $target"
384*84d8c05bSMike Kupfer		$INSTALL_CP $2/${OBJD}$5/$3 $target || \
385fb9f9b97Skupfer		    fail "can't create $target"
386fb9f9b97Skupfer		;;
387fb9f9b97Skupfer	SYMLINK)
388fb9f9b97Skupfer		targdir=$INSTALL_FILES/$4
389fb9f9b97Skupfer		tstmkdir $targdir
390fb9f9b97Skupfer		target=$targdir/$5
391fb9f9b97Skupfer		rm -f $target
392*84d8c05bSMike Kupfer		verbose "ln -s $3 $target"
393*84d8c05bSMike Kupfer		ln -s $3 $target || fail "can't create $target"
394*84d8c05bSMike Kupfer		;;
395*84d8c05bSMike Kupfer	LINK)
396*84d8c05bSMike Kupfer		targdir=$INSTALL_FILES/$5
397*84d8c05bSMike Kupfer		tstmkdir $targdir
398*84d8c05bSMike Kupfer		target=$targdir/$6
399*84d8c05bSMike Kupfer		rm -f $target
400*84d8c05bSMike Kupfer		verbose "ln $INSTALL_FILES/$3/$4 $target"
401*84d8c05bSMike Kupfer		ln $INSTALL_FILES/$3/$4 $target || fail "can't create $target"
402fb9f9b97Skupfer		;;
403fb9f9b97Skupfer	CONF)
404*84d8c05bSMike Kupfer		target=$INSTALL_FILES/$3
405fb9f9b97Skupfer		tstmkdir `dirname $target`
406*84d8c05bSMike Kupfer		conffile=`basename $3`
407*84d8c05bSMike Kupfer		verbose "$INSTALL_CP $4/$conffile $target"
408*84d8c05bSMike Kupfer		$INSTALL_CP $4/$conffile $target
409fb9f9b97Skupfer		;;
410fb9f9b97Skupfer	*)
411fb9f9b97Skupfer		fail "unrecognized modlist entry: $*"
412fb9f9b97Skupfer		;;
413fb9f9b97Skupfer	esac
414fb9f9b97Skupfer}
415fb9f9b97Skupfer
416*84d8c05bSMike Kupfer# Sanity-check the given module list.
417*84d8c05bSMike Kupferfunction check_modlist {
418*84d8c05bSMike Kupfer	nawk '
419*84d8c05bSMike Kupfer	BEGIN {
420*84d8c05bSMike Kupfer		nfields["MOD"] = 6
421*84d8c05bSMike Kupfer		nfields["CONF"] = 6
422*84d8c05bSMike Kupfer		nfields["LINK"] = 7
423*84d8c05bSMike Kupfer		nfields["SYMLINK"] = 7
424*84d8c05bSMike Kupfer	}
425*84d8c05bSMike Kupfer	{
426*84d8c05bSMike Kupfer		# This also catches unknown tags.
427*84d8c05bSMike Kupfer		if (nfields[$1] != NF) {
428*84d8c05bSMike Kupfer			print "error: invalid modlist record:"
429*84d8c05bSMike Kupfer			print $0
430*84d8c05bSMike Kupfer			print "expected", nfields[$1], "fields, found", NF
431*84d8c05bSMike Kupfer			status=1
432*84d8c05bSMike Kupfer		}
433*84d8c05bSMike Kupfer	}
434*84d8c05bSMike Kupfer	END {
435*84d8c05bSMike Kupfer		exit status
436*84d8c05bSMike Kupfer	}
437*84d8c05bSMike Kupfer	' $1 || fail "Errors in kernel module list"
438*84d8c05bSMike Kupfer}
439*84d8c05bSMike Kupfer
440fb9f9b97Skupfer#
4417c478bd9Sstevel@tonic-gate# Copy kernel modules to $INSTALL_DIR
4427c478bd9Sstevel@tonic-gate#
4437c478bd9Sstevel@tonic-gate
444597bd30bSMike Kupferfunction copy_kernel {
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate	case $KARCH in
447fb9f9b97Skupfer		sun4*)		ISA=sparc;	MACH=sparc	;;
448ae115bc7Smrj		i86*)		ISA=intel;	MACH=i386	;;
4497c478bd9Sstevel@tonic-gate		*)		fail "${KARCH}: invalid kernel architecture";;
4507c478bd9Sstevel@tonic-gate	esac
451fb9f9b97Skupfer	export MACH
4527c478bd9Sstevel@tonic-gate
4537c478bd9Sstevel@tonic-gate	if [ "$GLOM" = "no" ]; then
4547c478bd9Sstevel@tonic-gate		verbose "Source = $UTS, ISA = $ISA, kernel = $KARCH"
4557c478bd9Sstevel@tonic-gate	else
4567c478bd9Sstevel@tonic-gate		verbose "Source = $UTS, ISA = $ISA, kernel = $KARCH, impl = $IMPL"
4577c478bd9Sstevel@tonic-gate	fi
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate	test -d $KARCH || fail "${KARCH}: invalid kernel architecture"
4607c478bd9Sstevel@tonic-gate	test -d $ISA || fail "${ISA}: invalid instruction set architecture"
461fb9f9b97Skupfer
462fb9f9b97Skupfer	tstmkdir $INSTALL_FILES
463fb9f9b97Skupfer	rm -rf $modstatedir
464fb9f9b97Skupfer	tstmkdir $modstatedir
465fb9f9b97Skupfer	export MODSTATE=$modstatedir/state
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate	#
468fb9f9b97Skupfer	# Figure out which "make" to use.  dmake is faster than serial
469fb9f9b97Skupfer	# make, but dmake 7.3 has a bug that causes it to lose log
470fb9f9b97Skupfer	# output, which means the modlist might be incomplete.
4717c478bd9Sstevel@tonic-gate	#
472fb9f9b97Skupfer	make=dmake
473fb9f9b97Skupfer	dmvers=`$make -version`
474fb9f9b97Skupfer	if [ $? -ne 0 ]; then
475fb9f9b97Skupfer		make=/usr/ccs/bin/make
476fb9f9b97Skupfer	elif [[ $dmvers = *Distributed?Make?7.3* ]]; then
477fb9f9b97Skupfer		unset make
478fb9f9b97Skupfer		searchpath="/ws/onnv-tools/SUNWspro/SOS10/bin
479fb9f9b97Skupfer			/opt/SUNWspro/SOS10/bin
480fb9f9b97Skupfer			/opt/SUNWspro/bin"
481fb9f9b97Skupfer		for dmpath in $searchpath; do
482fb9f9b97Skupfer			verbose "Trying $dmpath/dmake"
483fb9f9b97Skupfer			if [ -x $dmpath/dmake ]; then
484fb9f9b97Skupfer				dmvers=`$dmpath/dmake -version`
485fb9f9b97Skupfer				if [[ $dmvers != *Distributed?Make?7.3* ]]; then
486fb9f9b97Skupfer					make="$dmpath/dmake"
487fb9f9b97Skupfer					break;
4887c478bd9Sstevel@tonic-gate				fi
489fb9f9b97Skupfer			fi
490fb9f9b97Skupfer		done
491fb9f9b97Skupfer		if [ -z $make ]; then
492fb9f9b97Skupfer			make=/usr/ccs/bin/make
493fb9f9b97Skupfer			echo "Warning: dmake 7.3 doesn't work with Install;" \
494fb9f9b97Skupfer				"using $make"
495fb9f9b97Skupfer		fi
4967c478bd9Sstevel@tonic-gate	fi
4977c478bd9Sstevel@tonic-gate
498fb9f9b97Skupfer	#
499fb9f9b97Skupfer	# Get a list of all modules, configuration files, and links
500fb9f9b97Skupfer	# that we might want to install.
501fb9f9b97Skupfer	#
502fb9f9b97Skupfer	verbose "Building module list..."
503fb9f9b97Skupfer	(cd $KARCH; MAKEFLAGS=e $make -K $MODSTATE modlist.karch) | \
504fb9f9b97Skupfer	    egrep "^MOD|^CONF|^LINK|^SYMLINK" > $modlist
505597bd30bSMike Kupfer	[ "$VERBOSE" = "V" ] && cat $modlist
506*84d8c05bSMike Kupfer	check_modlist $modlist
507fb9f9b97Skupfer	if [ "$GLOM" = "yes" ]; then
508fb9f9b97Skupfer		fixglom $modlist $GLOMNAME
509fb9f9b97Skupfer		filtimpl $modlist $IMPL
510fb9f9b97Skupfer	fi
511fb9f9b97Skupfer	if [[ -n "$files" && "$files" != All ]]; then
512fb9f9b97Skupfer		filtmod $modlist "$files"
513fb9f9b97Skupfer	fi
5147c478bd9Sstevel@tonic-gate
515fb9f9b97Skupfer	#
516fb9f9b97Skupfer	# Copy modules and create links.  For architectures with both
517fb9f9b97Skupfer	# 32- and 64-bit modules, we'll likely have duplicate
518fb9f9b97Skupfer	# configuration files, so do those after filtering out the
519fb9f9b97Skupfer	# duplicates.
520fb9f9b97Skupfer	#
5217c478bd9Sstevel@tonic-gate	verbose "Copying files to ${INSTALL_FILES}..."
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate	#
524fb9f9b97Skupfer	# The IFS is reset to the newline character so we can buffer the
525fb9f9b97Skupfer	# output of grep without piping it directly to copymod, otherwise
526fb9f9b97Skupfer	# if fail() is called, then it will deadlock in fail()'s wait call
5277c478bd9Sstevel@tonic-gate	#
528fb9f9b97Skupfer	OIFS="$IFS"
529fb9f9b97Skupfer	IFS="
530fb9f9b97Skupfer	"
531fb9f9b97Skupfer	set -- `grep -v "^CONF" $modlist`;
532fb9f9b97Skupfer	IFS="$OIFS"
533fb9f9b97Skupfer	for onemod in "$@"; do
534fb9f9b97Skupfer		copymod $onemod
535fb9f9b97Skupfer	done
5367c478bd9Sstevel@tonic-gate
537fb9f9b97Skupfer	OIFS="$IFS"
538fb9f9b97Skupfer	IFS="
539fb9f9b97Skupfer	"
540fb9f9b97Skupfer	set -- `grep "^CONF" $modlist | sort | uniq`;
541fb9f9b97Skupfer	IFS="$OIFS"
542fb9f9b97Skupfer	for onemod in "$@"; do
543fb9f9b97Skupfer		copymod $onemod
544fb9f9b97Skupfer	done
5457c478bd9Sstevel@tonic-gate
5467c478bd9Sstevel@tonic-gate	#
547986fd29aSsetje	# Add the glommed kernel name to the root archive
5487c478bd9Sstevel@tonic-gate	#
549986fd29aSsetje	if [[ $GLOM == "yes" ]];
550ae115bc7Smrj	then
5517c478bd9Sstevel@tonic-gate		filelist="$INSTALL_FILES/etc/boot/solaris/filelist.ramdisk"
5527c478bd9Sstevel@tonic-gate		mkdir -p `dirname $filelist`
5537c478bd9Sstevel@tonic-gate		echo "platform/$KARCH/$GLOMNAME" >$filelist
5547c478bd9Sstevel@tonic-gate	fi
5557c478bd9Sstevel@tonic-gate
5567c478bd9Sstevel@tonic-gate	STATE=1 # all kernel modules copied correctly
5577c478bd9Sstevel@tonic-gate	save_state
5587c478bd9Sstevel@tonic-gate}
5597c478bd9Sstevel@tonic-gate
560597bd30bSMike Kupferfunction kmdb_copy {
5617c478bd9Sstevel@tonic-gate	typeset src="$1"
5627c478bd9Sstevel@tonic-gate	typeset destdir="$2"
5637c478bd9Sstevel@tonic-gate
5647c478bd9Sstevel@tonic-gate	if [[ ! -d $dest ]] ; then
565597bd30bSMike Kupfer		[[ "$VERBOSE" != "q" ]] && echo "mkdir -p $destdir"
5667c478bd9Sstevel@tonic-gate
5677c478bd9Sstevel@tonic-gate		mkdir -p $destdir || fail "failed to create $destdir"
5687c478bd9Sstevel@tonic-gate	fi
5697c478bd9Sstevel@tonic-gate
570597bd30bSMike Kupfer	[[ "$VERBOSE" != "q" ]] && echo "cp $src $destdir"
5717c478bd9Sstevel@tonic-gate
5727c478bd9Sstevel@tonic-gate	cp $src $destdir || fail "failed to copy $src to $destdir"
5737c478bd9Sstevel@tonic-gate}
5747c478bd9Sstevel@tonic-gate
575597bd30bSMike Kupferfunction kmdb_copy_machkmods {
5767c478bd9Sstevel@tonic-gate	typeset modbase="$1"
5777c478bd9Sstevel@tonic-gate	typeset destdir="$2"
5787c478bd9Sstevel@tonic-gate	typeset dir=
5797c478bd9Sstevel@tonic-gate	typeset kmod=
5807c478bd9Sstevel@tonic-gate
5817c478bd9Sstevel@tonic-gate	[[ ! -d $modbase ]] && return
5827c478bd9Sstevel@tonic-gate
5837c478bd9Sstevel@tonic-gate	for dir in $(find $modbase -name kmod) ; do
5847c478bd9Sstevel@tonic-gate		set -- $(echo $dir |tr '/' ' ')
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate		[[ $# -lt 2 ]] && fail "invalid mach kmod dir $dir"
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate		shift $(($# - 2))
5897c478bd9Sstevel@tonic-gate		kmod=$1
5907c478bd9Sstevel@tonic-gate
5917c478bd9Sstevel@tonic-gate		[[ ! -f $dir/$kmod ]] && continue
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate		kmdb_copy $dir/$kmod $destdir
5947c478bd9Sstevel@tonic-gate	done
5957c478bd9Sstevel@tonic-gate}
5967c478bd9Sstevel@tonic-gate
597597bd30bSMike Kupferfunction kmdb_copy_karchkmods {
5987c478bd9Sstevel@tonic-gate	typeset modbase="$1"
5997c478bd9Sstevel@tonic-gate	typeset destdir="$2"
6007c478bd9Sstevel@tonic-gate	typeset bitdir="$3"
6017c478bd9Sstevel@tonic-gate	typeset dir=
6027c478bd9Sstevel@tonic-gate	typeset kmod=
6037c478bd9Sstevel@tonic-gate	typeset karch=
6047c478bd9Sstevel@tonic-gate
6057c478bd9Sstevel@tonic-gate	[[ ! -d $modbase ]] && return
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate	for dir in $(find $modbase -name kmod) ; do
6087c478bd9Sstevel@tonic-gate		set -- $(echo $dir | tr '/' ' ')
6097c478bd9Sstevel@tonic-gate
6107c478bd9Sstevel@tonic-gate		[[ $# -lt 3 ]] && fail "invalid karch kmod dir $dir"
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate		shift $(($# - 3))
6137c478bd9Sstevel@tonic-gate		kmod=$1
6147c478bd9Sstevel@tonic-gate		bdir=$2
6157c478bd9Sstevel@tonic-gate
6167c478bd9Sstevel@tonic-gate		[[ $bdir != $bitdir ]] && continue
6177c478bd9Sstevel@tonic-gate		[[ ! -f $dir/$1 ]] && continue
6187c478bd9Sstevel@tonic-gate
6197c478bd9Sstevel@tonic-gate		kmdb_copy $dir/$kmod $destdir
6207c478bd9Sstevel@tonic-gate	done
6217c478bd9Sstevel@tonic-gate}
6227c478bd9Sstevel@tonic-gate
623597bd30bSMike Kupferfunction kmdb_copy_kmdbmod {
6247c478bd9Sstevel@tonic-gate	typeset kmdbpath="$1"
6257c478bd9Sstevel@tonic-gate	typeset destdir="$2"
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate	[[ ! -f $kmdbpath ]] && return 1
6287c478bd9Sstevel@tonic-gate
6297c478bd9Sstevel@tonic-gate	kmdb_copy $kmdbpath $destdir
6307c478bd9Sstevel@tonic-gate
6317c478bd9Sstevel@tonic-gate	return 0
6327c478bd9Sstevel@tonic-gate}
6337c478bd9Sstevel@tonic-gate
634597bd30bSMike Kupferfunction copy_kmdb {
6357c478bd9Sstevel@tonic-gate	typeset kmdbtgtdir=$INSTALL_FILES/platform/$KARCH/$GLOMNAME/misc
6367c478bd9Sstevel@tonic-gate	typeset bitdirs=
6377c478bd9Sstevel@tonic-gate	typeset isadir=
6387c478bd9Sstevel@tonic-gate	typeset b64srcdir=
6397c478bd9Sstevel@tonic-gate	typeset b64tgtdir=
6407c478bd9Sstevel@tonic-gate	typeset b32srcdir=
6417c478bd9Sstevel@tonic-gate	typeset b32tgtdir=
6427c478bd9Sstevel@tonic-gate	typeset machdir=
6437c478bd9Sstevel@tonic-gate	typeset platdir=
6447c478bd9Sstevel@tonic-gate
6457c478bd9Sstevel@tonic-gate	if [[ $KMDB = "no" || ! -d $SRC/cmd/mdb ]] ; then
6467c478bd9Sstevel@tonic-gate		# The kmdb copy was suppressed or the workspace doesn't contain
6477c478bd9Sstevel@tonic-gate		# the mdb subtree.  Either way, there's nothing to do.
6487c478bd9Sstevel@tonic-gate		STATE=2
6497c478bd9Sstevel@tonic-gate		save_state
6507c478bd9Sstevel@tonic-gate		return
6517c478bd9Sstevel@tonic-gate	fi
6527c478bd9Sstevel@tonic-gate
6537c478bd9Sstevel@tonic-gate	if [[ $(mach) = "i386" ]] ; then
6547c478bd9Sstevel@tonic-gate		isadir="intel"
6557c478bd9Sstevel@tonic-gate		b64srcdir="amd64"
6567c478bd9Sstevel@tonic-gate		b64tgtdir="amd64"
6577c478bd9Sstevel@tonic-gate		b32srcdir="ia32"
6587c478bd9Sstevel@tonic-gate		b32tgtdir="."
6597c478bd9Sstevel@tonic-gate	else
6607c478bd9Sstevel@tonic-gate		isadir="sparc"
6617c478bd9Sstevel@tonic-gate		b64srcdir="v9"
6627c478bd9Sstevel@tonic-gate		b64tgtdir="sparcv9"
6637c478bd9Sstevel@tonic-gate		b32srcdir="v7"
6647c478bd9Sstevel@tonic-gate		b32tgtdir="."
6657c478bd9Sstevel@tonic-gate	fi
6667c478bd9Sstevel@tonic-gate
6677c478bd9Sstevel@tonic-gate	typeset foundkmdb=no
6687c478bd9Sstevel@tonic-gate	typeset kmdbpath=
669a9857382Sae112802	typeset destdir=
6707c478bd9Sstevel@tonic-gate
6717c478bd9Sstevel@tonic-gate	platdir=$INSTALL_FILES/platform/$KARCH/$GLOMNAME
6727c478bd9Sstevel@tonic-gate	if [[ $GLOM = "yes" ]] ; then
6737c478bd9Sstevel@tonic-gate		machdir=$platdir
6747c478bd9Sstevel@tonic-gate	else
6757c478bd9Sstevel@tonic-gate		machdir=$INSTALL_FILES/kernel
6767c478bd9Sstevel@tonic-gate	fi
6777c478bd9Sstevel@tonic-gate
678fb9f9b97Skupfer	srctrees=$SRC
6797c478bd9Sstevel@tonic-gate	if [[ $WANT64 = "yes" ]] ; then
680a9857382Sae112802		# kmdbmod for sparc and x86 are built and installed
681a9857382Sae112802		# in different places
682a9857382Sae112802		if [[ $(mach) = "i386" ]] ; then
683a9857382Sae112802			kmdbpath=$SRC/cmd/mdb/$isadir/$b64srcdir/kmdb/kmdbmod
684a9857382Sae112802			destdir=$machdir/misc/$b64tgtdir
685a9857382Sae112802		else
686a9857382Sae112802			kmdbpath=$SRC/cmd/mdb/$KARCH/$b64srcdir/kmdb/kmdbmod
687a9857382Sae112802			destdir=$platdir/misc/$b64tgtdir
688a9857382Sae112802		fi
689a9857382Sae112802
690a9857382Sae112802		if kmdb_copy_kmdbmod $kmdbpath $destdir ; then
6917c478bd9Sstevel@tonic-gate			foundkmdb="yes"
6927c478bd9Sstevel@tonic-gate
693fb9f9b97Skupfer			for tree in $srctrees; do
694fb9f9b97Skupfer				kmdb_copy_machkmods \
695fb9f9b97Skupfer				    $tree/cmd/mdb/$isadir/$b64srcdir \
6967c478bd9Sstevel@tonic-gate				    $machdir/kmdb/$b64tgtdir
697fb9f9b97Skupfer				kmdb_copy_karchkmods $tree/cmd/mdb/$KARCH \
6987c478bd9Sstevel@tonic-gate				    $platdir/kmdb/$b64tgtdir $b64srcdir
699fb9f9b97Skupfer			done
7007c478bd9Sstevel@tonic-gate		fi
7017c478bd9Sstevel@tonic-gate	fi
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate	if [[ $WANT32 = "yes" ]] ; then
704a9857382Sae112802		kmdbpath=$SRC/cmd/mdb/$isadir/$b32srcdir/kmdb/kmdbmod
705a9857382Sae112802		destdir=$machdir/misc/$b32tgtdir
706a9857382Sae112802
707a9857382Sae112802		if kmdb_copy_kmdbmod $kmdbpath $destdir ; then
7087c478bd9Sstevel@tonic-gate			foundkmdb="yes"
7097c478bd9Sstevel@tonic-gate
710fb9f9b97Skupfer			for tree in $srctrees; do
711fb9f9b97Skupfer				kmdb_copy_machkmods \
712fb9f9b97Skupfer				    $tree/cmd/mdb/$isadir/$b32srcdir \
7137c478bd9Sstevel@tonic-gate				    $machdir/kmdb/$b32tgtdir
714fb9f9b97Skupfer				kmdb_copy_karchkmods $tree/cmd/mdb/$KARCH \
7157c478bd9Sstevel@tonic-gate				    $platdir/kmdb/$b32tgtdir $b32srcdir
716fb9f9b97Skupfer			done
7177c478bd9Sstevel@tonic-gate		fi
7187c478bd9Sstevel@tonic-gate	fi
7197c478bd9Sstevel@tonic-gate
7207c478bd9Sstevel@tonic-gate	# A kmdb-less workspace isn't fatal, but it is potentially problematic,
7217c478bd9Sstevel@tonic-gate	# as the changes made to uts may have altered something upon which kmdb
7227c478bd9Sstevel@tonic-gate	# depends.  We will therefore remind the user that they haven't built it
7237c478bd9Sstevel@tonic-gate	# yet.
7247c478bd9Sstevel@tonic-gate	if [[ $foundkmdb != "yes" ]] ; then
7257c478bd9Sstevel@tonic-gate		echo "WARNING: kmdb isn't built, and won't be included"
7267c478bd9Sstevel@tonic-gate	fi
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate	STATE=2
7297c478bd9Sstevel@tonic-gate	save_state
7307c478bd9Sstevel@tonic-gate	return
7317c478bd9Sstevel@tonic-gate}
7327c478bd9Sstevel@tonic-gate
7337c478bd9Sstevel@tonic-gate#
7347c478bd9Sstevel@tonic-gate# Make tarfile
7357c478bd9Sstevel@tonic-gate#
7367c478bd9Sstevel@tonic-gate
737597bd30bSMike Kupferfunction make_tarfile {
7387c478bd9Sstevel@tonic-gate	echo "Creating tarfile $TARFILE"
7397c478bd9Sstevel@tonic-gate	test -d $INSTALL_FILES || fail "Can't find $INSTALL_FILES"
7407c478bd9Sstevel@tonic-gate	cd $INSTALL_FILES
7417c478bd9Sstevel@tonic-gate	rm -f $TARFILE files
7427c478bd9Sstevel@tonic-gate
7437c478bd9Sstevel@tonic-gate	# We don't want to change the permissions or ownership of pre-existing
7447c478bd9Sstevel@tonic-gate	# directories on the target machine, so we're going to take care to
7457c478bd9Sstevel@tonic-gate	# avoid including directories in the tarfile.  On extraction, tar won't
7467c478bd9Sstevel@tonic-gate	# modify pre-existing directories, and will create non-existent ones as
7477c478bd9Sstevel@tonic-gate	# the user doing the extraction.
7487c478bd9Sstevel@tonic-gate	find . ! -type d -print |fgrep -vx './files' >files
7497c478bd9Sstevel@tonic-gate	tar cf $TARFILE -I files || fail "Couldn't create tarfile $TARFILE"
7507c478bd9Sstevel@tonic-gate	STATE=3
7517c478bd9Sstevel@tonic-gate}
7527c478bd9Sstevel@tonic-gate
7537c478bd9Sstevel@tonic-gate#
7547c478bd9Sstevel@tonic-gate# Routines to copy files to the target machine
7557c478bd9Sstevel@tonic-gate#
7567c478bd9Sstevel@tonic-gate
757597bd30bSMike Kupferfunction remote_fail {
7587c478bd9Sstevel@tonic-gate	fail "" "$1" "" \
7597c478bd9Sstevel@tonic-gate		"Make sure that $TARGET_MACHINE is up." \
7607c478bd9Sstevel@tonic-gate"Check .rhosts in the home directory of user $TARGET_USER on $TARGET_MACHINE." \
7617c478bd9Sstevel@tonic-gate		"Check /etc/hosts.equiv, /etc/passwd, and /etc/shadow." \
7627c478bd9Sstevel@tonic-gate		"Change permissions on $TARGET_MACHINE as necessary." \
7637c478bd9Sstevel@tonic-gate		"Then, use \"$INSTALL -R\" to resume the install." ""
7647c478bd9Sstevel@tonic-gate}
7657c478bd9Sstevel@tonic-gate
766597bd30bSMike Kupferfunction remote_install {
7677c478bd9Sstevel@tonic-gate	if [ "$IMODE" = "n" ]; then
7687c478bd9Sstevel@tonic-gate		STATE=4
7697c478bd9Sstevel@tonic-gate		return 0
7707c478bd9Sstevel@tonic-gate	fi
7717c478bd9Sstevel@tonic-gate	test -s $TARFILE || fail "$TARFILE missing or empty"
7727c478bd9Sstevel@tonic-gate	verbose "Installing system on $TARGET"
7737c478bd9Sstevel@tonic-gate	test -d $INSTALL_DIR || fail "Can't find $INSTALL_DIR"
7747c478bd9Sstevel@tonic-gate	cd $INSTALL_DIR
7757c478bd9Sstevel@tonic-gate	rm -f errors fatal nonfatal
7767c478bd9Sstevel@tonic-gate	if [ "$IMODE" = "T" ]; then
7777c478bd9Sstevel@tonic-gate		EMESG="Can't rcp to $TARGET"
7787c478bd9Sstevel@tonic-gate		touch errors
7797c478bd9Sstevel@tonic-gate		sh -e${SHV}c "$INSTALL_RCP $TARFILE $TARGET/Install.tar"
7807c478bd9Sstevel@tonic-gate	else
7817c478bd9Sstevel@tonic-gate		EMESG="Can't rsh to $TARGET_MACHINE"
7827c478bd9Sstevel@tonic-gate		rsh -l $TARGET_USER $TARGET_MACHINE \
7837c478bd9Sstevel@tonic-gate		    "(cd $TARGET_DIR; /usr/bin/tar x${V}f -)" \
7847c478bd9Sstevel@tonic-gate		    <$TARFILE 2>errors
7857c478bd9Sstevel@tonic-gate	fi
7867c478bd9Sstevel@tonic-gate	test $? -ne 0 && remote_fail "$EMESG"
7877c478bd9Sstevel@tonic-gate	cd $INSTALL_DIR
7887c478bd9Sstevel@tonic-gate	egrep "set time|warning|blocksize" errors >nonfatal
7897c478bd9Sstevel@tonic-gate	egrep -v "set time|warning|blocksize" errors >fatal
7907c478bd9Sstevel@tonic-gate	if [ -s fatal ]; then
7917c478bd9Sstevel@tonic-gate		echo "Fatal errors from rsh:"
7927c478bd9Sstevel@tonic-gate		cat fatal
7937c478bd9Sstevel@tonic-gate		remote_fail "Can't install on $TARGET_MACHINE"
7947c478bd9Sstevel@tonic-gate	fi
7957c478bd9Sstevel@tonic-gate	if [ -s nonfatal -a "$VERBOSE" != "q" ]; then
7967c478bd9Sstevel@tonic-gate		echo "Non-fatal errors from rsh:"
7977c478bd9Sstevel@tonic-gate		cat nonfatal
7987c478bd9Sstevel@tonic-gate	fi
7997c478bd9Sstevel@tonic-gate	rm -f fatal nonfatal errors
8007c478bd9Sstevel@tonic-gate	test "$IMODE" = "T" && echo "Files can be extracted on \
8017c478bd9Sstevel@tonic-gate$TARGET_MACHINE using 'tar xvf $TARGET_DIR/Install.tar'"
8027c478bd9Sstevel@tonic-gate	STATE=4
8037c478bd9Sstevel@tonic-gate}
8047c478bd9Sstevel@tonic-gate
805597bd30bSMike Kupferfunction okexit {
8067c478bd9Sstevel@tonic-gate	cd /tmp
8077c478bd9Sstevel@tonic-gate	test "$CLEANUP" = c && remove_dir $INSTALL_DIR
8087c478bd9Sstevel@tonic-gate	save_state
809fb9f9b97Skupfer	rm -rf $modstatedir
810fb9f9b97Skupfer	rm -f $modlist
811597bd30bSMike Kupfer	[ -n "$cryptotree" ] && rm -rf "$cryptotree"
8127c478bd9Sstevel@tonic-gate	verbose "Install complete"
8137c478bd9Sstevel@tonic-gate	exit 0
8147c478bd9Sstevel@tonic-gate}
8157c478bd9Sstevel@tonic-gate
8167c478bd9Sstevel@tonic-gate#
8177c478bd9Sstevel@tonic-gate# Process options
8187c478bd9Sstevel@tonic-gate#
8197c478bd9Sstevel@tonic-gate
8207c478bd9Sstevel@tonic-gateRCOPTS=""
8217c478bd9Sstevel@tonic-gateLIBCREATE="no"
8227c478bd9Sstevel@tonic-gateLIBSRC=""
8237c478bd9Sstevel@tonic-gateENV_PATH=$CODEMGR_WS
8247c478bd9Sstevel@tonic-gateOBJD="debug"
8257c478bd9Sstevel@tonic-gateKMDB="yes"
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gatetest -s $INSTALL_RC && RCOPTS=`cat $INSTALL_RC`
8287c478bd9Sstevel@tonic-gateset $INSTALL $DEFAULT_OPTIONS $RCOPTS $*
8297c478bd9Sstevel@tonic-gateshift
8307c478bd9Sstevel@tonic-gate
8317c478bd9Sstevel@tonic-gatewhile getopts acd:D:G:hi:k:Kl:Lmno:pPqRs:t:T:uvVw:xX36 opt
8327c478bd9Sstevel@tonic-gatedo
8337c478bd9Sstevel@tonic-gate	case $opt in
8347c478bd9Sstevel@tonic-gate	    w)	ENV_PATH="$OPTARG"; SRC="$ENV_PATH/usr/src";;
8357c478bd9Sstevel@tonic-gate	    s)	UTS="$OPTARG";;
8367c478bd9Sstevel@tonic-gate	    k)	KARCH="$OPTARG";;
8377c478bd9Sstevel@tonic-gate	  t|T)	TARGET="$OPTARG"; IMODE=$opt; CLEANUP="c";;
8387c478bd9Sstevel@tonic-gate	    n)	TARGET=""; IMODE="n"; CLEANUP="p";;
8397c478bd9Sstevel@tonic-gate	    u)	files="unix genunix";;
840fb9f9b97Skupfer	    m)	files="Modules";;
841fb9f9b97Skupfer	    a)	files="All";;
8427c478bd9Sstevel@tonic-gate	v|V|q)	VERBOSE=$opt;;
8437c478bd9Sstevel@tonic-gate	  c|p)	CLEANUP=$opt;;
8447c478bd9Sstevel@tonic-gate	    L)	LIBCREATE="yes"; CLEANUP="c";;
8457c478bd9Sstevel@tonic-gate	    l)	LIBSRC="$OPTARG";;
8467c478bd9Sstevel@tonic-gate	    D)	INSTALL_LIB="$OPTARG";;
8477c478bd9Sstevel@tonic-gate	    d)	INSTALL_DIR="$OPTARG/$TRAILER";;
8487c478bd9Sstevel@tonic-gate	    G)	GLOM=yes; GLOMNAME="$OPTARG";;
8499df5481aSEric Schrock	P|X|x)	echo "-$opt is obsolete; ignored";;
8507c478bd9Sstevel@tonic-gate	    h)	usage "${INSTALL}: installs unix and modules";;
8517c478bd9Sstevel@tonic-gate	    R)	x=$OPTIND; restore_state; OPTIND=$x;;
8527c478bd9Sstevel@tonic-gate	    i)	IMPL="$OPTARG";;
8537c478bd9Sstevel@tonic-gate	    o)	OBJD="$OPTARG";;
8547c478bd9Sstevel@tonic-gate	    K)  KMDB="no";;
8557c478bd9Sstevel@tonic-gate	    3)  WANT64="no";;
8567c478bd9Sstevel@tonic-gate	    6)  WANT32="no";;
8577c478bd9Sstevel@tonic-gate	   \?)	usage "Illegal option";;
8587c478bd9Sstevel@tonic-gate	esac
8597c478bd9Sstevel@tonic-gatedone
8607c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
8617c478bd9Sstevel@tonic-gate
8627c478bd9Sstevel@tonic-gateENV_NAME=`basename $ENV_PATH`
8637c478bd9Sstevel@tonic-gate
8647c478bd9Sstevel@tonic-gate#
8657c478bd9Sstevel@tonic-gate# The rest of the command line is a list of individual files to copy.
8667c478bd9Sstevel@tonic-gate# If non-null, this list overrides the -uma options.
8677c478bd9Sstevel@tonic-gate#
8687c478bd9Sstevel@tonic-gate
8697c478bd9Sstevel@tonic-gateif [[ $# -gt 0 ]] ; then
8707c478bd9Sstevel@tonic-gate	files="$*"
8717c478bd9Sstevel@tonic-gate	KMDB="no"
8727c478bd9Sstevel@tonic-gatefi
8737c478bd9Sstevel@tonic-gate
874597bd30bSMike Kupfercase "$VERBOSE" in
8757c478bd9Sstevel@tonic-gate	v)	V="v"; SHV="x";;
8767c478bd9Sstevel@tonic-gate	V)	V="v"; SHV="x"; set -x;;
8777c478bd9Sstevel@tonic-gate	q)	V=""; SHV="";;
8787c478bd9Sstevel@tonic-gateesac
8797c478bd9Sstevel@tonic-gate
8807c478bd9Sstevel@tonic-gate#
8817c478bd9Sstevel@tonic-gate# Create temp directory for Install's files
8827c478bd9Sstevel@tonic-gate#
8837c478bd9Sstevel@tonic-gate
884fb9f9b97Skupfertstmkdir $INSTALL_DIR
8857c478bd9Sstevel@tonic-gate
8867c478bd9Sstevel@tonic-gateTARFILE=$INSTALL_DIR/Install.${KARCH}.tar
8877c478bd9Sstevel@tonic-gateINSTALL_FILES=$INSTALL_DIR/$KARCH
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate#
8907c478bd9Sstevel@tonic-gate# Extract the target machine and target directory from a target of the
8917c478bd9Sstevel@tonic-gate# form [user@]machine:/dir .
8927c478bd9Sstevel@tonic-gate#
8937c478bd9Sstevel@tonic-gate
8947c478bd9Sstevel@tonic-gateif [ "$IMODE" != "n" ]; then
8957c478bd9Sstevel@tonic-gate	eval `echo $TARGET | nawk -F':' '{
8967c478bd9Sstevel@tonic-gate		if (NF != 2 || !length($1) || !length($2))
8977c478bd9Sstevel@tonic-gate			print "usage \"Invalid target\""
8987c478bd9Sstevel@tonic-gate		m = $1; d = $2
8997c478bd9Sstevel@tonic-gate		if ($1 ~ /@/) {
9007c478bd9Sstevel@tonic-gate		    k = split($1, f, "@");
9017c478bd9Sstevel@tonic-gate		    if (k != 2 || !length(f[1]) || !length (f[2]))
9027c478bd9Sstevel@tonic-gate			    print "usage \"Invalid target\""
9037c478bd9Sstevel@tonic-gate		    u = f[1]; m = f[2]
9047c478bd9Sstevel@tonic-gate		}
9057c478bd9Sstevel@tonic-gate		print "TARGET_USER=" u ";"
9067c478bd9Sstevel@tonic-gate		print "TARGET_MACHINE=" m ";"
9077c478bd9Sstevel@tonic-gate		print "TARGET_DIR=" d ";"
9087c478bd9Sstevel@tonic-gate	}'`
9097c478bd9Sstevel@tonic-gate	if [ -z "$TARGET_USER" ]; then
9107c478bd9Sstevel@tonic-gate		TARGET_USER=$LOGNAME
9117c478bd9Sstevel@tonic-gate	fi
9127c478bd9Sstevel@tonic-gatefi
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate#
9157c478bd9Sstevel@tonic-gate# Allow the use of library source or target for the install
9167c478bd9Sstevel@tonic-gate#
9177c478bd9Sstevel@tonic-gate
9187c478bd9Sstevel@tonic-gateif [ -n "$LIBSRC" ]; then
9197c478bd9Sstevel@tonic-gate	LIBSRC="`basename $LIBSRC .tar`.tar"
9207c478bd9Sstevel@tonic-gate	TARFILE=$INSTALL_LIB/$LIBSRC
9217c478bd9Sstevel@tonic-gate	test -s $TARFILE || fail "Can't find tarfile $TARFILE"
9227c478bd9Sstevel@tonic-gate	verbose "Installing from library tarfile $TARFILE"
9237c478bd9Sstevel@tonic-gate	STATE=3
9247c478bd9Sstevel@tonic-gateelif [ "$LIBCREATE" = "yes" ]; then
925fb9f9b97Skupfer	tstmkdir $INSTALL_LIB
9267c478bd9Sstevel@tonic-gate	TARFILE="$INSTALL_LIB/${ENV_NAME}.${KARCH}.tar"
9277c478bd9Sstevel@tonic-gatefi
9287c478bd9Sstevel@tonic-gate
9297c478bd9Sstevel@tonic-gate#
930fb9f9b97Skupfer# The next few lines allow recovery and activation with -R,
9317c478bd9Sstevel@tonic-gate# and library installs with -l.
9327c478bd9Sstevel@tonic-gate#
9337c478bd9Sstevel@tonic-gate
9347c478bd9Sstevel@tonic-gate[[ $STATE -eq 1 ]] && copy_kmdb
9357c478bd9Sstevel@tonic-gate[[ $STATE -eq 2 ]] && make_tarfile
9367c478bd9Sstevel@tonic-gate[[ $STATE -eq 3 ]] && remote_install
9377c478bd9Sstevel@tonic-gate[[ $STATE -eq 4 ]] && okexit
9387c478bd9Sstevel@tonic-gate
9397c478bd9Sstevel@tonic-gatesave_state
9407c478bd9Sstevel@tonic-gate
9417c478bd9Sstevel@tonic-gatecd $DOT
9427c478bd9Sstevel@tonic-gateDOTDOT=`cd ..; pwd`
9437c478bd9Sstevel@tonic-gate
9447c478bd9Sstevel@tonic-gate#
9457c478bd9Sstevel@tonic-gate# Try to be smart: if DOTDOT ends in uts, then infer UTS and KARCH from DOT
9467c478bd9Sstevel@tonic-gate# Otherwise, if SRC is set, infer UTS = $SRC/uts.
9477c478bd9Sstevel@tonic-gate#
9487c478bd9Sstevel@tonic-gate
9497c478bd9Sstevel@tonic-gateif [ "`basename $DOTDOT`" = "uts" ]; then
9507c478bd9Sstevel@tonic-gate	UTS=$DOTDOT
9517c478bd9Sstevel@tonic-gate	KARCH=`basename $DOT`
952fb9f9b97Skupfer	if [ ! -n "$SRC" ]; then
953fb9f9b97Skupfer		SRC=`dirname $DOTDOT`
954fb9f9b97Skupfer		verbose "Setting SRC to $SRC"
955fb9f9b97Skupfer	fi
956fb9f9b97Skupfer	export SRC
9577c478bd9Sstevel@tonic-gatefi
9587c478bd9Sstevel@tonic-gate
9597c478bd9Sstevel@tonic-gateif [ -z "$UTS" -a -n "$SRC" ]; then
9607c478bd9Sstevel@tonic-gate	UTS="${SRC}/uts"
9617c478bd9Sstevel@tonic-gate	test -n "$KARCH" || fail "no karch specified (e.g. -k sun4u)"
9627c478bd9Sstevel@tonic-gatefi
9637c478bd9Sstevel@tonic-gate
9647c478bd9Sstevel@tonic-gateif [ "$LIBCREATE" = "yes" ]; then
9657c478bd9Sstevel@tonic-gate	TARFILE=$INSTALL_LIB/${ENV_NAME}.${KARCH}.tar
9667c478bd9Sstevel@tonic-gateelse
9677c478bd9Sstevel@tonic-gate	TARFILE=$INSTALL_DIR/Install.${KARCH}.tar
9687c478bd9Sstevel@tonic-gatefi
9697c478bd9Sstevel@tonic-gateINSTALL_FILES=$INSTALL_DIR/$KARCH
9707c478bd9Sstevel@tonic-gatesave_state
9717c478bd9Sstevel@tonic-gate
9727c478bd9Sstevel@tonic-gatecd $DOT
9737c478bd9Sstevel@tonic-gatetest -z "$UTS" && fail 'Cannot find kernel sources -- $SRC not set'
9747c478bd9Sstevel@tonic-gatetest -d "$UTS" || fail "${UTS}: no such directory"
9757c478bd9Sstevel@tonic-gate
9767c478bd9Sstevel@tonic-gate#
9777c478bd9Sstevel@tonic-gate# Convert UTS into an absolute path.
9787c478bd9Sstevel@tonic-gate#
9797c478bd9Sstevel@tonic-gate
9807c478bd9Sstevel@tonic-gatecd $UTS
9817c478bd9Sstevel@tonic-gateUTS=`pwd`
9827c478bd9Sstevel@tonic-gate
9837c478bd9Sstevel@tonic-gatetest "`basename $UTS`" = "uts" || \
9847c478bd9Sstevel@tonic-gate	verbose "Warning: source path $UTS doesn't end in 'uts'"
9857c478bd9Sstevel@tonic-gate
9867c478bd9Sstevel@tonic-gateremove_dir $INSTALL_DIR/$KARCH
9877c478bd9Sstevel@tonic-gaterm -f $TARFILE
9887c478bd9Sstevel@tonic-gate
9897c478bd9Sstevel@tonic-gatecopy_kernel	# sets STATE=1 if successful
9907c478bd9Sstevel@tonic-gatecopy_kmdb	# sets STATE=2 if successful
9917c478bd9Sstevel@tonic-gatemake_tarfile	# sets STATE=3 if successful
9927c478bd9Sstevel@tonic-gateremote_install	# sets STATE=4 if successful
9937c478bd9Sstevel@tonic-gate
9947c478bd9Sstevel@tonic-gateokexit
995