xref: /titanic_51/usr/src/cmd/svr4pkg/pkgscripts/i.CompCpio.sh (revision 5c51f1241dbbdf2656d0e10011981411ed0c9673)
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 2005 Sun Microsystems, Inc.  All rights reserved.
25*5c51f124SMoriah Waterland# Use is subject to license terms.
26*5c51f124SMoriah Waterland#
27*5c51f124SMoriah Waterland
28*5c51f124SMoriah Waterland# i.CompCpio
29*5c51f124SMoriah Waterland#
30*5c51f124SMoriah Waterland# This shell script uncompresses and installs files archived in
31*5c51f124SMoriah Waterland# old-style WOS packages using the utilities cpio and compress. It
32*5c51f124SMoriah Waterland# looks in the PKGSRC directory for the archives which may be called
33*5c51f124SMoriah Waterland# out in one of eight ways :
34*5c51f124SMoriah Waterland#
35*5c51f124SMoriah Waterland#	reloc.cpio.Z	relocatable paths, less old style
36*5c51f124SMoriah Waterland#	root.cpio.Z	absolute paths, less old style
37*5c51f124SMoriah Waterland#	reloc.cpio	relocatable paths less old style, not compressed
38*5c51f124SMoriah Waterland#	root.cpio	absolute paths, less old style, not compressed
39*5c51f124SMoriah Waterland#	reloc.Z		relocatable paths, old style, compressed
40*5c51f124SMoriah Waterland#	root.Z		absolute paths, old style, compressed
41*5c51f124SMoriah Waterland#	reloc		relocatable paths, old style, not compressed
42*5c51f124SMoriah Waterland#	root		absolute paths, old style, not compressed
43*5c51f124SMoriah Waterland#
44*5c51f124SMoriah Waterland# stdin carries the source directory as the first entry followed by the
45*5c51f124SMoriah Waterland# paths of the files to be installed as indicated in the pkgmap. Since
46*5c51f124SMoriah Waterland# all operations take place from the declared base directory, both relative
47*5c51f124SMoriah Waterland# and absolute paths will install correctly. There are three methods and
48*5c51f124SMoriah Waterland# since speed is of the essence, we skip straight to the right one :
49*5c51f124SMoriah Waterland#
50*5c51f124SMoriah Waterland#	If it's an initial install
51*5c51f124SMoriah Waterland#		do a full cpio for each archive
52*5c51f124SMoriah Waterland#	else
53*5c51f124SMoriah Waterland#		If there's only the reloc archive
54*5c51f124SMoriah Waterland#			make a file list, rm executables, do a selective cpio
55*5c51f124SMoriah Waterland#		else
56*5c51f124SMoriah Waterland#			rm executables, do a full cpio for each archive
57*5c51f124SMoriah Waterland#
58*5c51f124SMoriah Waterland# Since the old-style archives contain no execute permissions, this
59*5c51f124SMoriah Waterland# script saves the executables it requires so it can clean up after
60*5c51f124SMoriah Waterland# unloading the archive. If /usr/lib/ld.so or .so.1 is included in the
61*5c51f124SMoriah Waterland# package, no cleanup will be possible (nothing will run) so we clean
62*5c51f124SMoriah Waterland# up first and then unload the entire archive without a file list.
63*5c51f124SMoriah Waterland#
64*5c51f124SMoriah WaterlandNAME="i.CompCpio"
65*5c51f124SMoriah WaterlandFILELIST=${PKGSAV:?undefined}/filelist
66*5c51f124SMoriah WaterlandBD=${BASEDIR:-/}
67*5c51f124SMoriah WaterlandIR=${PKG_INSTALL_ROOT:-/}
68*5c51f124SMoriah WaterlandMAXLIST=550	# This is arbitrary based upon 2.4 cpio
69*5c51f124SMoriah Waterlandcount=0
70*5c51f124SMoriah Waterland
71*5c51f124SMoriah Waterlandreloc_cpio_Z=0
72*5c51f124SMoriah Waterlandroot_cpio_Z=0
73*5c51f124SMoriah Waterlandreloc_cpio=0
74*5c51f124SMoriah Waterlandroot_cpio=0
75*5c51f124SMoriah WaterlandReloc_Arch=""
76*5c51f124SMoriah WaterlandRoot_Arch=""
77*5c51f124SMoriah Waterlandis_an_archive=0
78*5c51f124SMoriah Waterlandis_a_filelist=0
79*5c51f124SMoriah Waterlandmk_filelist=0
80*5c51f124SMoriah Waterlandlist_empty=1
81*5c51f124SMoriah Waterlandlocal_install=0
82*5c51f124SMoriah WaterlandSpcl_init=0
83*5c51f124SMoriah WaterlandRm_alt_sav=0
84*5c51f124SMoriah Waterland
85*5c51f124SMoriah Waterland# critical archived dynamic libraries and executables
86*5c51f124SMoriah WaterlandSpcl_lib=0
87*5c51f124SMoriah WaterlandSpcl_exec=0
88*5c51f124SMoriah WaterlandMovelist=""
89*5c51f124SMoriah WaterlandLd_Preload=""
90*5c51f124SMoriah WaterlandLd1=usr/lib/ld.so.1
91*5c51f124SMoriah WaterlandLd=usr/lib/ld.so
92*5c51f124SMoriah WaterlandLibintl=usr/lib/libintl.so.1
93*5c51f124SMoriah WaterlandLibmalloc=usr/lib/libmapmalloc.so.1
94*5c51f124SMoriah WaterlandLibc=usr/lib/libc.so.1
95*5c51f124SMoriah WaterlandLibw=usr/lib/libw.so.1
96*5c51f124SMoriah WaterlandLibdl=usr/lib/libdl.so.1
97*5c51f124SMoriah WaterlandCpio=usr/bin/cpio
98*5c51f124SMoriah WaterlandRm=usr/bin/rm
99*5c51f124SMoriah WaterlandLn=usr/bin/ln
100*5c51f124SMoriah WaterlandMv=usr/bin/mv
101*5c51f124SMoriah WaterlandNawk=usr/bin/nawk
102*5c51f124SMoriah WaterlandZcat=usr/bin/zcat
103*5c51f124SMoriah Waterland
104*5c51f124SMoriah Waterland# Set up the default paths
105*5c51f124SMoriah WaterlandMV_xpath=/usr/bin
106*5c51f124SMoriah WaterlandMV_cmd=$MV_xpath/mv
107*5c51f124SMoriah WaterlandCPIO_xpath=/usr/bin
108*5c51f124SMoriah WaterlandCPIO_cmd=$CPIO_xpath/cpio
109*5c51f124SMoriah WaterlandZCAT_xpath=/usr/bin
110*5c51f124SMoriah WaterlandZCAT_cmd=$ZCAT_xpath/zcat
111*5c51f124SMoriah WaterlandLN_xpath=/usr/bin
112*5c51f124SMoriah WaterlandLN_cmd=$LN_xpath/ln
113*5c51f124SMoriah WaterlandNAWK_xpath=/usr/bin
114*5c51f124SMoriah WaterlandNAWK_cmd=$NAWK_xpath/nawk
115*5c51f124SMoriah WaterlandRM_xpath=/usr/bin
116*5c51f124SMoriah WaterlandRM_cmd=$RM_xpath/rm
117*5c51f124SMoriah WaterlandTmp_xpath=/usr/tmp$$dir
118*5c51f124SMoriah WaterlandTmp_Creat=0
119*5c51f124SMoriah Waterlandrm_cpio=0
120*5c51f124SMoriah Waterlandrm_ln=0
121*5c51f124SMoriah Waterlandrm_zcat=0
122*5c51f124SMoriah Waterlandrm_nawk=0
123*5c51f124SMoriah Waterlandrm_rm=0
124*5c51f124SMoriah Waterlandrm_mv=0
125*5c51f124SMoriah Waterlandno_select=0
126*5c51f124SMoriah Waterland
127*5c51f124SMoriah Waterland# Functions
128*5c51f124SMoriah Waterland
129*5c51f124SMoriah Waterland#
130*5c51f124SMoriah Waterland# This creates the temporary directory for holding the old dynamic
131*5c51f124SMoriah Waterland# libraries and executables.
132*5c51f124SMoriah Waterland#
133*5c51f124SMoriah Waterlandmktempdir() {
134*5c51f124SMoriah Waterland	if [ ! -d $Tmp_xpath ]; then
135*5c51f124SMoriah Waterland		mkdir $Tmp_xpath
136*5c51f124SMoriah Waterland		if [ $? -ne 0 ]; then
137*5c51f124SMoriah Waterland			echo `gettext "ERROR : $NAME cannot create $Tmp_xpath."`
138*5c51f124SMoriah Waterland			exit 1
139*5c51f124SMoriah Waterland		fi
140*5c51f124SMoriah Waterland	fi
141*5c51f124SMoriah Waterland	Tmp_Creat=1
142*5c51f124SMoriah Waterland}
143*5c51f124SMoriah Waterland
144*5c51f124SMoriah Waterland#
145*5c51f124SMoriah Waterland# Test a path to see if it represents a dynamic library or executable that
146*5c51f124SMoriah Waterland# we use in this script. If it is, deal with the special case.
147*5c51f124SMoriah Waterland#
148*5c51f124SMoriah Waterlandspclcase() {	# $1 is the pathname to special case
149*5c51f124SMoriah Waterland	if [ $local_install -eq 1 ]; then
150*5c51f124SMoriah Waterland		case $1 in
151*5c51f124SMoriah Waterland			$Ld)		no_select=1;;
152*5c51f124SMoriah Waterland			$Ld1)		no_select=1;;
153*5c51f124SMoriah Waterland			$Libintl)	Spcl_lib=1; file=libintl.so.1;;
154*5c51f124SMoriah Waterland			$Libmalloc)	Spcl_lib=1; file=libmapmalloc.so.1;;
155*5c51f124SMoriah Waterland			$Libc)		Spcl_lib=1; file=libc.so.1;;
156*5c51f124SMoriah Waterland			$Libw)		Spcl_lib=1; file=libw.so.1;;
157*5c51f124SMoriah Waterland			$Libdl)		Spcl_lib=1; file=libdl.so.1;;
158*5c51f124SMoriah Waterland			$Cpio)		rm_cpio=1; Spcl_exec=1;;
159*5c51f124SMoriah Waterland			$Ln)		rm_ln=1; Spcl_exec=1;;
160*5c51f124SMoriah Waterland			$Zcat)		rm_zcat=1; Spcl_exec=1;;
161*5c51f124SMoriah Waterland			$Nawk)		rm_nawk=1; Spcl_exec=1;;
162*5c51f124SMoriah Waterland			$Rm)		rm_rm=1; Spcl_exec=1;;
163*5c51f124SMoriah Waterland			$Mv)		rm_mv=1; Spcl_exec=1;;
164*5c51f124SMoriah Waterland		esac
165*5c51f124SMoriah Waterland
166*5c51f124SMoriah Waterland		if [ $no_select -eq 1 ]; then
167*5c51f124SMoriah Waterland			is_a_filelist=0
168*5c51f124SMoriah Waterland			list_empty=1
169*5c51f124SMoriah Waterland			$RM_cmd $FILELIST
170*5c51f124SMoriah Waterland			if [ $Rm_alt_sav -eq 1 ]; then
171*5c51f124SMoriah Waterland				$RM_cmd -r $PKGSAV
172*5c51f124SMoriah Waterland				Rm_alt_sav=0
173*5c51f124SMoriah Waterland			fi
174*5c51f124SMoriah Waterland			exec_clean 1
175*5c51f124SMoriah Waterland			return 1
176*5c51f124SMoriah Waterland		elif [ $Spcl_lib -eq 1 ]; then
177*5c51f124SMoriah Waterland			if [ $Tmp_Creat -eq 0 ]; then
178*5c51f124SMoriah Waterland				mktempdir
179*5c51f124SMoriah Waterland			fi
180*5c51f124SMoriah Waterland
181*5c51f124SMoriah Waterland			if [ $Spcl_init -eq 0 ]; then
182*5c51f124SMoriah Waterland				Org_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
183*5c51f124SMoriah Waterland				LD_LIBRARY_PATH="$Org_LD_LIBRARY_PATH $Tmp_xpath"
184*5c51f124SMoriah Waterland				export LD_LIBRARY_PATH
185*5c51f124SMoriah Waterland				Spcl_init=1
186*5c51f124SMoriah Waterland			fi
187*5c51f124SMoriah Waterland			Ld_Preload="$Ld_Preload $Tmp_xpath/$file"
188*5c51f124SMoriah Waterland			LD_PRELOAD=$Ld_Preload
189*5c51f124SMoriah Waterland			export LD_PRELOAD
190*5c51f124SMoriah Waterland			Movelist="$1 $file $Movelist"
191*5c51f124SMoriah Waterland			$MV_cmd $1 $Tmp_xpath
192*5c51f124SMoriah Waterland			$LN_cmd -s ../..$Tmp_xpath/$file $1
193*5c51f124SMoriah Waterland			Spcl_lib=0
194*5c51f124SMoriah Waterland		elif [ $Spcl_exec -eq 1 ]; then
195*5c51f124SMoriah Waterland			if [ $Tmp_Creat -eq 0 ]; then
196*5c51f124SMoriah Waterland				mktempdir
197*5c51f124SMoriah Waterland			fi
198*5c51f124SMoriah Waterland
199*5c51f124SMoriah Waterland			$MV_cmd $1 $Tmp_xpath
200*5c51f124SMoriah Waterland			if [ $rm_cpio -eq 1 ]; then
201*5c51f124SMoriah Waterland				$LN_cmd -s ../..$Tmp_xpath/cpio $1
202*5c51f124SMoriah Waterland				CPIO_cmd="$Tmp_xpath/cpio"
203*5c51f124SMoriah Waterland				Movelist="$1 cpio $Movelist"
204*5c51f124SMoriah Waterland				rm_cpio=0
205*5c51f124SMoriah Waterland			elif [ $rm_ln -eq 1 ]; then
206*5c51f124SMoriah Waterland				$Tmp_xpath/ln -s ../..$Tmp_xpath/ln $1
207*5c51f124SMoriah Waterland				LN_cmd="$Tmp_xpath/ln"
208*5c51f124SMoriah Waterland				Movelist="$1 ln $Movelist"
209*5c51f124SMoriah Waterland				rm_ln=0
210*5c51f124SMoriah Waterland			elif [ $rm_nawk -eq 1 ]; then
211*5c51f124SMoriah Waterland				$LN_cmd -s ../..$Tmp_xpath/nawk $1
212*5c51f124SMoriah Waterland				NAWK_cmd="$Tmp_xpath/nawk"
213*5c51f124SMoriah Waterland				Movelist="$1 nawk $Movelist"
214*5c51f124SMoriah Waterland				rm_nawk=0
215*5c51f124SMoriah Waterland			elif [ $rm_zcat -eq 1 ]; then
216*5c51f124SMoriah Waterland				$LN_cmd -s ../..$Tmp_xpath/zcat $1
217*5c51f124SMoriah Waterland				ZCAT_cmd="$Tmp_xpath/zcat"
218*5c51f124SMoriah Waterland				Movelist="$1 zcat $Movelist"
219*5c51f124SMoriah Waterland				rm_zcat=0
220*5c51f124SMoriah Waterland			elif [ $rm_rm -eq 1 ]; then
221*5c51f124SMoriah Waterland				$LN_cmd -s ../..$Tmp_xpath/rm $1
222*5c51f124SMoriah Waterland				RM_cmd="$Tmp_xpath/rm"
223*5c51f124SMoriah Waterland				Movelist="$Movelist $1 rm"
224*5c51f124SMoriah Waterland				rm_rm=0
225*5c51f124SMoriah Waterland			elif [ $rm_mv -eq 1 ]; then
226*5c51f124SMoriah Waterland				$LN_cmd -s ../..$Tmp_xpath/mv $1
227*5c51f124SMoriah Waterland				MV_cmd="$Tmp_xpath/mv"
228*5c51f124SMoriah Waterland				Movelist="$Movelist $1 mv"
229*5c51f124SMoriah Waterland				rm_mv=0
230*5c51f124SMoriah Waterland			fi
231*5c51f124SMoriah Waterland			Spcl_exec=0
232*5c51f124SMoriah Waterland		fi
233*5c51f124SMoriah Waterland	fi
234*5c51f124SMoriah Waterland
235*5c51f124SMoriah Waterland	return 0
236*5c51f124SMoriah Waterland}
237*5c51f124SMoriah Waterland
238*5c51f124SMoriah Waterland#
239*5c51f124SMoriah Waterland# Clean up the libraries and executables that were moved.
240*5c51f124SMoriah Waterland#
241*5c51f124SMoriah Waterlandexec_clean() {	# $1 =1 means be quiet
242*5c51f124SMoriah Waterland	if [ ! -z "${Movelist}" ]; then
243*5c51f124SMoriah Waterland		echo $Movelist | $NAWK_cmd '
244*5c51f124SMoriah Waterland			{ split ($0, line)
245*5c51f124SMoriah Waterland			for (n=1; n <= NF; n++) {
246*5c51f124SMoriah Waterland				print line[n]
247*5c51f124SMoriah Waterland			}
248*5c51f124SMoriah Waterland		}' | while read path; do
249*5c51f124SMoriah Waterland			read file
250*5c51f124SMoriah Waterland			if [ -h $path ]; then	# If it's our slink
251*5c51f124SMoriah Waterland				# then put the original back
252*5c51f124SMoriah Waterland				if [ $1 -eq 0 ]; then
253*5c51f124SMoriah Waterland					echo `gettext "WARNING : $path not found in archive."`
254*5c51f124SMoriah Waterland				fi
255*5c51f124SMoriah Waterland				$MV_cmd $Tmp_xpath/$file $path
256*5c51f124SMoriah Waterland			else	# if the archive put something down
257*5c51f124SMoriah Waterland				# remove the temporary copy
258*5c51f124SMoriah Waterland				$RM_cmd $Tmp_xpath/$file
259*5c51f124SMoriah Waterland			fi
260*5c51f124SMoriah Waterland		done
261*5c51f124SMoriah Waterland		for path in $Movelist; do
262*5c51f124SMoriah Waterland			if [ -x $path ]; then
263*5c51f124SMoriah Waterland				case $path in
264*5c51f124SMoriah Waterland					$Cpio)	CPIO_cmd="$CPIO_xpath/cpio";;
265*5c51f124SMoriah Waterland					$Ln)	LN_cmd="$LN_xpath/ln";;
266*5c51f124SMoriah Waterland					$Zcat)	ZCAT_cmd="$ZCAT_xpath/zcat";;
267*5c51f124SMoriah Waterland					$Nawk)	NAWK_cmd="$NAWK_xpath/nawk";;
268*5c51f124SMoriah Waterland					$Rm)	RM_cmd="$RM_xpath/rm";;
269*5c51f124SMoriah Waterland					$Mv)	MV_cmd="$MV_xpath/mv";;
270*5c51f124SMoriah Waterland				esac
271*5c51f124SMoriah Waterland			fi
272*5c51f124SMoriah Waterland		done
273*5c51f124SMoriah Waterland		Movelist=""
274*5c51f124SMoriah Waterland
275*5c51f124SMoriah Waterland		if [ $Tmp_Creat -eq 1 ]; then
276*5c51f124SMoriah Waterland			$RM_cmd -r $Tmp_xpath
277*5c51f124SMoriah Waterland			Tmp_Creat=0
278*5c51f124SMoriah Waterland		fi
279*5c51f124SMoriah Waterland	fi
280*5c51f124SMoriah Waterland}
281*5c51f124SMoriah Waterland
282*5c51f124SMoriah Waterland#
283*5c51f124SMoriah Waterland# Figure out what kind of package this is
284*5c51f124SMoriah Waterland#
285*5c51f124SMoriah Waterlandeval_pkg() {
286*5c51f124SMoriah Waterland
287*5c51f124SMoriah Waterland	# Any archive, whether compressed or not needs to be handled
288*5c51f124SMoriah Waterland	# the same. i.e. reloc.cpio.Z and root.cpio.Z should cause
289*5c51f124SMoriah Waterland	# the global is_an_archive to be set to 1.
290*5c51f124SMoriah Waterland
291*5c51f124SMoriah Waterland	read path
292*5c51f124SMoriah Waterland	if [ ${path:-NULL} != NULL ]; then # get the package source directory
293*5c51f124SMoriah Waterland		PKGSRC=${path:?undefined}
294*5c51f124SMoriah Waterland
295*5c51f124SMoriah Waterland		if [ ${PKG_INSTALL_ROOT:-/} = "/" ]; then
296*5c51f124SMoriah Waterland			local_install=1
297*5c51f124SMoriah Waterland		fi
298*5c51f124SMoriah Waterland
299*5c51f124SMoriah Waterland		if [ -r $PKGSRC/reloc.cpio.Z ]; then
300*5c51f124SMoriah Waterland			reloc_cpio_Z=1
301*5c51f124SMoriah Waterland			Reloc_Arch=$PKGSRC/reloc.cpio.Z
302*5c51f124SMoriah Waterland			is_an_archive=1
303*5c51f124SMoriah Waterland		fi
304*5c51f124SMoriah Waterland
305*5c51f124SMoriah Waterland		if [ -r $PKGSRC/root.cpio.Z ]; then
306*5c51f124SMoriah Waterland			root_cpio_Z=1
307*5c51f124SMoriah Waterland			Root_Arch=$PKGSRC/root.cpio.Z
308*5c51f124SMoriah Waterland			is_an_archive=1
309*5c51f124SMoriah Waterland		fi
310*5c51f124SMoriah Waterland
311*5c51f124SMoriah Waterland		if [ -r $PKGSRC/reloc.cpio ]; then
312*5c51f124SMoriah Waterland			reloc_cpio=1
313*5c51f124SMoriah Waterland			Reloc_Arch=$PKGSRC/reloc.cpio
314*5c51f124SMoriah Waterland			is_an_archive=1
315*5c51f124SMoriah Waterland		fi
316*5c51f124SMoriah Waterland
317*5c51f124SMoriah Waterland		if [ -r $PKGSRC/root.cpio ]; then
318*5c51f124SMoriah Waterland			root_cpio=1
319*5c51f124SMoriah Waterland			Root_Arch=$PKGSRC/root.cpio
320*5c51f124SMoriah Waterland			is_an_archive=1
321*5c51f124SMoriah Waterland		fi
322*5c51f124SMoriah Waterland
323*5c51f124SMoriah Waterland		if [ -r $PKGSRC/reloc.Z ]; then
324*5c51f124SMoriah Waterland			reloc_cpio_Z=1
325*5c51f124SMoriah Waterland			Reloc_Arch=$PKGSRC/reloc.Z
326*5c51f124SMoriah Waterland			is_an_archive=2
327*5c51f124SMoriah Waterland		fi
328*5c51f124SMoriah Waterland
329*5c51f124SMoriah Waterland		if [ -r $PKGSRC/root.Z ]; then
330*5c51f124SMoriah Waterland			root_cpio_Z=1
331*5c51f124SMoriah Waterland			Root_Arch=$PKGSRC/root.Z
332*5c51f124SMoriah Waterland			is_an_archive=2
333*5c51f124SMoriah Waterland		fi
334*5c51f124SMoriah Waterland
335*5c51f124SMoriah Waterland		if [ -f $PKGSRC/reloc ]; then
336*5c51f124SMoriah Waterland			reloc_cpio=1
337*5c51f124SMoriah Waterland			Reloc_Arch=$PKGSRC/reloc
338*5c51f124SMoriah Waterland			is_an_archive=2
339*5c51f124SMoriah Waterland		fi
340*5c51f124SMoriah Waterland
341*5c51f124SMoriah Waterland		if [ -f $PKGSRC/root ]; then
342*5c51f124SMoriah Waterland			root_cpio=1
343*5c51f124SMoriah Waterland			Root_Arch=$PKGSRC/root
344*5c51f124SMoriah Waterland			is_an_archive=2
345*5c51f124SMoriah Waterland		fi
346*5c51f124SMoriah Waterland	else
347*5c51f124SMoriah Waterland		exit 0	# empty pipe, we're done
348*5c51f124SMoriah Waterland	fi
349*5c51f124SMoriah Waterland}
350*5c51f124SMoriah Waterland
351*5c51f124SMoriah Waterland#
352*5c51f124SMoriah Waterland# main
353*5c51f124SMoriah Waterland#
354*5c51f124SMoriah Waterland
355*5c51f124SMoriah Waterlandeval_pkg
356*5c51f124SMoriah Waterland
357*5c51f124SMoriah Waterlandif [ $BD = "/" ]; then
358*5c51f124SMoriah Waterland	Client_BD=""
359*5c51f124SMoriah Waterlandelse
360*5c51f124SMoriah Waterland	Client_BD=`echo $BD | sed s@/@@`
361*5c51f124SMoriah Waterlandfi
362*5c51f124SMoriah Waterland
363*5c51f124SMoriah Waterlandif [ $is_an_archive -eq 0 ]; then
364*5c51f124SMoriah Waterland	echo `gettext "ERROR : $NAME cannot find archived files in $PKGSRC."`
365*5c51f124SMoriah Waterland	exit 1
366*5c51f124SMoriah Waterlandfi
367*5c51f124SMoriah Waterland
368*5c51f124SMoriah Waterlandif [ ! -d $PKGSAV ]; then
369*5c51f124SMoriah Waterland	echo `gettext "WARNING : $NAME cannot find save directory $PKGSAV."`
370*5c51f124SMoriah Waterland	PKGSAV=/tmp/$PKG.sav
371*5c51f124SMoriah Waterland
372*5c51f124SMoriah Waterland	if [ ! -d $PKGSAV ]; then
373*5c51f124SMoriah Waterland		/usr/bin/mkdir $PKGSAV
374*5c51f124SMoriah Waterland	fi
375*5c51f124SMoriah Waterland
376*5c51f124SMoriah Waterland	if [ $? -eq 0 ]; then
377*5c51f124SMoriah Waterland		echo `gettext "  Using alternate save directory" $PKGSAV`
378*5c51f124SMoriah Waterland		FILELIST=$PKGSAV/filelist
379*5c51f124SMoriah Waterland		Rm_alt_sav=1
380*5c51f124SMoriah Waterland	else
381*5c51f124SMoriah Waterland		echo `gettext "ERROR : cannot create alternate save directory"` $PKGSAV
382*5c51f124SMoriah Waterland		exit 1
383*5c51f124SMoriah Waterland	fi
384*5c51f124SMoriah Waterlandfi
385*5c51f124SMoriah Waterland
386*5c51f124SMoriah Waterlandif [ -f $FILELIST ]; then
387*5c51f124SMoriah Waterland	rm $FILELIST
388*5c51f124SMoriah Waterlandfi
389*5c51f124SMoriah Waterland
390*5c51f124SMoriah Waterlandcd $BD
391*5c51f124SMoriah Waterland
392*5c51f124SMoriah Waterland# If there's one old-style archive and it is relocatable and this is
393*5c51f124SMoriah Waterland# not an initial install then make a file list for extraction.
394*5c51f124SMoriah Waterlandif [ $is_an_archive -eq 1 -a ${PKG_INIT_INSTALL:-null} = null ]; then
395*5c51f124SMoriah Waterland	mk_filelist=1
396*5c51f124SMoriah Waterlandfi
397*5c51f124SMoriah Waterland
398*5c51f124SMoriah Waterland# If this is not an initial install then clear out potentially executing
399*5c51f124SMoriah Waterland# files and libraries for cpio and create an extraction list if necessary
400*5c51f124SMoriah Waterlandif [ ${PKG_INIT_INSTALL:-null} = null ]; then
401*5c51f124SMoriah Waterland	if [ $local_install -eq 1 ]; then
402*5c51f124SMoriah Waterland		# If extraction list is desired, create it
403*5c51f124SMoriah Waterland		if [ $mk_filelist -eq 1 ]; then
404*5c51f124SMoriah Waterland			is_a_filelist=1
405*5c51f124SMoriah Waterland			while	read path
406*5c51f124SMoriah Waterland			do
407*5c51f124SMoriah Waterland				echo $path >> $FILELIST
408*5c51f124SMoriah Waterland				list_empty=0
409*5c51f124SMoriah Waterland				if [ -x ${path:-NULL} ]; then
410*5c51f124SMoriah Waterland					full_path=`echo $Client_BD/$path | sed s@//@/@g`
411*5c51f124SMoriah Waterland					spclcase $full_path
412*5c51f124SMoriah Waterland					if [ $? -eq 1 ]; then
413*5c51f124SMoriah Waterland						break
414*5c51f124SMoriah Waterland					fi
415*5c51f124SMoriah Waterland				fi
416*5c51f124SMoriah Waterland			done
417*5c51f124SMoriah Waterland
418*5c51f124SMoriah Waterland			# If there's a path containing a '$' then we can't
419*5c51f124SMoriah Waterland			# use the extraction list because of the shell
420*5c51f124SMoriah Waterland			if [ $list_empty -eq 0 ]; then
421*5c51f124SMoriah Waterland				s=`LD_PRELOAD="$Ld_Preload" $NAWK_cmd ' /\\$/ { print } ' $FILELIST`
422*5c51f124SMoriah Waterland
423*5c51f124SMoriah Waterland				if [ ! -z "${s}" ]; then
424*5c51f124SMoriah Waterland					is_a_filelist=0
425*5c51f124SMoriah Waterland				fi
426*5c51f124SMoriah Waterland			fi
427*5c51f124SMoriah Waterland		else	# No extraction list is desired
428*5c51f124SMoriah Waterland			while	read  path
429*5c51f124SMoriah Waterland			do
430*5c51f124SMoriah Waterland				if [ -x ${path:-NULL} ]; then
431*5c51f124SMoriah Waterland					full_path=`echo $Client_BD/$path | sed s@//@/@g`
432*5c51f124SMoriah Waterland					spclcase $full_path
433*5c51f124SMoriah Waterland					if [ $? -eq 1 ]; then
434*5c51f124SMoriah Waterland						break
435*5c51f124SMoriah Waterland					fi
436*5c51f124SMoriah Waterland				fi
437*5c51f124SMoriah Waterland			done
438*5c51f124SMoriah Waterland		fi	# $mk_filelist -eq 1
439*5c51f124SMoriah Waterland	else	# ! ($local_install -eq 1)
440*5c51f124SMoriah Waterland		# If extraction list is desired, create it
441*5c51f124SMoriah Waterland		if [ $mk_filelist -eq 1 ]; then
442*5c51f124SMoriah Waterland			is_a_filelist=1
443*5c51f124SMoriah Waterland			while	read path
444*5c51f124SMoriah Waterland			do
445*5c51f124SMoriah Waterland				echo $path >> $FILELIST
446*5c51f124SMoriah Waterland				list_empty=0
447*5c51f124SMoriah Waterland			done
448*5c51f124SMoriah Waterland
449*5c51f124SMoriah Waterland			# If there's a path containing a '$' then we can't
450*5c51f124SMoriah Waterland			# use the extraction list because of the shell
451*5c51f124SMoriah Waterland			if [ $list_empty -eq 0 ]; then
452*5c51f124SMoriah Waterland				s=`LD_PRELOAD="$Ld_Preload" $NAWK_cmd ' /\\$/ { print } ' $FILELIST`
453*5c51f124SMoriah Waterland
454*5c51f124SMoriah Waterland				if [ ! -z "${s}" ]; then
455*5c51f124SMoriah Waterland					is_a_filelist=0
456*5c51f124SMoriah Waterland				fi
457*5c51f124SMoriah Waterland			fi
458*5c51f124SMoriah Waterland		fi	# $mk_filelist -eq 1
459*5c51f124SMoriah Waterland	fi	# $local_install -eq 1
460*5c51f124SMoriah Waterlandfi	# ${PKG_INIT_INSTALL:-null} = null
461*5c51f124SMoriah Waterland
462*5c51f124SMoriah Waterland# Now extract the data from the archive(s)
463*5c51f124SMoriah Waterland# extract compressed cpio relocatable archive
464*5c51f124SMoriah Waterlandif [ $reloc_cpio_Z -eq 1 ]; then
465*5c51f124SMoriah Waterland	cd $BD
466*5c51f124SMoriah Waterland	if [ $is_a_filelist -eq 1 ]; then
467*5c51f124SMoriah Waterland		if [ $list_empty -eq 0 ]; then
468*5c51f124SMoriah Waterland			$ZCAT_cmd $Reloc_Arch | $CPIO_cmd -idukm -E $FILELIST
469*5c51f124SMoriah Waterland			if [ $? -ne 0 ]; then
470*5c51f124SMoriah Waterland				echo `gettext "cpio of $Reloc_Arch failed with error $?."`
471*5c51f124SMoriah Waterland				exit 1
472*5c51f124SMoriah Waterland		   	 fi
473*5c51f124SMoriah Waterland
474*5c51f124SMoriah Waterland		fi
475*5c51f124SMoriah Waterland	else
476*5c51f124SMoriah Waterland		$ZCAT_cmd $Reloc_Arch | $CPIO_cmd -idukm
477*5c51f124SMoriah Waterland	fi
478*5c51f124SMoriah Waterlandfi
479*5c51f124SMoriah Waterland
480*5c51f124SMoriah Waterland# extract compressed cpio absolute archive
481*5c51f124SMoriah Waterlandif [ $root_cpio_Z -eq 1 ]; then
482*5c51f124SMoriah Waterland	cd $IR
483*5c51f124SMoriah Waterland	$ZCAT_cmd $Root_Arch | $CPIO_cmd -idukm
484*5c51f124SMoriah Waterland		if [ $? -ne 0 ]; then
485*5c51f124SMoriah Waterland			echo `gettext "cpio of $Root_Arch failed with error $?."`
486*5c51f124SMoriah Waterland			exit 1
487*5c51f124SMoriah Waterland		fi
488*5c51f124SMoriah Waterlandfi
489*5c51f124SMoriah Waterland
490*5c51f124SMoriah Waterland# extract cpio relocatable archive
491*5c51f124SMoriah Waterlandif [ $reloc_cpio -eq 1 ]; then
492*5c51f124SMoriah Waterland	cd $BD
493*5c51f124SMoriah Waterland	if [ $is_a_filelist -eq 1 ]; then
494*5c51f124SMoriah Waterland		if [ $list_empty -eq 0 ]; then
495*5c51f124SMoriah Waterland			$CPIO_cmd -idukm -I $Reloc_Arch -E $FILELIST
496*5c51f124SMoriah Waterland
497*5c51f124SMoriah Waterland			if [ $? -ne 0 ]; then
498*5c51f124SMoriah Waterland				echo `gettext "cpio of $Reloc_Arch failed with error $?."`
499*5c51f124SMoriah Waterland				exit 1
500*5c51f124SMoriah Waterland			fi
501*5c51f124SMoriah Waterland		fi
502*5c51f124SMoriah Waterland	else
503*5c51f124SMoriah Waterland		$CPIO_cmd -idukm -I $Reloc_Arch
504*5c51f124SMoriah Waterland	fi
505*5c51f124SMoriah Waterlandfi
506*5c51f124SMoriah Waterland
507*5c51f124SMoriah Waterland# extract cpio absolute archive
508*5c51f124SMoriah Waterlandif [ $root_cpio -eq 1 ]; then
509*5c51f124SMoriah Waterland	cd $IR
510*5c51f124SMoriah Waterland	$CPIO_cmd -idukm -I $Root_Arch
511*5c51f124SMoriah Waterland		if [ $? -ne 0 ]; then
512*5c51f124SMoriah Waterland			echo `gettext "cpio of $Root_Arch failed with error $?."`
513*5c51f124SMoriah Waterland			exit 1
514*5c51f124SMoriah Waterland		fi
515*5c51f124SMoriah Waterlandfi
516*5c51f124SMoriah Waterland
517*5c51f124SMoriah Waterlandif [ -f $FILELIST ]; then
518*5c51f124SMoriah Waterland	$RM_cmd $FILELIST
519*5c51f124SMoriah Waterlandfi
520*5c51f124SMoriah Waterland
521*5c51f124SMoriah Waterlandif [ $Rm_alt_sav -eq 1 ]; then
522*5c51f124SMoriah Waterland	$RM_cmd -r $PKGSAV
523*5c51f124SMoriah Waterland	Rm_alt_sav=0
524*5c51f124SMoriah Waterlandfi
525*5c51f124SMoriah Waterland
526*5c51f124SMoriah Waterlandexec_clean 0
527*5c51f124SMoriah Waterland
528*5c51f124SMoriah Waterlandif [ $Tmp_Creat -eq 1 ]; then
529*5c51f124SMoriah Waterland	$RM_cmd -r $Tmp_xpath
530*5c51f124SMoriah Waterlandfi
531*5c51f124SMoriah Waterland
532*5c51f124SMoriah Waterlandif [ $Spcl_init -eq 1 ]; then
533*5c51f124SMoriah Waterland	LD_LIBRARY_PATH=$Org_LD_LIBRARY_PATH
534*5c51f124SMoriah Waterland	export LD_LIBRARY_PATH
535*5c51f124SMoriah Waterland	Spcl_init=0
536*5c51f124SMoriah Waterlandfi
537*5c51f124SMoriah Waterland
538*5c51f124SMoriah Waterlandexit 0
539