Skip to content

Commit

Permalink
Add -h help info.
Browse files Browse the repository at this point in the history
  • Loading branch information
msqr committed Jun 21, 2024
1 parent 3415f10 commit 5f72802
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions solarnet-db-setup/postgres/bin/setup-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,54 @@ CREATE_USER=""
DRY_RUN=""
VERBOSE=""

while getopts ":c:d:D:mrtT:u:U:v" opt; do
do_help () {
cat 1>&2 <<EOF
Usage: $0 <arguments>
-c <args> - extra arguments to pass to psql
-d <db name> - the database name; defaults to 'solarnetwork_unittest'
-D <admin db> - the Postgres admin database name; defaults to 'postgres'
-m - create the Postgres database user
-r - recreate the database (drop and create again)
-t - dry run
-T <db name> - the Postgres template database name to use; defaults to
'template0'
-u <db user> - the Postgres database user to use; defaults to 'solartest'
-U <admin user> - the Postgres admin user to use; defaults to 'postgres'
-v - increase verbosity
Example that creates the test database and user for the first time:
./bin/setup-db.sh -m
To connect to a different Postgres port:
./bin/setup-db.sh -c '-p 5412'
To recreate the database (drop and create):
./bin/setup-db.sh -r
EOF
}

while getopts ":c:d:D:hmrtT:u:U:v" opt; do
case $opt in
c) PSQL_CONN_ARGS="${OPTARG}";;
d) PG_DB="${OPTARG}";;
D) PG_ADMIN_DB="${OPTARG}";;
h) do_help
exit 0
;;
m) CREATE_USER='TRUE';;
r) RECREATE_DB='TRUE';;
t) DRY_RUN='TRUE';;
T) PG_TEMPLATE_DB="${OPTARG}";;
u) PG_USER="${OPTARG}";;
U) PG_ADMIN_USER="${OPTARG}";;
v) VERBOSE='TRUE';;
?)
echo "Unknown argument ${OPTARG}"
*) echo "Unknown argument ${OPTARG}"
do_help
exit 1
esac
done
Expand Down

0 comments on commit 5f72802

Please sign in to comment.