The attached patch is a rewrite of build-db.sh. I originally intended to
just make it gracefully handle missing files, but I got on a roll. A break
down of changes, by bullet points:
- 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)
There aren't a large number of shell scripts in the depot, the only thing
which had a sufficiently large amount of style to go by was
Open-ILS/examples/oils_ctl.sh. I adopted that commenting and indenting
style, if that's not an appropriate example, please provide suggestions or
pointers to a style guide. oils_ctl.sh is a bash script, but build-db.sh
originally defined #!/bin/sh, so I opted to avoid the few bash style
elements from oils_ctl.sh that caught my eye (function foo()..., for
example), and leave it as a /bin/sh script, figuring it's better for
compatibility.
I've endeavoured to follow the submitting doc as closely as possible (
http://open-ils.org/documentation/contributing.html#Submitting%20a%20Patch),
but if I'm missed anything, or you require any additional information, just
let me know.
Thanks for the interesting project! I look forward to contributing more
code in the future.
Aaron S. Joyner
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 <[EMAIL PROTECTED]>
Index: Open-ILS/src/sql/Pg/build-db.sh
===================================================================
--- Open-ILS/src/sql/Pg/build-db.sh (revision 10052)
+++ Open-ILS/src/sql/Pg/build-db.sh (working copy)
@@ -1,38 +1,100 @@
#!/bin/sh
+
+# ---------------------------------------------------------------------------
+# Store command line args for later use
# args: {db-host} {db-port} {db-name} {db-user} {db-password} {db-version}
+# ---------------------------------------------------------------------------
+PGHOST=$1
+PGPORT=$2
+PGDATABASE=$3
+PGUSER=$4
+PGPASSWORD=$5
+DB_VERSION=$6
-# echo "You may be prompted several times for your database password..."
+find_latest_fts_config_version() {
+ for i in $(seq 80 99 | sort -rn); do
+ if [ -e "000.english.pg$i.fts-config.sql" ]; then
+ echo $i
+ return
+ fi
+ done
+ echo 82
+ return
+}
-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
+# ---------------------------------------------------------------------------
+# 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
+ last_ver=$(find_latest_fts_config_version)
+ 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 specified ($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 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 100.circ_matrix.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 110.hold_matrix.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 300.schema.staged_search.sql
+ 300.schema.staged_search.sql
-PGPASSWORD=$5 PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 500.view.cross-schema.sql
+ 500.view.cross-schema.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
+ 800.fkeys.sql
+ 900.audit-functions.sql
+ 901.audit-tables.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
+ 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.
+ # 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
+