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
|
hidden_srcs()
|
8
|
{
|
9
|
local hidden_srcs=1 inputs=() # with_all adds the hidden srcs to @inputs
|
10
|
. "$selfDir/with_all" import by_col=1 "$@"
|
11
|
}
|
12
|
|
13
|
delete_logs() { find . -name "${n:+n=$n.}$version.log.sql" -delete; }
|
14
|
|
15
|
main()
|
16
|
{
|
17
|
local self="${BASH_SOURCE[0]}"
|
18
|
local selfDir="$(dirname -- "$self")"
|
19
|
pushd "$selfDir/.."
|
20
|
|
21
|
if ! test "$SHLVL" -ge 2; then # was run without subshell
|
22
|
# needs subshell so errexits don't close the terminal window
|
23
|
echo 'usage: must be run in a subshell, obtained by running `$0`' >&2
|
24
|
return 0 # not nonzero because this will close the terminal window
|
25
|
fi
|
26
|
if test "${BASH_LINENO[1]}" = 0; then # was run without initial "."
|
27
|
echo "usage: (*in subshell*) [version=...] [inputs=(inputs/src/ ...)]; \
|
28
|
. $self [vars...] (note initial \".\")"|fold -s >&2
|
29
|
return 0 # not nonzero because this will close the subshell
|
30
|
fi
|
31
|
: ${version=$(make -s version)}
|
32
|
local by_col=${by_col-1} full_import=1
|
33
|
export version by_col full_import
|
34
|
|
35
|
if test ! "${log-1}"; then trap delete_logs EXIT SIGINT SIGTERM; fi #log==''
|
36
|
|
37
|
local log=1 # always use log files for background processes
|
38
|
|
39
|
# remove any leftover TNRS lockfile. usually, the PID in it would not exist,
|
40
|
# but sometimes it now refers to an active process which blocks tnrs.make.
|
41
|
"rm" -f inputs/.TNRS/tnrs/tnrs.make.lock
|
42
|
|
43
|
make schemas/$version/reinstall
|
44
|
|
45
|
set +o errexit # don't errexit if a background process is Ctrl-C'd
|
46
|
|
47
|
local hidden_srcs=1; . "$selfDir/with_all" Source/import "$@"
|
48
|
# note that this isn't affected by $import_source
|
49
|
wait # wait for asynchronous commands
|
50
|
unset hidden_srcs
|
51
|
|
52
|
local import_source= # Source tables have already been imported
|
53
|
export import_source # must come after local
|
54
|
|
55
|
hidden_srcs "$@" # separate function to avoid overwriting @inputs
|
56
|
wait # wait for asynchronous commands
|
57
|
|
58
|
. "$selfDir/with_all" import_scrub "$@" # uses $by_col
|
59
|
|
60
|
local jobs="$(jobs -p)"
|
61
|
echo "import_scrub PIDs: $jobs" >&2
|
62
|
|
63
|
bin/after_import $jobs &
|
64
|
echo "after_import PID: $!" >&2
|
65
|
|
66
|
. bin/disown_all
|
67
|
|
68
|
popd
|
69
|
}
|
70
|
main "$@"
|