use Getopt::Long;
use File::Spec;
use File::Basename;
+use DBI;
-my ($dbhost, $dbport, $dbname, $dbuser, $dbpw, $help);
+my ($dbhost, $dbport, $dbname, $dbuser, $dbpw, $help, $admin_user, $admin_pw);
my $config_file = '';
my $build_db_sh = '';
my $offline_file = '';
# Get the directory for this script
my $script_dir = dirname($0);
+=over
+
+=item update_config() - Puts command line specified settings into xml file
+=cut
sub update_config {
- # Puts command line specified settings into xml file
my ($services, $settings) = @_;
my $parser = XML::LibXML->new();
die "ERROR: Failed to update the configuration file '$config_file'\n";
}
-# write out the offline config
+=item create_offline_config() - Write out the offline config
+=cut
sub create_offline_config {
my ($setup, $settings) = @_;
close(FH);
}
-# Extracts database settings from opensrf.xml
+
+=item get_settings() - Extracts database settings from opensrf.xml
+=cut
sub get_settings {
my $settings = shift;
$settings->{pw} = $settings->{pw} || $opensrf_config->findnodes($pw);
}
-# Creates the database schema by calling build-db.sh
+=item create_schema() - Creates the database schema by calling build-db.sh
+=cut
sub create_schema {
my $settings = shift;
chdir($script_dir);
}
+=item set_admin_account() - Sets the administrative user's user name and password
+=cut
+sub set_admin_account {
+ my $admin_user = shift;
+ my $admin_pw = shift;
+ my $settings = shift;
+
+ my $dbh = DBI->connect('dbi:Pg:dbname=' . $settings->{db} .
+ ';host=' . $settings->{host} . ';port=' . $settings->{port} . ';',
+ $settings->{user} . "", $settings->{pw} . "", {AutoCommit => 1}
+ );
+ if ($dbh->err) {
+ print STDERR "Could not connect to database to set admin account. ";
+ print STDERR "Error was " . $dbh->errstr . "\n";
+ return;
+ }
+ my $stmt = $dbh->prepare("UPDATE actor.usr SET usrname = ?, passwd = ? WHERE id = 1");
+ $stmt->execute(($admin_user, $admin_pw));
+ if ($dbh->err) {
+ print STDERR "Failed to set admin account. ";
+ print STDERR "Error was " . $dbh->errstr . "\n";
+ return;
+ }
+}
+
my $offline;
my $cschema;
my $uconfig;
"update-config" => \$uconfig,
"config-file=s" => \$config_file,
"build-db-file=s" => \$build_db_sh,
+ "admin-user=s" => \$admin_user,
+ "admin-password=s" => \$admin_pw,
"service=s" => \@services,
"user=s" => \$settings{'user'},
"password=s" => \$settings{'pw'},
get_settings(\%settings);
if ($cschema) { create_schema(\%settings); }
+if ($admin_user && $admin_pw) {
+ set_admin_account($admin_user, $admin_pw, \%settings);
+}
if ($offline) { create_offline_config($offline_file, \%settings); }
-if ((!$cschema && !$uconfig && !$offline) || $help) {
+if ((!$cschema && !$uconfig && !$offline && !$admin_pw) || $help) {
print <<HERE;
SYNOPSIS
--port port number for database access
+ --admin-user administration user's user name
+
+ --admin-pass administration user's password
+
EXAMPLES
This script is normally used during the initial installation and
- configuration process.
+ configuration process. This creates the database schema, sets
+ the administration user's user name and password, and modifies your
+ configuration files to include the correct database connection
+ information.
For a single server install, or an install with one web/application
server and one database server, you will typically want to invoke this
perl Open-ILS/src/support-scripts/eg_db_config.pl --update-config \
--service all --create-schema --create-offline \
- --user evergreen --password evergreen --hostname localhost --port 5432 \
- --database evergreen
+ --user <db-user> --password <db-pass> --hostname localhost --port 5432 \
+ --database evergreen --admin-user <admin-user> --admin-pass <admin-pass>
To update the configuration for a single service - for example, if you
replicated a database for reporting purposes - just issue the