2 # Copyright (C) 2014 Ian Kelling
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 local help="Usage: ex [--help|-q] FILE...
18 Extract many types of files
20 Based on their extensions,
21 7z [tar.]bz2 deb [tar.]gz iso dsc rar rpm sfs tar xpi [tar.]xz zip Z.
22 See source for exact file extensions.
23 Note: dtrx (package & command) extracts most of these plus some others."
36 local x super restore_nullglob f cmd
39 # tars first, so they are higher pri than non-tar extensions
41 $quiet ||
echo tar xf
"$x"
45 $quiet ||
echo tar xjf
"$x"
49 $quiet ||
echo tar xzf
"$x"
53 $quiet ||
echo tar Jxf
"$x"
57 $quiet ||
echo tar -I unzstd
-xf "$x"
58 tar -I unzstd
-xf "$x"
61 $quiet ||
echo unzstd
"$x"
65 $quiet ||
echo pixz
-d "$x"
69 if type -p 7za
&>/dev
/null
; then
74 $quiet ||
echo 7zr x
"$x"
78 $quiet ||
echo bunzip2
"$x"
82 $quiet ||
echo ar x
"$x"
84 restore_nullglob
=false
85 if ! shopt -q nullglob
; then
88 tmp
=(data.
tar.
* control.
tar.
*)
89 if $restore_nullglob; then
92 if (( ${#tmp[@]} != 2 )); then
93 echo "error: could not find data.tar.* or control.tar.*" >&2
96 for f
in ${tmp[@]}; do
99 $quiet ||
echo tar xJf
$f
104 $quiet ||
echo tar -I unzstd
-xf $f
109 $quiet ||
echo tar xzf
$f
114 echo "ex: ERROR: file i didnt expect: $f"
120 $quiet ||
echo dpkg-source
-x "$x"
124 $quiet ||
echo gunzip
"$x"
129 if [[ $EUID != 0 ]]; then
133 temp_dir
=$
(mktemp
-d)
135 $quiet ||
echo $super mount
-o loop
"$x" "$temp_dir"
136 $super mount
-o loop
"$x" "$temp_dir"
137 local dir
="${x%%.iso}"
139 $quiet ||
cp -a "$temp_dir"/* "$dir"
140 cp -a "$temp_dir"/* "$dir"
141 $quiet ||
$super umount
"$temp_dir"
142 $super umount
"$temp_dir"
145 $quiet ||
echo jar xf
"$x"
148 *.r
[0-9][0-9]|
*.rar
)
149 $quiet ||
echo unrar x
"$x"
153 $quiet ||
echo "rpm2cpio $x | cpio --extract --make-directories"
154 rpm2cpio
"$x" |
cpio --extract --make-directories
157 $quiet ||
echo $super unsquashfs
"$x"
158 $super unsquashfs
"$x"
161 $quiet ||
echo uncompress "$x"
165 $quiet ||
echo unzip "$x"
169 *) echo "I don't know how to extract $x";;