-
Notifications
You must be signed in to change notification settings - Fork 0
/
duntarball
executable file
·71 lines (59 loc) · 1.49 KB
/
duntarball
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
#!/bin/bash
#
# Unpack an archive regardless of it's compression format (or lack thereof)
#
# Set usage output
USAGE="[-h |--help] [-p | --patch] [-d <dir> | --directory=<dir>] <archive>"
LONGUSAGE="\t-h, --help\n\t\tPrint this help message
\t-p, --patch\n\t\tExtract twice, once with .orig appended to the dir
\t-d <dir>, --directory=<dir>\n\t\textract to <dir>
\t<archive>\n\t\tPath to archive to extract"
# Standard functions
source ${SCRIPTS}/functions.sh
atool --help > /dev/null 2>&1
if [ "$?" != "0" ]; then
die "You must install atool"
fi
# Script name
ME=$(basename $0)
# Parse arguments
ARGS=`getopt -o hpd: --long help,patch,directory: -n "${ME}" -- "$@"`
if [ $? != 0 ] ; then
usage
fi
eval set -- "$ARGS"
while true ; do
case "$1" in
-h|--help) usage; shift ;;
-p|--patch) PATCH="yes"; shift ;;
-d|--directory) DIR=$2 ; shift 2 ;;
--) shift ; break ;;
* ) usage "Invalid argument $1";;
esac
done
# Remaining arguments are in $1, $2, etc. as normal
ARCHIVE=${1}
if [ -z "${ARCHIVE}" ]; then
usage "Must give an archive"
fi
TMP=$(mktemp)
atool -xq --save-outdir=$TMP "${ARCHIVE}"
UDIR=$(cat ${TMP})
DIRNAME=$(basename ${UDIR})
if [ -n "${PATCH}" ]; then
if [ ! -d "${DIRNAME}.orig" ]; then
if [ -n "${UDIR}" ]; then
mv "${UDIR}" "${DIRNAME}.orig"
else
die "Failed to extract .orig version: \"${DIRNAME}\""
fi
fi
if [ ! -d "${DIRNAME}" ]; then
atool -xq "${ARCHIVE}"
fi
fi
echo "${DIRNAME}"
rm ${TMP}
if [ -n "$(/bin/ls -d Unpack-* 2>/dev/null)" ]; then
rmdir Unpack-*
fi