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:

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

Also available in: Unified diff