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
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 pixz
-d "$x"
61 $quiet ||
echo 7za x
"$x"
65 $quiet ||
echo bunzip2
"$x"
71 restore_nullglob
=false
72 if ! shopt -q nullglob
; then
75 tmp
=(data.
tar.
* control.
tar.
*)
76 if $restore_nullglob; then
79 if (( ${#tmp[@]} != 2 )); then
80 echo "error: could not find data.tar.* or control.tar.*" >&2
83 for f
in ${tmp[@]}; do
86 $quiet ||
echo tar xJf
$f
90 $quiet ||
echo tar xzf
$f
98 $quiet ||
echo dpkg-source
-x "$x"
102 $quiet ||
echo gunzip
"$x"
107 if [[ $EUID != 0 ]]; then
111 temp_dir
=$
(mktemp
-d)
113 $quiet ||
echo $super mount
-o loop
"$x" "$temp_dir"
114 $super mount
-o loop
"$x" "$temp_dir"
115 local dir
="${x%%.iso}"
117 $quiet ||
cp -a "$temp_dir"/* "$dir"
118 cp -a "$temp_dir"/* "$dir"
119 $quiet ||
$super umount
"$temp_dir"
120 $super umount
"$temp_dir"
123 $quiet ||
echo jar xf
"$x"
126 *.r
[0-9][0-9]|
*.rar
)
127 $quiet ||
echo unrar x
"$x"
131 $quiet ||
echo "rpm2cpio $x | cpio --extract --make-directories"
132 rpm2cpio
"$x" |
cpio --extract --make-directories
135 $quiet ||
echo $super unsquashfs
"$x"
136 $super unsquashfs
"$x"
139 $quiet ||
echo uncompress "$x"
143 $quiet ||
echo unzip "$x"
147 *) echo "I don't know how to extract $x";;