Project

General

Profile

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