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 "${BASH_LINENO[1]}" = 0; then # was run without initial "."
20
        echo "usage: [version=...] [inputs=(inputs/src/ ...)]; . $self \
21
[vars...] (note initial \".\")"|fold -s >&2
22
        return 2
23
    fi
24
    : ${version=$(make -s version)}
25
    local by_col=${by_col-1} full_import=1
26
    export version by_col full_import
27
    
28
    # remove any leftover TNRS lockfile. usually, the PID in it would not exist,
29
    # but sometimes it now refers to an active process which blocks tnrs.make.
30
    "rm" -f inputs/.TNRS/tnrs/tnrs.make.lock
31
    
32
    make schemas/$version/reinstall
33
    
34
    local hidden_srcs=1; . "$selfDir/with_all" Source/import "$@"
35
        # note that this isn't affected by $import_source
36
    wait # wait for asynchronous commands
37
    unset hidden_srcs
38
    
39
    local import_source= # Source tables have already been imported
40
    export import_source # must come after local
41
    
42
    hidden_srcs "$@" # separate function to avoid overwriting @inputs
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 "$@"
(31-31/86)