ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / modules / extfs / cpio.in
1 #!/bin/sh
2 #
3 # Written by Stas Maximov 1998 SVR4 (UnixWare)
4 # stmax@u213.srcc.msu.su 
5 # (C) 1996 The Free Software Foundation.
6 #
7 #
8
9 uni_cat ()
10 # $1 is the archive name
11 {
12     case "$1" in
13     *.cpio.Z)   compress -dc "$1"
14         ;;
15     *.cpio.gz)  gzip -dc "$1"
16         ;;
17     *.cpio)     cat "$1"
18         ;;
19     *)          echo "unknown extension"
20     esac
21 }
22
23 mccpiofs_list ()
24 # $1 is the archive name
25 {
26     uni_cat "$1" | cpio -itv | @AWK@ '
27         {
28             if (substr($9,length($9),1) == ",")
29             {
30                 tmp = substr($9, 1, length($9)-1);
31                 $9 = $8;
32                 $8 = tmp
33             }
34             else if (substr($10,length($10),1) == ",")
35             {
36                 tmp = substr($10, 1, length($10)-1);
37                 $10 = $9
38                 $9 = tmp 
39             }
40                 
41             print $0
42         }'
43 }
44
45 mccpiofs_copyout ()
46 # $1 is the archive name
47 # $2 is a name of a file within the archive
48 # $3 is a name of a file within the system (to add from or extract to)
49 {
50     TMPDIR=/tmp/mctmpdir.$$
51 # FIXME bugzilla.eazel.com 1225: Try harder to generate a unique directory if this fails
52     mkdir -m 0700 $TMPDIR || exit 1
53     cd $TMPDIR
54     uni_cat "$1" | cpio -icumd "$2" 2>/dev/null
55     mv "$2" "$3"
56     cd /
57     rm -rf $TMPDIR
58 }
59
60 #
61 # main
62 #
63     umask 077
64
65     case "$1" in
66     list)   mccpiofs_list $2
67             exit 0
68             ;;
69     copyout) mccpiofs_copyout $2 $3 $4
70             exit 0
71             ;;
72     esac
73
74     exit 1
75