[open-ils-commits] r10156 - in trunk: . Open-ILS/src Open-ILS/src/extras/import Open-ILS/src/sql/Pg

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Jul 27 15:04:25 EDT 2008


Author: dbs
Date: 2008-07-27 15:04:17 -0400 (Sun, 27 Jul 2008)
New Revision: 10156

Modified:
   trunk/Open-ILS/src/Makefile
   trunk/Open-ILS/src/extras/import/build-oils-db.sh
   trunk/Open-ILS/src/sql/Pg/build-db.sh
   trunk/config.sh
   trunk/install.conf.default
   trunk/install.sh
Log:
Apply patch from Aaron S. Joyner to improve user friendliness of database build script

- validate that the fts-config.sql script exists for the specified database version
- if it does not, detect the latest available version, warn the user, suggest aborting, offer to continue w/ the latest available version
- rework call of psql to avoid PGPASSWORD on the command line, visible via ps
- warn user if psql fails attempting to import any of these files for reasons such as couldn't connect, or file not found (not sql script errors)
- provide commented out option to fail on sql script errors, for future convenience when the scripts run cleanly w/o errors
- limit line length to 80 characters (a nearly unbreakable habit from work)
- remove database version entirely from the user interface, down to build-db.sh.  This makes minor removals from:
  - install.sh
  - config.sh
  - install.conf.default
  - Open-ILS/src/Makefile
  - Open-ILS/src/extras/import/build-oils-db.sh
- implement automatic detection of PostgreSQL database version
- abort if we can not detect the db version, providing the user with our best guess (it's probably not going to be, but oh well)
- maintain fallback in the case of missing fts-config.sql for specific db version, with big shiny warnings adapted to the autodetection
- abort if no fts-config.sql files exist

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: Aaron S. Joyner <aaron at joyner.ws>




Modified: trunk/Open-ILS/src/Makefile
===================================================================
--- trunk/Open-ILS/src/Makefile	2008-07-27 18:40:48 UTC (rev 10155)
+++ trunk/Open-ILS/src/Makefile	2008-07-27 19:04:17 UTC (rev 10156)
@@ -177,7 +177,7 @@
 	@echo "Type control-c to avoid destroying all of the data.  Type enter to continue..."
 	@echo ""
 	@read X;
-	./extras/import/build-oils-db.sh $(DBDRVR) $(DBHOST) $(DBPORT) $(DBNAME) $(DBUSER) $(DBPW) $(DBVER)
+	./extras/import/build-oils-db.sh $(DBDRVR) $(DBHOST) $(DBPORT) $(DBNAME) $(DBUSER) $(DBPW)
 
 # -----------------------------------------------------------------------------------
 

Modified: trunk/Open-ILS/src/extras/import/build-oils-db.sh
===================================================================
--- trunk/Open-ILS/src/extras/import/build-oils-db.sh	2008-07-27 18:40:48 UTC (rev 10155)
+++ trunk/Open-ILS/src/extras/import/build-oils-db.sh	2008-07-27 19:04:17 UTC (rev 10156)
@@ -1,7 +1,7 @@
 #!/bin/bash
 if [ "_$4" == "_" ]; then
 	echo "Usage:"
-	echo "	$0 {Open-ILS-driver} {db-host} {db-port} {db-name} {db-user} {db-password} [db-version]"
+	echo "	$0 {Open-ILS-driver} {db-host} {db-port} {db-name} {db-user} {db-password}"
 	exit 1;
 fi
 
@@ -12,5 +12,5 @@
 	echo "cd $WD/../../sql/$1/;"
 	cd $WD/../../sql/$1/;
 	pwd
-	./build-db.sh $2 $3 $4 $5 $6 $7
+	./build-db.sh $2 $3 $4 $5 $6
 )

Modified: trunk/Open-ILS/src/sql/Pg/build-db.sh
===================================================================
--- trunk/Open-ILS/src/sql/Pg/build-db.sh	2008-07-27 18:40:48 UTC (rev 10155)
+++ trunk/Open-ILS/src/sql/Pg/build-db.sh	2008-07-27 19:04:17 UTC (rev 10156)
@@ -1,38 +1,129 @@
 #!/bin/sh
-# args: {db-host} {db-port} {db-name} {db-user} {db-password} {db-version}
 
