1*5c51f124SMoriah Waterland#!/bin/sh
2*5c51f124SMoriah Waterland#
3*5c51f124SMoriah Waterland# CDDL HEADER START
4*5c51f124SMoriah Waterland#
5*5c51f124SMoriah Waterland# The contents of this file are subject to the terms of the
6*5c51f124SMoriah Waterland# Common Development and Distribution License (the "License").
7*5c51f124SMoriah Waterland# You may not use this file except in compliance with the License.
8*5c51f124SMoriah Waterland#
9*5c51f124SMoriah Waterland# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*5c51f124SMoriah Waterland# or http://www.opensolaris.org/os/licensing.
11*5c51f124SMoriah Waterland# See the License for the specific language governing permissions
12*5c51f124SMoriah Waterland# and limitations under the License.
13*5c51f124SMoriah Waterland#
14*5c51f124SMoriah Waterland# When distributing Covered Code, include this CDDL HEADER in each
15*5c51f124SMoriah Waterland# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*5c51f124SMoriah Waterland# If applicable, add the following below this CDDL HEADER, with the
17*5c51f124SMoriah Waterland# fields enclosed by brackets "[]" replaced with your own identifying
18*5c51f124SMoriah Waterland# information: Portions Copyright [yyyy] [name of copyright owner]
19*5c51f124SMoriah Waterland#
20*5c51f124SMoriah Waterland# CDDL HEADER END
21*5c51f124SMoriah Waterland#
22*5c51f124SMoriah Waterland
23*5c51f124SMoriah Waterland#
24*5c51f124SMoriah Waterland# Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
25*5c51f124SMoriah Waterland# Use is subject to license terms.
26*5c51f124SMoriah Waterland#
27*5c51f124SMoriah Waterland
28*5c51f124SMoriah Waterlanderror=no
29*5c51f124SMoriah Waterlandwhile read src dest
30*5c51f124SMoriah Waterlanddo
31*5c51f124SMoriah Waterland	[ "$src" = /dev/null ] && continue
32*5c51f124SMoriah Waterland
33*5c51f124SMoriah Waterland	echo "Modifying $dest"
34*5c51f124SMoriah Waterland
35*5c51f124SMoriah Waterland	# Strip PKG_INSTALL_ROOT from dest if installation is to an
36*5c51f124SMoriah Waterland	# alternate root.
37*5c51f124SMoriah Waterland
38*5c51f124SMoriah Waterland	if [ -n "$PKG_INSTALL_ROOT" -a "$PKG_INSTALL_ROOT" != "/" ]; then
39*5c51f124SMoriah Waterland		client_dest=`echo $dest | \
40*5c51f124SMoriah Waterland			/usr/bin/nawk -v rootdir="$PKG_INSTALL_ROOT" '{
41*5c51f124SMoriah Waterland				{ print substr($0, length(rootdir)+1)} }'`
42*5c51f124SMoriah Waterland		savepath=$PKGSAV/build${client_dest}
43*5c51f124SMoriah Waterland	else
44*5c51f124SMoriah Waterland		savepath=$PKGSAV/build${dest}
45*5c51f124SMoriah Waterland	fi
46*5c51f124SMoriah Waterland
47*5c51f124SMoriah Waterland	dirname=`dirname $savepath`
48*5c51f124SMoriah Waterland	if [ $? -ne 0 ]
49*5c51f124SMoriah Waterland	then
50*5c51f124SMoriah Waterland		error=yes
51*5c51f124SMoriah Waterland		continue
52*5c51f124SMoriah Waterland	fi
53*5c51f124SMoriah Waterland
54*5c51f124SMoriah Waterland	if [ ! -d $dirname ]
55*5c51f124SMoriah Waterland	then
56*5c51f124SMoriah Waterland		# ignore return since mkdir has bug
57*5c51f124SMoriah Waterland		mkdir -p $dirname
58*5c51f124SMoriah Waterland	fi
59*5c51f124SMoriah Waterland
60*5c51f124SMoriah Waterland	cp $src $savepath &&
61*5c51f124SMoriah Waterland		chmod 500 $savepath
62*5c51f124SMoriah Waterland	if [ $? -ne 0 ]
63*5c51f124SMoriah Waterland	then
64*5c51f124SMoriah Waterland		error=yes
65*5c51f124SMoriah Waterland		continue
66*5c51f124SMoriah Waterland	fi
67*5c51f124SMoriah Waterland
68*5c51f124SMoriah Waterland	if $savepath install > /tmp/$$build
69*5c51f124SMoriah Waterland	then
70*5c51f124SMoriah Waterland		if [ -s /tmp/$$build ]
71*5c51f124SMoriah Waterland		then
72*5c51f124SMoriah Waterland			cp /tmp/$$build $dest || error=yes
73*5c51f124SMoriah Waterland		fi
74*5c51f124SMoriah Waterland	else
75*5c51f124SMoriah Waterland		error=yes
76*5c51f124SMoriah Waterland	fi
77*5c51f124SMoriah Waterland	rm -f /tmp/$$build
78*5c51f124SMoriah Waterlanddone
79*5c51f124SMoriah Waterland[ "$error" = yes ] &&
80*5c51f124SMoriah Waterland	exit 2
81*5c51f124SMoriah Waterlandexit 0
82