-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathunpack
executable file
·44 lines (38 loc) · 1.01 KB
/
unpack
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
#!/usr/bin/env bash
# unpack: Extract common file formats
# Dependencies: unrar, unzip, p7zip-full
# Author: Patrick Brisbin
# From: http://linuxtidbits.wordpress.com/2009/08/04/week-of-bash-scripts-extract/
# Display usage if no parameters given
if [[ -z "$@" ]]; then
echo " ${0##*/} <archive> - extract common file formats)"
exit
fi
# Required program(s)
req_progs=(7z unrar unzip)
for p in ${req_progs[@]}; do
hash "$p" 2>&- || \
{ echo >&2 " Required program \"$p\" not installed."; exit 1; }
done
# Test if file exists
if [ ! -f "$@" ]; then
echo "File "$@" doesn't exist"
exit
fi
# Extract file by using extension as reference
case "$@" in
*.7z ) 7z x "$@" ;;
*.tar.bz2 ) tar xvjf "$@" ;;
*.bz2 ) bunzip2 "$@" ;;
*.deb ) ar vx "$@" ;;
*.tar.gz ) tar xvf "$@" ;;
*.gz ) gunzip "$@" ;;
*.tar ) tar xvf "$@" ;;
*.tbz2 ) tar xvjf "$@" ;;
*.tar.xz ) tar xvf "$@" ;;
*.tgz ) tar xvzf "$@" ;;
*.rar ) unrar x "$@" ;;
*.zip ) unzip "$@" ;;
*.Z ) uncompress "$@" ;;
* ) echo " Unsupported file format" ;;
esac