xref: /titanic_44/usr/src/tools/scripts/Install.sh (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate#!/bin/ksh
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate#
24*7c478bd9Sstevel@tonic-gate# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25*7c478bd9Sstevel@tonic-gate# Use is subject to license terms.
26*7c478bd9Sstevel@tonic-gate#
27*7c478bd9Sstevel@tonic-gate#From: "@(#)Install	1.56	96/10/11 SMI"
28*7c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
29*7c478bd9Sstevel@tonic-gate#
30*7c478bd9Sstevel@tonic-gate# Author:  Jeff Bonwick
31*7c478bd9Sstevel@tonic-gate#
32*7c478bd9Sstevel@tonic-gate#	Please report any bugs to bonwick@eng.
33*7c478bd9Sstevel@tonic-gate#
34*7c478bd9Sstevel@tonic-gate# How Install works:
35*7c478bd9Sstevel@tonic-gate#
36*7c478bd9Sstevel@tonic-gate#	Install performs the following steps:
37*7c478bd9Sstevel@tonic-gate#
38*7c478bd9Sstevel@tonic-gate#	1. Figure out how to construct /kernel by looking at Makefile.uts,
39*7c478bd9Sstevel@tonic-gate#	   Makefile.$ISA (sparc default), Makefile.$KARCH and the Makefiles
40*7c478bd9Sstevel@tonic-gate#	   in the module directories (uts/arch/*/Makefile).
41*7c478bd9Sstevel@tonic-gate#
42*7c478bd9Sstevel@tonic-gate#	2. Create the requested subset of /kernel in Install's temp space
43*7c478bd9Sstevel@tonic-gate#	   (/tmp/Install.username by default.)
44*7c478bd9Sstevel@tonic-gate#
45*7c478bd9Sstevel@tonic-gate#	3. Create a tar file (/tmp/Install.username/Install.tar) based on (3).
46*7c478bd9Sstevel@tonic-gate#
47*7c478bd9Sstevel@tonic-gate#	4. If -n was specified, exit.  If a target was specified using -T,
48*7c478bd9Sstevel@tonic-gate#	   rcp the tarfile to the target and exit.  If a target was specified
49*7c478bd9Sstevel@tonic-gate#	   using -t, rsh to the target machine and untar the tarfile in the
50*7c478bd9Sstevel@tonic-gate#	   target directory.
51*7c478bd9Sstevel@tonic-gate#
52*7c478bd9Sstevel@tonic-gate# If any of these steps fail, Install will give you an error message and,
53*7c478bd9Sstevel@tonic-gate# in most cases, suggest corrective measures.  Then, you can recover the
54*7c478bd9Sstevel@tonic-gate# install with "Install -R". (This is not required; it's just faster than
55*7c478bd9Sstevel@tonic-gate# starting from scratch.)
56*7c478bd9Sstevel@tonic-gate#
57*7c478bd9Sstevel@tonic-gate# One final comment:  Unfortunately, tar and I disagree on what
58*7c478bd9Sstevel@tonic-gate# constitutes a fatal error.  (tar -x will exit 0 even if it can't write
59*7c478bd9Sstevel@tonic-gate# anything in the current directory.)  Thus, I am reduced to grepping stderr
60*7c478bd9Sstevel@tonic-gate# for (what I consider) fatal and nonfatal error messages.  If you run into
61*7c478bd9Sstevel@tonic-gate# a situation where this doesn't behave the way you think it should (either
62*7c478bd9Sstevel@tonic-gate# an "Install failed" message after a successful install, or an "Install
63*7c478bd9Sstevel@tonic-gate# complete" message after it bombs), please let me know.
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gate#
66*7c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
67*7c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
68*7c478bd9Sstevel@tonic-gate#
69*7c478bd9Sstevel@tonic-gateunset CDPATH
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gateINSTALL=`basename $0`
72*7c478bd9Sstevel@tonic-gateDOT=`pwd`
73*7c478bd9Sstevel@tonic-gate
74*7c478bd9Sstevel@tonic-gateTRAILER="Install.$LOGNAME"
75*7c478bd9Sstevel@tonic-gateINSTALL_STATE=${INSTALL_STATE-$HOME/.Install.state}
76*7c478bd9Sstevel@tonic-gateexport INSTALL_STATE
77*7c478bd9Sstevel@tonic-gateINSTALL_DIR=${INSTALL_DIR-/tmp/$TRAILER}
78*7c478bd9Sstevel@tonic-gateif [ "`basename $INSTALL_DIR`" != "$TRAILER" ]; then
79*7c478bd9Sstevel@tonic-gate	INSTALL_DIR="$INSTALL_DIR/$TRAILER"
80*7c478bd9Sstevel@tonic-gatefi
81*7c478bd9Sstevel@tonic-gateexport INSTALL_DIR
82*7c478bd9Sstevel@tonic-gateINSTALL_LIB=${INSTALL_LIB-$HOME/LibInstall}
83*7c478bd9Sstevel@tonic-gateexport INSTALL_LIB
84*7c478bd9Sstevel@tonic-gateINSTALL_RC=${INSTALL_RC-$HOME/.Installrc}
85*7c478bd9Sstevel@tonic-gateexport INSTALL_RC
86*7c478bd9Sstevel@tonic-gateINSTALL_CP=${INSTALL_CP-"cp -p"}
87*7c478bd9Sstevel@tonic-gateexport INSTALL_CP
88*7c478bd9Sstevel@tonic-gateINSTALL_RCP=${INSTALL_RCP-"rcp -p"}
89*7c478bd9Sstevel@tonic-gateexport INSTALL_RCP
90*7c478bd9Sstevel@tonic-gate
91*7c478bd9Sstevel@tonic-gateSTATE=0
92*7c478bd9Sstevel@tonic-gate
93*7c478bd9Sstevel@tonic-gateDEFAULT_OPTIONS="-naqX"
94*7c478bd9Sstevel@tonic-gateGLOM=no
95*7c478bd9Sstevel@tonic-gateGLOMNAME=kernel
96*7c478bd9Sstevel@tonic-gateIMPL="default"
97*7c478bd9Sstevel@tonic-gateWANT32="yes"
98*7c478bd9Sstevel@tonic-gateWANT64="yes"
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gatetrap 'fail "User Interrupt" "You can resume by typing \"$INSTALL -R\""' 1 2 3 15
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gateusage() {
103*7c478bd9Sstevel@tonic-gate	echo ""
104*7c478bd9Sstevel@tonic-gate	echo $1
105*7c478bd9Sstevel@tonic-gate	echo '
106*7c478bd9Sstevel@tonic-gateUsage: Install	[ -w workspace ]
107*7c478bd9Sstevel@tonic-gate		[ -s srcdir (default: usr/src/uts) ]
108*7c478bd9Sstevel@tonic-gate		[ -k karch (e.g. sun4u; required if not deducible from pwd) ]
109*7c478bd9Sstevel@tonic-gate		[ -t target (extract tar file on target, e.g. user@machine:/) ]
110*7c478bd9Sstevel@tonic-gate		[ -T target (copy tar file to target, e.g. user@machine:/tmp) ]
111*7c478bd9Sstevel@tonic-gate		[ -n (no target, just create tar file in /tmp (default)) ]
112*7c478bd9Sstevel@tonic-gate		[ -u (install unix only) ]
113*7c478bd9Sstevel@tonic-gate		[ -m (install modules only) ]
114*7c478bd9Sstevel@tonic-gate		[ -a (install everything, i.e. unix + modules (default)) ]
115*7c478bd9Sstevel@tonic-gate		[ -v (verbose output) ]
116*7c478bd9Sstevel@tonic-gate		[ -V (REALLY verbose output) ]
117*7c478bd9Sstevel@tonic-gate		[ -q (quiet (default)) ]
118*7c478bd9Sstevel@tonic-gate		[ -c (clean up (remove temp files) when done (default) ]
119*7c478bd9Sstevel@tonic-gate		[ -p (preserve temp files -- useful for debugging) ]
120*7c478bd9Sstevel@tonic-gate		[ -L (library create: put tarfile in $INSTALL_LIB/env.karch) ]
121*7c478bd9Sstevel@tonic-gate		[ -l lib (library extract: use $INSTALL_LIB/lib as source) ]
122*7c478bd9Sstevel@tonic-gate		[ -D libdir (default: $HOME/LibInstall) ]
123*7c478bd9Sstevel@tonic-gate		[ -d tempdir (Install work area (default: /tmp)) ]
124*7c478bd9Sstevel@tonic-gate		[ -G glomname (put all files under platform/karch/glomname) ]
125*7c478bd9Sstevel@tonic-gate		[ -i impl (e.g. sunfire; recommended with -G) ]
126*7c478bd9Sstevel@tonic-gate		[ -x (update /etc/name_to_major et al) ]
127*7c478bd9Sstevel@tonic-gate		[ -X (do not update /etc/name_to_major et al (default)) ]
128*7c478bd9Sstevel@tonic-gate		[ -P (update /etc/path_to_inst -- generally not advisable) ]
129*7c478bd9Sstevel@tonic-gate		[ -h (help -- prints this message) ]
130*7c478bd9Sstevel@tonic-gate		[ -R (recover a previous Install) ]
131*7c478bd9Sstevel@tonic-gate		[ -o objdir (object directory - either obj or debug (the default)) ]
132*7c478bd9Sstevel@tonic-gate		[ -K (do not copy kmdb) ]
133*7c478bd9Sstevel@tonic-gate		[ -3 32-bit modules only ]
134*7c478bd9Sstevel@tonic-gate		[ -6 64-bit modules only ]
135*7c478bd9Sstevel@tonic-gate		[ list of modules to install ]
136*7c478bd9Sstevel@tonic-gate
137*7c478bd9Sstevel@tonic-gateFor full details:
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate	man -M /ws/on297-gate/public/docs Install
140*7c478bd9Sstevel@tonic-gate'
141*7c478bd9Sstevel@tonic-gate	exit 1
142*7c478bd9Sstevel@tonic-gate}
143*7c478bd9Sstevel@tonic-gate
144*7c478bd9Sstevel@tonic-gate#
145*7c478bd9Sstevel@tonic-gate# Save the current state of Install
146*7c478bd9Sstevel@tonic-gate#
147*7c478bd9Sstevel@tonic-gate
148*7c478bd9Sstevel@tonic-gatesave_state() {
149*7c478bd9Sstevel@tonic-gate	rm -f $INSTALL_STATE
150*7c478bd9Sstevel@tonic-gate	(echo "# State of previous Install
151*7c478bd9Sstevel@tonic-gateTARGET=$TARGET
152*7c478bd9Sstevel@tonic-gateENV_PATH=$ENV_PATH
153*7c478bd9Sstevel@tonic-gateENV_NAME=$ENV_NAME
154*7c478bd9Sstevel@tonic-gateKARCH=$KARCH
155*7c478bd9Sstevel@tonic-gateUTS=$UTS
156*7c478bd9Sstevel@tonic-gateINSTALL_DIR=$INSTALL_DIR
157*7c478bd9Sstevel@tonic-gateINSTALL_LIB=$INSTALL_LIB
158*7c478bd9Sstevel@tonic-gateIMODE=$IMODE
159*7c478bd9Sstevel@tonic-gateLIBCREATE=$LIBCREATE
160*7c478bd9Sstevel@tonic-gateLIBSRC=$LIBSRC
161*7c478bd9Sstevel@tonic-gateVERBOSE=$VERBOSE
162*7c478bd9Sstevel@tonic-gateCLEANUP=$CLEANUP
163*7c478bd9Sstevel@tonic-gateGLOM=$GLOM
164*7c478bd9Sstevel@tonic-gateGLOMNAME=$GLOMNAME
165*7c478bd9Sstevel@tonic-gateKMDB=$KMDB
166*7c478bd9Sstevel@tonic-gateXFLAG=$XFLAG
167*7c478bd9Sstevel@tonic-gatefiles='$files'
168*7c478bd9Sstevel@tonic-gateSTATE=$STATE" >$INSTALL_STATE) || verbose "Warning: cannot save state"
169*7c478bd9Sstevel@tonic-gate}
170*7c478bd9Sstevel@tonic-gate
171*7c478bd9Sstevel@tonic-gate#
172*7c478bd9Sstevel@tonic-gate# Restore the previous state of Install
173*7c478bd9Sstevel@tonic-gate#
174*7c478bd9Sstevel@tonic-gate
175*7c478bd9Sstevel@tonic-gaterestore_state() {
176*7c478bd9Sstevel@tonic-gate	test -s $INSTALL_STATE || fail "Can't find $INSTALL_STATE"
177*7c478bd9Sstevel@tonic-gate	eval "`cat $INSTALL_STATE`"
178*7c478bd9Sstevel@tonic-gate}
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate#
181*7c478bd9Sstevel@tonic-gate# Install failed -- print error messages and exit 2
182*7c478bd9Sstevel@tonic-gate#
183*7c478bd9Sstevel@tonic-gate
184*7c478bd9Sstevel@tonic-gatefail() {
185*7c478bd9Sstevel@tonic-gate	save_state
186*7c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]
187*7c478bd9Sstevel@tonic-gate	do
188*7c478bd9Sstevel@tonic-gate		echo $1
189*7c478bd9Sstevel@tonic-gate		shift
190*7c478bd9Sstevel@tonic-gate	done
191*7c478bd9Sstevel@tonic-gate	echo "Install failed"
192*7c478bd9Sstevel@tonic-gate	exit 2
193*7c478bd9Sstevel@tonic-gate}
194*7c478bd9Sstevel@tonic-gate
195*7c478bd9Sstevel@tonic-gate#
196*7c478bd9Sstevel@tonic-gate# Echo a string in verbose mode only
197*7c478bd9Sstevel@tonic-gate#
198*7c478bd9Sstevel@tonic-gate
199*7c478bd9Sstevel@tonic-gateverbose() {
200*7c478bd9Sstevel@tonic-gate	test "$VERBOSE" != "q" && echo $1
201*7c478bd9Sstevel@tonic-gate}
202*7c478bd9Sstevel@tonic-gate
203*7c478bd9Sstevel@tonic-gate#
204*7c478bd9Sstevel@tonic-gate# hack for tmpfs bug -- remove files gradually
205*7c478bd9Sstevel@tonic-gate#
206*7c478bd9Sstevel@tonic-gate
207*7c478bd9Sstevel@tonic-gateremove_dir() {
208*7c478bd9Sstevel@tonic-gate	test -d $1 || return
209*7c478bd9Sstevel@tonic-gate	local_dot=`pwd`
210*7c478bd9Sstevel@tonic-gate	cd $1
211*7c478bd9Sstevel@tonic-gate	touch foo
212*7c478bd9Sstevel@tonic-gate	rm -f `find . -type f -print`
213*7c478bd9Sstevel@tonic-gate	cd $local_dot
214*7c478bd9Sstevel@tonic-gate	rm -rf $1
215*7c478bd9Sstevel@tonic-gate}
216*7c478bd9Sstevel@tonic-gate
217*7c478bd9Sstevel@tonic-gate#
218*7c478bd9Sstevel@tonic-gate# Copy kernel modules to $INSTALL_DIR
219*7c478bd9Sstevel@tonic-gate#
220*7c478bd9Sstevel@tonic-gate
221*7c478bd9Sstevel@tonic-gatecopy_kernel() {
222*7c478bd9Sstevel@tonic-gate	# The awk script below looks in Makefile.uts to find out what module
223*7c478bd9Sstevel@tonic-gate	# subdirectories to make.  It then looks in Makefile.$KARCH (for root
224*7c478bd9Sstevel@tonic-gate	# modules) and Makefile.$ISA (for usr modules) to create a list of
225*7c478bd9Sstevel@tonic-gate	# all possible modules.  Finally, it looks at each module's Makefile
226*7c478bd9Sstevel@tonic-gate	# to determine where it belongs and what links are required.
227*7c478bd9Sstevel@tonic-gate	# This script makes three assumptions:
228*7c478bd9Sstevel@tonic-gate	#
229*7c478bd9Sstevel@tonic-gate	# 1) Module subdirectories are specified in Makefile.uts by lines of the
230*7c478bd9Sstevel@tonic-gate	#    form:
231*7c478bd9Sstevel@tonic-gate	#
232*7c478bd9Sstevel@tonic-gate	#	ROOT_FOO_DIR = $(ROOT_MOD_DIR)/foo
233*7c478bd9Sstevel@tonic-gate	#	USR_BAR_DIR = $(USR_MOD_DIR)/bar
234*7c478bd9Sstevel@tonic-gate	#
235*7c478bd9Sstevel@tonic-gate	# 2) The corresponding lists of modules appear in Makefile.$KARCH and
236*7c478bd9Sstevel@tonic-gate	#    Makefile.$ISA on one or more lines of the form:
237*7c478bd9Sstevel@tonic-gate	#
238*7c478bd9Sstevel@tonic-gate	#	FOO_KMODS = foo bar
239*7c478bd9Sstevel@tonic-gate	#	FOO_KMODS += red white blue
240*7c478bd9Sstevel@tonic-gate	#
241*7c478bd9Sstevel@tonic-gate	# 3) Each module directory has a Makefile with lines of the form:
242*7c478bd9Sstevel@tonic-gate	#
243*7c478bd9Sstevel@tonic-gate	#	ROOTMODULE = $(ROOT_FOO_DIR)/$(MODULE)
244*7c478bd9Sstevel@tonic-gate	#	USRMODULE = $(USR_FOO_DIR)/$(MODULE)
245*7c478bd9Sstevel@tonic-gate	#	ROOTLINK* = $(ROOT_BAR_DIR)/something
246*7c478bd9Sstevel@tonic-gate	#	USRLINK* = $(USR_BAR_DIR)/something
247*7c478bd9Sstevel@tonic-gate	#
248*7c478bd9Sstevel@tonic-gate	# If the structure of Makefile.{$KARCH,uts,$ISA} changes in a way that
249*7c478bd9Sstevel@tonic-gate	# invalidates these assumptions, you'll need to pick up a new version of
250*7c478bd9Sstevel@tonic-gate	# Install.
251*7c478bd9Sstevel@tonic-gate
252*7c478bd9Sstevel@tonic-gate	case $KARCH in
253*7c478bd9Sstevel@tonic-gate		sun4*)		ISA=sparc;	MACH=sparc;	SUBISA_MAKE=;;
254*7c478bd9Sstevel@tonic-gate		i86pc)		ISA=intel;	MACH=i386;	SUBISA_MAKE=$ISA/ia32/Makefile.ia32;;
255*7c478bd9Sstevel@tonic-gate		*)		fail "${KARCH}: invalid kernel architecture";;
256*7c478bd9Sstevel@tonic-gate	esac
257*7c478bd9Sstevel@tonic-gate
258*7c478bd9Sstevel@tonic-gate	if [ "$GLOM" = "no" ]; then
259*7c478bd9Sstevel@tonic-gate		verbose "Source = $UTS, ISA = $ISA, kernel = $KARCH"
260*7c478bd9Sstevel@tonic-gate	else
261*7c478bd9Sstevel@tonic-gate		verbose "Source = $UTS, ISA = $ISA, kernel = $KARCH, impl = $IMPL"
262*7c478bd9Sstevel@tonic-gate	fi
263*7c478bd9Sstevel@tonic-gate
264*7c478bd9Sstevel@tonic-gate	UTS_MAKE=Makefile.uts
265*7c478bd9Sstevel@tonic-gate	ISA_MAKE=$ISA/Makefile.$ISA
266*7c478bd9Sstevel@tonic-gate	KARCH_MAKE=$KARCH/Makefile.$KARCH
267*7c478bd9Sstevel@tonic-gate	PSM_MAKE=$UTS/../Makefile.psm
268*7c478bd9Sstevel@tonic-gate
269*7c478bd9Sstevel@tonic-gate	test -d $KARCH || fail "${KARCH}: invalid kernel architecture"
270*7c478bd9Sstevel@tonic-gate	test -d $ISA || fail "${ISA}: invalid instruction set architecture"
271*7c478bd9Sstevel@tonic-gate	test -s $UTS_MAKE || fail "Can't find $UTS_MAKE"
272*7c478bd9Sstevel@tonic-gate	test -s $ISA_MAKE || fail "Can't find $ISA_MAKE"
273*7c478bd9Sstevel@tonic-gate	test -s $KARCH_MAKE || fail "Can't find $KARCH_MAKE"
274*7c478bd9Sstevel@tonic-gate	test -s $PSM_MAKE || fail "Can't find $PSM_MAKE"
275*7c478bd9Sstevel@tonic-gate
276*7c478bd9Sstevel@tonic-gate	#
277*7c478bd9Sstevel@tonic-gate	# For 5.8 and 5.9 we used to build a few x86 things in an ia32 subdirectory
278*7c478bd9Sstevel@tonic-gate	#
279*7c478bd9Sstevel@tonic-gate	[[ -n "$SUBISA_MAKE" && -s "$SUBISA_MAKE" ]] || SUBISA_MAKE=;
280*7c478bd9Sstevel@tonic-gate
281*7c478bd9Sstevel@tonic-gate	if [ $GLOM = "yes" ]; then
282*7c478bd9Sstevel@tonic-gate		if [ -f $KARCH/$IMPL/Makefile.$IMPL ]; then
283*7c478bd9Sstevel@tonic-gate			IMPL_MAKE="$KARCH/$IMPL/Makefile.$IMPL"
284*7c478bd9Sstevel@tonic-gate		fi
285*7c478bd9Sstevel@tonic-gate	else
286*7c478bd9Sstevel@tonic-gate		IMPL_MAKE=`nawk -v karch="$KARCH" '
287*7c478bd9Sstevel@tonic-gate			$1 == "IMPLEMENTATIONS" {
288*7c478bd9Sstevel@tonic-gate			for (i = 3; i <= NF; i++)
289*7c478bd9Sstevel@tonic-gate				if ($i != ".WAIT")
290*7c478bd9Sstevel@tonic-gate					printf("%s ", karch "/" $i "/Makefile." $i)
291*7c478bd9Sstevel@tonic-gate			}' $KARCH_MAKE`
292*7c478bd9Sstevel@tonic-gate	fi
293*7c478bd9Sstevel@tonic-gate
294*7c478bd9Sstevel@tonic-gate	DEVFS="./$ISA/devfs/Makefile"
295*7c478bd9Sstevel@tonic-gate
296*7c478bd9Sstevel@tonic-gate	verbose "Copying files to ${INSTALL_FILES}..."
297*7c478bd9Sstevel@tonic-gate	test -d $INSTALL_FILES || mkdir -p $INSTALL_FILES
298*7c478bd9Sstevel@tonic-gate
299*7c478bd9Sstevel@tonic-gate	nawk \
300*7c478bd9Sstevel@tonic-gate		-v isa="$ISA" \
301*7c478bd9Sstevel@tonic-gate		-v mach="$MACH" \
302*7c478bd9Sstevel@tonic-gate		-v insd="$INSTALL_FILES" \
303*7c478bd9Sstevel@tonic-gate		-v files="$files" \
304*7c478bd9Sstevel@tonic-gate		-v verbose=$VERBOSE \
305*7c478bd9Sstevel@tonic-gate		-v karch=$KARCH \
306*7c478bd9Sstevel@tonic-gate		-v copy="$INSTALL_CP" \
307*7c478bd9Sstevel@tonic-gate		-v devfs=$DEVFS \
308*7c478bd9Sstevel@tonic-gate		-v auxfiles=$XFLAG \
309*7c478bd9Sstevel@tonic-gate		-v ptiflag=$PFLAG \
310*7c478bd9Sstevel@tonic-gate		-v glom=$GLOM \
311*7c478bd9Sstevel@tonic-gate		-v glomname=$GLOMNAME \
312*7c478bd9Sstevel@tonic-gate		-v impl=$IMPL \
313*7c478bd9Sstevel@tonic-gate		-v objd=$OBJD \
314*7c478bd9Sstevel@tonic-gate		-v want32=$WANT32 \
315*7c478bd9Sstevel@tonic-gate		-v want64=$WANT64 \
316*7c478bd9Sstevel@tonic-gate		'
317*7c478bd9Sstevel@tonic-gate	function run(s) {
318*7c478bd9Sstevel@tonic-gate		if (verbose != "q")
319*7c478bd9Sstevel@tonic-gate			print s
320*7c478bd9Sstevel@tonic-gate		if (system(s))
321*7c478bd9Sstevel@tonic-gate			exit 1
322*7c478bd9Sstevel@tonic-gate	}
323*7c478bd9Sstevel@tonic-gate	function cpf(f1,f2) {
324*7c478bd9Sstevel@tonic-gate		if (verbose != "q")
325*7c478bd9Sstevel@tonic-gate			print copy " " f1 " " f2
326*7c478bd9Sstevel@tonic-gate		if (system(copy " " f1 " " f2))
327*7c478bd9Sstevel@tonic-gate			print "WARNING: copy of " f1 " failed"
328*7c478bd9Sstevel@tonic-gate	}
329*7c478bd9Sstevel@tonic-gate	function mkdir(dir) {
330*7c478bd9Sstevel@tonic-gate		if (!touched[dir]) {
331*7c478bd9Sstevel@tonic-gate			run("test -d " dir " || mkdir -p " dir)
332*7c478bd9Sstevel@tonic-gate			touched[dir]=1
333*7c478bd9Sstevel@tonic-gate		}
334*7c478bd9Sstevel@tonic-gate		return dir
335*7c478bd9Sstevel@tonic-gate	}
336*7c478bd9Sstevel@tonic-gate	function vprint(s) {
337*7c478bd9Sstevel@tonic-gate		if (verbose == "V")
338*7c478bd9Sstevel@tonic-gate			print s
339*7c478bd9Sstevel@tonic-gate	}
340*7c478bd9Sstevel@tonic-gate	function try_run(s) {
341*7c478bd9Sstevel@tonic-gate		if (verbose != "q")
342*7c478bd9Sstevel@tonic-gate			print s
343*7c478bd9Sstevel@tonic-gate		if (system(s))
344*7c478bd9Sstevel@tonic-gate			return 1
345*7c478bd9Sstevel@tonic-gate		return 0
346*7c478bd9Sstevel@tonic-gate	}
347*7c478bd9Sstevel@tonic-gate	function exist(s) {
348*7c478bd9Sstevel@tonic-gate		if (verbose != "q")
349*7c478bd9Sstevel@tonic-gate			print "test -f " s
350*7c478bd9Sstevel@tonic-gate		return !system("test -f " s)
351*7c478bd9Sstevel@tonic-gate	}
352*7c478bd9Sstevel@tonic-gate
353*7c478bd9Sstevel@tonic-gate	function copymod(src, targ, om) {
354*7c478bd9Sstevel@tonic-gate		if (om) {
355*7c478bd9Sstevel@tonic-gate			run("if [ -f " src " ] ; then " \
356*7c478bd9Sstevel@tonic-gate			    copy " " src " " targ " ; fi")
357*7c478bd9Sstevel@tonic-gate		} else {
358*7c478bd9Sstevel@tonic-gate			run(copy " " src " " targ)
359*7c478bd9Sstevel@tonic-gate		}
360*7c478bd9Sstevel@tonic-gate	}
361*7c478bd9Sstevel@tonic-gate
362*7c478bd9Sstevel@tonic-gate	function copymod32(idx, modtarg) {
363*7c478bd9Sstevel@tonic-gate		modsrc = modsrcd[idx] "/" objd32 "/" modname[idx]
364*7c478bd9Sstevel@tonic-gate
365*7c478bd9Sstevel@tonic-gate		if (!exist(modsrc))
366*7c478bd9Sstevel@tonic-gate			return (0)
367*7c478bd9Sstevel@tonic-gate
368*7c478bd9Sstevel@tonic-gate		copymod(modsrc, modtarg, optmod[idx])
369*7c478bd9Sstevel@tonic-gate		return (1)
370*7c478bd9Sstevel@tonic-gate	}
371*7c478bd9Sstevel@tonic-gate
372*7c478bd9Sstevel@tonic-gate	function copymod64(idx, modtarg) {
373*7c478bd9Sstevel@tonic-gate		modsrc = modsrcd[idx] "/" objd64 "/" modname[idx]
374*7c478bd9Sstevel@tonic-gate
375*7c478bd9Sstevel@tonic-gate		if (!exist(modsrc))
376*7c478bd9Sstevel@tonic-gate			return (0)
377*7c478bd9Sstevel@tonic-gate
378*7c478bd9Sstevel@tonic-gate		copymod(modsrc, modtarg subdir64, optmod[idx])
379*7c478bd9Sstevel@tonic-gate		return (1)
380*7c478bd9Sstevel@tonic-gate	}
381*7c478bd9Sstevel@tonic-gate
382*7c478bd9Sstevel@tonic-gate	function linkmod(lmod, idx, modtarg, did32, did64) {
383*7c478bd9Sstevel@tonic-gate		if (lmod ~ /^...MODULE.$/)
384*7c478bd9Sstevel@tonic-gate			lmod = "/" modname[idx]
385*7c478bd9Sstevel@tonic-gate
386*7c478bd9Sstevel@tonic-gate		if (did32 == "yes") {
387*7c478bd9Sstevel@tonic-gate			m = modtarg "/" modname[i]
388*7c478bd9Sstevel@tonic-gate			run("rm -f " dir lmod "; ln " m " " dir lmod)
389*7c478bd9Sstevel@tonic-gate		}
390*7c478bd9Sstevel@tonic-gate
391*7c478bd9Sstevel@tonic-gate		if (did64 == "yes") {
392*7c478bd9Sstevel@tonic-gate			m = modtarg subdir64 "/" modname[i]
393*7c478bd9Sstevel@tonic-gate			run("rm -f " dir subdir64 lmod "; ln " m " " \
394*7c478bd9Sstevel@tonic-gate			    dir subdir64 lmod)
395*7c478bd9Sstevel@tonic-gate		}
396*7c478bd9Sstevel@tonic-gate	}
397*7c478bd9Sstevel@tonic-gate
398*7c478bd9Sstevel@tonic-gate	function slinkmod(slinktarg, idx, modtarg, did32, did64) {
399*7c478bd9Sstevel@tonic-gate		if (did32 == "yes") {
400*7c478bd9Sstevel@tonic-gate			slink = modtarg "/" slinktarg
401*7c478bd9Sstevel@tonic-gate			run("rm -f " slink "; ln -s " modname[i] " " slink)
402*7c478bd9Sstevel@tonic-gate		}
403*7c478bd9Sstevel@tonic-gate
404*7c478bd9Sstevel@tonic-gate		if (did64 == "yes") {
405*7c478bd9Sstevel@tonic-gate			slink = modtarg subdir64 "/" slinktarg
406*7c478bd9Sstevel@tonic-gate			run("rm -f " slink "; ln -s " modname[i] " " slink)
407*7c478bd9Sstevel@tonic-gate		}
408*7c478bd9Sstevel@tonic-gate	}
409*7c478bd9Sstevel@tonic-gate
410*7c478bd9Sstevel@tonic-gate	BEGIN {
411*7c478bd9Sstevel@tonic-gate		# If you do NOT want the SVVS modules, set svvs to 0.
412*7c478bd9Sstevel@tonic-gate		svvs=1
413*7c478bd9Sstevel@tonic-gate		# If you do NOT want the excluded modules, set xmods to 0.
414*7c478bd9Sstevel@tonic-gate		xmods=1
415*7c478bd9Sstevel@tonic-gate
416*7c478bd9Sstevel@tonic-gate		machkernel = "/platform/" karch "/" glomname
417*7c478bd9Sstevel@tonic-gate
418*7c478bd9Sstevel@tonic-gate		nmods=0
419*7c478bd9Sstevel@tonic-gate		do32="no"
420*7c478bd9Sstevel@tonic-gate		do64="no"
421*7c478bd9Sstevel@tonic-gate		objd32=objd "32"
422*7c478bd9Sstevel@tonic-gate		objd64=objd "64"
423*7c478bd9Sstevel@tonic-gate		build64and32="no"
424*7c478bd9Sstevel@tonic-gate	}
425*7c478bd9Sstevel@tonic-gate
426*7c478bd9Sstevel@tonic-gate	$1 == "SUBDIR64_" mach {
427*7c478bd9Sstevel@tonic-gate		vprint($0)
428*7c478bd9Sstevel@tonic-gate		subdir64="/" $3
429*7c478bd9Sstevel@tonic-gate		subdir64_relative=$3
430*7c478bd9Sstevel@tonic-gate	}
431*7c478bd9Sstevel@tonic-gate
432*7c478bd9Sstevel@tonic-gate	FILENAME == "Makefile.uts" && $1 == "ALL_BUILDS64" {
433*7c478bd9Sstevel@tonic-gate		vprint($0)
434*7c478bd9Sstevel@tonic-gate		if ($0 ~ /32/)
435*7c478bd9Sstevel@tonic-gate			build64and32="yes"
436*7c478bd9Sstevel@tonic-gate	}
437*7c478bd9Sstevel@tonic-gate
438*7c478bd9Sstevel@tonic-gate	FILENAME == karch "/Makefile." karch && $1 == "ALL_BUILDS" {
439*7c478bd9Sstevel@tonic-gate		vprint($0)
440*7c478bd9Sstevel@tonic-gate		if ($3 ~ /32/)
441*7c478bd9Sstevel@tonic-gate			do32=want32
442*7c478bd9Sstevel@tonic-gate		if ($4 ~ /32/)
443*7c478bd9Sstevel@tonic-gate			build64and32="yes"
444*7c478bd9Sstevel@tonic-gate		if ($3 ~ /ALL_BUILDS64/ && build64and32 == "yes")
445*7c478bd9Sstevel@tonic-gate			do32=want32
446*7c478bd9Sstevel@tonic-gate		if ($3 ~ /64/ && want64)
447*7c478bd9Sstevel@tonic-gate			do64=want64
448*7c478bd9Sstevel@tonic-gate	}
449*7c478bd9Sstevel@tonic-gate
450*7c478bd9Sstevel@tonic-gate	$1 ~ /^(ROOT|USR)_.+_DIR(_32)?$/ {
451*7c478bd9Sstevel@tonic-gate		vprint($0)
452*7c478bd9Sstevel@tonic-gate		if ($3 ~ /_..CLASS..$/)
453*7c478bd9Sstevel@tonic-gate			next
454*7c478bd9Sstevel@tonic-gate		slash=index($3,"/")
455*7c478bd9Sstevel@tonic-gate		sub(/_32$/,"",$1)
456*7c478bd9Sstevel@tonic-gate		if (!slash)
457*7c478bd9Sstevel@tonic-gate			slash=length($3)+1
458*7c478bd9Sstevel@tonic-gate		parent=substr($3,3,slash-4)
459*7c478bd9Sstevel@tonic-gate		subdir=substr($3,slash)
460*7c478bd9Sstevel@tonic-gate		if (parent == "ROOT")
461*7c478bd9Sstevel@tonic-gate			child=subdir
462*7c478bd9Sstevel@tonic-gate		else if (moddirs[parent]) {
463*7c478bd9Sstevel@tonic-gate			if ($3 ~ /..PLATFORM.$/)
464*7c478bd9Sstevel@tonic-gate				child=moddirs[parent] "/" karch
465*7c478bd9Sstevel@tonic-gate			else
466*7c478bd9Sstevel@tonic-gate				child=moddirs[parent] subdir
467*7c478bd9Sstevel@tonic-gate		} else {
468*7c478bd9Sstevel@tonic-gate			print "missing mod dir " parent
469*7c478bd9Sstevel@tonic-gate			exit 1
470*7c478bd9Sstevel@tonic-gate		}
471*7c478bd9Sstevel@tonic-gate		moddirs[$1]=child
472*7c478bd9Sstevel@tonic-gate		sub(/^.*kernel/,machkernel,child)
473*7c478bd9Sstevel@tonic-gate		glomdirs[$1]=child
474*7c478bd9Sstevel@tonic-gate		n=split($1,foo,"_")
475*7c478bd9Sstevel@tonic-gate		if (n == 4 && foo[2] != "PSM")
476*7c478bd9Sstevel@tonic-gate			notdef[$1]=tolower(foo[2])
477*7c478bd9Sstevel@tonic-gate	}
478*7c478bd9Sstevel@tonic-gate
479*7c478bd9Sstevel@tonic-gate	FILENAME != isa "/Makefile." isa && $1 ~ /^(GENLIB|UNIX)_DIR$/ {
480*7c478bd9Sstevel@tonic-gate		vprint($0)
481*7c478bd9Sstevel@tonic-gate		n=split($3,foo,"/")
482*7c478bd9Sstevel@tonic-gate		slash=index($3,"/")
483*7c478bd9Sstevel@tonic-gate		dir="." substr($3,slash)
484*7c478bd9Sstevel@tonic-gate		sub(/..PLATFORM./,karch,dir)
485*7c478bd9Sstevel@tonic-gate		nmods++
486*7c478bd9Sstevel@tonic-gate		modsrcd[nmods]=dir
487*7c478bd9Sstevel@tonic-gate		modname[nmods]=foo[n]
488*7c478bd9Sstevel@tonic-gate		unixmod[nmods]=1
489*7c478bd9Sstevel@tonic-gate	}
490*7c478bd9Sstevel@tonic-gate
491*7c478bd9Sstevel@tonic-gate	FILENAME != "Makefile.uts" && $1 ~ /KMODS|XMODS/ &&
492*7c478bd9Sstevel@tonic-gate	    $1 != "GENUNIX_KMODS" {
493*7c478bd9Sstevel@tonic-gate		dir = FILENAME;
494*7c478bd9Sstevel@tonic-gate		sub(/\/Makefile.*$/, "", dir);
495*7c478bd9Sstevel@tonic-gate		if ($1 ~ "^SVVS_")
496*7c478bd9Sstevel@tonic-gate			if (svvs == 0)
497*7c478bd9Sstevel@tonic-gate				next
498*7c478bd9Sstevel@tonic-gate			else
499*7c478bd9Sstevel@tonic-gate				dir = dir "/svvs"
500*7c478bd9Sstevel@tonic-gate		if ($1 ~ "XMODS" && xmods == 0)
501*7c478bd9Sstevel@tonic-gate			next
502*7c478bd9Sstevel@tonic-gate		if ($0 !~ /\$/) {
503*7c478bd9Sstevel@tonic-gate			vprint($0)
504*7c478bd9Sstevel@tonic-gate			for (i = 3; i <= NF; i++) {
505*7c478bd9Sstevel@tonic-gate				if ($i ~ /^(ramdisk|wsdrv|vdi)$/)
506*7c478bd9Sstevel@tonic-gate					continue;
507*7c478bd9Sstevel@tonic-gate				nmods++
508*7c478bd9Sstevel@tonic-gate				modname[nmods]=$i
509*7c478bd9Sstevel@tonic-gate				modsrcd[nmods]="./" dir "/" $i
510*7c478bd9Sstevel@tonic-gate				if ($1 ~ "^MPSAS_")
511*7c478bd9Sstevel@tonic-gate					optmod[nmods] = 1
512*7c478bd9Sstevel@tonic-gate			}
513*7c478bd9Sstevel@tonic-gate		}
514*7c478bd9Sstevel@tonic-gate	}
515*7c478bd9Sstevel@tonic-gate
516*7c478bd9Sstevel@tonic-gate	FILENAME == karch "/Makefile." karch && $1 == "PLATFORMS" &&
517*7c478bd9Sstevel@tonic-gate	    $3 !~ /\(/ {
518*7c478bd9Sstevel@tonic-gate		for (i = 3; i <= NF; i++)
519*7c478bd9Sstevel@tonic-gate			mkdir(insd "/platform/" $i)
520*7c478bd9Sstevel@tonic-gate	}
521*7c478bd9Sstevel@tonic-gate
522*7c478bd9Sstevel@tonic-gate	FILENAME == karch "/Makefile." karch && ($1 == "IMPLEMENTED_PLATFORM" ||
523*7c478bd9Sstevel@tonic-gate	    $1 == "LINKED_PLATFORMS") {
524*7c478bd9Sstevel@tonic-gate		for (i = 3; i <= NF; i++)
525*7c478bd9Sstevel@tonic-gate			mkdir(insd "/platform/" $i)
526*7c478bd9Sstevel@tonic-gate	}
527*7c478bd9Sstevel@tonic-gate
528*7c478bd9Sstevel@tonic-gate	FILENAME != "Makefile.uts" && $1 == "CONFS" {
529*7c478bd9Sstevel@tonic-gate		for (i = 3; i <= NF; i++) {
530*7c478bd9Sstevel@tonic-gate			kbi_brain_damage[$i] = "yes"
531*7c478bd9Sstevel@tonic-gate		}
532*7c478bd9Sstevel@tonic-gate	}
533*7c478bd9Sstevel@tonic-gate
534*7c478bd9Sstevel@tonic-gate	END {
535*7c478bd9Sstevel@tonic-gate		split(files, modlist)
536*7c478bd9Sstevel@tonic-gate		for (m in modlist) {
537*7c478bd9Sstevel@tonic-gate			mm = modlist[m]
538*7c478bd9Sstevel@tonic-gate			if (mm == "modules") {
539*7c478bd9Sstevel@tonic-gate				for (i = 1; i <= nmods; i++)
540*7c478bd9Sstevel@tonic-gate					if (unixmod[i] == 0)
541*7c478bd9Sstevel@tonic-gate						modcopy[i]=1
542*7c478bd9Sstevel@tonic-gate				continue
543*7c478bd9Sstevel@tonic-gate			}
544*7c478bd9Sstevel@tonic-gate			nomodfound = 1
545*7c478bd9Sstevel@tonic-gate			for (i = 1; i <= nmods; i++) {
546*7c478bd9Sstevel@tonic-gate				if (modname[i] == mm) {
547*7c478bd9Sstevel@tonic-gate					modcopy[i]=1
548*7c478bd9Sstevel@tonic-gate					nomodfound = 0
549*7c478bd9Sstevel@tonic-gate				}
550*7c478bd9Sstevel@tonic-gate			}
551*7c478bd9Sstevel@tonic-gate			if (nomodfound) {
552*7c478bd9Sstevel@tonic-gate				print mm ": invalid module"
553*7c478bd9Sstevel@tonic-gate				exit 1
554*7c478bd9Sstevel@tonic-gate			}
555*7c478bd9Sstevel@tonic-gate		}
556*7c478bd9Sstevel@tonic-gate
557*7c478bd9Sstevel@tonic-gate		for(i = 1; i <= nmods; i++) {
558*7c478bd9Sstevel@tonic-gate			if (!modcopy[i])
559*7c478bd9Sstevel@tonic-gate				continue
560*7c478bd9Sstevel@tonic-gate
561*7c478bd9Sstevel@tonic-gate			confsrc = ""
562*7c478bd9Sstevel@tonic-gate			drvfiles[1] = ""
563*7c478bd9Sstevel@tonic-gate			classfile = ""
564*7c478bd9Sstevel@tonic-gate			ptifile = ""
565*7c478bd9Sstevel@tonic-gate			did32=do32
566*7c478bd9Sstevel@tonic-gate			did64=do64
567*7c478bd9Sstevel@tonic-gate			no_builds="false"
568*7c478bd9Sstevel@tonic-gate			modmake=modsrcd[i] "/Makefile"
569*7c478bd9Sstevel@tonic-gate
570*7c478bd9Sstevel@tonic-gate			while (getline <modmake > 0) {
571*7c478bd9Sstevel@tonic-gate				if ($1 == "NO_BUILDS") {
572*7c478bd9Sstevel@tonic-gate					vprint($0)
573*7c478bd9Sstevel@tonic-gate					no_builds="true"
574*7c478bd9Sstevel@tonic-gate				}
575*7c478bd9Sstevel@tonic-gate
576*7c478bd9Sstevel@tonic-gate				if ($1 == "ALL_BUILDS" && $3 ~ /64/) {
577*7c478bd9Sstevel@tonic-gate					vprint($0)
578*7c478bd9Sstevel@tonic-gate					did32="ok"
579*7c478bd9Sstevel@tonic-gate				}
580*7c478bd9Sstevel@tonic-gate
581*7c478bd9Sstevel@tonic-gate				if ($1 == "ALL_BUILDS" && $3 ~ /32/) {
582*7c478bd9Sstevel@tonic-gate					vprint($0)
583*7c478bd9Sstevel@tonic-gate					did64="ok"
584*7c478bd9Sstevel@tonic-gate				}
585*7c478bd9Sstevel@tonic-gate
586*7c478bd9Sstevel@tonic-gate				if ($1 ~ /^(MODULE|UNIX)$/) {
587*7c478bd9Sstevel@tonic-gate					vprint($0)
588*7c478bd9Sstevel@tonic-gate					modname[i] = $3
589*7c478bd9Sstevel@tonic-gate				}
590*7c478bd9Sstevel@tonic-gate
591*7c478bd9Sstevel@tonic-gate				if ($1 ~ /^(ROOT|USR)(LINK|MODULE$)/) {
592*7c478bd9Sstevel@tonic-gate					vprint($0)
593*7c478bd9Sstevel@tonic-gate					slash=index($3,"/")
594*7c478bd9Sstevel@tonic-gate					parent=substr($3,3,slash-4)
595*7c478bd9Sstevel@tonic-gate
596*7c478bd9Sstevel@tonic-gate					if (notdef[parent] &&
597*7c478bd9Sstevel@tonic-gate					    notdef[parent] != impl &&
598*7c478bd9Sstevel@tonic-gate					    glom == "yes") {
599*7c478bd9Sstevel@tonic-gate						confsrc = ""
600*7c478bd9Sstevel@tonic-gate						break
601*7c478bd9Sstevel@tonic-gate					}
602*7c478bd9Sstevel@tonic-gate
603*7c478bd9Sstevel@tonic-gate					dir = (glom == "no") ? \
604*7c478bd9Sstevel@tonic-gate					    moddirs[parent] : glomdirs[parent]
605*7c478bd9Sstevel@tonic-gate					if (!dir) {
606*7c478bd9Sstevel@tonic-gate						print "no parent for " modname[i]
607*7c478bd9Sstevel@tonic-gate						exit 1
608*7c478bd9Sstevel@tonic-gate					}
609*7c478bd9Sstevel@tonic-gate
610*7c478bd9Sstevel@tonic-gate					dir=insd dir
611*7c478bd9Sstevel@tonic-gate					mkdir(dir)
612*7c478bd9Sstevel@tonic-gate
613*7c478bd9Sstevel@tonic-gate					if (do64 == "yes")
614*7c478bd9Sstevel@tonic-gate						mkdir(dir subdir64)
615*7c478bd9Sstevel@tonic-gate
616*7c478bd9Sstevel@tonic-gate					if ($1 ~ /^(ROOT|USR)MODULE$/) {
617*7c478bd9Sstevel@tonic-gate						modtarg=dir
618*7c478bd9Sstevel@tonic-gate						conftarg=dir
619*7c478bd9Sstevel@tonic-gate						if (modname[i] in \
620*7c478bd9Sstevel@tonic-gate						    kbi_brain_damage) {
621*7c478bd9Sstevel@tonic-gate							confsrc = "./" karch \
622*7c478bd9Sstevel@tonic-gate							    "/io"
623*7c478bd9Sstevel@tonic-gate							conftarg = insd \
624*7c478bd9Sstevel@tonic-gate							    machkernel "/drv"
625*7c478bd9Sstevel@tonic-gate
626*7c478bd9Sstevel@tonic-gate							mkdir(conftarg)
627*7c478bd9Sstevel@tonic-gate
628*7c478bd9Sstevel@tonic-gate							if (do64 == "yes") {
629*7c478bd9Sstevel@tonic-gate								mkdir(conftarg \
630*7c478bd9Sstevel@tonic-gate								    subdir64)
631*7c478bd9Sstevel@tonic-gate							}
632*7c478bd9Sstevel@tonic-gate						}
633*7c478bd9Sstevel@tonic-gate
634*7c478bd9Sstevel@tonic-gate						if (do32 == "yes" &&
635*7c478bd9Sstevel@tonic-gate						    !copymod32(i, modtarg))
636*7c478bd9Sstevel@tonic-gate							did32="no"
637*7c478bd9Sstevel@tonic-gate
638*7c478bd9Sstevel@tonic-gate						if (do64 == "yes" &&
639*7c478bd9Sstevel@tonic-gate						    !copymod64(i, modtarg))
640*7c478bd9Sstevel@tonic-gate							did64="no"
641*7c478bd9Sstevel@tonic-gate
642*7c478bd9Sstevel@tonic-gate					} else {
643*7c478bd9Sstevel@tonic-gate						linkmod(substr($3, slash),
644*7c478bd9Sstevel@tonic-gate						    i, modtarg, did32, did64)
645*7c478bd9Sstevel@tonic-gate					}
646*7c478bd9Sstevel@tonic-gate				}
647*7c478bd9Sstevel@tonic-gate
648*7c478bd9Sstevel@tonic-gate				if ($1 == "SOFTLINKS") {
649*7c478bd9Sstevel@tonic-gate					vprint($0)
650*7c478bd9Sstevel@tonic-gate					for (j = 3; j <= NF; j++) {
651*7c478bd9Sstevel@tonic-gate						slinkmod($j, i, modtarg, did32,
652*7c478bd9Sstevel@tonic-gate						    did64)
653*7c478bd9Sstevel@tonic-gate					}
654*7c478bd9Sstevel@tonic-gate				}
655*7c478bd9Sstevel@tonic-gate
656*7c478bd9Sstevel@tonic-gate				if ($1 == "CONF_SRCDIR") {
657*7c478bd9Sstevel@tonic-gate					vprint($0)
658*7c478bd9Sstevel@tonic-gate					slash = index($3, "/")
659*7c478bd9Sstevel@tonic-gate					confsrc = "." substr($3, slash)
660*7c478bd9Sstevel@tonic-gate				}
661*7c478bd9Sstevel@tonic-gate			}
662*7c478bd9Sstevel@tonic-gate
663*7c478bd9Sstevel@tonic-gate			if (do32 == "yes" && did32 == "no" &&
664*7c478bd9Sstevel@tonic-gate			    no_builds == "false") {
665*7c478bd9Sstevel@tonic-gate				print "missing 32b file " confsrc "/" modname[i]
666*7c478bd9Sstevel@tonic-gate				exit 1
667*7c478bd9Sstevel@tonic-gate			}
668*7c478bd9Sstevel@tonic-gate
669*7c478bd9Sstevel@tonic-gate			if (do64 == "yes" && did64 == "no" &&
670*7c478bd9Sstevel@tonic-gate			    no_builds == "false") {
671*7c478bd9Sstevel@tonic-gate				print "missing 64b file " confsrc "/" modname[i]
672*7c478bd9Sstevel@tonic-gate				exit 1
673*7c478bd9Sstevel@tonic-gate			}
674*7c478bd9Sstevel@tonic-gate
675*7c478bd9Sstevel@tonic-gate			if (confsrc != "") {
676*7c478bd9Sstevel@tonic-gate				conffile = confsrc "/" modname[i] ".conf"
677*7c478bd9Sstevel@tonic-gate				cpf(conffile, conftarg)
678*7c478bd9Sstevel@tonic-gate			}
679*7c478bd9Sstevel@tonic-gate
680*7c478bd9Sstevel@tonic-gate			close(modmake)
681*7c478bd9Sstevel@tonic-gate		}
682*7c478bd9Sstevel@tonic-gate
683*7c478bd9Sstevel@tonic-gate		#
684*7c478bd9Sstevel@tonic-gate		# Make symlinks for KBI for different root node names for a
685*7c478bd9Sstevel@tonic-gate		# given platform
686*7c478bd9Sstevel@tonic-gate		#
687*7c478bd9Sstevel@tonic-gate		km = "./" karch "/Makefile"
688*7c478bd9Sstevel@tonic-gate		while (getline <km > 0) {
689*7c478bd9Sstevel@tonic-gate			if ($1 == "PLAT_LINKS") {
690*7c478bd9Sstevel@tonic-gate				for (i = 3; i <= NF; i++) {
691*7c478bd9Sstevel@tonic-gate					mkdir(insd "/platform")
692*7c478bd9Sstevel@tonic-gate					run("ln -s " karch " " insd \
693*7c478bd9Sstevel@tonic-gate					    "/platform/" $i)
694*7c478bd9Sstevel@tonic-gate				}
695*7c478bd9Sstevel@tonic-gate			}
696*7c478bd9Sstevel@tonic-gate		}
697*7c478bd9Sstevel@tonic-gate		close(km)
698*7c478bd9Sstevel@tonic-gate
699*7c478bd9Sstevel@tonic-gate		if (did64 == "yes" && build64and32 == "no" &&
700*7c478bd9Sstevel@tonic-gate		    (try_run("test -f " insd "/platform/" karch "/" \
701*7c478bd9Sstevel@tonic-gate		    glomname "/" subdir64_relative "/unix") == 0))
702*7c478bd9Sstevel@tonic-gate		{
703*7c478bd9Sstevel@tonic-gate			run("ln -s " subdir64_relative "/unix " insd \
704*7c478bd9Sstevel@tonic-gate			    "/platform/" karch "/" glomname "/unix")
705*7c478bd9Sstevel@tonic-gate
706*7c478bd9Sstevel@tonic-gate			if (isa == "sparc" && glom == "no" &&
707*7c478bd9Sstevel@tonic-gate			    (try_run("test -f " insd \
708*7c478bd9Sstevel@tonic-gate			     "/platform/SUNW,Ultra-Enterprise-10000/" glomname \
709*7c478bd9Sstevel@tonic-gate			     "/" subdir64_relative "/unix") == 0)) {
710*7c478bd9Sstevel@tonic-gate				run("ln -s " subdir64_relative "/unix " insd \
711*7c478bd9Sstevel@tonic-gate				    "/platform/SUNW,Ultra-Enterprise-10000/" \
712*7c478bd9Sstevel@tonic-gate				    glomname "/unix")
713*7c478bd9Sstevel@tonic-gate			}
714*7c478bd9Sstevel@tonic-gate		}
715*7c478bd9Sstevel@tonic-gate
716*7c478bd9Sstevel@tonic-gate		while (getline <devfs > 0) {
717*7c478bd9Sstevel@tonic-gate			if ($1 == "SRCDIR")
718*7c478bd9Sstevel@tonic-gate				configdir = "." substr($3, index($3, "/")) "/"
719*7c478bd9Sstevel@tonic-gate			if ($1 == "CLASSFILE")
720*7c478bd9Sstevel@tonic-gate				classfile = $3
721*7c478bd9Sstevel@tonic-gate			if ($1 == "PTIFILE")
722*7c478bd9Sstevel@tonic-gate				ptifile = $3
723*7c478bd9Sstevel@tonic-gate			if ($1 == "DRVFILES")
724*7c478bd9Sstevel@tonic-gate				split(substr($0, index($0, $3)), drvfiles)
725*7c478bd9Sstevel@tonic-gate		}
726*7c478bd9Sstevel@tonic-gate		close(devfs)
727*7c478bd9Sstevel@tonic-gate
728*7c478bd9Sstevel@tonic-gate		if (classfile != "" && auxfiles == 1) {
729*7c478bd9Sstevel@tonic-gate			dir = mkdir(targ["ROOT_DRV"])
730*7c478bd9Sstevel@tonic-gate			cpf(configdir classfile, dir)
731*7c478bd9Sstevel@tonic-gate		}
732*7c478bd9Sstevel@tonic-gate
733*7c478bd9Sstevel@tonic-gate		if (ptifile != "" && ptiflag == 1) {
734*7c478bd9Sstevel@tonic-gate			dir = mkdir(insd "/etc")
735*7c478bd9Sstevel@tonic-gate			cpf(configdir ptifile, dir)
736*7c478bd9Sstevel@tonic-gate		}
737*7c478bd9Sstevel@tonic-gate
738*7c478bd9Sstevel@tonic-gate		if (drvfiles[1] != "" && auxfiles == 1) {
739*7c478bd9Sstevel@tonic-gate			dir = mkdir(insd "/etc")
740*7c478bd9Sstevel@tonic-gate			for (file in drvfiles)
741*7c478bd9Sstevel@tonic-gate				cpf(configdir drvfiles[file], dir)
742*7c478bd9Sstevel@tonic-gate		}
743*7c478bd9Sstevel@tonic-gate	}' $UTS_MAKE $PSM_MAKE $ISA_MAKE $SUBISA_MAKE $KARCH_MAKE $IMPL_MAKE
744*7c478bd9Sstevel@tonic-gate	[[ $? -ne 0 ]] && fail "Files missing in environment"
745*7c478bd9Sstevel@tonic-gate
746*7c478bd9Sstevel@tonic-gate	#
747*7c478bd9Sstevel@tonic-gate	# on x86, add the glommed kernel name to the root archive
748*7c478bd9Sstevel@tonic-gate	#
749*7c478bd9Sstevel@tonic-gate	if [[ $KARCH = "i86pc" && $GLOM == "yes" ]]; then
750*7c478bd9Sstevel@tonic-gate		filelist="$INSTALL_FILES/etc/boot/solaris/filelist.ramdisk"
751*7c478bd9Sstevel@tonic-gate		mkdir -p `dirname $filelist`
752*7c478bd9Sstevel@tonic-gate		echo "platform/$KARCH/$GLOMNAME" >$filelist
753*7c478bd9Sstevel@tonic-gate	fi
754*7c478bd9Sstevel@tonic-gate
755*7c478bd9Sstevel@tonic-gate	STATE=1 # all kernel modules copied correctly
756*7c478bd9Sstevel@tonic-gate	save_state
757*7c478bd9Sstevel@tonic-gate}
758*7c478bd9Sstevel@tonic-gate
759*7c478bd9Sstevel@tonic-gatekmdb_copy() {
760*7c478bd9Sstevel@tonic-gate	typeset src="$1"
761*7c478bd9Sstevel@tonic-gate	typeset destdir="$2"
762*7c478bd9Sstevel@tonic-gate
763*7c478bd9Sstevel@tonic-gate	if [[ ! -d $dest ]] ; then
764*7c478bd9Sstevel@tonic-gate		[[ $VERBOSE != "q" ]] && echo "mkdir -p $destdir"
765*7c478bd9Sstevel@tonic-gate
766*7c478bd9Sstevel@tonic-gate		mkdir -p $destdir || fail "failed to create $destdir"
767*7c478bd9Sstevel@tonic-gate	fi
768*7c478bd9Sstevel@tonic-gate
769*7c478bd9Sstevel@tonic-gate	[[ $VERBOSE != "q" ]] && echo "cp $src $destdir"
770*7c478bd9Sstevel@tonic-gate
771*7c478bd9Sstevel@tonic-gate	cp $src $destdir || fail "failed to copy $src to $destdir"
772*7c478bd9Sstevel@tonic-gate}
773*7c478bd9Sstevel@tonic-gate
774*7c478bd9Sstevel@tonic-gatekmdb_copy_machkmods() {
775*7c478bd9Sstevel@tonic-gate	typeset modbase="$1"
776*7c478bd9Sstevel@tonic-gate	typeset destdir="$2"
777*7c478bd9Sstevel@tonic-gate	typeset dir=
778*7c478bd9Sstevel@tonic-gate	typeset kmod=
779*7c478bd9Sstevel@tonic-gate
780*7c478bd9Sstevel@tonic-gate	[[ ! -d $modbase ]] && return
781*7c478bd9Sstevel@tonic-gate
782*7c478bd9Sstevel@tonic-gate	for dir in $(find $modbase -name kmod) ; do
783*7c478bd9Sstevel@tonic-gate		set -- $(echo $dir |tr '/' ' ')
784*7c478bd9Sstevel@tonic-gate
785*7c478bd9Sstevel@tonic-gate		[[ $# -lt 2 ]] && fail "invalid mach kmod dir $dir"
786*7c478bd9Sstevel@tonic-gate
787*7c478bd9Sstevel@tonic-gate		shift $(($# - 2))
788*7c478bd9Sstevel@tonic-gate		kmod=$1
789*7c478bd9Sstevel@tonic-gate
790*7c478bd9Sstevel@tonic-gate		[[ ! -f $dir/$kmod ]] && continue
791*7c478bd9Sstevel@tonic-gate
792*7c478bd9Sstevel@tonic-gate		kmdb_copy $dir/$kmod $destdir
793*7c478bd9Sstevel@tonic-gate	done
794*7c478bd9Sstevel@tonic-gate}
795*7c478bd9Sstevel@tonic-gate
796*7c478bd9Sstevel@tonic-gatekmdb_copy_karchkmods() {
797*7c478bd9Sstevel@tonic-gate	typeset modbase="$1"
798*7c478bd9Sstevel@tonic-gate	typeset destdir="$2"
799*7c478bd9Sstevel@tonic-gate	typeset bitdir="$3"
800*7c478bd9Sstevel@tonic-gate	typeset dir=
801*7c478bd9Sstevel@tonic-gate	typeset kmod=
802*7c478bd9Sstevel@tonic-gate	typeset karch=
803*7c478bd9Sstevel@tonic-gate
804*7c478bd9Sstevel@tonic-gate	[[ ! -d $modbase ]] && return
805*7c478bd9Sstevel@tonic-gate
806*7c478bd9Sstevel@tonic-gate	for dir in $(find $modbase -name kmod) ; do
807*7c478bd9Sstevel@tonic-gate		set -- $(echo $dir | tr '/' ' ')
808*7c478bd9Sstevel@tonic-gate
809*7c478bd9Sstevel@tonic-gate		[[ $# -lt 3 ]] && fail "invalid karch kmod dir $dir"
810*7c478bd9Sstevel@tonic-gate
811*7c478bd9Sstevel@tonic-gate		shift $(($# - 3))
812*7c478bd9Sstevel@tonic-gate		kmod=$1
813*7c478bd9Sstevel@tonic-gate		bdir=$2
814*7c478bd9Sstevel@tonic-gate
815*7c478bd9Sstevel@tonic-gate		[[ $bdir != $bitdir ]] && continue
816*7c478bd9Sstevel@tonic-gate		[[ ! -f $dir/$1 ]] && continue
817*7c478bd9Sstevel@tonic-gate
818*7c478bd9Sstevel@tonic-gate		kmdb_copy $dir/$kmod $destdir
819*7c478bd9Sstevel@tonic-gate	done
820*7c478bd9Sstevel@tonic-gate}
821*7c478bd9Sstevel@tonic-gate
822*7c478bd9Sstevel@tonic-gatekmdb_copy_kmdbmod() {
823*7c478bd9Sstevel@tonic-gate	typeset kmdbpath="$1"
824*7c478bd9Sstevel@tonic-gate	typeset destdir="$2"
825*7c478bd9Sstevel@tonic-gate
826*7c478bd9Sstevel@tonic-gate	[[ ! -f $kmdbpath ]] && return 1
827*7c478bd9Sstevel@tonic-gate
828*7c478bd9Sstevel@tonic-gate	kmdb_copy $kmdbpath $destdir
829*7c478bd9Sstevel@tonic-gate
830*7c478bd9Sstevel@tonic-gate	return 0
831*7c478bd9Sstevel@tonic-gate}
832*7c478bd9Sstevel@tonic-gate
833*7c478bd9Sstevel@tonic-gatecopy_kmdb() {
834*7c478bd9Sstevel@tonic-gate	typeset kmdbtgtdir=$INSTALL_FILES/platform/$KARCH/$GLOMNAME/misc
835*7c478bd9Sstevel@tonic-gate	typeset bitdirs=
836*7c478bd9Sstevel@tonic-gate	typeset isadir=
837*7c478bd9Sstevel@tonic-gate	typeset b64srcdir=
838*7c478bd9Sstevel@tonic-gate	typeset b64tgtdir=
839*7c478bd9Sstevel@tonic-gate	typeset b32srcdir=
840*7c478bd9Sstevel@tonic-gate	typeset b32tgtdir=
841*7c478bd9Sstevel@tonic-gate	typeset machdir=
842*7c478bd9Sstevel@tonic-gate	typeset platdir=
843*7c478bd9Sstevel@tonic-gate
844*7c478bd9Sstevel@tonic-gate	if [[ $KMDB = "no" || ! -d $SRC/cmd/mdb ]] ; then
845*7c478bd9Sstevel@tonic-gate		# The kmdb copy was suppressed or the workspace doesn't contain
846*7c478bd9Sstevel@tonic-gate		# the mdb subtree.  Either way, there's nothing to do.
847*7c478bd9Sstevel@tonic-gate		STATE=2
848*7c478bd9Sstevel@tonic-gate		save_state
849*7c478bd9Sstevel@tonic-gate		return
850*7c478bd9Sstevel@tonic-gate	fi
851*7c478bd9Sstevel@tonic-gate
852*7c478bd9Sstevel@tonic-gate	if [[ $(mach) = "i386" ]] ; then
853*7c478bd9Sstevel@tonic-gate		isadir="intel"
854*7c478bd9Sstevel@tonic-gate		b64srcdir="amd64"
855*7c478bd9Sstevel@tonic-gate		b64tgtdir="amd64"
856*7c478bd9Sstevel@tonic-gate		b32srcdir="ia32"
857*7c478bd9Sstevel@tonic-gate		b32tgtdir="."
858*7c478bd9Sstevel@tonic-gate	else
859*7c478bd9Sstevel@tonic-gate		isadir="sparc"
860*7c478bd9Sstevel@tonic-gate		b64srcdir="v9"
861*7c478bd9Sstevel@tonic-gate		b64tgtdir="sparcv9"
862*7c478bd9Sstevel@tonic-gate		b32srcdir="v7"
863*7c478bd9Sstevel@tonic-gate		b32tgtdir="."
864*7c478bd9Sstevel@tonic-gate	fi
865*7c478bd9Sstevel@tonic-gate
866*7c478bd9Sstevel@tonic-gate	typeset foundkmdb=no
867*7c478bd9Sstevel@tonic-gate	typeset kmdbpath=
868*7c478bd9Sstevel@tonic-gate
869*7c478bd9Sstevel@tonic-gate	platdir=$INSTALL_FILES/platform/$KARCH/$GLOMNAME
870*7c478bd9Sstevel@tonic-gate	if [[ $GLOM = "yes" ]] ; then
871*7c478bd9Sstevel@tonic-gate		machdir=$platdir
872*7c478bd9Sstevel@tonic-gate	else
873*7c478bd9Sstevel@tonic-gate		machdir=$INSTALL_FILES/kernel
874*7c478bd9Sstevel@tonic-gate	fi
875*7c478bd9Sstevel@tonic-gate
876*7c478bd9Sstevel@tonic-gate	kmdbpath=$SRC/cmd/mdb/$KARCH/$b64srcdir/kmdb/kmdbmod
877*7c478bd9Sstevel@tonic-gate	if [[ $WANT64 = "yes" ]] ; then
878*7c478bd9Sstevel@tonic-gate		if kmdb_copy_kmdbmod $kmdbpath $platdir/misc/$b64tgtdir ; then
879*7c478bd9Sstevel@tonic-gate			foundkmdb="yes"
880*7c478bd9Sstevel@tonic-gate
881*7c478bd9Sstevel@tonic-gate			kmdb_copy_machkmods $SRC/cmd/mdb/$isadir/$b64srcdir \
882*7c478bd9Sstevel@tonic-gate			    $machdir/kmdb/$b64tgtdir
883*7c478bd9Sstevel@tonic-gate			kmdb_copy_karchkmods $SRC/cmd/mdb/$KARCH \
884*7c478bd9Sstevel@tonic-gate			    $platdir/kmdb/$b64tgtdir $b64srcdir
885*7c478bd9Sstevel@tonic-gate		fi
886*7c478bd9Sstevel@tonic-gate	fi
887*7c478bd9Sstevel@tonic-gate
888*7c478bd9Sstevel@tonic-gate	kmdbpath=$SRC/cmd/mdb/$isadir/$b32srcdir/kmdb/kmdbmod
889*7c478bd9Sstevel@tonic-gate	if [[ $WANT32 = "yes" ]] ; then
890*7c478bd9Sstevel@tonic-gate		if kmdb_copy_kmdbmod $kmdbpath $machdir/misc/$b32tgtdir ; then
891*7c478bd9Sstevel@tonic-gate			foundkmdb="yes"
892*7c478bd9Sstevel@tonic-gate
893*7c478bd9Sstevel@tonic-gate			kmdb_copy_machkmods $SRC/cmd/mdb/$isadir/$b32srcdir \
894*7c478bd9Sstevel@tonic-gate			    $machdir/kmdb/$b32tgtdir
895*7c478bd9Sstevel@tonic-gate			kmdb_copy_karchkmods $SRC/cmd/mdb/$KARCH \
896*7c478bd9Sstevel@tonic-gate			    $platdir/kmdb/$b32tgtdir $b32srcdir
897*7c478bd9Sstevel@tonic-gate		fi
898*7c478bd9Sstevel@tonic-gate	fi
899*7c478bd9Sstevel@tonic-gate
900*7c478bd9Sstevel@tonic-gate	# A kmdb-less workspace isn't fatal, but it is potentially problematic,
901*7c478bd9Sstevel@tonic-gate	# as the changes made to uts may have altered something upon which kmdb
902*7c478bd9Sstevel@tonic-gate	# depends.  We will therefore remind the user that they haven't built it
903*7c478bd9Sstevel@tonic-gate	# yet.
904*7c478bd9Sstevel@tonic-gate	if [[ $foundkmdb != "yes" ]] ; then
905*7c478bd9Sstevel@tonic-gate		echo "WARNING: kmdb isn't built, and won't be included"
906*7c478bd9Sstevel@tonic-gate	fi
907*7c478bd9Sstevel@tonic-gate
908*7c478bd9Sstevel@tonic-gate	STATE=2
909*7c478bd9Sstevel@tonic-gate	save_state
910*7c478bd9Sstevel@tonic-gate	return
911*7c478bd9Sstevel@tonic-gate}
912*7c478bd9Sstevel@tonic-gate
913*7c478bd9Sstevel@tonic-gate#
914*7c478bd9Sstevel@tonic-gate# Make tarfile
915*7c478bd9Sstevel@tonic-gate#
916*7c478bd9Sstevel@tonic-gate
917*7c478bd9Sstevel@tonic-gatemake_tarfile() {
918*7c478bd9Sstevel@tonic-gate	echo "Creating tarfile $TARFILE"
919*7c478bd9Sstevel@tonic-gate	test -d $INSTALL_FILES || fail "Can't find $INSTALL_FILES"
920*7c478bd9Sstevel@tonic-gate	cd $INSTALL_FILES
921*7c478bd9Sstevel@tonic-gate	rm -f $TARFILE files
922*7c478bd9Sstevel@tonic-gate
923*7c478bd9Sstevel@tonic-gate	# We don't want to change the permissions or ownership of pre-existing
924*7c478bd9Sstevel@tonic-gate	# directories on the target machine, so we're going to take care to
925*7c478bd9Sstevel@tonic-gate	# avoid including directories in the tarfile.  On extraction, tar won't
926*7c478bd9Sstevel@tonic-gate	# modify pre-existing directories, and will create non-existent ones as
927*7c478bd9Sstevel@tonic-gate	# the user doing the extraction.
928*7c478bd9Sstevel@tonic-gate	find . ! -type d -print |fgrep -vx './files' >files
929*7c478bd9Sstevel@tonic-gate	tar cf $TARFILE -I files || fail "Couldn't create tarfile $TARFILE"
930*7c478bd9Sstevel@tonic-gate	STATE=3
931*7c478bd9Sstevel@tonic-gate}
932*7c478bd9Sstevel@tonic-gate
933*7c478bd9Sstevel@tonic-gate#
934*7c478bd9Sstevel@tonic-gate# Routines to copy files to the target machine
935*7c478bd9Sstevel@tonic-gate#
936*7c478bd9Sstevel@tonic-gate
937*7c478bd9Sstevel@tonic-gateremote_fail() {
938*7c478bd9Sstevel@tonic-gate	fail "" "$1" "" \
939*7c478bd9Sstevel@tonic-gate		"Make sure that $TARGET_MACHINE is up." \
940*7c478bd9Sstevel@tonic-gate"Check .rhosts in the home directory of user $TARGET_USER on $TARGET_MACHINE." \
941*7c478bd9Sstevel@tonic-gate		"Check /etc/hosts.equiv, /etc/passwd, and /etc/shadow." \
942*7c478bd9Sstevel@tonic-gate		"Change permissions on $TARGET_MACHINE as necessary." \
943*7c478bd9Sstevel@tonic-gate		"Then, use \"$INSTALL -R\" to resume the install." ""
944*7c478bd9Sstevel@tonic-gate}
945*7c478bd9Sstevel@tonic-gate
946*7c478bd9Sstevel@tonic-gateremote_install() {
947*7c478bd9Sstevel@tonic-gate	if [ "$IMODE" = "n" ]; then
948*7c478bd9Sstevel@tonic-gate		STATE=4
949*7c478bd9Sstevel@tonic-gate		return 0
950*7c478bd9Sstevel@tonic-gate	fi
951*7c478bd9Sstevel@tonic-gate	test -s $TARFILE || fail "$TARFILE missing or empty"
952*7c478bd9Sstevel@tonic-gate	verbose "Installing system on $TARGET"
953*7c478bd9Sstevel@tonic-gate	test -d $INSTALL_DIR || fail "Can't find $INSTALL_DIR"
954*7c478bd9Sstevel@tonic-gate	cd $INSTALL_DIR
955*7c478bd9Sstevel@tonic-gate	rm -f errors fatal nonfatal
956*7c478bd9Sstevel@tonic-gate	if [ "$IMODE" = "T" ]; then
957*7c478bd9Sstevel@tonic-gate		EMESG="Can't rcp to $TARGET"
958*7c478bd9Sstevel@tonic-gate		touch errors
959*7c478bd9Sstevel@tonic-gate		sh -e${SHV}c "$INSTALL_RCP $TARFILE $TARGET/Install.tar"
960*7c478bd9Sstevel@tonic-gate	else
961*7c478bd9Sstevel@tonic-gate		EMESG="Can't rsh to $TARGET_MACHINE"
962*7c478bd9Sstevel@tonic-gate		rsh -l $TARGET_USER $TARGET_MACHINE \
963*7c478bd9Sstevel@tonic-gate		    "(cd $TARGET_DIR; /usr/bin/tar x${V}f -)" \
964*7c478bd9Sstevel@tonic-gate		    <$TARFILE 2>errors
965*7c478bd9Sstevel@tonic-gate	fi
966*7c478bd9Sstevel@tonic-gate	test $? -ne 0 && remote_fail "$EMESG"
967*7c478bd9Sstevel@tonic-gate	cd $INSTALL_DIR
968*7c478bd9Sstevel@tonic-gate	egrep "set time|warning|blocksize" errors >nonfatal
969*7c478bd9Sstevel@tonic-gate	egrep -v "set time|warning|blocksize" errors >fatal
970*7c478bd9Sstevel@tonic-gate	if [ -s fatal ]; then
971*7c478bd9Sstevel@tonic-gate		echo "Fatal errors from rsh:"
972*7c478bd9Sstevel@tonic-gate		cat fatal
973*7c478bd9Sstevel@tonic-gate		remote_fail "Can't install on $TARGET_MACHINE"
974*7c478bd9Sstevel@tonic-gate	fi
975*7c478bd9Sstevel@tonic-gate	if [ -s nonfatal -a "$VERBOSE" != "q" ]; then
976*7c478bd9Sstevel@tonic-gate		echo "Non-fatal errors from rsh:"
977*7c478bd9Sstevel@tonic-gate		cat nonfatal
978*7c478bd9Sstevel@tonic-gate	fi
979*7c478bd9Sstevel@tonic-gate	rm -f fatal nonfatal errors
980*7c478bd9Sstevel@tonic-gate	test "$IMODE" = "T" && echo "Files can be extracted on \
981*7c478bd9Sstevel@tonic-gate$TARGET_MACHINE using 'tar xvf $TARGET_DIR/Install.tar'"
982*7c478bd9Sstevel@tonic-gate	STATE=4
983*7c478bd9Sstevel@tonic-gate}
984*7c478bd9Sstevel@tonic-gate
985*7c478bd9Sstevel@tonic-gateokexit() {
986*7c478bd9Sstevel@tonic-gate	cd /tmp
987*7c478bd9Sstevel@tonic-gate	test "$CLEANUP" = c && remove_dir $INSTALL_DIR
988*7c478bd9Sstevel@tonic-gate	save_state
989*7c478bd9Sstevel@tonic-gate	verbose "Install complete"
990*7c478bd9Sstevel@tonic-gate	exit 0
991*7c478bd9Sstevel@tonic-gate}
992*7c478bd9Sstevel@tonic-gate
993*7c478bd9Sstevel@tonic-gate#
994*7c478bd9Sstevel@tonic-gate# Process options
995*7c478bd9Sstevel@tonic-gate#
996*7c478bd9Sstevel@tonic-gate
997*7c478bd9Sstevel@tonic-gateRCOPTS=""
998*7c478bd9Sstevel@tonic-gateLIBCREATE="no"
999*7c478bd9Sstevel@tonic-gateLIBSRC=""
1000*7c478bd9Sstevel@tonic-gatePFLAG=0
1001*7c478bd9Sstevel@tonic-gateENV_PATH=$CODEMGR_WS
1002*7c478bd9Sstevel@tonic-gateOBJD="debug"
1003*7c478bd9Sstevel@tonic-gateKMDB="yes"
1004*7c478bd9Sstevel@tonic-gate
1005*7c478bd9Sstevel@tonic-gatetest -s $INSTALL_RC && RCOPTS=`cat $INSTALL_RC`
1006*7c478bd9Sstevel@tonic-gateset $INSTALL $DEFAULT_OPTIONS $RCOPTS $*
1007*7c478bd9Sstevel@tonic-gateshift
1008*7c478bd9Sstevel@tonic-gate
1009*7c478bd9Sstevel@tonic-gatewhile getopts acd:D:G:hi:k:Kl:Lmno:pPqRs:t:T:uvVw:xX36 opt
1010*7c478bd9Sstevel@tonic-gatedo
1011*7c478bd9Sstevel@tonic-gate	case $opt in
1012*7c478bd9Sstevel@tonic-gate	    w)	ENV_PATH="$OPTARG"; SRC="$ENV_PATH/usr/src";;
1013*7c478bd9Sstevel@tonic-gate	    s)	UTS="$OPTARG";;
1014*7c478bd9Sstevel@tonic-gate	    k)	KARCH="$OPTARG";;
1015*7c478bd9Sstevel@tonic-gate	  t|T)	TARGET="$OPTARG"; IMODE=$opt; CLEANUP="c";;
1016*7c478bd9Sstevel@tonic-gate	    n)	TARGET=""; IMODE="n"; CLEANUP="p";;
1017*7c478bd9Sstevel@tonic-gate	    u)	files="unix genunix";;
1018*7c478bd9Sstevel@tonic-gate	    m)	files="modules";;
1019*7c478bd9Sstevel@tonic-gate	    a)	files="unix genunix modules";;
1020*7c478bd9Sstevel@tonic-gate	v|V|q)	VERBOSE=$opt;;
1021*7c478bd9Sstevel@tonic-gate	  c|p)	CLEANUP=$opt;;
1022*7c478bd9Sstevel@tonic-gate	    L)	LIBCREATE="yes"; CLEANUP="c";;
1023*7c478bd9Sstevel@tonic-gate	    l)	LIBSRC="$OPTARG";;
1024*7c478bd9Sstevel@tonic-gate	    D)	INSTALL_LIB="$OPTARG";;
1025*7c478bd9Sstevel@tonic-gate	    d)	INSTALL_DIR="$OPTARG/$TRAILER";;
1026*7c478bd9Sstevel@tonic-gate	    G)	GLOM=yes; GLOMNAME="$OPTARG";;
1027*7c478bd9Sstevel@tonic-gate	    x)	XFLAG=1;;
1028*7c478bd9Sstevel@tonic-gate	    X)	XFLAG=0;;
1029*7c478bd9Sstevel@tonic-gate	    P)	PFLAG=1;;
1030*7c478bd9Sstevel@tonic-gate	    h)	usage "${INSTALL}: installs unix and modules";;
1031*7c478bd9Sstevel@tonic-gate	    R)	x=$OPTIND; restore_state; OPTIND=$x;;
1032*7c478bd9Sstevel@tonic-gate	    i)	IMPL="$OPTARG";;
1033*7c478bd9Sstevel@tonic-gate	    o)	OBJD="$OPTARG";;
1034*7c478bd9Sstevel@tonic-gate	    K)  KMDB="no";;
1035*7c478bd9Sstevel@tonic-gate	    3)  WANT64="no";;
1036*7c478bd9Sstevel@tonic-gate	    6)  WANT32="no";;
1037*7c478bd9Sstevel@tonic-gate	   \?)	usage "Illegal option";;
1038*7c478bd9Sstevel@tonic-gate	esac
1039*7c478bd9Sstevel@tonic-gatedone
1040*7c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
1041*7c478bd9Sstevel@tonic-gate
1042*7c478bd9Sstevel@tonic-gateENV_NAME=`basename $ENV_PATH`
1043*7c478bd9Sstevel@tonic-gate
1044*7c478bd9Sstevel@tonic-gate#
1045*7c478bd9Sstevel@tonic-gate# The rest of the command line is a list of individual files to copy.
1046*7c478bd9Sstevel@tonic-gate# If non-null, this list overrides the -uma options.
1047*7c478bd9Sstevel@tonic-gate#
1048*7c478bd9Sstevel@tonic-gate
1049*7c478bd9Sstevel@tonic-gateif [[ $# -gt 0 ]] ; then
1050*7c478bd9Sstevel@tonic-gate	files="$*"
1051*7c478bd9Sstevel@tonic-gate	KMDB="no"
1052*7c478bd9Sstevel@tonic-gatefi
1053*7c478bd9Sstevel@tonic-gate
1054*7c478bd9Sstevel@tonic-gatecase $VERBOSE in
1055*7c478bd9Sstevel@tonic-gate	v)	V="v"; SHV="x";;
1056*7c478bd9Sstevel@tonic-gate	V)	V="v"; SHV="x"; set -x;;
1057*7c478bd9Sstevel@tonic-gate	q)	V=""; SHV="";;
1058*7c478bd9Sstevel@tonic-gateesac
1059*7c478bd9Sstevel@tonic-gate
1060*7c478bd9Sstevel@tonic-gate#
1061*7c478bd9Sstevel@tonic-gate# Create temp directory for Install's files
1062*7c478bd9Sstevel@tonic-gate#
1063*7c478bd9Sstevel@tonic-gate
1064*7c478bd9Sstevel@tonic-gatetest -d $INSTALL_DIR || mkdir -p $INSTALL_DIR || fail "Can't mkdir $INSTALL_DIR"
1065*7c478bd9Sstevel@tonic-gate
1066*7c478bd9Sstevel@tonic-gateTARFILE=$INSTALL_DIR/Install.${KARCH}.tar
1067*7c478bd9Sstevel@tonic-gateINSTALL_FILES=$INSTALL_DIR/$KARCH
1068*7c478bd9Sstevel@tonic-gate
1069*7c478bd9Sstevel@tonic-gate#
1070*7c478bd9Sstevel@tonic-gate# Extract the target machine and target directory from a target of the
1071*7c478bd9Sstevel@tonic-gate# form [user@]machine:/dir .
1072*7c478bd9Sstevel@tonic-gate#
1073*7c478bd9Sstevel@tonic-gate
1074*7c478bd9Sstevel@tonic-gateif [ "$IMODE" != "n" ]; then
1075*7c478bd9Sstevel@tonic-gate	eval `echo $TARGET | nawk -F':' '{
1076*7c478bd9Sstevel@tonic-gate		if (NF != 2 || !length($1) || !length($2))
1077*7c478bd9Sstevel@tonic-gate			print "usage \"Invalid target\""
1078*7c478bd9Sstevel@tonic-gate		m = $1; d = $2
1079*7c478bd9Sstevel@tonic-gate		if ($1 ~ /@/) {
1080*7c478bd9Sstevel@tonic-gate		    k = split($1, f, "@");
1081*7c478bd9Sstevel@tonic-gate		    if (k != 2 || !length(f[1]) || !length (f[2]))
1082*7c478bd9Sstevel@tonic-gate			    print "usage \"Invalid target\""
1083*7c478bd9Sstevel@tonic-gate		    u = f[1]; m = f[2]
1084*7c478bd9Sstevel@tonic-gate		}
1085*7c478bd9Sstevel@tonic-gate		print "TARGET_USER=" u ";"
1086*7c478bd9Sstevel@tonic-gate		print "TARGET_MACHINE=" m ";"
1087*7c478bd9Sstevel@tonic-gate		print "TARGET_DIR=" d ";"
1088*7c478bd9Sstevel@tonic-gate	}'`
1089*7c478bd9Sstevel@tonic-gate	if [ -z "$TARGET_USER" ]; then
1090*7c478bd9Sstevel@tonic-gate		TARGET_USER=$LOGNAME
1091*7c478bd9Sstevel@tonic-gate	fi
1092*7c478bd9Sstevel@tonic-gatefi
1093*7c478bd9Sstevel@tonic-gate
1094*7c478bd9Sstevel@tonic-gate#
1095*7c478bd9Sstevel@tonic-gate# Allow the use of library source or target for the install
1096*7c478bd9Sstevel@tonic-gate#
1097*7c478bd9Sstevel@tonic-gate
1098*7c478bd9Sstevel@tonic-gateif [ -n "$LIBSRC" ]; then
1099*7c478bd9Sstevel@tonic-gate	LIBSRC="`basename $LIBSRC .tar`.tar"
1100*7c478bd9Sstevel@tonic-gate	TARFILE=$INSTALL_LIB/$LIBSRC
1101*7c478bd9Sstevel@tonic-gate	test -s $TARFILE || fail "Can't find tarfile $TARFILE"
1102*7c478bd9Sstevel@tonic-gate	verbose "Installing from library tarfile $TARFILE"
1103*7c478bd9Sstevel@tonic-gate	STATE=3
1104*7c478bd9Sstevel@tonic-gateelif [ "$LIBCREATE" = "yes" ]; then
1105*7c478bd9Sstevel@tonic-gate	test -d $INSTALL_LIB \
1106*7c478bd9Sstevel@tonic-gate		|| mkdir -p $INSTALL_LIB \
1107*7c478bd9Sstevel@tonic-gate		|| fail "Can't mkdir $INSTALL_LIB"
1108*7c478bd9Sstevel@tonic-gate	TARFILE="$INSTALL_LIB/${ENV_NAME}.${KARCH}.tar"
1109*7c478bd9Sstevel@tonic-gatefi
1110*7c478bd9Sstevel@tonic-gate
1111*7c478bd9Sstevel@tonic-gate#
1112*7c478bd9Sstevel@tonic-gate# The next three lines allow recovery and activation with -R,
1113*7c478bd9Sstevel@tonic-gate# and library installs with -l.
1114*7c478bd9Sstevel@tonic-gate#
1115*7c478bd9Sstevel@tonic-gate
1116*7c478bd9Sstevel@tonic-gate[[ $STATE -eq 1 ]] && copy_kmdb
1117*7c478bd9Sstevel@tonic-gate[[ $STATE -eq 2 ]] && make_tarfile
1118*7c478bd9Sstevel@tonic-gate[[ $STATE -eq 3 ]] && remote_install
1119*7c478bd9Sstevel@tonic-gate[[ $STATE -eq 4 ]] && okexit
1120*7c478bd9Sstevel@tonic-gate
1121*7c478bd9Sstevel@tonic-gatesave_state
1122*7c478bd9Sstevel@tonic-gate
1123*7c478bd9Sstevel@tonic-gatecd $DOT
1124*7c478bd9Sstevel@tonic-gateDOTDOT=`cd ..; pwd`
1125*7c478bd9Sstevel@tonic-gate
1126*7c478bd9Sstevel@tonic-gate#
1127*7c478bd9Sstevel@tonic-gate# Try to be smart: if DOTDOT ends in uts, then infer UTS and KARCH from DOT
1128*7c478bd9Sstevel@tonic-gate# Otherwise, if SRC is set, infer UTS = $SRC/uts.
1129*7c478bd9Sstevel@tonic-gate#
1130*7c478bd9Sstevel@tonic-gate
1131*7c478bd9Sstevel@tonic-gateif [ "`basename $DOTDOT`" = "uts" ]; then
1132*7c478bd9Sstevel@tonic-gate	UTS=$DOTDOT
1133*7c478bd9Sstevel@tonic-gate	KARCH=`basename $DOT`
1134*7c478bd9Sstevel@tonic-gatefi
1135*7c478bd9Sstevel@tonic-gate
1136*7c478bd9Sstevel@tonic-gateif [ -z "$UTS" -a -n "$SRC" ]; then
1137*7c478bd9Sstevel@tonic-gate	UTS="${SRC}/uts"
1138*7c478bd9Sstevel@tonic-gate	test -n "$KARCH" || fail "no karch specified (e.g. -k sun4u)"
1139*7c478bd9Sstevel@tonic-gatefi
1140*7c478bd9Sstevel@tonic-gate
1141*7c478bd9Sstevel@tonic-gateif [ "$LIBCREATE" = "yes" ]; then
1142*7c478bd9Sstevel@tonic-gate	TARFILE=$INSTALL_LIB/${ENV_NAME}.${KARCH}.tar
1143*7c478bd9Sstevel@tonic-gateelse
1144*7c478bd9Sstevel@tonic-gate	TARFILE=$INSTALL_DIR/Install.${KARCH}.tar
1145*7c478bd9Sstevel@tonic-gatefi
1146*7c478bd9Sstevel@tonic-gateINSTALL_FILES=$INSTALL_DIR/$KARCH
1147*7c478bd9Sstevel@tonic-gatesave_state
1148*7c478bd9Sstevel@tonic-gate
1149*7c478bd9Sstevel@tonic-gatecd $DOT
1150*7c478bd9Sstevel@tonic-gatetest -z "$UTS" && fail 'Cannot find kernel sources -- $SRC not set'
1151*7c478bd9Sstevel@tonic-gatetest -d "$UTS" || fail "${UTS}: no such directory"
1152*7c478bd9Sstevel@tonic-gate
1153*7c478bd9Sstevel@tonic-gate#
1154*7c478bd9Sstevel@tonic-gate# Convert UTS into an absolute path.
1155*7c478bd9Sstevel@tonic-gate#
1156*7c478bd9Sstevel@tonic-gate
1157*7c478bd9Sstevel@tonic-gatecd $UTS
1158*7c478bd9Sstevel@tonic-gateUTS=`pwd`
1159*7c478bd9Sstevel@tonic-gate
1160*7c478bd9Sstevel@tonic-gatetest "`basename $UTS`" = "uts" || \
1161*7c478bd9Sstevel@tonic-gate	verbose "Warning: source path $UTS doesn't end in 'uts'"
1162*7c478bd9Sstevel@tonic-gate
1163*7c478bd9Sstevel@tonic-gateremove_dir $INSTALL_DIR/$KARCH
1164*7c478bd9Sstevel@tonic-gaterm -f $TARFILE
1165*7c478bd9Sstevel@tonic-gate
1166*7c478bd9Sstevel@tonic-gatecopy_kernel	# sets STATE=1 if successful
1167*7c478bd9Sstevel@tonic-gatecopy_kmdb	# sets STATE=2 if successful
1168*7c478bd9Sstevel@tonic-gatemake_tarfile	# sets STATE=3 if successful
1169*7c478bd9Sstevel@tonic-gateremote_install	# sets STATE=4 if successful
1170*7c478bd9Sstevel@tonic-gate
1171*7c478bd9Sstevel@tonic-gateokexit
1172