Mercurial > gemma
view schema/install-db.sh @ 244:4ebb791b8278
Added simple script to install db schema.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Thu, 26 Jul 2018 18:51:24 +0200 |
parents | |
children | 946baea3d280 |
line wrap: on
line source
#!/bin/bash # Author(s): # Sascha Wilde <wilde@intevation.de> ME=`basename "$0"` BASEDIR=`dirname "$0"` usage() { cat <<EOF $ME [OPION]... Options: -d, --db=NAME connect to the database NAME -p, --port=PORT connect do the postgresql cluster at PORT -D, --demo install demo accounts and data --help display this help and exit EOF } fatal() { echo >&2 "$1" exit 23 } # Defaults: db=gemma port=5432 demo=0 # Parse options: OPTS=`getopt \ -l help,demo,db:,port: \ -o Dd:p: -n "$ME" -- "$@"` [ $? -eq 0 ] || { usage ; exit 1 ; } eval set -- "$OPTS" while true ; do case "$1" in --db|-d) db="$2" shift 2 ;; --port|-p) port="$2" shift 2 ;; --demo|-D) demo=1 shift 1 ;; --help) { usage ; exit 0 ; } ;; --) shift break ;; esac done # Main ------------------------------------------------------------ psql -p "$port" -f "$BASEDIR/roles.sql" createdb -p "$port" "$db" psql -p "$port" -f "$BASEDIR/gemma.sql" \ -f "$BASEDIR/auth.sql" -f "$BASEDIR/manage_users.sql" -d "$db" if [[ $demo -eq 1 ]] ; then psql -p "$port" -f "$BASEDIR/demo-data/responsibility_areas.sql" \ -d "$db" psql -p "$port" -f "$BASEDIR/demo-data/roles.sql" \ -f "$BASEDIR/demo-data/users.sql" -d "$db" fi