-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx
executable file
·47 lines (41 loc) · 1.02 KB
/
tx
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
#!/bin/bash
# Author: Fraser Hanson
# Date: 2015-09-29
# Purpose:
# Unpack all the tar archives in $PWD.
# Handle gracefully the situation where they're double-zipped but named
# like real tar archives.
# NOTE: --warning=no-timestamp argument suppresses warnings of file timestamps in the future.
set -e
set -x
# Test whether the give *.tar.gz file actually contains a tar archive.
# If so, unpack tarball. If not, gunzip the file and try untarring again
# (recursive.)
function untar(){
local f="$1"
if tar tf "$f" > /dev/null 2>&1; then
tar xzf "$f" --warning=no-timestamp
else
# Double-zipped. Unzip before tar.
mv "$f"{,.gz}
gunzip "$f.gz"
untar "$f"
fi
}
# If argument list is empty
if [ -z "$@" ]; then
# untar all tarball files
for f in *.tar.gz; do
echo "tar xzf $f"
untar "$f"
done
else
# untar the specified files only
for f in $@; do
# if file exists and is non-zero
if test -s $f; then
echo "tar xzf $f"
untar "$f"
fi
done
fi