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_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