2020-02-08 23:43:37 +00:00
|
|
|
#!/bin/sh
|
2019-05-31 23:38:43 +00:00
|
|
|
|
|
|
|
# A general, all-purpose extraction script. Not all extraction programs here
|
|
|
|
# are installed by LARBS automatically.
|
2019-05-20 00:47:24 +00:00
|
|
|
#
|
|
|
|
# Default behavior: Extract archive into new directory
|
|
|
|
# Behavior with `-c` option: Extract contents into current directory
|
|
|
|
|
|
|
|
while getopts "hc" o; do case "${o}" in
|
|
|
|
c) extracthere="True" ;;
|
2020-08-27 19:57:16 +00:00
|
|
|
*) printf "Options:\\n -c: Extract archive into current directory rather than a new one.\\n" && exit 1 ;;
|
2019-05-20 00:47:24 +00:00
|
|
|
esac done
|
|
|
|
|
|
|
|
if [ -z "$extracthere" ]; then
|
|
|
|
archive="$(readlink -f "$*")" &&
|
|
|
|
directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" &&
|
|
|
|
mkdir -p "$directory" &&
|
2020-08-27 19:57:16 +00:00
|
|
|
cd "$directory" || exit 1
|
2019-05-20 00:47:24 +00:00
|
|
|
else
|
2020-08-27 19:57:16 +00:00
|
|
|
archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)" 2>/dev/null)"
|
2019-05-20 00:47:24 +00:00
|
|
|
fi
|
|
|
|
|
2020-08-27 19:57:16 +00:00
|
|
|
[ -z "$archive" ] && printf "Give archive to extract as argument.\\n" && exit 1
|
2019-05-20 00:47:24 +00:00
|
|
|
|
|
|
|
if [ -f "$archive" ] ; then
|
|
|
|
case "$archive" in
|
2021-08-19 11:56:44 +00:00
|
|
|
*.tar.bz2|*.tbz2) bsdtar -xf "$archive" ;;
|
|
|
|
*.tar.xz) bsdtar -xf "$archive" ;;
|
|
|
|
*.tar.gz|*.tgz) bsdtar -xf "$archive" ;;
|
|
|
|
*.tar.zst) bsdtar -xf "$archive" ;;
|
|
|
|
*.tar) bsdtar -xf "$archive" ;;
|
2019-05-20 00:47:24 +00:00
|
|
|
*.lzma) unlzma "$archive" ;;
|
|
|
|
*.bz2) bunzip2 "$archive" ;;
|
|
|
|
*.rar) unrar x -ad "$archive" ;;
|
|
|
|
*.gz) gunzip "$archive" ;;
|
|
|
|
*.zip) unzip "$archive" ;;
|
|
|
|
*.Z) uncompress "$archive" ;;
|
|
|
|
*.7z) 7z x "$archive" ;;
|
|
|
|
*.xz) unxz "$archive" ;;
|
|
|
|
*.exe) cabextract "$archive" ;;
|
|
|
|
*) printf "extract: '%s' - unknown archive method\\n" "$archive" ;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
printf "File \"%s\" not found.\\n" "$archive"
|
|
|
|
fi
|