1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23# Use is subject to license terms.
24#
25
26#
27# set path, but inherit /tmp/bfubin if it is sane
28#
29if [ "`echo $PATH | cut -f 1 -d :`" = /tmp/bfubin ] && \
30    [ -O /tmp/bfubin ] ; then
31	export PATH=/tmp/bfubin:/usr/sbin:/usr/bin:/sbin
32else
33	export PATH=/usr/sbin:/usr/bin:/sbin
34fi
35
36usage() {
37	echo "This utility is a component of the bootadm(8) implementation"
38	echo "and it is not recommended for stand-alone use."
39	echo "Please use bootadm(8) instead."
40	echo ""
41	echo "Usage: ${0##*/}: [-R <root>] [-p <platform>] <filelist> ..."
42	echo "where <platform> is one of i86pc, sun4u or sun4v"
43	exit 2
44}
45
46build_platform() {
47
48	altroot=$1
49
50	(
51		cd $altroot/
52		if [ -z "$STRIP" ] ; then
53			ls -d platform/*/kernel
54		else
55			ls -d platform/*/kernel | grep -v $STRIP
56		fi
57	)
58}
59
60# default platform is what we're running on
61PLATFORM=`uname -m`
62
63altroot=""
64filelists=
65platform_provided=no
66
67OPTIND=1
68while getopts R:p: FLAG
69do
70        case $FLAG in
71        R)	if [ "$OPTARG" != "/" ]; then
72			altroot="$OPTARG"
73		fi
74		;;
75	p)	platform_provided=yes
76		PLATFORM="$OPTARG"
77		;;
78        *)      usage
79		;;
80        esac
81done
82
83shift `expr $OPTIND - 1`
84if [ $# -eq 0 ]; then
85	usage
86fi
87
88filelists=$*
89
90#
91# If the target platform is provided, as is the case for diskless,
92# or we're building an archive for this machine, we can build
93# a smaller archive by not including unnecessary components.
94#
95filtering=no
96if [ "$altroot" == "" ] || [ $platform_provided = yes ]; then
97	case $PLATFORM in
98	i86pc)
99		STRIP=
100		;;
101	sun4u)
102		STRIP=platform/sun4v/
103		;;
104	sun4v)
105		STRIP=platform/sun4u/
106		;;
107	*)
108		STRIP=
109		;;
110	esac
111fi
112
113for list in $filelists
114do
115	if [ -f $altroot/$list ]; then
116		grep ^platform$ $altroot/$list > /dev/null
117		if [ $? = 0 ] ; then
118			build_platform $altroot
119			if [ -z "$STRIP" ] ; then
120				cat $altroot/$list | grep -v ^platform$
121			else
122				cat $altroot/$list | grep -v ^platform$ | \
123				    grep -v $STRIP
124			fi
125		else
126			if [ -z "$STRIP" ] ; then
127				cat $altroot/$list
128			else
129				cat $altroot/$list | grep -v $STRIP
130			fi
131		fi
132
133	fi
134done
135
136exit 0
137