Teach eg_db_config.pl to generate offline-config.pl
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 28 Oct 2008 03:11:22 +0000 (03:11 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 28 Oct 2008 03:11:22 +0000 (03:11 +0000)
Make eg_db_config.pl generate timestamped backups of opensrf.xml
Clean up configure options and output
Remove no-longer-necessary offline-config.pl.in

git-svn-id: svn://svn.open-ils.org/ILS/trunk@10930 dcc99617-32d9-48b4-a31d-7c20da2025e4

Makefile.am
Open-ILS/src/offline/offline-config.pl.in [deleted file]
Open-ILS/src/support-scripts/eg_db_config.pl
configure.ac

index 8659466..5b0cf53 100644 (file)
@@ -37,13 +37,6 @@ export LIBXML2_HEADERS = @LIBXML2_HEADERS@
 export DBI_LIBS = @DBI_LIBS@
 export OPENSRF_HEADERS = @OPENSRF_HEADERS@
 export OPENSRF_LIBS = @OPENSRF_LIBS@
-#export DBDRVR = @DBDRVR@
-#export DBHOST = @DBHOST@
-#export DBPORT = @DBPORT@
-#export DBNAME = @DBNAME@
-#export DBUSER = @DBUSER@
-#export DBPW = @DBPW@
-#export DBVER = @DBVER@
 
 SUBDIRS = Open-ILS/src
 
diff --git a/Open-ILS/src/offline/offline-config.pl.in b/Open-ILS/src/offline/offline-config.pl.in
deleted file mode 100644 (file)
index 068b0c3..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-$main::config{base_dir} = '@localstatedir@/data/offline/';
-$main::config{bootstrap} = '@sysconfdir@/opensrf_core.xml';
-$main::config{dsn} = 'dbi:@DBDRVR@:host=@DBHOST@;dbname=@DBNAME@;port=@DBPORT@';
-$main::config{usr} = '@DBUSER@';
-$main::config{pw} = '@DBPW@';
index f012448..2e3dcac 100644 (file)
@@ -28,8 +28,13 @@ my ($dbhost, $dbport, $dbname, $dbuser, $dbpw, $help);
 my $config_file = '';
 my $build_db_sh = '';
 my $bootstrap_file = '';
+my $offline_file = '';
+my $prefix = '';
+my $sysconfdir = '';
 my @services;
 
+my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
+
 # Get the directory for this script
 my $script_dir = dirname($0);
 
@@ -61,10 +66,12 @@ sub update_config {
                }
        }
 
