#!/bin/sh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2005 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # i.CompCpio # # This shell script uncompresses and installs files archived in # old-style WOS packages using the utilities cpio and compress. It # looks in the PKGSRC directory for the archives which may be called # out in one of eight ways : # # reloc.cpio.Z relocatable paths, less old style # root.cpio.Z absolute paths, less old style # reloc.cpio relocatable paths less old style, not compressed # root.cpio absolute paths, less old style, not compressed # reloc.Z relocatable paths, old style, compressed # root.Z absolute paths, old style, compressed # reloc relocatable paths, old style, not compressed # root absolute paths, old style, not compressed # # stdin carries the source directory as the first entry followed by the # paths of the files to be installed as indicated in the pkgmap. Since # all operations take place from the declared base directory, both relative # and absolute paths will install correctly. There are three methods and # since speed is of the essence, we skip straight to the right one : # # If it's an initial install # do a full cpio for each archive # else # If there's only the reloc archive # make a file list, rm executables, do a selective cpio # else # rm executables, do a full cpio for each archive # # Since the old-style archives contain no execute permissions, this # script saves the executables it requires so it can clean up after # unloading the archive. If /usr/lib/ld.so or .so.1 is included in the # package, no cleanup will be possible (nothing will run) so we clean # up first and then unload the entire archive without a file list. # setvar NAME = ""i.CompCpio"" setvar FILELIST = "${PKGSAV:?undefined}/filelist" setvar BD = ${BASEDIR:-/} setvar IR = ${PKG_INSTALL_ROOT:-/} setvar MAXLIST = '550' # This is arbitrary based upon 2.4 cpio setvar count = '0' setvar reloc_cpio_Z = '0' setvar root_cpio_Z = '0' setvar reloc_cpio = '0' setvar root_cpio = '0' setvar Reloc_Arch = """" setvar Root_Arch = """" setvar is_an_archive = '0' setvar is_a_filelist = '0' setvar mk_filelist = '0' setvar list_empty = '1' setvar local_install = '0' setvar Spcl_init = '0' setvar Rm_alt_sav = '0' # critical archived dynamic libraries and executables setvar Spcl_lib = '0' setvar Spcl_exec = '0' setvar Movelist = """" setvar Ld_Preload = """" setvar Ld1 = 'usr/lib/ld.so.1' setvar Ld = 'usr/lib/ld.so' setvar Libintl = 'usr/lib/libintl.so.1' setvar Libmalloc = 'usr/lib/libmapmalloc.so.1' setvar Libc = 'usr/lib/libc.so.1' setvar Libw = 'usr/lib/libw.so.1' setvar Libdl = 'usr/lib/libdl.so.1' setvar Cpio = 'usr/bin/cpio' setvar Rm = 'usr/bin/rm' setvar Ln = 'usr/bin/ln' setvar Mv = 'usr/bin/mv' setvar Nawk = 'usr/bin/nawk' setvar Zcat = 'usr/bin/zcat' # Set up the default paths setvar MV_xpath = '/usr/bin' setvar MV_cmd = "$MV_xpath/mv" setvar CPIO_xpath = '/usr/bin' setvar CPIO_cmd = "$CPIO_xpath/cpio" setvar ZCAT_xpath = '/usr/bin' setvar ZCAT_cmd = "$ZCAT_xpath/zcat" setvar LN_xpath = '/usr/bin' setvar LN_cmd = "$LN_xpath/ln" setvar NAWK_xpath = '/usr/bin' setvar NAWK_cmd = "$NAWK_xpath/nawk" setvar RM_xpath = '/usr/bin' setvar RM_cmd = "$RM_xpath/rm" setvar Tmp_xpath = "/usr/tmp$Piddir" setvar Tmp_Creat = '0' setvar rm_cpio = '0' setvar rm_ln = '0' setvar rm_zcat = '0' setvar rm_nawk = '0' setvar rm_rm = '0' setvar rm_mv = '0' setvar no_select = '0' # Functions # # This creates the temporary directory for holding the old dynamic # libraries and executables. # proc mktempdir { if test ! -d $Tmp_xpath { mkdir $Tmp_xpath if test $Status -ne 0 { echo $(gettext "ERROR : $NAME cannot create $Tmp_xpath.) exit 1 } } setvar Tmp_Creat = '1' } # # Test a path to see if it represents a dynamic library or executable that # we use in this script. If it is, deal with the special case. # proc spclcase { # $1 is the pathname to special case if test $local_install -eq 1 { match $1 { with $Ld setvar no_select = '1' with $Ld1 setvar no_select = '1' with $Libintl setvar Spcl_lib = '1'; setvar file = 'libintl.so.1' with $Libmalloc setvar Spcl_lib = '1'; setvar file = 'libmapmalloc.so.1' with $Libc setvar Spcl_lib = '1'; setvar file = 'libc.so.1' with $Libw setvar Spcl_lib = '1'; setvar file = 'libw.so.1' with $Libdl setvar Spcl_lib = '1'; setvar file = 'libdl.so.1' with $Cpio setvar rm_cpio = '1'; setvar Spcl_exec = '1' with $Ln setvar rm_ln = '1'; setvar Spcl_exec = '1' with $Zcat setvar rm_zcat = '1'; setvar Spcl_exec = '1' with $Nawk setvar rm_nawk = '1'; setvar Spcl_exec = '1' with $Rm setvar rm_rm = '1'; setvar Spcl_exec = '1' with $Mv setvar rm_mv = '1'; setvar Spcl_exec = '1' } if test $no_select -eq 1 { setvar is_a_filelist = '0' setvar list_empty = '1' $RM_cmd $FILELIST if test $Rm_alt_sav -eq 1 { $RM_cmd -r $PKGSAV setvar Rm_alt_sav = '0' } exec_clean 1 return 1 } elif test $Spcl_lib -eq 1 { if test $Tmp_Creat -eq 0 { mktempdir } if test $Spcl_init -eq 0 { setvar Org_LD_LIBRARY_PATH = ${LD_LIBRARY_PATH} setvar LD_LIBRARY_PATH = ""$Org_LD_LIBRARY_PATH $Tmp_xpath"" export LD_LIBRARY_PATH setvar Spcl_init = '1' } setvar Ld_Preload = ""$Ld_Preload $Tmp_xpath/$file"" setvar LD_PRELOAD = "$Ld_Preload" export LD_PRELOAD setvar Movelist = ""$1 $file $Movelist"" $MV_cmd $1 $Tmp_xpath $LN_cmd -s ../..$Tmp_xpath/$file $1 setvar Spcl_lib = '0' } elif test $Spcl_exec -eq 1 { if test $Tmp_Creat -eq 0 { mktempdir } $MV_cmd $1 $Tmp_xpath if test $rm_cpio -eq 1 { $LN_cmd -s ../..$Tmp_xpath/cpio $1 setvar CPIO_cmd = ""$Tmp_xpath/cpio"" setvar Movelist = ""$1 cpio $Movelist"" setvar rm_cpio = '0' } elif test $rm_ln -eq 1 { $Tmp_xpath/ln -s ../..$Tmp_xpath/ln $1 setvar LN_cmd = ""$Tmp_xpath/ln"" setvar Movelist = ""$1 ln $Movelist"" setvar rm_ln = '0' } elif test $rm_nawk -eq 1 { $LN_cmd -s ../..$Tmp_xpath/nawk $1 setvar NAWK_cmd = ""$Tmp_xpath/nawk"" setvar Movelist = ""$1 nawk $Movelist"" setvar rm_nawk = '0' } elif test $rm_zcat -eq 1 { $LN_cmd -s ../..$Tmp_xpath/zcat $1 setvar ZCAT_cmd = ""$Tmp_xpath/zcat"" setvar Movelist = ""$1 zcat $Movelist"" setvar rm_zcat = '0' } elif test $rm_rm -eq 1 { $LN_cmd -s ../..$Tmp_xpath/rm $1 setvar RM_cmd = ""$Tmp_xpath/rm"" setvar Movelist = ""$Movelist $1 rm"" setvar rm_rm = '0' } elif test $rm_mv -eq 1 { $LN_cmd -s ../..$Tmp_xpath/mv $1 setvar MV_cmd = ""$Tmp_xpath/mv"" setvar Movelist = ""$Movelist $1 mv"" setvar rm_mv = '0' } setvar Spcl_exec = '0' } } return 0 } # # Clean up the libraries and executables that were moved. # proc exec_clean { # $1 =1 means be quiet if test ! -z ${Movelist} { echo $Movelist | $NAWK_cmd ' { split ($0, line) for (n=1; n <= NF; n++) { print line[n] } }' | while read path { read file if test -h $path { # If it's our slink # then put the original back if test $1 -eq 0 { echo $(gettext "WARNING : $path not found in archive.) } $MV_cmd $Tmp_xpath/$file $path } else { # if the archive put something down # remove the temporary copy $RM_cmd $Tmp_xpath/$file } } for path in [$Movelist] { if test -x $path { match $path { with $Cpio setvar CPIO_cmd = ""$CPIO_xpath/cpio"" with $Ln setvar LN_cmd = ""$LN_xpath/ln"" with $Zcat setvar ZCAT_cmd = ""$ZCAT_xpath/zcat"" with $Nawk setvar NAWK_cmd = ""$NAWK_xpath/nawk"" with $Rm setvar RM_cmd = ""$RM_xpath/rm"" with $Mv setvar MV_cmd = ""$MV_xpath/mv"" } } } setvar Movelist = """" if test $Tmp_Creat -eq 1 { $RM_cmd -r $Tmp_xpath setvar Tmp_Creat = '0' } } } # # Figure out what kind of package this is # proc eval_pkg { # Any archive, whether compressed or not needs to be handled # the same. i.e. reloc.cpio.Z and root.cpio.Z should cause # the global is_an_archive to be set to 1. read path if test ${path:-NULL} != NULL { # get the package source directory setvar PKGSRC = ${path:?undefined} if test ${PKG_INSTALL_ROOT:-/} = "/" { setvar local_install = '1' } if test -r $PKGSRC/reloc.cpio.Z { setvar reloc_cpio_Z = '1' setvar Reloc_Arch = "$PKGSRC/reloc.cpio.Z" setvar is_an_archive = '1' } if test -r $PKGSRC/root.cpio.Z { setvar root_cpio_Z = '1' setvar Root_Arch = "$PKGSRC/root.cpio.Z" setvar is_an_archive = '1' } if test -r $PKGSRC/reloc.cpio { setvar reloc_cpio = '1' setvar Reloc_Arch = "$PKGSRC/reloc.cpio" setvar is_an_archive = '1' } if test -r $PKGSRC/root.cpio { setvar root_cpio = '1' setvar Root_Arch = "$PKGSRC/root.cpio" setvar is_an_archive = '1' } if test -r $PKGSRC/reloc.Z { setvar reloc_cpio_Z = '1' setvar Reloc_Arch = "$PKGSRC/reloc.Z" setvar is_an_archive = '2' } if test -r $PKGSRC/root.Z { setvar root_cpio_Z = '1' setvar Root_Arch = "$PKGSRC/root.Z" setvar is_an_archive = '2' } if test -f $PKGSRC/reloc { setvar reloc_cpio = '1' setvar Reloc_Arch = "$PKGSRC/reloc" setvar is_an_archive = '2' } if test -f $PKGSRC/root { setvar root_cpio = '1' setvar Root_Arch = "$PKGSRC/root" setvar is_an_archive = '2' } } else { exit 0 # empty pipe, we're done } } # # main # eval_pkg if test $BD = "/" { setvar Client_BD = """" } else { setvar Client_BD = $(echo $BD | sed s@/@@) } if test $is_an_archive -eq 0 { echo $(gettext "ERROR : $NAME cannot find archived files in $PKGSRC.) exit 1 } if test ! -d $PKGSAV { echo $(gettext "WARNING : $NAME cannot find save directory $PKGSAV.) setvar PKGSAV = "/tmp/$PKG.sav" if test ! -d $PKGSAV { /usr/bin/mkdir $PKGSAV } if test $Status -eq 0 { echo $(gettext " Using alternate save directory" $PKGSAV) setvar FILELIST = "$PKGSAV/filelist" setvar Rm_alt_sav = '1' } else { echo $(gettext "ERROR : cannot create alternate save directory) $PKGSAV exit 1 } } if test -f $FILELIST { rm $FILELIST } cd $BD # If there's one old-style archive and it is relocatable and this is # not an initial install then make a file list for extraction. if test $is_an_archive -eq 1 -a ${PKG_INIT_INSTALL:-null} = null { setvar mk_filelist = '1' } # If this is not an initial install then clear out potentially executing # files and libraries for cpio and create an extraction list if necessary if test ${PKG_INIT_INSTALL:-null} = null { if test $local_install -eq 1 { # If extraction list is desired, create it if test $mk_filelist -eq 1 { setvar is_a_filelist = '1' while read path { echo $path >> $FILELIST setvar list_empty = '0' if test -x ${path:-NULL} { setvar full_path = $(echo $Client_BD/$path | sed s@//@/@g) spclcase $full_path if test $Status -eq 1 { break } } } # If there's a path containing a '$' then we can't # use the extraction list because of the shell if test $list_empty -eq 0 { setvar s = $("LD_PRELOAD=$Ld_Preload" $NAWK_cmd ' /\\$/ { print } ' $FILELIST) if test ! -z ${s} { setvar is_a_filelist = '0' } } } else { # No extraction list is desired while read path { if test -x ${path:-NULL} { setvar full_path = $(echo $Client_BD/$path | sed s@//@/@g) spclcase $full_path if test $Status -eq 1 { break } } } } # $mk_filelist -eq 1 } else { # ! ($local_install -eq 1) # If extraction list is desired, create it if test $mk_filelist -eq 1 { setvar is_a_filelist = '1' while read path { echo $path >> $FILELIST setvar list_empty = '0' } # If there's a path containing a '$' then we can't # use the extraction list because of the shell if test $list_empty -eq 0 { setvar s = $("LD_PRELOAD=$Ld_Preload" $NAWK_cmd ' /\\$/ { print } ' $FILELIST) if test ! -z ${s} { setvar is_a_filelist = '0' } } } # $mk_filelist -eq 1 } # $local_install -eq 1 } # ${PKG_INIT_INSTALL:-null} = null # Now extract the data from the archive(s) # extract compressed cpio relocatable archive if test $reloc_cpio_Z -eq 1 { cd $BD if test $is_a_filelist -eq 1 { if test $list_empty -eq 0 { $ZCAT_cmd $Reloc_Arch | $CPIO_cmd -idukm -E $FILELIST if test $Status -ne 0 { echo $(gettext "cpio of $Reloc_Arch failed with error $Status.) exit 1 } } } else { $ZCAT_cmd $Reloc_Arch | $CPIO_cmd -idukm } } # extract compressed cpio absolute archive if test $root_cpio_Z -eq 1 { cd $IR $ZCAT_cmd $Root_Arch | $CPIO_cmd -idukm if test $Status -ne 0 { echo $(gettext "cpio of $Root_Arch failed with error $Status.) exit 1 } } # extract cpio relocatable archive if test $reloc_cpio -eq 1 { cd $BD if test $is_a_filelist -eq 1 { if test $list_empty -eq 0 { $CPIO_cmd -idukm -I $Reloc_Arch -E $FILELIST if test $Status -ne 0 { echo $(gettext "cpio of $Reloc_Arch failed with error $Status.) exit 1 } } } else { $CPIO_cmd -idukm -I $Reloc_Arch } } # extract cpio absolute archive if test $root_cpio -eq 1 { cd $IR $CPIO_cmd -idukm -I $Root_Arch if test $Status -ne 0 { echo $(gettext "cpio of $Root_Arch failed with error $Status.) exit 1 } } if test -f $FILELIST { $RM_cmd $FILELIST } if test $Rm_alt_sav -eq 1 { $RM_cmd -r $PKGSAV setvar Rm_alt_sav = '0' } exec_clean 0 if test $Tmp_Creat -eq 1 { $RM_cmd -r $Tmp_xpath } if test $Spcl_init -eq 1 { setvar LD_LIBRARY_PATH = "$Org_LD_LIBRARY_PATH" export LD_LIBRARY_PATH setvar Spcl_init = '0' } exit 0