Project

General

Profile

« Previous | Next » 

Revision 11559

Added cmd-line options to biengeo bash scripts.

All biengeo bash scripts now accept command line options to specify psql
user, host, and database values.
These options are the same as those defined by the psql command.
If an invalid option is given to a script, a usage message is printed
and the script quits.
For example:
setup.sh -U bien -h localhost -d geoscrub_test

View differences:

derived/biengeo/geoscrub.sh
17 17
DB_HOST_OPT=""
18 18
SCRIPT_DIR="$(dirname $0)"
19 19

  
20
function usage {
21
    echo "Usage: $0 [OPTIONS]" >&2
22
    echo "Valid Options:" >&2
23
    echo "-d, --dbname=DBNAME      database name psql commands will connect to" >&2
24
    echo "-h, --host=HOSTNAME      database server host or socket directory" >&2
25
    echo "-U, --username=USERNAME  database user name" >&2
26
    exit 1;
27
}
28

  
29
while [[ $# -gt 0  ]]; do
30
    case "$1" in
31
        -\? | --help)
32
            usage
33
            ;;
34
        -h)
35
            if [[ -z $2  ]];  then
36
                echo "Option $1 requires an argument." >&2
37
                usage
38
            fi
39
            DB_HOST_OPT="-h $2"
40
            shift 2
41
            ;;
42
        --host=*)
43
            DB_HOST_OPT="-h ${1#*=}"
44
            shift
45
            ;;
46
        -U)
47
            if [[ -z $2  ]];  then
48
                echo "Option $1 requires an argument." >&2
49
                usage
50
            fi
51
            DB_USER="$2"
52
            shift 2
53
            ;;
54
        --username=*)
55
            DB_USER="${1#*=}"
56
            shift
57
            ;;
58
        -d)
59
            if [[ -z $2  ]];  then
60
                echo "Option $1 requires an argument." >&2
61
                usage
62
            fi
63
            DB_NAME="$2"
64
            shift 2
65
            ;;
66
        --dbname=*)
67
            DB_NAME="${1#*=}"
68
            shift
69
            ;;
70
        *)
71
            echo "Invalid option: $1" >&2
72
            usage
73
            ;;
74
    esac
75
done
76

  
20 77
function run_sql_script {
21 78
    local SCRIPT=$1
22 79

  
......
27 84
    fi
28 85
}
29 86

  
30
"${SCRIPT_DIR}"/load-geoscrub-input.sh
87
"${SCRIPT_DIR}"/load-geoscrub-input.sh -U "$DB_USER" $DB_HOST_OPT -d "$DB_NAME"
31 88
if [[ $? != 0 ]]; then
32 89
    echo "Could not load ${DB_NAME} database with geonames.org data."
33 90
    exit 1
derived/biengeo/load-geoscrub-input.sh
31 31
DATADIR="${SCRIPT_DIR}/input"
32 32
DATAFILE="${DATADIR}/geoscrub-corpus.csv"
33 33

  
34
function usage {
35
    echo "Usage: $0 [OPTIONS]" >&2
36
    echo "Valid Options:" >&2
37
    echo "-d, --dbname=DBNAME      database name psql commands will connect to" >&2
38
    echo "-h, --host=HOSTNAME      database server host or socket directory" >&2
39
    echo "-U, --username=USERNAME  database user name" >&2
40
    exit 1;
41
}
42

  
43
while [[ $# -gt 0  ]]; do
44
    case "$1" in
45
        -\? | --help)
46
            usage
47
            ;;
48
        -h)
49
            if [[ -z $2  ]];  then
50
                echo "Option $1 requires an argument." >&2
51
                usage
52
            fi
53
            DB_HOST_OPT="-h $2"
54
            shift 2
55
            ;;
56
        --host=*)
57
            DB_HOST_OPT="-h ${1#*=}"
58
            shift
59
            ;;
60
        -U)
61
            if [[ -z $2  ]];  then
62
                echo "Option $1 requires an argument." >&2
63
                usage
64
            fi
65
            DB_USER="$2"
66
            shift 2
67
            ;;
68
        --username=*)
69
            DB_USER="${1#*=}"
70
            shift
71
            ;;
72
        -d)
73
            if [[ -z $2  ]];  then
74
                echo "Option $1 requires an argument." >&2
75
                usage
76
            fi
77
            DB_NAME="$2"
78
            shift 2
79
            ;;
80
        --dbname=*)
81
            DB_NAME="${1#*=}"
82
            shift
83
            ;;
