1986fd29aSsetje#!/bin/ksh -p
2986fd29aSsetje#
3986fd29aSsetje# CDDL HEADER START
4986fd29aSsetje#
5986fd29aSsetje# The contents of this file are subject to the terms of the
6986fd29aSsetje# Common Development and Distribution License (the "License").
7986fd29aSsetje# You may not use this file except in compliance with the License.
8986fd29aSsetje#
9986fd29aSsetje# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10986fd29aSsetje# or http://www.opensolaris.org/os/licensing.
11986fd29aSsetje# See the License for the specific language governing permissions
12986fd29aSsetje# and limitations under the License.
13986fd29aSsetje#
14986fd29aSsetje# When distributing Covered Code, include this CDDL HEADER in each
15986fd29aSsetje# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16986fd29aSsetje# If applicable, add the following below this CDDL HEADER, with the
17986fd29aSsetje# fields enclosed by brackets "[]" replaced with your own identifying
18986fd29aSsetje# information: Portions Copyright [yyyy] [name of copyright owner]
19986fd29aSsetje#
20986fd29aSsetje# CDDL HEADER END
21986fd29aSsetje#
22d876c67dSjg# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23986fd29aSsetje# Use is subject to license terms.
24986fd29aSsetje#
25986fd29aSsetje
26986fd29aSsetje#
27986fd29aSsetje# set path, but inherit /tmp/bfubin if it is sane
28986fd29aSsetje#
29986fd29aSsetjeif [ "`echo $PATH | cut -f 1 -d :`" = /tmp/bfubin ] && \
30986fd29aSsetje    [ -O /tmp/bfubin ] ; then
31986fd29aSsetje	export PATH=/tmp/bfubin:/usr/sbin:/usr/bin:/sbin
32986fd29aSsetjeelse
33986fd29aSsetje	export PATH=/usr/sbin:/usr/bin:/sbin
34986fd29aSsetjefi
35986fd29aSsetje
36986fd29aSsetjeusage() {
37*bbf21555SRichard Lowe	echo "This utility is a component of the bootadm(8) implementation"
38d876c67dSjg	echo "and it is not recommended for stand-alone use."
39*bbf21555SRichard Lowe	echo "Please use bootadm(8) instead."
40d876c67dSjg	echo ""
4179755401Ssetje	echo "Usage: ${0##*/}: [-R <root>] [-p <platform>] <filelist> ..."
4279755401Ssetje	echo "where <platform> is one of i86pc, sun4u or sun4v"
43986fd29aSsetje	exit 2
44986fd29aSsetje}
45986fd29aSsetje
4679755401Ssetjebuild_platform() {
4779755401Ssetje
4879755401Ssetje	altroot=$1
4979755401Ssetje
5079755401Ssetje	(
5179755401Ssetje		cd $altroot/
5279755401Ssetje		if [ -z "$STRIP" ] ; then
5379755401Ssetje			ls -d platform/*/kernel
5479755401Ssetje		else
5579755401Ssetje			ls -d platform/*/kernel | grep -v $STRIP
5679755401Ssetje		fi
5779755401Ssetje	)
5879755401Ssetje}
5979755401Ssetje
60d876c67dSjg# default platform is what we're running on
61d876c67dSjgPLATFORM=`uname -m`
62d876c67dSjg
63986fd29aSsetjealtroot=""
64986fd29aSsetjefilelists=
65d876c67dSjgplatform_provided=no
66d876c67dSjg
67d876c67dSjgOPTIND=1
68d876c67dSjgwhile getopts R:p: FLAG
69986fd29aSsetjedo
70986fd29aSsetje        case $FLAG in
71d876c67dSjg        R)	if [ "$OPTARG" != "/" ]; then
72d876c67dSjg			altroot="$OPTARG"
73986fd29aSsetje		fi
74986fd29aSsetje		;;
75d876c67dSjg	p)	platform_provided=yes
76d876c67dSjg		PLATFORM="$OPTARG"
77d876c67dSjg		;;
78986fd29aSsetje        *)      usage
79986fd29aSsetje		;;
80986fd29aSsetje        esac
81986fd29aSsetjedone
82986fd29aSsetje
83d876c67dSjgshift `expr $OPTIND - 1`
84986fd29aSsetjeif [ $# -eq 0 ]; then
85986fd29aSsetje	usage
86986fd29aSsetjefi
87986fd29aSsetje
88986fd29aSsetjefilelists=$*
89986fd29aSsetje
90d876c67dSjg#
91d876c67dSjg# If the target platform is provided, as is the case for diskless,
92d876c67dSjg# or we're building an archive for this machine, we can build
93d876c67dSjg# a smaller archive by not including unnecessary components.
94d876c67dSjg#
95986fd29aSsetjefiltering=no
96d876c67dSjgif [ "$altroot" == "" ] || [ $platform_provided = yes ]; then
97d876c67dSjg	case $PLATFORM in
98986fd29aSsetje	i86pc)
9979755401Ssetje		STRIP=
100986fd29aSsetje		;;
101986fd29aSsetje	sun4u)
10279755401Ssetje		STRIP=platform/sun4v/
103986fd29aSsetje		;;
104986fd29aSsetje	sun4v)
10579755401Ssetje		STRIP=platform/sun4u/
106986fd29aSsetje		;;
107d876c67dSjg	*)
10879755401Ssetje		STRIP=
109d876c67dSjg		;;
110986fd29aSsetje	esac
111986fd29aSsetjefi
112986fd29aSsetje
113986fd29aSsetjefor list in $filelists
114986fd29aSsetjedo
115986fd29aSsetje	if [ -f $altroot/$list ]; then
11679755401Ssetje		grep ^platform$ $altroot/$list > /dev/null
11779755401Ssetje		if [ $? = 0 ] ; then
11879755401Ssetje			build_platform $altroot
11979755401Ssetje			if [ -z "$STRIP" ] ; then
12079755401Ssetje				cat $altroot/$list | grep -v ^platform$
12179755401Ssetje			else
12279755401Ssetje				cat $altroot/$list | grep -v ^platform$ | \
12379755401Ssetje				    grep -v $STRIP
12479755401Ssetje			fi
125986fd29aSsetje		else
12679755401Ssetje			if [ -z "$STRIP" ] ; then
12779755401Ssetje				cat $altroot/$list
12879755401Ssetje			else
12979755401Ssetje				cat $altroot/$list | grep -v $STRIP
13079755401Ssetje			fi
131986fd29aSsetje		fi
13279755401Ssetje
133986fd29aSsetje	fi
134986fd29aSsetjedone
135986fd29aSsetje
136986fd29aSsetjeexit 0
137