-
Notifications
You must be signed in to change notification settings - Fork 0
/
duntarball.old
74 lines (66 loc) · 1.64 KB
/
duntarball.old
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
# Untar a tarball regardless of it's compression format (or lack thereof)
#
source ${SCRIPTS}/functions.sh
if [ -z "${1}" ]; then
die "Usage: ${0} [ --patch ] <tarball>"
fi
if [ "${1}" == "--patch" ]; then
PATCH="yes"
TARBALL=${2}
else
TARBALL=${1}
fi
if [ -z ${TARBALL} ]; then
die "Usage: ${0} [ --patch ] <tarball>"
fi
FILETYPE=`file "${TARBALL}"`
if echo "${FILETYPE}" | grep gzip >/dev/null; then
CMD="tar zpxf"
if [ -n "$(echo ${TARBALL} | grep tar)" ]; then
EXT=".tar.gz"
else
EXT=".tgz"
fi
elif echo "${FILETYPE}" | grep bzip2 >/dev/null; then
CMD="tar jpxf"
if [ -n "$(echo ${TARBALL} | grep tar)" ]; then
EXT=".tar.bz2"
elif [ -n "$(echo ${TARBALL} | grep tbz2)" ]; then
EXT=".tbz2"
else
EXT=".tbz"
fi
elif echo "${FILETYPE}" | grep tar >/dev/null; then
CMD="tar pxf"
EXT=".tar"
elif echo "${FILETYPE}" | grep Zip >/dev/null; then
CMD="unzip"
EXT=".zip"
elif echo "${FILETYPE}" | grep RAR >/dev/null; then
CMD="unrar e"
EXT=".rar"
else
echo "${0}: ${1} not recognized"
echo "FILETYPE: ${FILETYPE}"
exit
fi
BASENAME=$(basename ${TARBALL} ${EXT})
if [ ! -d ${BASENAME} ]; then
${CMD} "${TARBALL}" || die "${CMD} failed"
fi
if [ -n "${PATCH}" ]; then
if [ -d ${BASENAME} ]; then
# Directory exists; get a .orig
TEMPNAME=$(tempfile -d .)
rm -f ${TEMPNAME}
mv ${BASENAME} ${TEMPNAME} || die "mv ${BASENAME} ${TEMPNAME} failed"
${CMD} "${TARBALL}" || die "${CMD} failed"
mv ${BASENAME} ${BASENAME}.orig || die "mv failed"
mv ${TEMPNAME} ${BASENAME} || die "mv ${TEMPNAME} ${BASENAME} failed"
else
mv ${BASENAME} ${BASENAME}.orig || die "mv failed"
${CMD} "${TARBALL}" || die "${CMD} failed"
fi
fi