-# echo "You may be prompted several times for your database password..."
+# ---------------------------------------------------------------------------
+# Store command line args for later use
+# args: {db-host} {db-port} {db-name} {db-user} {db-password}
+# ---------------------------------------------------------------------------
+PGHOST=$1
+PGPORT=$2
+PGDATABASE=$3
+PGUSER=$4
+PGPASSWORD=$5
+export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD
 
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 000.english.pg$6.fts-config.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 001.schema.offline.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 002.schema.config.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 002.functions.aggregate.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 002.functions.config.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 005.schema.actors.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 006.schema.permissions.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 010.schema.biblio.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 011.schema.authority.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 020.schema.functions.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 030.schema.metabib.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 040.schema.asset.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 070.schema.container.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 080.schema.money.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 090.schema.action.sql
+# ---------------------------------------------------------------------------
+# Lookup the database version from the PostgreSQL server.
+# ---------------------------------------------------------------------------
+DB_VERSION=`psql -qtc 'show server_version;' | xargs | cut -c1,3`
+if [ -z "$DB_VERSION" ] || [ `echo $DB_VERSION | grep -c '[^0-9]'` != 0 ]; then
+  cat <<EOM
+********************************************************************************
+* Could not determine the version of PostgreSQL you have installed.  Our best  *
+* guess was:                                                                   *
+* $DB_VERSION
+* which didn't make any sense.  For assistance, please email                   *
+* open-ils-general at list.georgialibraries.org or join #OpenILS-Evergreen on the *
+* freenode IRC network.                                                        *
+********************************************************************************
+EOM
+  exit 1
+fi
 
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 100.circ_matrix.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 110.hold_matrix.sql
+# ---------------------------------------------------------------------------
+# Validate fts-config file is available for specified DB_VERSION.
+# ---------------------------------------------------------------------------
+if [ -e "000.english.pg$DB_VERSION.fts-config.sql" ]; then
+  fts_config_file="000.english.pg$DB_VERSION.fts-config.sql"
+else
+  # -------------------------------------------------------------------------
+  # Attempt to auto-detect the latest available config file.
+  # -------------------------------------------------------------------------
+  last_ver=""
+  for i in $(seq 80 99 | sort -rn); do
+    if [ -e "000.english.pg$i.fts-config.sql" ]; then
+      last_ver=$i
+      break
+    fi
+  done
+  if [ -z "$last_ver" ]; then
+    cat <<EOM
+********************************************************************************
+* Cannot locate any configuration files for  full text search config.  This    *
+* may indicate a problem with your copy of the source files.  We attempted to  *
+* find files like 000.english.pg83.fts-config.sql in this directory:           *
+* `pwd` 
+* but were unsuccessful.  Aborting.                                            *
+********************************************************************************
+EOM
+    exit 1
+  fi
 
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 300.schema.staged_search.sql
+  a=$DB_VERSION  # preserves the text alignment below, in a cheap fashion
+  b=$last_ver    # assuming of course two character DB_VERSION and last_ver
+cat <<EOM
+********************************************************************************
+* There is no configuration for full text search config, for the database      *
+* version you have installed ($a).  If you're not really sure why, you should  *
+* proabably press 'Control-C' now, and abort.  To continue using the latest    *
+* available version ($b), press enter. For assistance, please email            *
+* open-ils-general at list.georgialibraries.org or join #OpenILS-Evergreen on the *
+* freenode IRC network.                                                        *
+********************************************************************************
+EOM
+  read unused
+  fts_config_file="000.english.pg$last_ver.fts-config.sql"
+fi
 
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 500.view.cross-schema.sql
+# ---------------------------------------------------------------------------
+# This describes the order in which the SQL files will be eval'd by psql.
+# ---------------------------------------------------------------------------
+ordered_file_list="
+  $fts_config_file
+  001.schema.offline.sql
+  002.schema.config.sql
+  005.schema.actors.sql
+  006.schema.permissions.sql
+  010.schema.biblio.sql
+  011.schema.authority.sql
+  020.schema.functions.sql
+  030.schema.metabib.sql
+  040.schema.asset.sql
+  070.schema.container.sql
+  080.schema.money.sql
+  090.schema.action.sql
 
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 800.fkeys.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 900.audit-functions.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 901.audit-tables.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 950.data.seed-values.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 951.data.MODS-xsl.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 952.data.MODS3-xsl.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 953.data.MODS32-xsl.sql
+  300.schema.staged_search.sql
 
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f reporter-schema.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f extend-reporter.sql
+  500.view.cross-schema.sql
+
+  800.fkeys.sql
+  900.audit-functions.sql
+  901.audit-tables.sql
+
+  reporter-schema.sql
+"
+
+# ---------------------------------------------------------------------------
+# Import files via psql, warn user on error, suggest abort.
+# ---------------------------------------------------------------------------
+for sql_file in $ordered_file_list; do
+  # It would be wise to turn this on only if confidence is high that errors in
+  # scripts will result in terminal failures.  Currently, there are a couple
+  # that seem benign.  --asjoyner
+  # export ON_ERROR_STOP=1
+
+  export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD
+  psql -f $sql_file
+  if [ $? != 0 ]; then
+    cat <<EOM
+********************************************************************************
+* There was an error with a database configuration file:                       *
+* $sql_file
+* It is very likely that your installation will be unsuccessful because of     *
+* this error.  Press Control-C to abort, or press enter to charge ahead.       *
+********************************************************************************
+EOM
+    read unused
+  fi
+done
+

