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:

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"

Also available in: Unified diff