-
Notifications
You must be signed in to change notification settings - Fork 6
/
bulk-sanitize.sh
executable file
·53 lines (45 loc) · 1.59 KB
/
bulk-sanitize.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
#!/usr/bin/env bash
set -e;
# example usage for all downloads: ./bulk-sanitize.sh files/downloads
# example usage for just paypal: ./bulk-sanitize.sh files/downloads paypal
# example usage with debug: ./bulk-sanitize.sh files/downloads paypal --debug
# example usage with debug: ./bulk-sanitize.sh files/downloads --debug
searchDir="$1"
debug=""
if [[ "$*" == *"--debug"* ]]; then
debug="--debug"
fi
specificParser=""
# I no good bash
if [[ "$#" -gt 1 && -z "$debug" ]]; then
specificParser="$2"
elif [[ "$#" -gt 2 && -n "$debug" ]]; then
if [[ "${*: -1:1}" -eq "--debug" ]]; then
# if the last argument is --debug then use the second to last argument for specificParser
specificParser="${*: -2:1}"
elif [[ "${*: -2:1}" -eq "--debug" ]]; then
# if the second to last argument is --debug then use the last argument for specificParser
specificParser="${*: -1:1}"
else
echo "Where did you put the --debug flag?"
exit 1
fi
fi
echo "search in: $searchDir"
echo "parser: $specificParser"
echo "debug: $debug"
if [ -z "$searchDir" ]; then
echo "Search dir is missing."
exit 1;
fi
npm run compile
if [ -z "$specificParser" ]; then
for filePath in "$searchDir"/**/*.pdf; do
parserType="$(basename "$(dirname "$filePath")")"
npm run sanitize:no-compile "$parserType" "$filePath" "$(basename "$filePath" .pdf).json" -- "$debug"
done
else
for filePath in "$searchDir"/"$specificParser"/*.pdf; do
npm run sanitize:no-compile "$specificParser" "$filePath" "$(basename "$filePath" .pdf).json" -- "$debug"
done
fi