Modified: trunk/config.sh
===================================================================
--- trunk/config.sh	2008-07-27 18:40:48 UTC (rev 10155)
+++ trunk/config.sh	2008-07-27 19:04:17 UTC (rev 10156)
@@ -102,11 +102,6 @@
 	prompt "Database Driver [$DBDRVR] "
 	read X; if [ ! -z "$X" ]; then DBDRVR="$X"; fi;
 
-	if [ "$DBDRVR" == "Pg" ]; then
-		prompt "Bootstrapping Database Version (80 for 8.0.x, 81 for 8.1.x, 82 for 8.2.x) [$DBVER] "
-		read X; if [ ! -z "$X" ]; then DBVER="$X"; fi;
-	fi;
-
 	prompt "Database Host [$DBHOST] "
 	read X; if [ ! -z "$X" ]; then DBHOST="$X"; fi;
 
@@ -185,7 +180,6 @@
 	_write "DBNAME=\"$DBNAME\"";
 	_write "DBUSER=\"$DBUSER\"";
 	_write "DBPW=\"$DBPW\"";
-	_write "DBVER=\"$DBVER\"";
 	_write "REPORTERDIR=\"$REPORTERDIR\"";
 	_write "ADMINDIR=\"$ADMINDIR\"";
 

Modified: trunk/install.conf.default
===================================================================
--- trunk/install.conf.default	2008-07-27 18:40:48 UTC (rev 10155)
+++ trunk/install.conf.default	2008-07-27 19:04:17 UTC (rev 10156)
@@ -120,6 +120,5 @@
 DBPORT="5432";
 DBNAME="evergreen";
 DBUSER="postgres";
-DBVER="82";
 DBPW="postgres";
 

Modified: trunk/install.sh
===================================================================
--- trunk/install.sh	2008-07-27 18:40:48 UTC (rev 10155)
+++ trunk/install.sh	2008-07-27 19:04:17 UTC (rev 10156)
@@ -123,7 +123,7 @@
 			WEBDIR=$WEBDIR TEMPLATEDIR=$TEMPLATEDIR ETCDIR=$ETCDIR REPORTERDIR=$REPORTERDIR\
 			OPENSRF_HEADERS=$OPENSRF_HEADERS OPENSRF_LIBS=$OPENSRF_LIBS OPENILSDIR=$OPENILSDIR EVERGREENDIR=$EVERGREENDIR \
 			CIRCRULESDIR=$CIRCRULESDIR CATALOGSCRIPTDIR=$CATALOGSCRIPTDIR CGIDIR=$CGIDIR \
-			DBDRVR=$DBDRVR DBHOST=$DBHOST DBVER=$DBVER DATADIR=$DATADIR ADMINDIR=$ADMINDIR\
+			DBDRVR=$DBDRVR DBHOST=$DBHOST DATADIR=$DATADIR ADMINDIR=$ADMINDIR\
 			PENALTYRULESDIR=$PENALTYRULESDIR DBNAME=$DBNAME DBUSER=$DBUSER DBPW=$DBPW XSLDIR=$XSLDIR NEW_OPAC_URL=$NEW_OPAC_URL \
 			NEW_XUL_PACKAGE_NAME=$NEW_XUL_PACKAGE_NAME NEW_XUL_PACKAGE_LABEL=$NEW_XUL_PACKAGE_LABEL";
 



More information about the open-ils-commits mailing list