-Note: apt-get install dtrx will do the same for
-most of these types, plus some more, I'm going
-to try it out sometime."
- if [[ $1 == --help ]]; then
- echo "$help"
- fi
- local x super
- for x in "$@"; do
- case "$x" in
- *.tar.bz2 | *.tbz2 ) tar xjf "$x" ;;
- *.tar.gz | *.tgz ) tar xzf "$x" ;;
- *.bz2 ) bunzip2 "$x" ;;
- *.gz ) gunzip "$x" ;;
- *.tar ) tar xf "$x" ;;
- *.zip ) unzip "$x" ;;
- *.Z ) uncompress "$x" ;;
- *.7z ) 7za x "$x" ;;
- *.deb ) ar x "$x" ;;
- *.rpm ) rpm2cpio "$x" | cpio --extract --make-directories ;;
- *.tar.xz ) tar Jxf "$x" ;;
- *.xz) xz -d "$x" ;;
- *.iso )
- local super
- if [[ $EUID != 0 ]]; then
- super=sudo
- fi
- local temp_dir=$(mktemp -d)
- $super losetup -f
- $super mount -o loop "$x" "$temp_dir"
- local dir="${x%%.iso}"
- mkdir "$dir"
- cp -a "$temp_dir"/* "$dir"
- $super umount "$temp_dir"
- ;;
- *.r[0-9][0-9]|*.rar ) unrar x "$x" ;;
- *.dsc) dpkg-source -x "$x" ;;
- *.sfs) $user unsquashfs "$x" ;;
- *) echo "I don't kno how to extract $x";;
- esac
- done
+Note: dtrx (package & command) extracts most of these plus some others."
+
+ local quiet=false
+ case $1 in
+ --help)
+ echo "$help"
+ return 0
+ ;;
+ -q)
+ quiet=true
+ shift
+ ;;
+ esac
+ local x super restore_nullglob f cmd
+ for x in "$@"; do
+ case "$x" in
+ # tars first, so they are higher pri than non-tar extensions
+ *.tar )
+ $quiet || echo tar xf "$x"
+ tar xf "$x"
+ ;;
+ *.tar.bz2 | *.tbz2 )
+ $quiet || echo tar xjf "$x"
+ tar xjf "$x"
+ ;;
+ *.tar.gz | *.tgz )
+ $quiet || echo tar xzf "$x"
+ tar xzf "$x"
+ ;;
+ *.tar.xz )
+ $quiet || echo tar Jxf "$x"
+ tar Jxf "$x"
+ ;;
+ *.tar.zst )
+ $quiet || echo tar -I unzstd -xf "$x"
+ tar -I unzstd -xf "$x"
+ ;;
+ *.zst )
+ $quiet || echo unzstd "$x"
+ unzstd "$x"
+ ;;
+ *.xz)
+ $quiet || echo pixz -d "$x"
+ pixz -d "$x"
+ ;;
+ *.7z )
+ if type -p 7za &>/dev/null; then
+ cmd=7za
+ else
+ cmd=7zr
+ fi
+ $quiet || echo 7zr x "$x"
+ $cmd x "$x"
+ ;;
+ *.bz2 )
+ $quiet || echo bunzip2 "$x"
+ bunzip2 "$x"
+ ;;
+ *.deb )
+ $quiet || echo ar x "$x"
+ ar x "$x"
+ restore_nullglob=false
+ if ! shopt -q nullglob; then
+ restore_nullglob=true
+ fi
+ tmp=(data.tar.* control.tar.*)
+ if $restore_nullglob; then
+ shopt -u nullglob
+ fi
+ if (( ${#tmp[@]} != 2 )); then
+ echo "error: could not find data.tar.* or control.tar.*" >&2
+ return 1
+ fi
+ for f in ${tmp[@]}; do
+ case $f in
+ *.xz)
+ $quiet || echo tar xJf $f
+ tar xJf $f
+ rm -f $f
+ ;;
+ *.zst)
+ $quiet || echo tar -I unzstd -xf $f
+ tar -I unzstd -xf $f
+ rm -f $f
+ ;;
+ *.gz)
+ $quiet || echo tar xzf $f
+ tar xzf $f
+ rm -f $f
+ ;;
+ *)
+ echo "ex: ERROR: file i didnt expect: $f"
+ ;;
+ esac
+ done
+ ;;
+ *.dsc)
+ $quiet || echo dpkg-source -x "$x"
+ dpkg-source -x "$x"
+ ;;
+ *.gz )
+ $quiet || echo gunzip "$x"
+ gunzip "$x"
+ ;;
+ *.iso )
+ local super
+ if [[ $EUID != 0 ]]; then
+ super=sudo
+ fi
+ local temp_dir
+ temp_dir=$(mktemp -d)
+ $super losetup -f
+ $quiet || echo $super mount -o loop "$x" "$temp_dir"
+ $super mount -o loop "$x" "$temp_dir"
+ local dir="${x%%.iso}"
+ mkdir "$dir"
+ $quiet || cp -a "$temp_dir"/* "$dir"
+ cp -a "$temp_dir"/* "$dir"
+ $quiet || $super umount "$temp_dir"
+ $super umount "$temp_dir"
+ ;;
+ *.jar)
+ $quiet || echo jar xf "$x"
+ jar xf "$x"
+ ;;
+ *.r[0-9][0-9]|*.rar )
+ $quiet || echo unrar x "$x"
+ unrar x "$x"
+ ;;
+ *.rpm )
+ $quiet || echo "rpm2cpio $x | cpio --extract --make-directories"
+ rpm2cpio "$x" | cpio --extract --make-directories
+ ;;
+ *.sfs)
+ $quiet || echo $super unsquashfs "$x"
+ $super unsquashfs "$x"
+ ;;
+ *.Z )
+ $quiet || echo uncompress "$x"
+ uncompress "$x"
+ ;;
+ *.zip|*.xpi )
+ $quiet || echo unzip "$x"
+ unzip "$x"
+ ;;
+
+ *) echo "I don't know how to extract $x";;
+ esac
+ done