4 # all this part is from mopshop and we will use it to construct the brisk database
6 if [ -f $HOME/.brisk-spu-db.conf ]; then
7 source $HOME/.brisk-spu-db.conf
8 elif [ -f $HOME/.db.conf ]; then
19 if [ -f $HOME/.brisk_spu_install ]; then
20 source $HOME/.brisk_spu_install
24 test "$DBHOST" != "" && pg_args="$pg_args -h $DBHOST"
25 test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER"
26 test "$DBPORT" != "" && pg_args="$pg_args -p $DBPORT"
27 test "$DBBASE" != "" && pg_args="$pg_args $DBBASE"
33 if [ $sht -eq 1 ]; then
34 sed "s/#PFX#/$PFX/g" | psql -a $pg_args 2>&1 | egrep 'ERROR|^-- MESG'
36 sed "s/#PFX#/$PFX/g" | psql -a $pg_args
43 if [ "$1" = "" ]; then
55 if [ "$1" = "-s" ]; then
60 if [ "$1" = "create" ]; then
62 su root -c "su postgres -c \"echo \\\"DBUser passwd: $DBPASS\\\" ; createuser -S -D -R -P $DBUSER && createdb -E utf8 -O $DBUSER $DBBASE\""
63 elif [ "$1" = "destroy" ]; then
65 su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
66 elif [ "$1" = "clean" ]; then
67 ( echo "-- MESG: clean start" ; one_or_all $2 | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; ) | sqlexe $sht
68 elif [ "$1" = "build" ]; then
69 ( echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) | sqlexe $sht
70 elif [ "$1" = "rebuild" ]; then
71 ( echo "-- MESG: clean start" ; one_or_all $2 | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; \
72 echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) \
74 elif [ "$1" = "psql" ]; then
77 elif [ "$1" = "piped" ]; then
79 psql $pg_args -t -q -A -F '|' $@
80 elif [ "$1" = "dump" ]; then
82 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
84 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $2
86 elif [ "$1" = "dumpall" ]; then
88 pg_dump -h $DBHOST -U $DBUSER $DBBASE
90 pg_dump -h $DBHOST -U $DBUSER $DBBASE > $2
92 elif [ "$1" = "add" ]; then
93 cat "$2" | psql $pg_args
96 echo " ./builder create"
97 echo " ./builder destroy"
98 echo " ./builder clean"
99 echo " ./builder build"
100 echo " ./builder rebuild"
101 echo " ./builder psql"
102 echo " ./builder piped"
103 echo " ./builder add <filesql>"
104 echo " ./builder dump [dumpfile]"
105 echo " ./builder dumpall [dumpfile]"
106 echo " ./builder all"
107 echo " ./builder help"