Do not show connction failure message on install if we are trying a different user.
authorGreg Sabino Mullane <greg@endpoint.com>
Fri, 13 Jun 2014 11:02:53 +0000 (07:02 -0400)
committerGreg Sabino Mullane <greg@endpoint.com>
Fri, 13 Jun 2014 11:02:53 +0000 (07:02 -0400)
If the postgres user fails on install, try ENV{USER} - even in batch mode.

bucardo

diff --git a/bucardo b/bucardo
index d62a03687284e72a890098b1ff647580f825df8d..7cc376aaaa1a38b243ad9224d5d733b2a127a51c 100755 (executable)
--- a/bucardo
+++ b/bucardo
@@ -8286,19 +8286,30 @@ sub install {
     my $res = qx{$COM 2>&1};
 
     ## Dump any problems verbatim to stderr
+    my $delayed_warning;
     if ($res =~ /FATAL|ERROR/ or $res =~ /psql:/) {
-        warn $res;
+        $delayed_warning = $res;
     }
 
     ## Check for some common errors
-    if ($res =~ /role ".+" does not exist/) {
-        print "-->Sorry, please try using a different user\n\n";
-        exit 1 if $bcargs->{batch};
+    if ($res =~ /role "(.+)" does not exist/) {
+        my $baduser = $1;
+        if ($baduser eq 'postgres' and exists $ENV{USER} and $ENV{USER} =~ /^\w+$/) {
+            $user = $ENV{USER};
+            if (!$QUIET and !$bcargs->{batch}) {
+                print "Failed to connect as user 'postgres', will try '$user'\n";
+            }
+        }
+        else {
+            print "-->Sorry, please try using a different user\n\n";
+            exit 1 if $bcargs->{batch};
+        }
         goto GOOEY;
     }
 
     if ($res !~ /(\d+)\.(\d+)(\S+)/) {
         print "-->Sorry, unable to connect to the database\n\n";
+        warn $delayed_warning;
         exit 1 if $bcargs->{batch};
         goto GOOEY;
     }