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] 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."
25 if [[ $1 == --help ]]; then
31 # tars first, so they are higher pri than non-tar extensions
32 *.
tar ) tar xf
"$x" ;;
33 *.
tar.bz2 |
*.tbz2
) tar xjf
"$x" ;;
34 *.
tar.gz |
*.tgz
) tar xzf
"$x" ;;
35 *.
tar.xz
) tar Jxf
"$x" ;;
38 *.bz2
) bunzip2
"$x" ;;
43 *.xz
) tar xJf data.
tar.xz
;;
44 *.gz
) tar xzf data.
tar.gz
;;
45 *) echo "error: could not find data.tar.*" >&2; exit 1 ;;
47 tar xzf control.
tar.gz
51 *.dsc
) dpkg-source
-x "$x" ;;
55 if [[ $EUID != 0 ]]; then
58 local temp_dir
=$
(mktemp
-d)
60 $super mount
-o loop
"$x" "$temp_dir"
61 local dir
="${x%%.iso}"
63 cp -a "$temp_dir"/* "$dir"
64 $super umount
"$temp_dir"
67 *.r
[0-9][0-9]|
*.rar
) unrar x
"$x" ;;
68 *.rpm
) rpm2cpio
"$x" |
cpio --extract --make-directories ;;
69 *.sfs
) $super unsquashfs
"$x" ;;
70 *.Z
) uncompress "$x" ;;
71 *.
zip|
*.xpi
) unzip "$x" ;;
73 *) echo "I don't know how to extract $x";;