4 # all this part is from mopshop and we will use it to construct the brisk database
7 if [ "$1" = "-d" -o "$1" = "--dryrun" ]; then
11 echo "MOCKPSQL params: $@"
16 if [ -f $HOME/.brisk-db.conf ]; then
17 source $HOME/.brisk-db.conf
18 elif [ -f $HOME/.db.conf ]; then
29 if [ -f $HOME/.brisk_install ]; then
30 source $HOME/.brisk_install
34 test "$DBHOST" != "" && pg_args="$pg_args -h $DBHOST"
35 test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER"
36 test "$DBPORT" != "" && pg_args="$pg_args -p $DBPORT"
37 test "$DBBASE" != "" && pg_args="$pg_args $DBBASE"
43 if [ $sht -eq 1 ]; then
44 sed "s/#PFX#/$PFX/g" | psql -a $pg_args 2>&1 | egrep 'ERROR|^-- MESG'
46 sed "s/#PFX#/$PFX/g" | psql -a $pg_args
53 if [ "$1" = "" ]; then
64 MATCH_DROP='^drop|^alter table.* drop '
66 if [ "$1" = "-s" ]; then
71 if [ "$1" = "create" ]; then
73 su root -c "su postgres -c \"echo \\\"DBUser passwd: $DBPASS\\\" ; createuser -S -D -R -P $DBUSER && createdb -E utf8 -O $DBUSER $DBBASE\""
74 elif [ "$1" = "destroy" ]; then
76 su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
77 elif [ "$1" = "clean" ]; then
78 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep -i "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; ) | sqlexe $sht
79 elif [ "$1" = "build" ]; then
80 ( echo "-- MESG: build start" ; one_or_all $2 | egrep -iv "$MATCH_DROP" ; echo "-- MESG: build end" ; ) | sqlexe $sht
81 elif [ "$1" = "rebuild" ]; then
82 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep -i "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; \
83 echo "-- MESG: build start" ; one_or_all $2 | egrep -iv "$MATCH_DROP" ; echo "-- MESG: build end" ; ) \
85 elif [ "$1" = "psql" ]; then
88 elif [ "$1" = "piped" ]; then
90 psql $pg_args -t -q -A -F '|' $@
91 elif [ "$1" = "dump" ]; then
93 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
95 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $2
97 elif [ "$1" = "dumpall" ]; then
99 pg_dump -h $DBHOST -U $DBUSER $DBBASE
101 pg_dump -h $DBHOST -U $DBUSER $DBBASE > $2
103 elif [ "$1" = "add" ]; then
104 cat "$2" | sqlexe $sht
107 echo " ./builder [-d|--dry-run] <command> ..."
108 echo " commands are:"
116 echo " add <filesql>"
117 echo " dump [dumpfile]"
118 echo " dumpall [dumpfile]"