Add the ability to generate live-db-setup.pl to eg_db_config.pl
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 11 Oct 2008 03:36:43 +0000 (03:36 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 11 Oct 2008 03:36:43 +0000 (03:36 +0000)
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
Open-ILS/src/support-scripts/eg_db_config.pl
configure.ac

index 0d96485..c14221e 100644 (file)
@@ -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:
index 92222ff..cdf88aa 100644 (file)
@@ -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 <<HERE;
 
 SYNOPSIS
@@ -142,19 +188,25 @@ OPTIONS
     --config-file
         specifies the opensrf.xml file. Defaults to /openils/conf/opensrf.xml
 
+    --bootstrap-file
+        specifies the database bootstrap file required by the CGI setup interface
+
     --build-db-file
         specifies the script that creates the database schema. Defaults to
         Open-ILS/src/sql/pg/build-db.sh
 
 COMMANDS
-    --create-schema
-        Create the Evergreen database schema according to the settings in
-        the file specified by --config-file.  
-
     --update-config
-        Configure Evergreen database settings in the file specified by
+        Configures Evergreen database settings in the file specified by
         --build-db-file.  
 
+    --create-bootstrap
+        Creates the database bootstrap file required by the CGI setup interface
+
+    --create-schema
+        Creates the Evergreen database schema according to the settings in
+        the file specified by --config-file.  
+
 SERVICE OPTIONS
     --service
         Specify "all" or one or more of the following services to update:
@@ -164,14 +216,36 @@ SERVICE OPTIONS
             * open-ils.reporter-store
     
 DATABASE CONFIGURATION OPTIONS
-     --user            username for the database 
+    --user            username for the database 
+
+    --password        password for the user 
+
+    --database        name of the database 
+
+    --hostname        name or address of the database host 
+
+    --port            port number for database access
+
+EXAMPLES
+   This script is normally used during the initial installation and
+   configuration process.
+
+   For a single server install, or an install with one web/application
+   server and one database server, you will typically want to invoke this
+   script with a complete set of commands:
 
-     --password        password for the user 
+   perl Open-ILS/src/support-scripts/eg_db_config.pl --update-config \
+       --service all --create-schema --create-bootstrap \
+       --user evergreen --password evergreen --hostname localhost --port 5432 \
+       --database evergreen 
 
-     --database        name of the database 
+   To update the configuration for a single service - for example, if you
+   replicated a database for reporting purposes - just issue the
+   --update-config command with the service identified and the changed
+   database parameters specified:
 
-     --hostname        name or address of the database host 
+   perl Open-ILS/src/support-scripts/eg_db_config.pl --update-config \
+       --service reporter --hostname foobar --password newpass
 
-     --port            port number for database access
 HERE
 }
index fe165bf..0ec85aa 100644 (file)
@@ -47,7 +47,6 @@ AC_PROG_MAKE_SET
 #    yes) openils_all=true;
 #       openils_core=true;
 #       openils_web=true;
-#       openils_db=true;
 #       openils_reporter=true;
 #       openils_client_xul=true;
 #       openils_server_xul=true ;;
@@ -81,19 +80,6 @@ esac],
 
 AM_CONDITIONAL([BUILDILSWEB], [test x$openils_web = xtrue])
 
-# build evergreendb ?
-#
-#AC_ARG_ENABLE([openils-db],
-#[  --disable-openils-db    disables the installation of the openils db modules ],
-#[case "${enableval}" in
-#    yes) openils_db=true ;;
-#    no)  openils_db=false ;;
-#  *) AC_MSG_ERROR([please choose another value for --disable-openils-db (supported values are yes or no])
-#esac],
-#[openils_db=true])
-#
-#AM_CONDITIONAL([BUILDILSDB], [test x$openils_db = xtrue])
-
 # build evergreen-reporter ?
 
 AC_ARG_ENABLE([evergreen-reporter],
@@ -224,60 +210,6 @@ AC_ARG_WITH([opensrf-libs],
 [OPENSRF_LIBS=/openils/lib/])
 AC_SUBST([OPENSRF_LIBS])
 
-#-------------------------------------------------------------
-# Set DB Info
-#-------------------------------------------------------------
-
-AC_ARG_WITH([dbdrvr],
-[ --with-dbdrvr=name           name of the database driver to be used by open-ils (default is Pg)],
-[DBDRVR=${withval}],
-[DBDRVR=Pg])
-AC_SUBST([DBDRVR])
-
-if test $DBDRVR="Pg"; then
-       AC_CHECK_PROG([PGSQL],pg,yes,no)
-       if test $PGSQL = "no"; then
-        AC_MSG_ERROR([*** postgresql not found, aborting])
-       fi
-fi
-
-AC_ARG_WITH([dbhost],
-[ --with-dbhost=address            name of the database hostname to be used by open-ils (default is 127.0.0.1)],
-[DBHOST=${withval}],
-[DBHOST=127.0.0.1])
-AC_SUBST([DBHOST])
-
-AC_ARG_WITH([dbport],
-[ --with-dbport=number            name of the database port to be used by open-ils (default is 5432)],
-[DBPORT=${withval}],
-[DBPORT=5432])
-AC_SUBST([DBPORT])
-
-AC_ARG_WITH([dbname],
-[ --with-dbname=name            name of the database to be used by open-ils (default is evergreen)],
-[DBNAME=${withval}],
-[DBNAME=evergreen])
-AC_SUBST([DBNAME])
-
-AC_ARG_WITH([dbuser],
-[ --with-dbuser=name            name of the database username to be used by open-ils (default is postgres)],
-[DBUSER=${withval}],
-[DBUSER=postgres])
-AC_SUBST([DBUSER])
-
-AC_ARG_WITH([dbver],
-[ --with-dbver=number            version of the database to be used by open-ils, leaving out the periods in the version number (default is 82)],
-[DBVER=${withval}],
-[DBVER=82])
-AC_SUBST([DBVER])
-
-
-AC_ARG_WITH([dbpw],
-[ --with-dbpw=password            password of the database to be used by open-ils (default is postgres)],
-[DBPW=${withval}],
-[DBPW=postgres])
-AC_SUBST([DBPW])
-
 #------------------------------------
 # Checks for libraries. 
 #------------------------------------
@@ -342,32 +274,6 @@ AC_FUNC_STRFTIME
 AC_FUNC_STRTOD
 AC_CHECK_FUNCS([localtime_r memset nl_langinfo setlocale strcasecmp strchr strdup strerror strncasecmp])
 
-
-#------------------------------------
-# Generate some config files
-#------------------------------------
-# write out the DB bootstrapping config
-       CONFIG_FILE='Open-ILS/src/cgi-bin/setup.pl';
-       rm -f "$CONFIG_FILE";
-       echo "Writing bootstrapping config to $CONFIG_FILE...";
-
-       STR='$main::config{dsn} =';
-               STR="$STR 'dbi:${DBDRVR}:host=";
-               STR="${STR}${DBHOST};dbname=";
-               STR="${STR}${DBNAME};port=";
-               STR="${STR}${DBPORT}';";
-       echo "$STR" >> "$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})