diff options
Diffstat (limited to 'extract.sh')
-rwxr-xr-x | extract.sh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/extract.sh b/extract.sh new file mode 100755 index 0000000..bbb317a --- /dev/null +++ b/extract.sh @@ -0,0 +1,52 @@ +#!/bin/bash +#----------------------------------------------------# +# File: ~/bin/extract.sh # +# Version: 0.1.0 # +# Date: 2008-11-02 # +# Author: Florian "Bluewind" Pritz <f-p@gmx.at> # +# Extract an archive based on the mime type # +#----------------------------------------------------# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +if [ "$1" = "" ] || [ "$1" = "-h" ]; then + echo -e "${blue}Usage:$NC $0 <file>"; + echo -e "Extracts <file>"; + echo -e "Also accepts multiple files"; + exit 0 +fi +for file in "$@" +do + if [ -f ${file} ] ; then + case ${file} in + *.tar.bz2) tar xjf ${file} ;; + *.tar.gz) tar xzf ${file} ;; + *.tbz2) tar xjf ${file} ;; + *.tgz) tar xzf ${file} ;; + *) + case $(file -bi ${file}) in + application/x-bzip2) bunzip2 ${file};; + application/rar) unrar x ${file};; + application/x-gzip) gunzip ${file};; + application/x-tar) tar xf ${file};; + application/zip) unzip ${file};; + application/x-compressed) uncompress ${file};; + application/x-7z-compressed) 7z x ${file};; + *) echo -e "${RED}Error:$NC No rule how to extract \"${file}\" ($(file -bi ${file}))" ;; + esac + ;; + esac + else + echo -e "${RED}Error:$NC \"${file}\" doesn't exist" + fi +done |