[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Further patches to prepare-company-database.sh



Here are two more patches to prepare-company-database.sh.

Jointly, they effect the removal of psql's chattyness, while preserving actual errors.

Chris, I'll send you a unified patch of everything I've done to date, in case you decide to apply them all. The first two are independent, but these only make sense together.

Luke
--- orig/tools/prepare-company-database.sh	2011-06-16 17:23:23.000000000 +0000
+++ prepare-company-database.sh	2011-06-16 19:06:10.000000000 +0000
@@ -74,6 +74,25 @@
 
 }
 
+# Function to remove unnecessary chatter from PSQL, as well as
+# some notices and errors that the user doesn't need to worry about
+unchatter () {
+sed -re "/^[[:space:]]*(\
+CREATE (TABLE|FUNCTION|TYPE|DOMAIN|OPERATOR|ROLE|SEQUENCE|INDEX|AGGREGATE|\
+DATABASE|VIEW|TRIGGER|RULE|LANGUAGE)|\
+COMMENT|GRANT|REVOKE|SET|setval|ALTER TABLE|COMMIT|BEGIN|INSERT 0|\
+account_(heading_)?save|\
+admin__(save_user|add_user_to_role)|\
+You are now connected to database|\
+NOTICE:.*will create implicit|\
+NOTICE:.*type.*gtrgm|\
+DETAIL: *Creating a shell type definition|\
+ERROR:  language \"plpgsql\" already exists|\
+[[:space:]0-9-]*$|\
+\([0-9[:space:]]+rows?\)\
+)/d" -
+}
+
 # Am I root?
 if ! test `whoami` = "root"
 then
--- prepare-company-database.sh	2011-06-16 09:42:26.000000000 +0000
+++ working/tools/prepare-company-database.sh	2011-06-16 08:55:48.000000000 +0000
@@ -168,7 +182,7 @@
 
 sed -e "s|WORKING_DIR|$dstdir|g" \
    $srcdir/ledgersmb-httpd.conf.template >$dstdir/ledgersmb-httpd.conf
-cat <<EOF | su -c "psql -U postgres -d postgres "  postgres
+cat <<EOF | su -c "psql -U postgres -d postgres "  postgres 2>&1 | unchatter
 CREATE ROLE $owner WITH SUPERUSER LOGIN NOINHERIT ENCRYPTED PASSWORD '$pass';
 CREATE DATABASE $company_name WITH ENCODING = 'UNICODE' OWNER = $owner TEMPLATE = template0;
 \\c $company_name
@@ -188,38 +202,38 @@
 then
   for contrib in tsearch2.sql pg_trgm.sql tablefunc.sql
   do
-    cat $pgsql_contrib_dir/$contrib | $psql_cmd
+    cat $pgsql_contrib_dir/$contrib | $psql_cmd 2>&1 | unchatter
   done
 fi
 
 # Load the base file(s)
 # -- Basic database structure
-cat $srcdir/sql/Pg-database.sql | $psql_cmd
+cat $srcdir/sql/Pg-database.sql | $psql_cmd 2>&1 | unchatter
 # -- Additional database structure
 for module in `grep -v -E '^[[:space:]]*#' sql/modules/LOADORDER`
 do
-  cat $srcdir/sql/modules/$module | $psql_cmd
+  cat $srcdir/sql/modules/$module | $psql_cmd 2>&1 | unchatter
 done
 # -- Authorizations
 sed -e "s/<?lsmb dbname ?>/$company_name/g" \
-  $srcdir/sql/modules/Roles.sql | $psql_cmd
+  $srcdir/sql/modules/Roles.sql | $psql_cmd 2>&1 | unchatter
 
 
 if test -n "$coa" ; then
   # Load a chart of accounts
-  cat $coa | $psql_cmd
+  cat $coa | $psql_cmd 2>&1 | unchatter
   if test -n "$gifi" ; then
-    cat $gifi | $psql_cmd
+    cat $gifi | $psql_cmd 2>&1 | unchatter
   fi
 fi
 
-cat <<EOF | $psql_cmd
+cat <<EOF | $psql_cmd 2>&1 | unchatter
 \\COPY language FROM stdin WITH DELIMITER '|'
 `$srcdir/tools/generate-language-table-contents.pl $srcdir/locale/po`
 EOF
 
 
-cat <<CREATE_USER | $psql_cmd
+cat <<CREATE_USER | $psql_cmd 2>&1 | unchatter
 SELECT admin__save_user(NULL,
                          person__save(NULL,
                                       3,