Project

General

Profile

1 11493 psarando
#!/bin/bash
2
3
# Bash script to create a new postgis database and prep it with GADM
4
# data for geovalidation purposes.
5
#
6
# Basic workflow:
7
#  1. Load geoscrub input data into database
8
#  2. Scrub geoscrub input data with the geonames.sql script
9
#  3. Scrub geoscrub input data with the geovalidate.sql script
10
#
11
# Paul Sarando
12
# iPlant Collaborative
13
# Oct 2013
14
15
DB_NAME="geoscrub"
16
DB_USER="bien"
17
DB_HOST="localhost"
18
SCRIPT_DIR="$(dirname $0)"
19
20
function run_sql_script {
21
    local SCRIPT=$1
22
23
    psql -e -U "$DB_USER" -h "$DB_HOST" -d "$DB_NAME" --set ON_ERROR_STOP=1 < "$SCRIPT"
24
    if [[ $? != 0 ]]; then
25
        echo "Error while executing SQL script ${SCRIPT}"
26
        exit 1
27
    fi
28
}
29
30
"${SCRIPT_DIR}"/load-geoscrub-input.sh
31
if [[ $? != 0 ]]; then
32
    echo "Could not load ${DB_NAME} database with geonames.org data."
33
    exit 1
34
fi
35
36
echo "Scrubbing input with geonames data..."
37
run_sql_script "${SCRIPT_DIR}/geonames.sql"
38
39
echo "Scrubbing input with geovalidate data..."
40
run_sql_script "${SCRIPT_DIR}/geovalidate.sql"
41
42
echo "Input successfully scrubbed."
43
echo "Scrubbed input available in the geoscrub table of the ${DB_NAME} database."