summaryrefslogtreecommitdiffstats
path: root/extract.sh
blob: bbb317a67a726b681be58671f772d7550cb131f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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