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:

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

  

Also available in: Unified diff