84
        *)
85
            echo "Invalid option: $1" >&2
86
            usage
87
            ;;
88
    esac
89
done
90

  
34 91
if [[ ! -d "$DATADIR" ]]; then
35 92
    echo "making directory ${DATADIR}"
36 93
    mkdir -p "$DATADIR"
derived/biengeo/update_validation_data.sh
17 17
DB_HOST_OPT=""
18 18
SCRIPT_DIR="$(dirname $0)"
19 19

  
20
function usage {
21
    echo "Usage: $0 [OPTIONS]" >&2
22
    echo "Valid Options:" >&2
23
    echo "-d, --dbname=DBNAME      database name psql commands will connect to" >&2
24
    echo "-h, --host=HOSTNAME      database server host or socket directory" >&2
25
    echo "-U, --username=USERNAME  database user name" >&2
26
    exit 1;
27
}
28

  
29
while [[ $# -gt 0  ]]; do
30
    case "$1" in
31
        -\? | --help)
32
            usage
33
            ;;
34
        -h)
35
            if [[ -z $2  ]];  then
36
                echo "Option $1 requires an argument." >&2
37
                usage
38
            fi
39
            DB_HOST_OPT="-h $2"
40
            shift 2
41
            ;;
42
        --host=*)
43
            DB_HOST_OPT="-h ${1#*=}"
44
            shift
45
            ;;
46
        -U)
47
            if [[ -z $2  ]];  then
48
                echo "Option $1 requires an argument." >&2
49
                usage
50
            fi
51
            DB_USER="$2"
52
            shift 2
53
            ;;
54
        --username=*)
55
            DB_USER="${1#*=}"
56
            shift
57
            ;;
58
        -d)
59
            if [[ -z $2  ]];  then
60
                echo "Option $1 requires an argument." >&2
61
                usage
62
            fi
63
            DB_NAME="$2"
64
            shift 2
65
            ;;
66
        --dbname=*)
67
            DB_NAME="${1#*=}"
68
            shift
69
            ;;
70
        *)
71
            echo "Invalid option: $1" >&2
72
            usage
73
            ;;
74
    esac
75
done
76

  
20 77
function run_sql_script {
21 78
    local SCRIPT=$1
22 79

  
......
29 86

  
30 87
echo "Updating geoscrub validation data."
31 88

  
32
"${SCRIPT_DIR}"/update_gadm_data.sh
89
"${SCRIPT_DIR}"/update_gadm_data.sh -U "$DB_USER" $DB_HOST_OPT -d "$DB_NAME"
33 90
if [[ $? != 0 ]]; then
34 91
    echo "Could not update ${DB_NAME} database with GADM data."
35 92
    exit 1
36 93
fi
37 94

  
38
"${SCRIPT_DIR}"/update_geonames_data.sh
95
"${SCRIPT_DIR}"/update_geonames_data.sh -U "$DB_USER" $DB_HOST_OPT -d "$DB_NAME"
39 96
if [[ $? != 0 ]]; then
40 97
    echo "Could not update ${DB_NAME} database with geonames.org data."
41 98
    exit 1
derived/biengeo/update_geonames_data.sh
33 33
HIERARCHY_ZIP=hierarchy.zip
34 34
HIERARCHY_TXT=hierarchy.txt
35 35

  
36
function usage {
37
    echo "Usage: $0 [OPTIONS]" >&2
38
    echo "Valid Options:" >&2
39
    echo "-d, --dbname=DBNAME      database name psql commands will connect to" >&2
40
    echo "-h, --host=HOSTNAME      database server host or socket directory" >&2
41
    echo "-U, --username=USERNAME  database user name" >&2
42
    exit 1;
43
}
44

  
45
while [[ $# -gt 0  ]]; do
46
    case "$1" in
47
        -\? | --help)
48
            usage
49
            ;;
50
        -h)
51
            if [[ -z $2  ]];  then
52
                echo "Option $1 requires an argument." >&2
53
                usage
54
            fi
55
            DB_HOST_OPT="-h $2"
56
            shift 2
57
            ;;
58
        --host=*)
59
            DB_HOST_OPT="-h ${1#*=}"
60
            shift
61
            ;;
62
        -U)
63
            if [[ -z $2  ]];  then
64
                echo "Option $1 requires an argument." >&2
65
                usage
66
            fi
67
            DB_USER="$2"
68
            shift 2
69
            ;;
70
        --username=*)
71
            DB_USER="${1#*=}"
72
            shift
73
            ;;
74
        -d)
