1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
|
#!/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.
#
NAME="i.CompCpio"
FILELIST=${PKGSAV:?undefined}/filelist
BD=${BASEDIR:-/}
IR=${PKG_INSTALL_ROOT:-/}
MAXLIST=550 # This is arbitrary based upon 2.4 cpio
count=0
reloc_cpio_Z=0
root_cpio_Z=0
reloc_cpio=0
root_cpio=0
Reloc_Arch=""
Root_Arch=""
is_an_archive=0
is_a_filelist=0
mk_filelist=0
list_empty=1
local_install=0
Spcl_init=0
Rm_alt_sav=0
# critical archived dynamic libraries and executables
Spcl_lib=0
Spcl_exec=0
Movelist=""
Ld_Preload=""
Ld1=usr/lib/ld.so.1
Ld=usr/lib/ld.so
Libintl=usr/lib/libintl.so.1
Libmalloc=usr/lib/libmapmalloc.so.1
Libc=usr/lib/libc.so.1
Libw=usr/lib/libw.so.1
Libdl=usr/lib/libdl.so.1
Cpio=usr/bin/cpio
Rm=usr/bin/rm
Ln=usr/bin/ln
Mv=usr/bin/mv
Nawk=usr/bin/nawk
Zcat=usr/bin/zcat
# Set up the default paths
MV_xpath=/usr/bin
MV_cmd=$MV_xpath/mv
CPIO_xpath=/usr/bin
CPIO_cmd=$CPIO_xpath/cpio
ZCAT_xpath=/usr/bin
ZCAT_cmd=$ZCAT_xpath/zcat
LN_xpath=/usr/bin
LN_cmd=$LN_xpath/ln
NAWK_xpath=/usr/bin
NAWK_cmd=$NAWK_xpath/nawk
RM_xpath=/usr/bin
RM_cmd=$RM_xpath/rm
Tmp_xpath=/usr/tmp$$dir
Tmp_Creat=0
rm_cpio=0
rm_ln=0
rm_zcat=0
rm_nawk=0
rm_rm=0
rm_mv=0
no_select=0
# Functions
#
# This creates the temporary directory for holding the old dynamic
# libraries and executables.
#
mktempdir() {
if [ ! -d $Tmp_xpath ]; then
mkdir $Tmp_xpath
if [ $? -ne 0 ]; then
echo `gettext "ERROR : $NAME cannot create $Tmp_xpath."`
exit 1
fi
fi
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.
#
spclcase() { # $1 is the pathname to special case
if [ $local_install -eq 1 ]; then
case $1 in
$Ld) no_select=1;;
$Ld1) no_select=1;;
$Libintl) Spcl_lib=1; file=libintl.so.1;;
$Libmalloc) Spcl_lib=1; file=libmapmalloc.so.1;;
$Libc) Spcl_lib=1; file=libc.so.1;;
$Libw) Spcl_lib=1; file=libw.so.1;;
$Libdl) Spcl_lib=1; file=libdl.so.1;;
$Cpio) rm_cpio=1; Spcl_exec=1;;
$Ln) rm_ln=1; Spcl_exec=1;;
$Zcat) rm_zcat=1; Spcl_exec=1;;
$Nawk) rm_nawk=1; Spcl_exec=1;;
$Rm) rm_rm=1; Spcl_exec=1;;
$Mv) rm_mv=1; Spcl_exec=1;;
esac
if [ $no_select -eq 1 ]; then
is_a_filelist=0
list_empty=1
$RM_cmd $FILELIST
if [ $Rm_alt_sav -eq 1 ]; then
$RM_cmd -r $PKGSAV
Rm_alt_sav=0
fi
exec_clean 1
return 1
elif [ $Spcl_lib -eq 1 ]; then
if [ $Tmp_Creat -eq 0 ]; then
mktempdir
fi
if [ $Spcl_init -eq 0 ]; then
Org_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
LD_LIBRARY_PATH="$Org_LD_LIBRARY_PATH $Tmp_xpath"
export LD_LIBRARY_PATH
Spcl_init=1
fi
Ld_Preload="$Ld_Preload $Tmp_xpath/$file"
LD_PRELOAD=$Ld_Preload
export LD_PRELOAD
Movelist="$1 $file $Movelist"
$MV_cmd $1 $Tmp_xpath
$LN_cmd -s ../..$Tmp_xpath/$file $1
Spcl_lib=0
elif [ $Spcl_exec -eq 1 ]; then
if [ $Tmp_Creat -eq 0 ]; then
mktempdir
fi
$MV_cmd $1 $Tmp_xpath
if [ $rm_cpio -eq 1 ]; then
$LN_cmd -s ../..$Tmp_xpath/cpio $1
CPIO_cmd="$Tmp_xpath/cpio"
Movelist="$1 cpio $Movelist"
rm_cpio=0
elif [ $rm_ln -eq 1 ]; then
$Tmp_xpath/ln -s ../..$Tmp_xpath/ln $1
LN_cmd="$Tmp_xpath/ln"
Movelist="$1 ln $Movelist"
rm_ln=0
elif [ $rm_nawk -eq 1 ]; then
$LN_cmd -s ../..$Tmp_xpath/nawk $1
NAWK_cmd="$Tmp_xpath/nawk"
Movelist="$1 nawk $Movelist"
rm_nawk=0
elif [ $rm_zcat -eq 1 ]; then
$LN_cmd -s ../..$Tmp_xpath/zcat $1
ZCAT_cmd="$Tmp_xpath/zcat"
Movelist="$1 zcat $Movelist"
rm_zcat=0
elif [ $rm_rm -eq 1 ]; then
$LN_cmd -s ../..$Tmp_xpath/rm $1
RM_cmd="$Tmp_xpath/rm"
Movelist="$Movelist $1 rm"
rm_rm=0
elif [ $rm_mv -eq 1 ]; then
$LN_cmd -s ../..$Tmp_xpath/mv $1
MV_cmd="$Tmp_xpath/mv"
Movelist="$Movelist $1 mv"
rm_mv=0
fi
Spcl_exec=0
fi
fi
return 0
}
#
# Clean up the libraries and executables that were moved.
#
exec_clean() { # $1 =1 means be quiet
if [ ! -z "${Movelist}" ]; then
echo $Movelist | $NAWK_cmd '
{ split ($0, line)
for (n=1; n <= NF; n++) {
print line[n]
}
}' | while read path; do
read file
if [ -h $path ]; then # If it's our slink
# then put the original back
if [ $1 -eq 0 ]; then
echo `gettext "WARNING : $path not found in archive."`
fi
$MV_cmd $Tmp_xpath/$file $path
else # if the archive put something down
# remove the temporary copy
$RM_cmd $Tmp_xpath/$file
fi
done
for path in $Movelist; do
if [ -x $path ]; then
case $path in
$Cpio) CPIO_cmd="$CPIO_xpath/cpio";;
$Ln) LN_cmd="$LN_xpath/ln";;
$Zcat) ZCAT_cmd="$ZCAT_xpath/zcat";;
$Nawk) NAWK_cmd="$NAWK_xpath/nawk";;
$Rm) RM_cmd="$RM_xpath/rm";;
$Mv) MV_cmd="$MV_xpath/mv";;
esac
fi
done
Movelist=""
if [ $Tmp_Creat -eq 1 ]; then
$RM_cmd -r $Tmp_xpath
Tmp_Creat=0
fi
fi
}
#
# Figure out what kind of package this is
#
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 [ ${path:-NULL} != NULL ]; then # get the package source directory
PKGSRC=${path:?undefined}
if [ ${PKG_INSTALL_ROOT:-/} = "/" ]; then
local_install=1
fi
if [ -r $PKGSRC/reloc.cpio.Z ]; then
reloc_cpio_Z=1
Reloc_Arch=$PKGSRC/reloc.cpio.Z
is_an_archive=1
fi
if [ -r $PKGSRC/root.cpio.Z ]; then
root_cpio_Z=1
Root_Arch=$PKGSRC/root.cpio.Z
is_an_archive=1
fi
if [ -r $PKGSRC/reloc.cpio ]; then
reloc_cpio=1
Reloc_Arch=$PKGSRC/reloc.cpio
is_an_archive=1
fi
if [ -r $PKGSRC/root.cpio ]; then
root_cpio=1
Root_Arch=$PKGSRC/root.cpio
is_an_archive=1
fi
if [ -r $PKGSRC/reloc.Z ]; then
reloc_cpio_Z=1
Reloc_Arch=$PKGSRC/reloc.Z
is_an_archive=2
fi
if [ -r $PKGSRC/root.Z ]; then
root_cpio_Z=1
Root_Arch=$PKGSRC/root.Z
is_an_archive=2
fi
if [ -f $PKGSRC/reloc ]; then
reloc_cpio=1
Reloc_Arch=$PKGSRC/reloc
is_an_archive=2
fi
if [ -f $PKGSRC/root ]; then
root_cpio=1
Root_Arch=$PKGSRC/root
is_an_archive=2
fi
else
exit 0 # empty pipe, we're done
fi
}
#
# main
#
eval_pkg
if [ $BD = "/" ]; then
Client_BD=""
else
Client_BD=`echo $BD | sed s@/@@`
fi
if [ $is_an_archive -eq 0 ]; then
echo `gettext "ERROR : $NAME cannot find archived files in $PKGSRC."`
exit 1
fi
if [ ! -d $PKGSAV ]; then
echo `gettext "WARNING : $NAME cannot find save directory $PKGSAV."`
PKGSAV=/tmp/$PKG.sav
if [ ! -d $PKGSAV ]; then
/usr/bin/mkdir $PKGSAV
fi
if [ $? -eq 0 ]; then
echo `gettext " Using alternate save directory" $PKGSAV`
FILELIST=$PKGSAV/filelist
Rm_alt_sav=1
else
echo `gettext "ERROR : cannot create alternate save directory"` $PKGSAV
exit 1
fi
fi
if [ -f $FILELIST ]; then
rm $FILELIST
fi
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 [ $is_an_archive -eq 1 -a ${PKG_INIT_INSTALL:-null} = null ]; then
mk_filelist=1
fi
# 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 [ ${PKG_INIT_INSTALL:-null} = null ]; then
if [ $local_install -eq 1 ]; then
# If extraction list is desired, create it
if [ $mk_filelist -eq 1 ]; then
is_a_filelist=1
while read path
do
echo $path >> $FILELIST
list_empty=0
if [ -x ${path:-NULL} ]; then
full_path=`echo $Client_BD/$path | sed s@//@/@g`
spclcase $full_path
if [ $? -eq 1 ]; then
break
fi
fi
done
# If there's a path containing a '$' then we can't
# use the extraction list because of the shell
if [ $list_empty -eq 0 ]; then
s=`LD_PRELOAD="$Ld_Preload" $NAWK_cmd ' /\\$/ { print } ' $FILELIST`
if [ ! -z "${s}" ]; then
is_a_filelist=0
fi
fi
else # No extraction list is desired
while read path
do
if [ -x ${path:-NULL} ]; then
full_path=`echo $Client_BD/$path | sed s@//@/@g`
spclcase $full_path
if [ $? -eq 1 ]; then
break
fi
fi
done
fi # $mk_filelist -eq 1
else # ! ($local_install -eq 1)
# If extraction list is desired, create it
if [ $mk_filelist -eq 1 ]; then
is_a_filelist=1
while read path
do
echo $path >> $FILELIST
list_empty=0
done
# If there's a path containing a '$' then we can't
# use the extraction list because of the shell
if [ $list_empty -eq 0 ]; then
s=`LD_PRELOAD="$Ld_Preload" $NAWK_cmd ' /\\$/ { print } ' $FILELIST`
if [ ! -z "${s}" ]; then
is_a_filelist=0
fi
fi
fi # $mk_filelist -eq 1
fi # $local_install -eq 1
fi # ${PKG_INIT_INSTALL:-null} = null
# Now extract the data from the archive(s)
# extract compressed cpio relocatable archive
if [ $reloc_cpio_Z -eq 1 ]; then
cd $BD
if [ $is_a_filelist -eq 1 ]; then
if [ $list_empty -eq 0 ]; then
$ZCAT_cmd $Reloc_Arch | $CPIO_cmd -idukm -E $FILELIST
if [ $? -ne 0 ]; then
echo `gettext "cpio of $Reloc_Arch failed with error $?."`
exit 1
fi
fi
else
$ZCAT_cmd $Reloc_Arch | $CPIO_cmd -idukm
fi
fi
# extract compressed cpio absolute archive
if [ $root_cpio_Z -eq 1 ]; then
cd $IR
$ZCAT_cmd $Root_Arch | $CPIO_cmd -idukm
if [ $? -ne 0 ]; then
echo `gettext "cpio of $Root_Arch failed with error $?."`
exit 1
fi
fi
# extract cpio relocatable archive
if [ $reloc_cpio -eq 1 ]; then
cd $BD
if [ $is_a_filelist -eq 1 ]; then
if [ $list_empty -eq 0 ]; then
$CPIO_cmd -idukm -I $Reloc_Arch -E $FILELIST
if [ $? -ne 0 ]; then
echo `gettext "cpio of $Reloc_Arch failed with error $?."`
exit 1
fi
fi
else
$CPIO_cmd -idukm -I $Reloc_Arch
fi
fi
# extract cpio absolute archive
if [ $root_cpio -eq 1 ]; then
cd $IR
$CPIO_cmd -idukm -I $Root_Arch
if [ $? -ne 0 ]; then
echo `gettext "cpio of $Root_Arch failed with error $?."`
exit 1
fi
fi
if [ -f $FILELIST ]; then
$RM_cmd $FILELIST
fi
if [ $Rm_alt_sav -eq 1 ]; then
$RM_cmd -r $PKGSAV
Rm_alt_sav=0
fi
exec_clean 0
if [ $Tmp_Creat -eq 1 ]; then
$RM_cmd -r $Tmp_xpath
fi
if [ $Spcl_init -eq 1 ]; then
LD_LIBRARY_PATH=$Org_LD_LIBRARY_PATH
export LD_LIBRARY_PATH
Spcl_init=0
fi
exit 0
|