Revision 17362,
2.3 KB
checked in by ghudson, 23 years ago
(diff) |
This commit was generated by cvs2svn to compensate for changes in r17361,
which included commits to RCS files with non-trunk default branches.
|
-
Property svn:executable set to
*
|
Line | |
---|
1 | #!/bin/sh |
---|
2 | |
---|
3 | # emulate-gnu-tar -- emulate the options of GNU tar that librep uses |
---|
4 | # in its tar-file handling code. |
---|
5 | |
---|
6 | # $Id: emulate-gnu-tar,v 1.1.1.1 2002-03-20 04:54:38 ghudson Exp $ |
---|
7 | |
---|
8 | compression_mode="" |
---|
9 | command="" |
---|
10 | tarfile="" |
---|
11 | to_stdout="" |
---|
12 | |
---|
13 | version="1.0" |
---|
14 | |
---|
15 | original_directory=`pwd` |
---|
16 | |
---|
17 | usage () { |
---|
18 | cat <<EOF |
---|
19 | usage: emulate-gnu-tar [OPTIONS..] COMMAND |
---|
20 | |
---|
21 | Supported options include: |
---|
22 | |
---|
23 | --compress |
---|
24 | --gzip |
---|
25 | --bzip2 |
---|
26 | |
---|
27 | Supported commands include: |
---|
28 | |
---|
29 | --version |
---|
30 | --list --file TARFILE --verbose |
---|
31 | --extract --file TARFILE -C DIR |
---|
32 | --extract --file TARFILE --to-stdout FILE |
---|
33 | |
---|
34 | EOF |
---|
35 | } |
---|
36 | |
---|
37 | absolutify () { |
---|
38 | case "$1" in |
---|
39 | /*) |
---|
40 | echo $1 |
---|
41 | ;; |
---|
42 | *) |
---|
43 | echo "$original_directory/$1" |
---|
44 | ;; |
---|
45 | esac |
---|
46 | } |
---|
47 | |
---|
48 | while [ x"$1" != x ]; do |
---|
49 | case $1 in |
---|
50 | --version) |
---|
51 | cat <<EOF |
---|
52 | tar (GNU tar) $version |
---|
53 | This isn't really GNU tar. It's just a wrapper script used by librep to |
---|
54 | make proprietary tars look somewhat like GNU tar. Don't use it. |
---|
55 | EOF |
---|
56 | exit 0 |
---|
57 | ;; |
---|
58 | |
---|
59 | --compress) |
---|
60 | compression_mode=compress |
---|
61 | ;; |
---|
62 | |
---|
63 | --gzip) |
---|
64 | compression_mode=gzip |
---|
65 | ;; |
---|
66 | |
---|
67 | --bzip2) |
---|
68 | compression_mode=bzip2 |
---|
69 | ;; |
---|
70 | |
---|
71 | --file) |
---|
72 | tarfile=`absolutify "$2"` |
---|
73 | shift |
---|
74 | ;; |
---|
75 | |
---|
76 | --verbose) |
---|
77 | ;; |
---|
78 | |
---|
79 | -C) |
---|
80 | cd "$2" |
---|
81 | shift |
---|
82 | ;; |
---|
83 | |
---|
84 | --to-stdout) |
---|
85 | to_stdout=$2 |
---|
86 | shift |
---|
87 | ;; |
---|
88 | |
---|
89 | --extract) |
---|
90 | command=extract |
---|
91 | ;; |
---|
92 | |
---|
93 | --list) |
---|
94 | command=list |
---|
95 | ;; |
---|
96 | |
---|
97 | *) |
---|
98 | echo "unknown option: $1" >&2 |
---|
99 | exit 1 |
---|
100 | ;; |
---|
101 | esac |
---|
102 | shift |
---|
103 | done |
---|
104 | |
---|
105 | if [ "x$command" = x ]; then |
---|
106 | usage |
---|
107 | exit 1 |
---|
108 | fi |
---|
109 | |
---|
110 | case "$compression_mode" in |
---|
111 | gzip) |
---|
112 | input="gzip -d -c \"$tarfile\" |" |
---|
113 | ;; |
---|
114 | |
---|
115 | compress) |
---|
116 | input="compress -d -c \"$tarfile\" |" |
---|
117 | ;; |
---|
118 | |
---|
119 | bzip2) |
---|
120 | input="bzip2 -d -c \"$tarfile\" |" |
---|
121 | ;; |
---|
122 | |
---|
123 | *) |
---|
124 | input="cat \"$tarfile\" |" |
---|
125 | ;; |
---|
126 | esac |
---|
127 | |
---|
128 | case "$command" in |
---|
129 | list) |
---|
130 | eval "$input tar tvf -" |
---|
131 | ;; |
---|
132 | |
---|
133 | extract) |
---|
134 | if [ "x$to_stdout" = "x" ]; then |
---|
135 | eval "$input tar xf -" |
---|
136 | exit $? |
---|
137 | else |
---|
138 | # Extract the file to a temporary directory, then cat it.. |
---|
139 | tmpdir="/tmp/rep-emulate-gnu-tar.$$.output" |
---|
140 | mkdir "$tmpdir" || exit $? |
---|
141 | cd "$tmpdir" |
---|
142 | eval "$input tar xf - $to_stdout" || ( rm -rf $tmpdir && exit $? ) |
---|
143 | cat "$to_stdout" |
---|
144 | cd "$original_directory" |
---|
145 | rm -rf "$tmpdir" |
---|
146 | exit 0 |
---|
147 | fi |
---|
148 | ;; |
---|
149 | |
---|
150 | *) |
---|
151 | echo "Unimplemented command: $command" |
---|
152 | exit 1 |
---|
153 | ;; |
---|
154 | esac |
---|
Note: See
TracBrowser
for help on using the repository browser.