-
Notifications
You must be signed in to change notification settings - Fork 0
/
expand_dbgap_data.sh
executable file
·52 lines (42 loc) · 1.43 KB
/
expand_dbgap_data.sh
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
usage="Usage: \nuntar_all.sh ROOTDIR\nrecursively finds and extracts all tar files under ROOTDIR"
ROOTDIR=$1
if [ -z "$ROOTDIR" ]
then echo -e $usage
fi
# Unextracted files are moved here, then deleted if no errors
DUMPROOT=$ROOTDIR/_extracted
tarfiles='.'
gzfiles='.'
# Sum of all return codes to test for overall success
retcodes=0
# Iterate as long as *.tar or *.gz are found
while [ "${tarfiles}" ] || [ "${gzfiles}" ]
do
tarfiles=$(find $ROOTDIR -path $DUMPROOT -prune -o -name "*.tar" -print); retcodes=$(($retcodes + $?))
gzfiles=$(find $ROOTDIR -path $DUMPROOT -prune -o -name "*.gz" -print); retcodes=$(($retcodes + $?))
for file in $tarfiles
do echo Expanding $file...
tar -xf $file -C $(dirname $file); retcodes=$(($retcodes + $?))
echo "...moving to $DUMPROOT"
dest=$DUMPROOT/$(dirname $file)
mkdir -p $dest; retcodes=$(($retcodes + $?))
mv $file $dest; retcodes=$(($retcodes + $?))
done
for file in $gzfiles
do echo Expanding $file...
outfile=$(dirname $file)/$(basename $file .gz)
gunzip -c $file > $outfile; retcodes=$(($retcodes + $?))
echo "...moving to $DUMPROOT"
dest=$DUMPROOT/$(dirname $file)
mkdir -p $dest; retcodes=$(($retcodes + $?))
mv $file $dest; retcodes=$(($retcodes + $?))
done
done
# If successful, clean up compressed and tarred files
if [ $retcodes -eq 0 ]
then
echo "Deleting unexpanded files in $DUMPROOT ..."
rm -r $DUMPROOT
echo "...Done"
fi