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.
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.
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]
24 # Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
30 # This shell script uncompresses and installs files archived in
31 # old-style WOS packages using the utilities cpio and compress. It
32 # looks in the PKGSRC directory for the archives which may be called
33 # out in one of eight ways :
35 # reloc.cpio.Z relocatable paths, less old style
36 # root.cpio.Z absolute paths, less old style
37 # reloc.cpio relocatable paths less old style, not compressed
38 # root.cpio absolute paths, less old style, not compressed
39 # reloc.Z relocatable paths, old style, compressed
40 # root.Z absolute paths, old style, compressed
41 # reloc relocatable paths, old style, not compressed
42 # root absolute paths, old style, not compressed
44 # stdin carries the source directory as the first entry followed by the
45 # paths of the files to be installed as indicated in the pkgmap. Since
46 # all operations take place from the declared base directory, both relative
47 # and absolute paths will install correctly. There are three methods and
48 # since speed is of the essence, we skip straight to the right one :
50 # If it's an initial install
51 # do a full cpio for each archive
53 # If there's only the reloc archive
54 # make a file list, rm executables, do a selective cpio
56 # rm executables, do a full cpio for each archive
58 # Since the old-style archives contain no execute permissions, this
59 # script saves the executables it requires so it can clean up after
60 # unloading the archive. If /usr/lib/ld.so or .so.1 is included in the
61 # package, no cleanup will be possible (nothing will run) so we clean
62 # up first and then unload the entire archive without a file list.
65 FILELIST
=${PKGSAV:?undefined}/filelist
67 IR
=${PKG_INSTALL_ROOT:-/}
68 MAXLIST
=550 # This is arbitrary based upon 2.4 cpio
85 # critical archived dynamic libraries and executables
92 Libintl
=usr
/lib
/libintl.so
.1
93 Libmalloc
=usr
/lib
/libmapmalloc.so
.1
94 Libc
=usr
/lib
/libc.so
.1
95 Libw
=usr
/lib
/libw.so
.1
96 Libdl
=usr
/lib
/libdl.so
.1
104 # Set up the default paths
108 CPIO_cmd
=$CPIO_xpath/cpio
110 ZCAT_cmd
=$ZCAT_xpath/zcat
114 NAWK_cmd
=$NAWK_xpath/nawk
117 Tmp_xpath
=/usr
/tmp$
$dir
130 # This creates the temporary directory for holding the old dynamic
131 # libraries and executables.
134 if [ ! -d $Tmp_xpath ]; then
136 if [ $?
-ne 0 ]; then
137 echo `gettext "ERROR : $NAME cannot create $Tmp_xpath."`
145 # Test a path to see if it represents a dynamic library or executable that
146 # we use in this script. If it is, deal with the special case.
148 spclcase
() { # $1 is the pathname to special case
149 if [ $local_install -eq 1 ]; then
153 $Libintl) Spcl_lib
=1; file=libintl.so
.1;;
154 $Libmalloc) Spcl_lib
=1; file=libmapmalloc.so
.1;;
155 $Libc) Spcl_lib
=1; file=libc.so
.1;;
156 $Libw) Spcl_lib
=1; file=libw.so
.1;;
157 $Libdl) Spcl_lib
=1; file=libdl.so
.1;;
158 $Cpio) rm_cpio
=1; Spcl_exec
=1;;
159 $Ln) rm_ln
=1; Spcl_exec
=1;;
160 $Zcat) rm_zcat
=1; Spcl_exec
=1;;
161 $Nawk) rm_nawk
=1; Spcl_exec
=1;;
162 $Rm) rm_rm
=1; Spcl_exec
=1;;
163 $Mv) rm_mv
=1; Spcl_exec
=1;;
166 if [ $no_select -eq 1 ]; then
170 if [ $Rm_alt_sav -eq 1 ]; then
176 elif [ $Spcl_lib -eq 1 ]; then
177 if [ $Tmp_Creat -eq 0 ]; then
181 if [ $Spcl_init -eq 0 ]; then
182 Org_LD_LIBRARY_PATH
=${LD_LIBRARY_PATH}
183 LD_LIBRARY_PATH
="$Org_LD_LIBRARY_PATH $Tmp_xpath"
184 export LD_LIBRARY_PATH
187 Ld_Preload
="$Ld_Preload $Tmp_xpath/$file"
188 LD_PRELOAD
=$Ld_Preload
190 Movelist
="$1 $file $Movelist"
191 $MV_cmd $1 $Tmp_xpath
192 $LN_cmd -s ..
/..
$Tmp_xpath/$file $1
194 elif [ $Spcl_exec -eq 1 ]; then
195 if [ $Tmp_Creat -eq 0 ]; then
199 $MV_cmd $1 $Tmp_xpath
200 if [ $rm_cpio -eq 1 ]; then
201 $LN_cmd -s ..
/..
$Tmp_xpath/cpio $1
202 CPIO_cmd
="$Tmp_xpath/cpio"
203 Movelist
="$1 cpio $Movelist"
205 elif [ $rm_ln -eq 1 ]; then
206 $Tmp_xpath/ln -s ..
/..
$Tmp_xpath/ln $1
207 LN_cmd
="$Tmp_xpath/ln"
208 Movelist
="$1 ln $Movelist"
210 elif [ $rm_nawk -eq 1 ]; then
211 $LN_cmd -s ..
/..
$Tmp_xpath/nawk
$1
212 NAWK_cmd
="$Tmp_xpath/nawk"
213 Movelist
="$1 nawk $Movelist"
215 elif [ $rm_zcat -eq 1 ]; then
216 $LN_cmd -s ..
/..
$Tmp_xpath/zcat
$1
217 ZCAT_cmd
="$Tmp_xpath/zcat"
218 Movelist
="$1 zcat $Movelist"
220 elif [ $rm_rm -eq 1 ]; then
221 $LN_cmd -s ..
/..
$Tmp_xpath/rm $1
222 RM_cmd
="$Tmp_xpath/rm"
223 Movelist
="$Movelist $1 rm"
225 elif [ $rm_mv -eq 1 ]; then
226 $LN_cmd -s ..
/..
$Tmp_xpath/mv $1
227 MV_cmd
="$Tmp_xpath/mv"
228 Movelist
="$Movelist $1 mv"
239 # Clean up the libraries and executables that were moved.
241 exec_clean
() { # $1 =1 means be quiet
242 if [ ! -z "${Movelist}" ]; then
243 echo $Movelist |
$NAWK_cmd '
245 for (n=1; n <= NF; n++) {
248 }' |
while read path
; do
250 if [ -h $path ]; then # If it's our slink
251 # then put the original back
252 if [ $1 -eq 0 ]; then
253 echo `gettext "WARNING : $path not found in archive."`
255 $MV_cmd $Tmp_xpath/$file $path
256 else # if the archive put something down
257 # remove the temporary copy
258 $RM_cmd $Tmp_xpath/$file
261 for path
in $Movelist; do
262 if [ -x $path ]; then
264 $Cpio) CPIO_cmd
="$CPIO_xpath/cpio";;
265 $Ln) LN_cmd
="$LN_xpath/ln";;
266 $Zcat) ZCAT_cmd
="$ZCAT_xpath/zcat";;
267 $Nawk) NAWK_cmd
="$NAWK_xpath/nawk";;
268 $Rm) RM_cmd
="$RM_xpath/rm";;
269 $Mv) MV_cmd
="$MV_xpath/mv";;
275 if [ $Tmp_Creat -eq 1 ]; then
276 $RM_cmd -r $Tmp_xpath
283 # Figure out what kind of package this is
287 # Any archive, whether compressed or not needs to be handled
288 # the same. i.e. reloc.cpio.Z and root.cpio.Z should cause
289 # the global is_an_archive to be set to 1.
292 if [ ${path:-NULL} != NULL
]; then # get the package source directory
293 PKGSRC
=${path:?undefined}
295 if [ ${PKG_INSTALL_ROOT:-/} = "/" ]; then
299 if [ -r $PKGSRC/reloc.
cpio.Z
]; then
301 Reloc_Arch
=$PKGSRC/reloc.
cpio.Z
305 if [ -r $PKGSRC/root.
cpio.Z
]; then
307 Root_Arch
=$PKGSRC/root.
cpio.Z
311 if [ -r $PKGSRC/reloc.
cpio ]; then
313 Reloc_Arch
=$PKGSRC/reloc.
cpio
317 if [ -r $PKGSRC/root.
cpio ]; then
319 Root_Arch
=$PKGSRC/root.
cpio
323 if [ -r $PKGSRC/reloc.Z
]; then
325 Reloc_Arch
=$PKGSRC/reloc.Z
329 if [ -r $PKGSRC/root.Z
]; then
331 Root_Arch
=$PKGSRC/root.Z
335 if [ -f $PKGSRC/reloc
]; then
337 Reloc_Arch
=$PKGSRC/reloc
341 if [ -f $PKGSRC/root
]; then
343 Root_Arch
=$PKGSRC/root
347 exit 0 # empty pipe, we're done
357 if [ $BD = "/" ]; then
360 Client_BD
=`echo $BD | sed s@/@@`
363 if [ $is_an_archive -eq 0 ]; then
364 echo `gettext "ERROR : $NAME cannot find archived files in $PKGSRC."`
368 if [ ! -d $PKGSAV ]; then
369 echo `gettext "WARNING : $NAME cannot find save directory $PKGSAV."`
372 if [ ! -d $PKGSAV ]; then
373 /usr
/bin
/mkdir
$PKGSAV
376 if [ $?
-eq 0 ]; then
377 echo `gettext " Using alternate save directory" $PKGSAV`
378 FILELIST
=$PKGSAV/filelist
381 echo `gettext "ERROR : cannot create alternate save directory"` $PKGSAV
386 if [ -f $FILELIST ]; then
392 # If there's one old-style archive and it is relocatable and this is
393 # not an initial install then make a file list for extraction.
394 if [ $is_an_archive -eq 1 -a ${PKG_INIT_INSTALL:-null} = null
]; then
398 # If this is not an initial install then clear out potentially executing
399 # files and libraries for cpio and create an extraction list if necessary
400 if [ ${PKG_INIT_INSTALL:-null} = null
]; then
401 if [ $local_install -eq 1 ]; then
402 # If extraction list is desired, create it
403 if [ $mk_filelist -eq 1 ]; then
407 echo $path >> $FILELIST
409 if [ -x ${path:-NULL} ]; then
410 full_path
=`echo $Client_BD/$path | sed s@//@/@g`
412 if [ $?
-eq 1 ]; then
418 # If there's a path containing a '$' then we can't
419 # use the extraction list because of the shell
420 if [ $list_empty -eq 0 ]; then
421 s
=`LD_PRELOAD="$Ld_Preload" $NAWK_cmd ' /\\$/ { print } ' $FILELIST`
423 if [ ! -z "${s}" ]; then
427 else # No extraction list is desired
430 if [ -x ${path:-NULL} ]; then
431 full_path
=`echo $Client_BD/$path | sed s@//@/@g`
433 if [ $?
-eq 1 ]; then
438 fi # $mk_filelist -eq 1
439 else # ! ($local_install -eq 1)
440 # If extraction list is desired, create it
441 if [ $mk_filelist -eq 1 ]; then
445 echo $path >> $FILELIST
449 # If there's a path containing a '$' then we can't
450 # use the extraction list because of the shell
451 if [ $list_empty -eq 0 ]; then
452 s
=`LD_PRELOAD="$Ld_Preload" $NAWK_cmd ' /\\$/ { print } ' $FILELIST`
454 if [ ! -z "${s}" ]; then
458 fi # $mk_filelist -eq 1
459 fi # $local_install -eq 1
460 fi # ${PKG_INIT_INSTALL:-null} = null
462 # Now extract the data from the archive(s)
463 # extract compressed cpio relocatable archive
464 if [ $reloc_cpio_Z -eq 1 ]; then
466 if [ $is_a_filelist -eq 1 ]; then
467 if [ $list_empty -eq 0 ]; then
468 $ZCAT_cmd $Reloc_Arch |
$CPIO_cmd -idukm -E $FILELIST
469 if [ $?
-ne 0 ]; then
470 echo `gettext "cpio of $Reloc_Arch failed with error $?."`
476 $ZCAT_cmd $Reloc_Arch |
$CPIO_cmd -idukm
480 # extract compressed cpio absolute archive
481 if [ $root_cpio_Z -eq 1 ]; then
483 $ZCAT_cmd $Root_Arch |
$CPIO_cmd -idukm
484 if [ $?
-ne 0 ]; then
485 echo `gettext "cpio of $Root_Arch failed with error $?."`
490 # extract cpio relocatable archive
491 if [ $reloc_cpio -eq 1 ]; then
493 if [ $is_a_filelist -eq 1 ]; then
494 if [ $list_empty -eq 0 ]; then
495 $CPIO_cmd -idukm -I $Reloc_Arch -E $FILELIST
497 if [ $?
-ne 0 ]; then
498 echo `gettext "cpio of $Reloc_Arch failed with error $?."`
503 $CPIO_cmd -idukm -I $Reloc_Arch
507 # extract cpio absolute archive
508 if [ $root_cpio -eq 1 ]; then
510 $CPIO_cmd -idukm -I $Root_Arch
511 if [ $?
-ne 0 ]; then
512 echo `gettext "cpio of $Root_Arch failed with error $?."`
517 if [ -f $FILELIST ]; then
521 if [ $Rm_alt_sav -eq 1 ]; then
528 if [ $Tmp_Creat -eq 1 ]; then
529 $RM_cmd -r $Tmp_xpath
532 if [ $Spcl_init -eq 1 ]; then
533 LD_LIBRARY_PATH
=$Org_LD_LIBRARY_PATH
534 export LD_LIBRARY_PATH