Project

General

Profile

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