Whoops.  :)  File actually attached...

Aaron S. Joyner


On Tue, Jul 15, 2008 at 10:54 PM, Aaron Joyner <[EMAIL PROTECTED]> wrote:

> Round 2!  This adds the following changes to the previously described list:
> - 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
>
> Let me know if you have any other handy ideas for making this part of the
> build process simpler.  Have vim, will code.
>
> Aaron S. Joyner
>
Index: install.sh
===================================================================
--- install.sh	(revision 10053)
+++ install.sh	(working copy)
@@ -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";
 
Index: Open-ILS/src/sql/Pg/build-db.sh
===================================================================
--- Open-ILS/src/sql/Pg/build-db.sh	(revision 10053)
+++ Open-ILS/src/sql/Pg/build-db.sh	(working copy)
@@ -1,38 +1,130 @@
 #!/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                   *
+* [EMAIL PROTECTED] 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            *
+* [EMAIL PROTECTED] 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
+  006.data.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
+
Index: Open-ILS/src/extras/import/build-oils-db.sh
===================================================================
--- Open-ILS/src/extras/import/build-oils-db.sh	(revision 10053)
+++ Open-ILS/src/extras/import/build-oils-db.sh	(working copy)
@@ -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
 )
Index: Open-ILS/src/Makefile
===================================================================
--- Open-ILS/src/Makefile	(revision 10053)
+++ Open-ILS/src/Makefile	(working copy)
@@ -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)
 
 # -----------------------------------------------------------------------------------
 
Index: install.conf.default
===================================================================
--- install.conf.default	(revision 10053)
+++ install.conf.default	(working copy)
@@ -120,6 +120,5 @@
 DBPORT="5432";
 DBNAME="evergreen";
 DBUSER="postgres";
-DBVER="82";
 DBPW="postgres";
 
Index: config.sh
===================================================================
--- config.sh	(revision 10053)
+++ config.sh	(working copy)
@@ -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\"";
 

Reply via email to