[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Update to tools/dbsetup.pl
- Subject: Update to tools/dbsetup.pl
- From: Chris Bennett <..hidden..>
- Date: Wed, 17 Oct 2012 13:50:32 -0500
After seeing someone having installation problems on users list, I
decided to look at dbsetup.pl to see if anything obvious was missing for
newbies.
I have added 3 things.
The directory that ledgersmb-httpd.conf will be installed.
The correct owner of the web site files.
The correct group of the web site files.
The destination files and directories are then chowned.
I have also moved the logger info inside of the progress option.
Not sure if this is OK or not, but it does eliminate a lot of useless
info to new user.
This is still shown:
2012/10/17 13:34:54 - INFO - LedgerSMB::Database::create -- Skipping
contrib_scripts pg_trgm tsearch2 tablefunc
Why?
If the directory that ledgersmb-httpd.conf is installed to does not
exist, then a warning is given and the copy is made into the destination
directory which can later be moved.
I also fixed LedgerSMB::Scripts::dirt to LedgerSMB::Scripts::dbsetup
and $ENV{SCRIPT_NAME} = "dirt.pl"; to
$ENV{SCRIPT_NAME} = "dbsetup.pl";
diff is attached.
Chris Bennett
--- tools/dbsetup.pl Tue Mar 27 20:34:52 2012
+++ tools/dbsetup.pl Wed Oct 17 13:34:17 2012
@@ -1,5 +1,6 @@
#!/usr/bin/perl
-package LedgerSMB::Scripts::dirt;
+package LedgerSMB::Scripts::dbsetup;
+our $VERSION = 0.3;
use warnings;
use strict;
@@ -19,6 +20,9 @@
chomp $srcdir;
my $dstdir = `pwd`;
chomp $dstdir;
+my $ledhttpconfdir = "/var/www/conf/modules";
+my $web_files_owner = "www";
+my $web_files_group = "www";
my $coa = "$srcdir/sql/coa/us/chart/General.sql";
my $chart_name;
my $gifi;
@@ -35,9 +39,10 @@
my $admin_password = 'admin';
my $interactive = 0;
my $no_postgress_pass = 0;
-my $progress = '';
+my $progress = undef;
my $help;
my $dbh;
+my $logger;
# Usage explanation section
@@ -69,20 +74,27 @@
--srcdir The path where the sources for LedgerSMB are located
[$srcdir]
--dstdir The path where the sources will be located when invoked
- from the webserver [$dstdir]
+ from the webserver
+ [$dstdir]
+ --ledhttpconfdir The directory that ledgersmb-httpd.conf will be installed
+ [$ledhttpconfdir]
+ --web_files_owner The correct owner of the web site files
+ [$web_files_owner]
+ --web_files_group The correct group of the web site files
+ [$web_files_group]
--host The PostgreSQL host to connect to (see 'man psql') [$host]
--port The PostgreSQL port to connect to (see 'man psql') [$port]
--pgsql_contrib The directory where the pg_trgm.sql and tablefunc.sql
are located [required for PostgreSQL version < 9.1.x]
--company The name of the database to be created for the company [*]
- --countrycode The name of the 2 character country code. Defaults to 'US'
+ --countrycode The name of the 2 character country code [$countrycode]
--owner The name of the superuser which is to become owner of the
company's database [$owner]
--password The password to be used to create the 'ledgersmb' user
on the specified PostgreSQL server [$pass]
--coa The path locating the file to be used to load the
Chart of Accounts data
- Defaults to '$srcdir/sql/coa/us/chart/General.sql'
+ [$srcdir/sql/coa/us/chart/General.sql]
--chart Chart used
--gifi The path locating the file to be
used to load the GIFI data with the chart of accounts
@@ -105,6 +117,9 @@
GetOptions (
'srcdir:s' => \$srcdir,
'dstdir:s' => \$dstdir,
+ 'ledhttpconfdir:s' => \$ledhttpconfdir,
+ 'web_files_owner:s' => \$web_files_owner,
+ 'web_files_group:s' => \$web_files_group,
'host:s' => \$host,
'port:i' => \$port,
'pgsql_contrib=s' => \$pgsql_contrib_dir,
@@ -148,6 +163,10 @@
unless (stat "/tmp/ledgersmb") {
mkdir "/tmp/ledgersmb";
}
+unless (stat "$ledhttpconfdir") {
+ warn ("Cannot find directory $ledhttpconfdir for ledgersmb-httpd.conf Will install in $dstdir");
+ $ledhttpconfdir = $dstdir;
+}
if (stat "$srcdir/ledgersmb.conf") {
require LedgerSMB;
require LedgerSMB::Database;
@@ -159,17 +178,20 @@
require LedgerSMB::Sysconfig;
};
-my $logger = Log::Log4perl->get_logger('LedgerSMB::Scripts::dirt');
-my $creds = dirt_get_credentials();
+if ($progress) {
+ $logger = Log::Log4perl->get_logger('LedgerSMB::Scripts::dbsetup');
+}
+my $creds = dbsetup_get_credentials();
my $request = {};
$request->{database} = $company_name;
-$ENV{SCRIPT_NAME} = "dirt.pl";
+$ENV{SCRIPT_NAME} = "dbsetup.pl";
# ENVIRONMENT NECESSARY
$ENV{PGUSER} = $creds->{login};
$ENV{PGPASSWORD} = $creds->{password};
$ENV{PGDATABASE} = $request->{database};
+chown_web_files($web_files_owner, $web_files_group, $dstdir);
create_ledgersmb_httpd_conf();
unless ($no_postgress_pass) {
$dbh = DBI->connect("DBI:Pg:dbname=$postgres_db;host=$host;port=5432", $postgres_username, $postgres_password, {'RaiseError' => 0, pg_enable_utf8 => 1 });
@@ -204,12 +226,14 @@
}
my $rc = $database->create();#TODO what if createdb fails?
-$logger->info("create rc=$rc");
+if ($progress) {
+ $logger->info("create rc=$rc");
+}
my $mc = $database->load_modules('LOADORDER');
if ($progress) {
print "\$mc = $mc\n";
+ $logger->info("load modules mc=$mc");
}
-$logger->info("load modules mc=$mc");
$database->process_roles('Roles.sql');
# Load a chart of accounts
@@ -301,7 +325,7 @@
-sub dirt_get_credentials {
+sub dbsetup_get_credentials {
my $return_value = {};
#$logger->debug("\$auth=$auth");#be aware of passwords in log!
($return_value->{login}, $return_value->{password}) = ($owner, $pass);
@@ -319,17 +343,17 @@
sub create_ledgersmb_httpd_conf {
open (my $tmpl_fh, "<", "$srcdir/ledgersmb-httpd.conf.template");
-open (my $lhttpconf_fh, ">", "$dstdir/ledgersmb-httpd.conf");
+open (my $lhttpconf_fh, ">", "$ledhttpconfdir/ledgersmb-httpd.conf");
my @tmpl = <$tmpl_fh>;
-$logger->info("Creating $dstdir/ledgersmb-httpd.conf\n");
if ($progress) {
- print "Creating $dstdir/ledgersmb-httpd.conf\n";
+ $logger->info("Creating $ledhttpconfdir/ledgersmb-httpd.conf\n");
+ print "Creating $ledhttpconfdir/ledgersmb-httpd.conf\n";
}
for my $line (@tmpl) {
$line =~ s/WORKING_DIR/$dstdir/g;
- $logger->info("$line");
if ($progress) {
+ $logger->info("$line");
print "$line";
}
print $lhttpconf_fh $line;
@@ -347,4 +371,10 @@
system "cp $srcdir/ledgersmb.conf.default $srcdir/ledgersmb.conf;$editor $srcdir/ledgersmb.conf";
}
+sub chown_web_files {
+ my $web_files_owner = shift;
+ my $web_files_group = shift;
+ my $dstdir = shift;
+ system "chown -R $web_files_owner:$web_files_group $dstdir";
+}
1;