75
            if [[ -z $2  ]];  then
76
                echo "Option $1 requires an argument." >&2
77
                usage
78
            fi
79
            DB_NAME="$2"
80
            shift 2
81
            ;;
82
        --dbname=*)
83
            DB_NAME="${1#*=}"
84
            shift
85
            ;;
86
        *)
87
            echo "Invalid option: $1" >&2
88
            usage
89
            ;;
90
    esac
91
done
92

  
36 93
function run_sql_cmd {
37 94
    local SQL_CMD=$1
38 95

  
derived/biengeo/setup.sh
26 26
DB_HOST_OPT=""
27 27
SCRIPT_DIR="$(dirname $0)"
28 28

  
29
function usage {
30
    echo "Usage: $0 [OPTIONS]" >&2
31
    echo "Valid Options:" >&2
32
    echo "-d, --dbname=DBNAME      database name psql commands will connect to" >&2
33
    echo "-h, --host=HOSTNAME      database server host or socket directory" >&2
34
    echo "-U, --username=USERNAME  database user name" >&2
35
    exit 1;
36
}
37

  
38
while [[ $# -gt 0  ]]; do
39
    case "$1" in
40
        -\? | --help)
41
            usage
42
            ;;
43
        -h)
44
            if [[ -z $2  ]];  then
45
                echo "Option $1 requires an argument." >&2
46
                usage
47
            fi
48
            DB_HOST_OPT="-h $2"
49
            shift 2
50
            ;;
51
        --host=*)
52
            DB_HOST_OPT="-h ${1#*=}"
53
            shift
54
            ;;
55
        -U)
56
            if [[ -z $2  ]];  then
57
                echo "Option $1 requires an argument." >&2
58
                usage
59
            fi
60
            DB_USER="$2"
61
            shift 2
62
            ;;
63
        --username=*)
64
            DB_USER="${1#*=}"
65
            shift
66
            ;;
67
        -d)
68
            if [[ -z $2  ]];  then
69
                echo "Option $1 requires an argument." >&2
70
                usage
71
            fi
72
            DB_NAME="$2"
73
            shift 2
74
            ;;
75
        --dbname=*)
76
            DB_NAME="${1#*=}"
77
            shift
78
            ;;
79
        *)
80
            echo "Invalid option: $1" >&2
81
            usage
82
            ;;
83
    esac
84
done
85

  
29 86
function run_sudo_sql_cmd {
30 87
    local SQL_CMD="$1"
31 88

  
derived/biengeo/update_gadm_data.sh
33 33
GADM_DATA_URL="http://biogeo.ucdavis.edu/data/gadm2/gadm_v2_shp.zip"
34 34
GADM_DATA_DIR="${SCRIPT_DIR}/gadm_v2_shp"
35 35

  
36
function usage {
37
    echo "Usage: $0 [OPTIONS]" >&2
38
    echo "Valid Options:" >&2
39
    echo "-d, --dbname=DBNAME      database name psql commands will connect to" >&2
40
    echo "-h, --host=HOSTNAME      database server host or socket directory" >&2
41
    echo "-U, --username=USERNAME  database user name" >&2
42
    exit 1;
43
}
44

  
45
while [[ $# -gt 0  ]]; do
46
    case "$1" in
47
        -\? | --help)
48
            usage
49
            ;;
50
        -h)
51
            if [[ -z $2  ]];  then
52
                echo "Option $1 requires an argument." >&2
53
                usage
54
            fi
55
            DB_HOST_OPT="-h $2"
56
            shift 2
57
            ;;
58
        --host=*)
59
            DB_HOST_OPT="-h ${1#*=}"
60
            shift
61
            ;;
62
        -U)
63
            if [[ -z $2  ]];  then
64
                echo "Option $1 requires an argument." >&2
65
                usage
66
            fi
67
            DB_USER="$2"
68
            shift 2
69
            ;;
70
        --username=*)
71
            DB_USER="${1#*=}"
72
            shift
73
            ;;
74
        -d)
75
            if [[ -z $2  ]];  then
76
                echo "Option $1 requires an argument." >&2
77
                usage
78
            fi
79
            DB_NAME="$2"
80
            shift 2
81
            ;;
82
        --dbname=*)
83
            DB_NAME="${1#*=}"
84
            shift
85
            ;;
86
        *)
87
            echo "Invalid option: $1" >&2
88
            usage
89
            ;;
90
    esac
91
done
92

  
36 93
#
37 94
# assemble input data
38 95
#

Also available in: Unified diff