-if [ "$1" = "create" ]; then
- echo "su root"
- su root -c "su postgres -c \"echo \\\"DBUser passwd: $DBPASS\\\" ; createuser -S -D -R -P $DBUSER && createdb -E utf8 -O $DBUSER $DBBASE\""
-elif [ "$1" = "destroy" ]; then
- echo "su root"
- su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
-elif [ "$1" = "clean" ]; then
- ( echo "-- MESG: clean start" ; one_or_all $2 | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; ) | sqlexe $sht
-elif [ "$1" = "build" ]; then
- ( echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) | sqlexe $sht
-elif [ "$1" = "rebuild" ]; then
- ( echo "-- MESG: clean start" ; one_or_all $2 | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; \
- echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) \
- | sqlexe $sht
-elif [ "$1" = "psql" ]; then
- psql -h $DBHOST -U $DBUSER $DBBASE
-elif [ "$1" = "dump" ]; then
- if [ $# -eq 1 ]; then
- pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
- else
- pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $2
- fi
-elif [ "$1" = "dumpall" ]; then
- if [ $# -eq 1 ]; then
- pg_dump -h $DBHOST -U $DBUSER $DBBASE
- else
- pg_dump -h $DBHOST -U $DBUSER $DBBASE > $2
- fi
-elif [ "$1" = "add" ]; then
- cat "$2" | psql -h $DBHOST -U $DBUSER $DBBASE
+while [ $# -gt 0 ]; do
+ case $1 in
+ -c|--config)
+ CONFIG_FILE=$2
+ shift
+ ;;
+ -d|--dryrun)
+ DRY_RUN=y
+ psql () {
+ echo "MOCKPSQL params: $@"
+ cat
+ }
+ ;;
+ -a|--allfiles)
+ TYPE_FILES=a
+ ;;
+ -p|--devfiles)
+ TYPE_FILES=d
+ ;;
+ -s|--short)
+ SHORT=y
+ ;;
+ -h|--help|help)
+ CMD=help
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+done
+
+if [ -f $HOME/.brisk-db.conf ]; then
+ source $HOME/.brisk-db.conf
+elif [ -f $HOME/.db.conf ]; then
+ source $HOME/.db.conf