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