4 # all this part is from mopshop and we will use it to construct the brisk database
7 if [ -f $HOME/.db.conf ]; then
18 if [ -f $HOME/.brisk_install ]; then
19 source $HOME/.brisk_install
23 test "$DBHOST" != "" && pg_args="$pg_args -h $DBHOST"
24 test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER"
25 test "$DBPORT" != "" && pg_args="$pg_args -p $DBPORT"
26 test "$DBBASE" != "" && pg_args="$pg_args $DBBASE"
32 if [ $sht -eq 1 ]; then
33 sed "s/#PFX#/$PFX/g" | psql -a $pg_args 2>&1 | egrep 'ERROR|^-- MESG'
35 sed "s/#PFX#/$PFX/g" | psql -a $pg_args
42 if [ "$1" = "" ]; then
54 if [ "$1" = "-s" ]; then
59 if [ "$1" = "create" ]; then
61 su root -c "su postgres -c \"echo \\\"DBUser passwd: $DBPASS\\\" ; createuser -S -D -R -P $DBUSER && createdb -E utf8 -O $DBUSER $DBBASE\""
62 elif [ "$1" = "destroy" ]; then
64 su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
65 elif [ "$1" = "clean" ]; then
66 ( echo "-- MESG: clean start" ; one_or_all $2 | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; ) | sqlexe $sht
67 elif [ "$1" = "build" ]; then
68 ( echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) | sqlexe $sht
69 elif [ "$1" = "rebuild" ]; then
70 ( echo "-- MESG: clean start" ; one_or_all $2 | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; \
71 echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) \
73 elif [ "$1" = "psql" ]; then
76 elif [ "$1" = "piped" ]; then
78 psql $pg_args -t -q -A -F '|' $@
79 elif [ "$1" = "dump" ]; then
81 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
83 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $2
85 elif [ "$1" = "dumpall" ]; then
87 pg_dump -h $DBHOST -U $DBUSER $DBBASE
89 pg_dump -h $DBHOST -U $DBUSER $DBBASE > $2
91 elif [ "$1" = "add" ]; then
92 cat "$2" | psql $pg_args
95 echo " ./builder create"
96 echo " ./builder destroy"
97 echo " ./builder clean"
98 echo " ./builder build"
99 echo " ./builder rebuild"
100 echo " ./builder psql"
101 echo " ./builder piped"
102 echo " ./builder add <filesql>"
103 echo " ./builder dump [dumpfile]"
104 echo " ./builder dumpall [dumpfile]"
105 echo " ./builder all"
106 echo " ./builder help"