Project

General

Profile

1 1551 aaronmk
#!/bin/bash
2 1541 aaronmk
# Imports all inputs at once
3
4 1952 aaronmk
import_all_main ()
5
{
6
    local self="${BASH_SOURCE[0]}"
7
    local selfDir="$(dirname -- "$self")"
8 6211 aaronmk
    cd "$selfDir/.."
9 1952 aaronmk
10 1953 aaronmk
    if test "${BASH_LINENO[1]}" = 0; then # was run without initial "."
11 6946 aaronmk
        echo "Usage: [version=...;] . $self [vars...] (note initial \".\")"\
12
        |fold -s >&2
13 1952 aaronmk
        return 2
14
    fi
15 7103 aaronmk
    : ${version=$(make -s version)}
16 10579 aaronmk
    local by_col=${by_col-1} full_import=1
17
    export version by_col full_import
18 1952 aaronmk
19 6946 aaronmk
    make schemas/$version/install
20
21 7121 aaronmk
    local all=1; . "$selfDir/with_all" Source/import by_col=1 "$@"
22 6897 aaronmk
        # note that this isn't affected by $import_source
23 6593 aaronmk
    wait # wait for asynchronous commands
24 6896 aaronmk
    unset all
25 6593 aaronmk
26 7095 aaronmk
    local import_source= # Source tables have already been imported
27
    export import_source # must come after local
28 6897 aaronmk
29 6382 aaronmk
    make inputs/.herbaria/import "$@" &
30
    sleep 5 # wait for make commands to scroll by
31
32 5957 aaronmk
    make inputs/.geoscrub/import "$@" &
33 5959 aaronmk
    sleep 5 # wait for make commands to scroll by
34
35 5836 aaronmk
    make inputs/.NCBI/import by_col=1 "$@"
36 5959 aaronmk
37 6594 aaronmk
    wait # wait for asynchronous commands
38 5503 aaronmk
39 10580 aaronmk
    . "$selfDir/with_all" import_scrub "$@" # uses $by_col
40 6210 aaronmk
41 7418 aaronmk
    local jobs="$(jobs -p)"
42
    echo "import_scrub PIDs: $jobs" >&2
43
44 6210 aaronmk
    after_import ()
45
    {
46 7418 aaronmk
        bin/waitpid $jobs
47
48 6210 aaronmk
        bin/make_analytical_db
49 6958 aaronmk
50 6960 aaronmk
        make backups/TNRS.backup-remake &
51 10576 aaronmk
        dump_opts=${dump_opts---exclude-schema=public} \
52
make backups/vegbien.$version.backup/test &
53 6958 aaronmk
        wait # wait for asynchronous commands
54 6210 aaronmk
    }
55
56 7418 aaronmk
    after_import &
57 7276 aaronmk
    echo "after_import PID: $!" >&2
58 7228 aaronmk
59
    . bin/disown_all
60 1952 aaronmk
}
61
import_all_main "$@"