From b668ef8a4317029227709d03a339560c5488613b Mon Sep 17 00:00:00 2001 From: dbs Date: Sat, 11 Oct 2008 03:36:43 +0000 Subject: [PATCH] Add the ability to generate live-db-setup.pl to eg_db_config.pl Database configuration can now be removed from configure and Makefiles git-svn-id: svn://svn.open-ils.org/ILS/trunk@10823 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/Makefile.am | 1 - Open-ILS/src/support-scripts/eg_db_config.pl | 120 +++++++++++++++---- configure.ac | 104 ---------------- 3 files changed, 97 insertions(+), 128 deletions(-) diff --git a/Open-ILS/src/Makefile.am b/Open-ILS/src/Makefile.am index 0d96485e3b..c14221e314 100644 --- a/Open-ILS/src/Makefile.am +++ b/Open-ILS/src/Makefile.am @@ -262,7 +262,6 @@ cgi-bootstrap: for i in @srcdir@/cgi-bin/*cgi; do perl -pe "s{##CONFIG##}{@sysconfdir@}" < $$i > $(TMP)/$$i; done cp $(TMP)/cgi-bin/*cgi $(CGIDIR) cp -r @srcdir@/cgi-bin/support $(CGIDIR) - cp @srcdir@/cgi-bin/setup.pl @sysconfdir@/live-db-setup.pl chmod 755 $(DESTDIR)$(CGIDIR)/*cgi server-xul: diff --git a/Open-ILS/src/support-scripts/eg_db_config.pl b/Open-ILS/src/support-scripts/eg_db_config.pl index 92222ff114..cdf88aa65b 100644 --- a/Open-ILS/src/support-scripts/eg_db_config.pl +++ b/Open-ILS/src/support-scripts/eg_db_config.pl @@ -27,6 +27,7 @@ use File::Basename; my ($dbhost, $dbport, $dbname, $dbuser, $dbpw, $help); my $config_file = ''; my $build_db_sh = ''; +my $bootstrap_file = ''; my @services; # Get the directory for this script @@ -70,8 +71,28 @@ sub update_config { die "ERROR: Failed to update the configuration file '$config_file'\n"; } -sub create_schema() { -# Extracts the info from opensrf.xml and builds the db by calling build-db.sh +# write out the DB bootstrapping config +sub create_db_bootstrap { + my ($setup, $settings) = @_; + + open(FH, '>', $setup) or die "Could not write database setup to $setup\n"; + + print "Writing database bootstrapping configuration to $setup...\n"; + + printf FH "\$main::config{dsn} = 'dbi:Pg:host=%s;dbname=%s;port=%d';\n", + $settings->{host}, $settings->{db}, $settings->{port}; + + printf FH "\$main::config{usr} = '%s';\n", $settings->{user}; + printf FH "\$main::config{pw} = '%s';\n", $settings->{pw}; + + print FH "\$main::config{index} = 'config.cgi';\n"; + close(FH); +} + +# Extracts database settings from opensrf.xml +sub get_settings { + my $settings = shift; + my $host = "/opensrf/default/apps/open-ils.storage/app_settings/databases/database/host/text()"; my $port = "/opensrf/default/apps/open-ils.storage/app_settings/databases/database/port/text()"; my $dbname = "/opensrf/default/apps/open-ils.storage/app_settings/databases/database/db/text()"; @@ -81,22 +102,34 @@ sub create_schema() { my $parser = XML::LibXML->new(); my $opensrf_config = $parser->parse_file($config_file); + $settings->{host} = $opensrf_config->findnodes($host); + $settings->{port} = $opensrf_config->findnodes($port); + $settings->{db} = $opensrf_config->findnodes($dbname); + $settings->{user} = $opensrf_config->findnodes($user); + $settings->{pw} = $opensrf_config->findnodes($pw); +} + +# Creates the database schema by calling build-db.sh +sub create_schema { + my $settings = shift; + chdir(dirname($build_db_sh)); system(File::Spec->catfile('.', basename($build_db_sh)) . " " . - $opensrf_config->findnodes($host) ." ". - $opensrf_config->findnodes($port) ." ". - $opensrf_config->findnodes($dbname) ." ". - $opensrf_config->findnodes($user) ." ". - $opensrf_config->findnodes($pw)); + $settings->{host} ." ". $settings->{port} ." ". + $settings->{db} ." ". $settings->{user} ." ". + $settings->{pw}); chdir($script_dir); } -my $cschema = ''; -my $uconfig = ''; -my %settings = (); +my $bootstrap; +my $cschema; +my $uconfig; +my %settings; GetOptions("create-schema" => \$cschema, + "create-bootstrap" => \$bootstrap, "update-config" => \$uconfig, + "bootstrap-file=s" => \$bootstrap_file, "config-file=s" => \$config_file, "build-db-file=s" => \$build_db_sh, "service=s" => \@services, @@ -113,20 +146,33 @@ if (grep(/^all$/, @services)) { } my $eg_config = File::Spec->catfile($script_dir, '../extras/eg_config'); -if ($config_file eq '') { + +if (!$config_file) { my @temp = `$eg_config --sysconfdir`; chomp $temp[0]; $config_file = File::Spec->catfile($temp[0], "opensrf.xml"); } -if ($build_db_sh eq '') { + +if (!$build_db_sh) { $build_db_sh = File::Spec->catfile($script_dir, '../sql/Pg/build-db.sh'); } + +if (!$bootstrap_file) { + $bootstrap_file = ('/openils/var/cgi-bin/live-db-setup.pl'); +} + unless (-e $build_db_sh) { die "Error: $build_db_sh does not exist. \n"; } unless (-e $config_file) { die "Error: $config_file does not exist. \n"; } + if ($uconfig) { update_config(\@services, \%settings); } + +# Get our settings from the config file +get_settings(\%settings); + if ($cschema) { create_schema(); } +if ($bootstrap) { create_db_bootstrap($bootstrap_file, \%settings); } -if ((!$cschema && !$uconfig) || $help) { +if ((!$cschema && !$uconfig && !$bootstrap) || $help) { print <> "$CONFIG_FILE"; - - STR='$main::config{usr} ='; - STR="$STR '$DBUSER';"; - echo "$STR" >> "$CONFIG_FILE"; - - STR='$main::config{pw} ='; - STR="$STR '$DBPW';"; - echo "$STR" >> "$CONFIG_FILE"; - - echo '$main::config{index} = "config.cgi";' >> "$CONFIG_FILE"; - #---------------------------- # Create Makefiles/Output #---------------------------- @@ -386,7 +292,6 @@ AC_CONFIG_FILES([Makefile build/i18n/Makefile], [if test -e "./Open-ILS/src/extras/eg_config"; then chmod 755 Open-ILS/src/extras/eg_config; fi]) AC_OUTPUT - #------------------------------------------------- # OUTPUT STUFF #------------------------------------------------- @@ -427,15 +332,6 @@ else AC_MSG_RESULT([Evergreen Java Components: no]) fi AC_MSG_RESULT([]) -AC_MSG_RESULT([-------- DB Info --------]) -AC_MSG_RESULT([Driver: ${DBDRVR}]) -AC_MSG_RESULT([Host: ${DBHOST}]) -AC_MSG_RESULT([Port: ${DBPORT}]) -AC_MSG_RESULT([DB Name: ${DBNAME}]) -AC_MSG_RESULT([Username: ${DBUSER}]) -AC_MSG_RESULT([Version: ${DBVER}]) -AC_MSG_RESULT([Password: ${DBPW}]) -AC_MSG_RESULT([]) AC_MSG_RESULT([-------- Installation Directories --------]) AC_MSG_RESULT(Installation dir prefix: ${prefix}) AC_MSG_RESULT(Temporary dir location: ${TMP}) -- 2.43.2