dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/bin/extraer

39 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# A general, all-purpose extraction script.
#
# Default behavior: Extract archive into new directory
# Behavior with `-c` option: Extract contents into current directory
while getopts "hc" o; do case "${o}" in
h) echo -e "Options:\\n -c: Extract archive into current directory rather than a new one." && exit ;;
c) dirpref="" && archive=${*:2} ;;
*) echo "only valid options are -h and -c." ;;
esac done
[ -z ${dirpref+x} ] && dirpref="../" && archive="$*"
if [ -f "$archive" ] ; then
[[ "$dirpref" == "../" ]] && NAME=${archive%.*} && mkdir "$NAME" && cd "$NAME" || exit
case "$archive" in
*.tar.bz2) tar xvjf "$dirpref""$archive" ;;
*.tar.gz) tar xvzf "$dirpref""$archive" ;;
*.tar.xz) tar xvJf "$dirpref""$archive" ;;
*.lzma) unlzma "$dirpref""$archive" ;;
*.bz2) bunzip2 "$dirpref""$archive" ;;
*.rar) unrar x -ad "$dirpref""$archive" ;;
*.gz) gunzip "$dirpref""$archive" ;;
*.tar) tar xvf "$dirpref""$archive" ;;
*.tbz2) tar xvjf "$dirpref""$archive" ;;
*.tgz) tar xvzf "$dirpref""$archive" ;;
*.zip) unzip "$dirpref""$archive" ;;
*.Z) uncompress "$dirpref""$archive" ;;
*.7z) 7z x "$dirpref""$archive" ;;
*.xz) unxz "$dirpref""$archive" ;;
*.exe) cabextract "$dirpref""$archive" ;;
*) echo "extract: '$archive' - unknown archive method" ;;
esac
else
echo "File \"$archive\" not found."
fi