Bug 6008 - Locating mysql/psql commands on Installer.pm
authorSalvador Zaragoza Rubio <salvazm@masmedios.com>
Wed, 30 Mar 2011 15:40:43 +0000 (17:40 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Mon, 27 Feb 2012 14:38:07 +0000 (15:38 +0100)
In Installer.pm when is looking for the system command to dump a file into the database
it might fail if the web user doesn't have it in its path. So we add before a search with
"which" and "whereis" commands, if they fail the command is itself without path.

E.g.: with OpenBSD 4.8 the web user "www" doesn't have the path to the installed mysql bin:
/usr/local/bin/mysql and fails in the web installer.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Seems to work fine, has a good default for if it fails to find that
path

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
tested on my linux box, no visible change, worked before, work after. Will hopefully improve behaviour for OpenBSD

C4/Installer.pm [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index a7eb1f6..43fd724
@@ -508,8 +508,13 @@ sub load_sql {
     my $datadir = C4::Context->config('intranetdir') . "/installer/data/$self->{dbms}";
     my $error;
     my $strcmd;
+    my $cmd;
     if ( $self->{dbms} eq 'mysql' ) {
-        $strcmd = "mysql "
+        $cmd = qx(which mysql 2>/dev/null || whereis mysql 2>/dev/null);
+        chomp $cmd;
+        $cmd = $1 if ($cmd && $cmd =~ /^(.+?)[\r\n]+$/);
+        $cmd = 'mysql' if (!$cmd || !-x $cmd);
+        $strcmd = "$cmd "
             . ( $self->{hostname} ? " -h $self->{hostname} " : "" )
             . ( $self->{port}     ? " -P $self->{port} "     : "" )
             . ( $self->{user}     ? " -u $self->{user} "     : "" )
@@ -517,7 +522,11 @@ sub load_sql {
             . " $self->{dbname} ";
         $error = qx($strcmd --default-character-set=utf8 <$filename 2>&1 1>/dev/null);
     } elsif ( $self->{dbms} eq 'Pg' ) {
-        $strcmd = "psql "
+        $cmd = qx(which psql 2>/dev/null || whereis psql 2>/dev/null);
+        chomp $cmd;
+        $cmd = $1 if ($cmd && $cmd =~ /^(.+?)[\r\n]+$/);
+        $cmd = 'psql' if (!$cmd || !-x $cmd);
+        $strcmd = "$cmd "
             . ( $self->{hostname} ? " -h $self->{hostname} " : "" )
             . ( $self->{port}     ? " -p $self->{port} "     : "" )
             . ( $self->{user}     ? " -U $self->{user} "     : "" )