xref: /illumos-gate/usr/src/cmd/boot/scripts/extract_boot_filelist.ksh (revision 915894ef19890baaed00080f85f6b69e225cda98)
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# ident	"%Z%%M%	%I%	%E% SMI"
26
27#
28# set path, but inherit /tmp/bfubin if it is sane
29#
30if [ "`echo $PATH | cut -f 1 -d :`" = /tmp/bfubin ] && \
31    [ -O /tmp/bfubin ] ; then
32	export PATH=/tmp/bfubin:/usr/sbin:/usr/bin:/sbin
33else
34	export PATH=/usr/sbin:/usr/bin:/sbin
35fi
36
37usage() {
38	echo "This utility is a component of the bootadm(1M) implementation"
39	echo "and it is not recommended for stand-alone use."
40	echo "Please use bootadm(1M) instead."
41	echo ""
42	echo "Usage: ${0##*/}: [-R <root>] [-p <platform>] <filelist> ..."
43	echo "where <platform> is one of i86pc, sun4u or sun4v"
44	exit 2
45}
46
47build_platform() {
48
49	altroot=$1
50
51	(
52		cd $altroot/
53		if [ -z "$STRIP" ] ; then
54			ls -d platform/*/kernel
55		else
56			ls -d platform/*/kernel | grep -v $STRIP
57		fi
58	)
59}
60
61# default platform is what we're running on
62PLATFORM=`uname -m`
63
64altroot=""
65filelists=
66platform_provided=no
67
68OPTIND=1
69while getopts R:p: FLAG
70do
71        case $FLAG in
72        R)	if [ "$OPTARG" != "/" ]; then
73			altroot="$OPTARG"
74		fi
75		;;
76	p)	platform_provided=yes
77		PLATFORM="$OPTARG"
78		;;
79        *)      usage
80		;;
81        esac
82done
83
84shift `expr $OPTIND - 1`
85if [ $# -eq 0 ]; then
86	usage
87fi
88
89filelists=$*
90
91#
92# If the target platform is provided, as is the case for diskless,
93# or we're building an archive for this machine, we can build
94# a smaller archive by not including unnecessary components.
95#
96filtering=no
97if [ "$altroot" == "" ] || [ $platform_provided = yes ]; then
98	case $PLATFORM in
99	i86pc)
100		STRIP=
101		;;
102	sun4u)
103		STRIP=platform/sun4v/
104		;;
105	sun4v)
106		STRIP=platform/sun4u/
107		;;
108	*)
109		STRIP=
110		;;
111	esac
112fi
113
114for list in $filelists
115do
116	if [ -f $altroot/$list ]; then
117		grep ^platform$ $altroot/$list > /dev/null
118		if [ $? = 0 ] ; then
119			build_platform $altroot
120			if [ -z "$STRIP" ] ; then
121				cat $altroot/$list | grep -v ^platform$
122			else
123				cat $altroot/$list | grep -v ^platform$ | \
124				    grep -v $STRIP
125			fi
126		else
127			if [ -z "$STRIP" ] ; then
128				cat $altroot/$list
129			else
130				cat $altroot/$list | grep -v $STRIP
131			fi
132		fi
133
134	fi
135done
136
137exit 0
138