1 |
11823
|
aaronmk
|
#!/bin/bash -e
|
2 |
1541
|
aaronmk
|
# Imports all inputs at once
|
3 |
11823
|
aaronmk
|
set -o errexit -o pipefail # errexit since may be called from shell
|
4 |
1541
|
aaronmk
|
|
5 |
11422
|
aaronmk
|
if test "$1" = .; then set --; fi # was .-included without args, so $@ is wrong
|
6 |
|
|
|
7 |
13978
|
aaronmk
|
hidden_srcs()
|
8 |
|
|
{
|
9 |
|
|
local hidden_srcs=1 inputs=() # with_all adds the hidden srcs to @inputs
|
10 |
14099
|
aaronmk
|
. "$selfDir/with_all" import "$@"
|
11 |
13978
|
aaronmk
|
}
|
12 |
|
|
|
13 |
14070
|
aaronmk
|
delete_logs()
|
14 |
|
|
{
|
15 |
|
|
if test "$delete_logs"; then
|
16 |
14072
|
aaronmk
|
(set -x; find . -name "${n:+n=$n.}$version.log.sql" -delete)
|
17 |
14070
|
aaronmk
|
fi
|
18 |
|
|
}
|
19 |
13985
|
aaronmk
|
|
20 |
11416
|
aaronmk
|
main()
|
21 |
1952
|
aaronmk
|
{
|
22 |
|
|
local self="${BASH_SOURCE[0]}"
|
23 |
|
|
local selfDir="$(dirname -- "$self")"
|
24 |
11430
|
aaronmk
|
pushd "$selfDir/.."
|
25 |
1952
|
aaronmk
|
|
26 |
13982
|
aaronmk
|
if ! test "$SHLVL" -ge 2; then # was run without subshell
|
27 |
|
|
# needs subshell so errexits don't close the terminal window
|
28 |
|
|
echo 'usage: must be run in a subshell, obtained by running `$0`' >&2
|
29 |
|
|
return 0 # not nonzero because this will close the terminal window
|
30 |
|
|
fi
|
31 |
1953
|
aaronmk
|
if test "${BASH_LINENO[1]}" = 0; then # was run without initial "."
|
32 |
13981
|
aaronmk
|
echo "usage: (*in subshell*) [version=...] [inputs=(inputs/src/ ...)]; \
|
33 |
|
|
. $self [vars...] (note initial \".\")"|fold -s >&2
|
34 |
13983
|
aaronmk
|
return 0 # not nonzero because this will close the subshell
|
35 |
1952
|
aaronmk
|
fi
|
36 |
7103
|
aaronmk
|
: ${version=$(make -s version)}
|
37 |
10579
|
aaronmk
|
local by_col=${by_col-1} full_import=1
|
38 |
|
|
export version by_col full_import
|
39 |
1952
|
aaronmk
|
|
40 |
14070
|
aaronmk
|
if test ! "${log-1}"; then local delete_logs=1; fi #log==''
|
41 |
14073
|
aaronmk
|
trap delete_logs SIGINT SIGTERM #not EXIT b/c doesn't run until *shell* exit
|
42 |
13985
|
aaronmk
|
|
43 |
13980
|
aaronmk
|
local log=1 # always use log files for background processes
|
44 |
|
|
|
45 |
10847
|
aaronmk
|
# remove any leftover TNRS lockfile. usually, the PID in it would not exist,
|
46 |
|
|
# but sometimes it now refers to an active process which blocks tnrs.make.
|
47 |
11419
|
aaronmk
|
"rm" -f inputs/.TNRS/tnrs/tnrs.make.lock
|
48 |
10847
|
aaronmk
|
|
49 |
11421
|
aaronmk
|
make schemas/$version/reinstall
|
50 |
6946
|
aaronmk
|
|
51 |
13984
|
aaronmk
|
set +o errexit # don't errexit if a background process is Ctrl-C'd
|
52 |
|
|
|
53 |
13979
|
aaronmk
|
local hidden_srcs=1; . "$selfDir/with_all" Source/import "$@"
|
54 |
6897
|
aaronmk
|
# note that this isn't affected by $import_source
|
55 |
6593
|
aaronmk
|
wait # wait for asynchronous commands
|
56 |
11374
|
aaronmk
|
unset hidden_srcs
|
57 |
6593
|
aaronmk
|
|
58 |
7095
|
aaronmk
|
local import_source= # Source tables have already been imported
|
59 |
|
|
export import_source # must come after local
|
60 |
6897
|
aaronmk
|
|
61 |
13978
|
aaronmk
|
hidden_srcs "$@" # separate function to avoid overwriting @inputs
|
62 |
6594
|
aaronmk
|
wait # wait for asynchronous commands
|
63 |
5503
|
aaronmk
|
|
64 |
11286
|
aaronmk
|
. "$selfDir/with_all" import_scrub "$@" # uses $by_col
|
65 |
6210
|
aaronmk
|
|
66 |
7418
|
aaronmk
|
local jobs="$(jobs -p)"
|
67 |
|
|
echo "import_scrub PIDs: $jobs" >&2
|
68 |
|
|
|
69 |
10586
|
aaronmk
|
bin/after_import $jobs &
|
70 |
7276
|
aaronmk
|
echo "after_import PID: $!" >&2
|
71 |
7228
|
aaronmk
|
|
72 |
11430
|
aaronmk
|
popd
|
73 |
14073
|
aaronmk
|
delete_logs # manually run b/c `trap EXIT` doesn't run until *shell* exit
|
74 |
1952
|
aaronmk
|
}
|
75 |
11416
|
aaronmk
|
main "$@"
|