-       if (copy($config_file, "$config_file.bak")) {
-               print "Backed up original configuration file to '$config_file.bak'\n";
+       my $timestamp = sprintf("%d.%d.%d.%d.%d.%d",
+               $year + 1900, $mon +1, $mday, $hour, $min, $sec);
+       if (copy($config_file, "$config_file.$timestamp")) {
+               print "Backed up original configuration file to '$config_file.$timestamp'\n";
        } else {
-               print STDERR "Unable to write to '$config_file.bak'; bailed out.\n";
+               print STDERR "Unable to write to '$config_file.$timestamp'; bailed out.\n";
     }
 
        $opensrf_config->toFile($config_file) or
@@ -77,7 +84,7 @@ sub create_db_bootstrap {
 
     open(FH, '>', $setup) or die "Could not write database setup to $setup\n";
 
-       print "Writing database bootstrapping configuration 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};
@@ -89,6 +96,25 @@ sub create_db_bootstrap {
     close(FH);
 }
 
+# write out the offline config
+sub create_offline_config {
+       my ($setup, $settings) = @_;
+
+    open(FH, '>', $setup) or die "Could not write offline database setup to $setup\n";
+
+       print "Writing offline database configuration to $setup\n";
+
+       printf FH "\$main::config{base_dir} = '%s/var/data/offline/';\n", $prefix;
+       printf FH "\$main::config{bootstrap} = '%s/opensrf_core.xml';\n", $sysconfdir;
+
+       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};
+
+    close(FH);
+}
 # Extracts database settings from opensrf.xml
 sub get_settings {
        my $settings = shift;
@@ -122,12 +148,14 @@ sub create_schema {
 }
 
 my $bootstrap;
+my $offline;
 my $cschema;
 my $uconfig;
 my %settings;
 
 GetOptions("create-schema" => \$cschema, 
                "create-bootstrap" => \$bootstrap,
+               "create-offline" => \$offline,
                "update-config" => \$uconfig,
                "bootstrap-file=s" => \$bootstrap_file,
                "config-file=s" => \$config_file,
@@ -150,7 +178,14 @@ my $eg_config = File::Spec->catfile($script_dir, '../extras/eg_config');
 if (!$config_file) { 
        my @temp = `$eg_config --sysconfdir`;
        chomp $temp[0];
-       $config_file = File::Spec->catfile($temp[0], "opensrf.xml");
+       $sysconfdir = $temp[0];
+       $config_file = File::Spec->catfile($sysconfdir, "opensrf.xml");
+}
+
+if (!$prefix) {
+       my @temp = `$eg_config --prefix`;
+       chomp $temp[0];
+       $prefix = $temp[0];
 }
 
 if (!$build_db_sh) {
@@ -158,7 +193,11 @@ if (!$build_db_sh) {
 }
 
 if (!$bootstrap_file) {
-       $bootstrap_file = ('/openils/var/cgi-bin/live-db-setup.pl');
+       $bootstrap_file = File::Spec->catfile($sysconfdir, 'live-db-setup.pl');
+}
+
+if (!$offline_file) {
+       $offline_file = File::Spec->catfile($sysconfdir, 'offline-config.pl');
 }
 
 unless (-e $build_db_sh) { die "Error: $build_db_sh does not exist. \n"; }
@@ -171,8 +210,9 @@ get_settings(\%settings);
 
 if ($cschema) { create_schema(\%settings); }
 if ($bootstrap) { create_db_bootstrap($bootstrap_file, \%settings); }
+if ($offline) { create_offline_config($offline_file, \%settings); }
 
-if ((!$cschema && !$uconfig && !$bootstrap) || $help) {
+if ((!$cschema && !$uconfig && !$bootstrap && !$offline) || $help) {
        print <<HERE;
 
 SYNOPSIS
@@ -189,12 +229,17 @@ OPTIONS
         specifies the opensrf.xml file. Defaults to /openils/conf/opensrf.xml
 
     --bootstrap-file
-        specifies the database bootstrap file required by the CGI setup interface
+        specifies the database bootstrap file required by the CGI setup
+        interface. Defaults to /openils/conf/live-db-setup.pl
 
     --build-db-file
         specifies the script that creates the database schema. Defaults to
         Open-ILS/src/sql/pg/build-db.sh
 
+    --offline-file
+        specifies the offline database settings file required by the offline
+        data uploader. Defaults to /openils/conf/offline-config.pl
+
 COMMANDS
     --update-config
         Configures Evergreen database settings in the file specified by
@@ -203,6 +248,9 @@ COMMANDS
     --create-bootstrap
         Creates the database bootstrap file required by the CGI setup interface
 
+    --create-offline
+        Creates the database setting file required by the offline data uploader
+
     --create-schema
         Creates the Evergreen database schema according to the settings in
         the file specified by --config-file.  
@@ -235,7 +283,7 @@ EXAMPLES
    script with a complete set of commands:
 
    perl Open-ILS/src/support-scripts/eg_db_config.pl --update-config \
-       --service all --create-schema --create-bootstrap \
+       --service all --create-schema --create-bootstrap --create-offline \
        --user evergreen --password evergreen --hostname localhost --port 5432 \
        --database evergreen 
 
index 645716a..b74d270 100644 (file)
@@ -56,12 +56,12 @@ AC_PROG_MAKE_SET
 #[openils_all=false])
 
 # install evergreen-core?
-AC_ARG_ENABLE([evergreen-core],
-[  --disable-evergreen-core    disables the installation of the evergreen core components ],
+AC_ARG_ENABLE([core],
+[  --disable-core    disables installation of the Evergreen core components ],
 [case "${enableval}" in
     yes) openils_core=true ;;
     no)  openils_core=false ;;
-  *) AC_MSG_ERROR([please choose another value for --disable-evergreen-core (supported values are yes or no])
+  *) AC_MSG_ERROR([please choose another value for --disable-core (supported values are yes or no])
 esac],
 [openils_core=true])
 
@@ -69,12 +69,12 @@ AM_CONDITIONAL([BUILDILSCORE], [test x$openils_core = xtrue])
 
 # install evergreen-web?
 
-AC_ARG_ENABLE([evergreen-web],
-[  --disable-evergreen-web    disables the installation of the openils web modules ],
+AC_ARG_ENABLE([web],
+[  --disable-web    disables installation of the Evergreen web modules ],
 [case "${enableval}" in
     yes) openils_web=true ;;
     no)  openils_web=false ;;
-  *) AC_MSG_ERROR([please choose another value for --disable-evergreen-web (supported values are yes or no])
+  *) AC_MSG_ERROR([please choose another value for --disable-web (supported values are yes or no])
 esac],
 [openils_web=true])
 
@@ -82,12 +82,12 @@ AM_CONDITIONAL([BUILDILSWEB], [test x$openils_web = xtrue])
 
 # build evergreen-reporter ?
 
-AC_ARG_ENABLE([evergreen-reporter],
-[  --disable-evergreen-reporter    disables the installation of the evergreen reporter module ],
+AC_ARG_ENABLE([reporter],
+[  --disable-reporter    disables installation of the Evergreen reporter module ],
 [case "${enableval}" in
     yes) openils_reporter=true ;;
     no)  openils_reporter=false ;;
-  *) AC_MSG_ERROR([please choose another value for --disable-evergreen-reporter (supported values are yes or no])
+  *) AC_MSG_ERROR([please choose another value for --disable-reporter (supported values are yes or no])
 esac],
 [openils_reporter=true])
 
@@ -95,12 +95,12 @@ AM_CONDITIONAL([BUILDILSREPORTER], [test x$openils_reporter = xtrue])
 
 # build evergreen-client ?
 
-AC_ARG_ENABLE([evergreen-client],
-[  --disable-evergreen-client    disables the installation of the evergreen staff client ],
+AC_ARG_ENABLE([client],
+[  --disable-client    disables installation of the Evergreen staff client ],
 [case "${enableval}" in
     yes) openils_client=true ;;
     no)  openils_client=false ;;
-  *) AC_MSG_ERROR([please choose another value for --disable-evergreen-client (supported values are yes or no])
+  *) AC_MSG_ERROR([please choose another value for --disable-client (supported values are yes or no])
 esac],
 [openils_client=true])
 
@@ -109,12 +109,12 @@ AM_CONDITIONAL([BUILDILSCLIENT], [test x$openils_client = xtrue])
 
 # build evergreen java ?
 
-AC_ARG_ENABLE([evergreen-java],
-[  --enable-evergreen-java    enables the installation of the evergreen java components ],
+AC_ARG_ENABLE([java],
+[  --enable-java    enables installation of the Evergreen Java components ],
 [case "${enableval}" in
     yes) evergreen_java=true ;;
     no)  evergreen_java=false ;;
-  *) AC_MSG_ERROR([please choose another value for --enable-evergreen-java (supported values are yes or no])
+  *) AC_MSG_ERROR([please choose another value for --enable-java (supported values are yes or no])
 esac],
 [evergreen_java=false])
 
@@ -123,12 +123,12 @@ AM_CONDITIONAL([BUILDEGJAVA], [test x$evergreen_java = xtrue])
 
 # build the evergreen python modules?
 
-AC_ARG_ENABLE([evergreen-python],
-[  --enable-evergreen-python    enables the installation of the evergreen python modules ],
+AC_ARG_ENABLE([python],
+[  --enable-python    enables installation of the Evergreen Python modules ],
 [case "${enableval}" in
     yes) EG_PYTHON_INSTALL=true ;;
     no)  EG_PYTHON_INSTALL=false ;;
-  *) AC_MSG_ERROR([please choose another value for --enable-python-install (supported values are yes or no)])
+  *) AC_MSG_ERROR([please choose another value for --enable-python (supported values are yes or no)])
 esac],
 [EG_PYTHON_INSTALL=false])
 
