Project

General

Profile

1
#!/bin/bash
2
# Imports all inputs at once
3

    
4
if test "$1" = .; then set --; fi # was .-included without args, so $@ is wrong
5

    
6
main()
7
{
8
    local self="${BASH_SOURCE[0]}"
9
    local selfDir="$(dirname -- "$self")"
10
    cd "$selfDir/.."
11
    
12
    if test "${BASH_LINENO[1]}" = 0; then # was run without initial "."
13
        echo "usage: [version=...] [inputs=(inputs/src/ ...)]; . $self \
14
[vars...] (note initial \".\")"|fold -s >&2
15
        return 2
16
    fi
17
    : ${version=$(make -s version)}
18
    local by_col=${by_col-1} full_import=1
19
    export version by_col full_import
20
    
21
    # remove any leftover TNRS lockfile. usually, the PID in it would not exist,
22
    # but sometimes it now refers to an active process which blocks tnrs.make.
23
    "rm" -f inputs/.TNRS/tnrs/tnrs.make.lock
24
    
25
    make schemas/$version/reinstall
26
    
27
    local hidden_srcs=1; . "$selfDir/with_all" Source/import by_col=1 "$@"
28
        # note that this isn't affected by $import_source
29
    wait # wait for asynchronous commands
30
    unset hidden_srcs
31
    
32
    local import_source= # Source tables have already been imported
33
    export import_source # must come after local
34
    
35
    # publish datasources that won't be published by `make .../import`
36
    make inputs/.TNRS/publish
37
    make inputs/.geoscrub/publish
38
    
39
    make inputs/.herbaria/import "$@" &
40
    sleep 5 # wait for make commands to scroll by
41
    
42
    make inputs/.NCBI/import by_col=1 "$@"
43
    
44
    wait # wait for asynchronous commands
45
    
46
    . "$selfDir/with_all" import_scrub "$@" # uses $by_col
47
    
48
    local jobs="$(jobs -p)"
49
    echo "import_scrub PIDs: $jobs" >&2
50
    
51
    bin/after_import $jobs &
52
    echo "after_import PID: $!" >&2
53
    
54
    . bin/disown_all
55
}
56
main "$@"
(30-30/85)