-
Notifications
You must be signed in to change notification settings - Fork 1
/
unzip_batch.sh
executable file
·58 lines (52 loc) · 1.12 KB
/
unzip_batch.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
53
54
55
56
57
58
#!/bin/bash
print_help(){
echo "$0 - Unzip multiple .zip files"
echo ""
echo "Usage: $0 [-p|h|r] [FILENAME.zip...]"
echo ""
echo "options:"
echo "-h, show brief help"
echo "-p, process in parallel"
exit 0
}
if [ $# -eq 0 ]; then
echo "No arguments to command:"
print_help
fi
while getopts ':hpr' flag; do
case "${flag}" in
h)
shift
print_help
exit ;;
p)
shift
parallel_process=true ;;
\?)
echo "Error: Invalid Option: ${OPTARG}"
exit ;;
esac
done
jobs=8 # default number of jobs
test_and_unzip() {
file="${1}"
if unzip -q -t "${file}"
then
unzip -qu "${file}"
else
echo "$File does not pass CRC check"
file_basename=$(basename "${file}")
mv "${file}" "${file_basename}.broken"
exit 1
fi
}
export -f test_and_unzip
if [[ "${parallel_process}" != true ]]
then
for file in "${@}"
do
test_and_unzip "${file}"
done
else
parallel --jobs "${jobs}" "test_and_unzip {}" ::: "${@}"
fi