-
Notifications
You must be signed in to change notification settings - Fork 1
/
ali_extract
executable file
·71 lines (61 loc) · 1.63 KB
/
ali_extract
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
#!/bin/bash
trap "exit" SIGINT
ZIP="root_archive.zip"
FILE="AnalysisResults.root"
CURDIR="$(pwd -P)"
help () {
echo "$0 -test -dir start_directory -zip zip_file -file file_to_be_extracted
all arguments are optional; the default values are :
-dir : current directory
-zip : root_archive.zip
-file : AnalysisResults.root
-test : no zip testing unless specified"
}
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="${1}"
case ${key} in
-test)
IS_TEST="1"
shift # past argument
;;
-h|-help|--h|--help)
help
exit 0
;;
-zip)
ZIP="${2}"
shift # past argument
shift # past value
;;
-file)
FILE="${2}"
shift # past argument
shift # past value
;;
-dir)
CURDIR="${2}"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("${1}") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
EXTRACT='unzip -o -u '
TEST='unzip -tq '
which 7za &> /dev/null && { EXTRACT='7za -y e '; TEST='7za t '; }
list=$(find -H "${CURDIR}" -type f -name "${ZIP}" -printf '%p\n')
for f in ${list};do
size=$(stat -c %s "${f}")
[[ ${size} == "0" ]] && { echo -e ${f} " ---> SIZE 0 <--- "; rm -rf "${f}"; continue; }
if [[ -n "${IS_TEST}" ]]; then
${TEST} "${f}" &> /dev/null || { echo -e "${f} ---> ZIP TEST FAILED <--- "; rm -rf "${f}"; }
else
cd "$(/usr/bin/dirname ${f})"
${EXTRACT} "$(/usr/bin/basename ${f})" "${FILE}"
fi
done