@@ -171,7 +171,7 @@ fi
 #-----------------------------------
 
 AC_ARG_WITH([tmp],
-[ --with-tmp=path              location for the tmp dir for OpenILS (default is /tmp) ],
+[  --with-tmp=path             location of the Evergreen temporary directory (default is /tmp) ],
 [TMP=${withval}],
 [TMP=/tmp])
 AC_SUBST([TMP])
@@ -186,26 +186,26 @@ AC_SUBST([APACHE2_HEADERS])
 APR_HEADERS=`apr-config --includedir`
 AC_SUBST([APR_HEADERS])
 
-AC_ARG_WITH([libxml],
-[  --with-libxml=path         location of the libxml headers (default is /usr/include/libxml2)],
+AC_ARG_WITH([libxml2],
+[  --with-libxml2=path         location of the libxml2 headers (default is /usr/include/libxml2)],
 [LIBXML2_HEADERS=${withval}],
 [LIBXML2_HEADERS=/usr/include/libxml2/])
 AC_SUBST([LIBXML2_HEADERS])
 
 AC_ARG_WITH([dbi],
-[  --with-dbi=path             location of the libdbi libraries (default is /usr/local/lib/dbd)],
+[  --with-dbi=path             location of the libdbi libraries (default is /usr/local/lib/dbd)],
 [DBI_LIBS=${withval}],
 [DBI_LIBS=/usr/local/lib/dbd/])
 AC_SUBST([DBI_LIBS])
 
 AC_ARG_WITH([opensrf-headers],
-[  --with-opensrf-headers=path         location of the opensrf header files (default is /openils/include/)],
+[  --with-opensrf-headers=path location of the OpenSRF header files (default is /openils/include/)],
 [OPENSRF_HEADERS=${withval}],
 [OPENSRF_HEADERS=/openils/include/])
 AC_SUBST([OPENSRF_HEADERS])
 
 AC_ARG_WITH([opensrf-libs],
-[  --with-opensrf-libs=path            location of the opensrf libraries (default is /openils/lib/)],
+[  --with-opensrf-libs=path    location of the OpenSRF libraries (default is /openils/lib/)],
 [OPENSRF_LIBS=${withval}],
 [OPENSRF_LIBS=/openils/lib/])
 AC_SUBST([OPENSRF_LIBS])
@@ -214,7 +214,7 @@ AC_SUBST([OPENSRF_LIBS])
 # Checks for libraries. 
 #------------------------------------
 
-# Check for the existance of libraries in non-standard locations
+# Check for the existence of libraries in non-standard locations
 
 AC_MSG_CHECKING(for -lopensrf)
 if test -e ${OPENSRF_LIBS}/libopensrf.so; then
@@ -286,7 +286,6 @@ AC_CONFIG_FILES([Makefile
                  Open-ILS/src/java/Makefile
                  Open-ILS/src/python/Makefile
                  Open-ILS/xul/staff_client/Makefile
-                 Open-ILS/src/offline/offline-config.pl
                  Open-ILS/src/extras/eg_config],  [if test -e "./Open-ILS/src/extras/eg_config"; then chmod 755 Open-ILS/src/extras/eg_config; fi])
 AC_OUTPUT
 
@@ -331,15 +330,15 @@ else
 fi
 AC_MSG_RESULT([]) 
 AC_MSG_RESULT([-------- Installation Directories --------])
-AC_MSG_RESULT(Installation dir prefix:                  ${prefix})
-AC_MSG_RESULT(Temporary dir location:                   ${TMP})
-AC_MSG_RESULT(APXS2 dir location:                       ${APXS2})
+AC_MSG_RESULT(Installation directory prefix:            ${prefix})
+AC_MSG_RESULT(Temporary directory:                      ${TMP})
+AC_MSG_RESULT(APXS2 location:                           ${APXS2})
 AC_MSG_RESULT(Apache headers location:                  ${APACHE2_HEADERS})
 AC_MSG_RESULT(APR headers location:                     ${APR_HEADERS})
-AC_MSG_RESULT(libxml headers location:                  ${LIBXML2_HEADERS})
-AC_MSG_RESULT(libdbi dir location:                      ${DBI_LIBS})
-AC_MSG_RESULT(OpenSRF Headers location:                 ${OPENSRF_HEADERS})
-AC_MSG_RESULT(OpenSRF Libraries location:               ${OPENSRF_LIBS})
+AC_MSG_RESULT(libxml2 headers location:                 ${LIBXML2_HEADERS})
+AC_MSG_RESULT(libdbi location:                          ${DBI_LIBS})
+AC_MSG_RESULT(OpenSRF headers location:                 ${OPENSRF_HEADERS})
+AC_MSG_RESULT(OpenSRF libraries location:               ${OPENSRF_LIBS})
 
 AC_MSG_RESULT([----------------------------------------------------------------------])