1
|
#!/bin/bash -e
|
2
|
# Imports all inputs at once
|
3
|
set -o errexit -o pipefail # errexit since may be called from shell
|
4
|
|
5
|
if test "$1" = .; then set --; fi # was .-included without args, so $@ is wrong
|
6
|
|
7
|
main()
|
8
|
{
|
9
|
local self="${BASH_SOURCE[0]}"
|
10
|
local selfDir="$(dirname -- "$self")"
|
11
|
pushd "$selfDir/.."
|
12
|
|
13
|
if test "${BASH_LINENO[1]}" = 0; then # was run without initial "."
|
14
|
echo "usage: [version=...] [inputs=(inputs/src/ ...)]; . $self \
|
15
|
[vars...] (note initial \".\")"|fold -s >&2
|
16
|
return 2
|
17
|
fi
|
18
|
: ${version=$(make -s version)}
|
19
|
local by_col=${by_col-1} full_import=1
|
20
|
export version by_col full_import
|
21
|
|
22
|
# remove any leftover TNRS lockfile. usually, the PID in it would not exist,
|
23
|
# but sometimes it now refers to an active process which blocks tnrs.make.
|
24
|
"rm" -f inputs/.TNRS/tnrs/tnrs.make.lock
|
25
|
|
26
|
make schemas/$version/reinstall
|
27
|
|
28
|
local hidden_srcs=1; . "$selfDir/with_all" Source/import by_col=1 "$@"
|
29
|
# note that this isn't affected by $import_source
|
30
|
wait # wait for asynchronous commands
|
31
|
unset hidden_srcs
|
32
|
|
33
|
local import_source= # Source tables have already been imported
|
34
|
export import_source # must come after local
|
35
|
|
36
|
# publish datasources that won't be published by `make .../import`
|
37
|
make inputs/.TNRS/publish
|
38
|
make inputs/.geoscrub/publish
|
39
|
|
40
|
make inputs/.herbaria/import "$@" &
|
41
|
sleep 5 # wait for make commands to scroll by
|
42
|
|
43
|
wait # wait for asynchronous commands
|
44
|
|
45
|
. "$selfDir/with_all" import_scrub "$@" # uses $by_col
|
46
|
|
47
|
local jobs="$(jobs -p)"
|
48
|
echo "import_scrub PIDs: $jobs" >&2
|
49
|
|
50
|
bin/after_import $jobs &
|
51
|
echo "after_import PID: $!" >&2
|
52
|
|
53
|
. bin/disown_all
|
54
|
|
55
|
popd
|
56
|
}
|
57
|
main "$@"
|