2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
25 local help="Usage: ex [--help|-q] FILE...
26 Extract many types of files
28 Based on their extensions,
29 7z [tar.]bz2 deb [tar.]gz iso dsc rar rpm sfs tar xpi [tar.]xz zip Z.
30 See source for exact file extensions.
31 Note: dtrx (package & command) extracts most of these plus some others."
44 local x super restore_nullglob f cmd
47 # tars first, so they are higher pri than non-tar extensions
49 $quiet ||
echo tar xf
"$x"
53 $quiet ||
echo tar xjf
"$x"
57 $quiet ||
echo tar xzf
"$x"
61 $quiet ||
echo tar Jxf
"$x"
65 $quiet ||
echo tar -I unzstd
-xf "$x"
66 tar -I unzstd
-xf "$x"
69 $quiet ||
echo unzstd
"$x"
73 $quiet ||
echo pixz
-d "$x"
77 if type -p 7za
&>/dev
/null
; then
82 $quiet ||
echo 7zr x
"$x"
86 $quiet ||
echo bunzip2
"$x"
90 $quiet ||
echo ar x
"$x"
92 restore_nullglob
=false
93 if ! shopt -q nullglob
; then
96 tmp
=(data.
tar.
* control.
tar.
*)
97 if $restore_nullglob; then
100 if (( ${#tmp[@]} != 2 )); then
101 echo "error: could not find data.tar.* or control.tar.*" >&2
104 for f
in ${tmp[@]}; do
107 $quiet ||
echo tar xJf
$f
112 $quiet ||
echo tar -I unzstd
-xf $f
117 $quiet ||
echo tar xzf
$f
122 echo "ex: ERROR: file i didnt expect: $f"
128 $quiet ||
echo dpkg-source
-x "$x"
132 $quiet ||
echo gunzip
"$x"
137 if [[ $EUID != 0 ]]; then
141 temp_dir
=$
(mktemp
-d)
143 $quiet ||
echo $super mount
-o loop
"$x" "$temp_dir"
144 $super mount
-o loop
"$x" "$temp_dir"
145 local dir
="${x%%.iso}"
147 $quiet ||
cp -a "$temp_dir"/* "$dir"
148 cp -a "$temp_dir"/* "$dir"
149 $quiet ||
$super umount
"$temp_dir"
150 $super umount
"$temp_dir"
153 $quiet ||
echo jar xf
"$x"
156 *.r
[0-9][0-9]|
*.rar
)
157 $quiet ||
echo unrar x
"$x"
161 $quiet ||
echo "rpm2cpio $x | cpio --extract --make-directories"
162 rpm2cpio
"$x" |
cpio --extract --make-directories
165 $quiet ||
echo $super unsquashfs
"$x"
166 $super unsquashfs
"$x"
169 $quiet ||
echo uncompress "$x"
173 $quiet ||
echo unzip "$x"
177 *) echo "I don't know how to extract $x";;