b0b401942ab87c2208fec5bfbeeeb4a1cb1bc326
angie
  Wed Dec 14 16:48:38 2016 -0800
If HGDB_CONF is not set and hg.conf is not in the usual places, look for it in hgVai's parent dir and set HGDB_CONF if found.  refs #12216 note-32

diff --git src/hg/utils/vai.pl src/hg/utils/vai.pl
index 7eba6c5..7e9e67f 100755
--- src/hg/utils/vai.pl
+++ src/hg/utils/vai.pl
@@ -247,42 +247,51 @@
 
 # Add command line options that map directly to hgva_... CGI params
 foreach my $param (keys %paramOptions) {
   my $value = $paramOptions{$param}->[0];
   $hgVaiParams{"hgva_$param"} = uriEscape($value);
 }
 
 # If variant file has relative path then convert to absolute.
 if ($hgVaiParams{hgva_variantTrack} eq 'hgva_useVariantFileOrUrl' &&
     $hgVaiParams{hgva_variantFileOrUrl} !~ /^(https?|ftp):\/\// &&
     $hgVaiParams{hgva_variantFileOrUrl} =~ /^[^\/]/) {
   $hgVaiParams{hgva_variantFileOrUrl} = getcwd() . '/' . $hgVaiParams{hgva_variantFileOrUrl};
 }
 
 # If env var ALL_JOINER_FILE is not already set, try to find an all.joiner to set it to.
-if (! $ENV{ALL_JOINER_FILE})
-  {
+my $hgVaiDir = dirname $hgVai;
+if (! $ENV{ALL_JOINER_FILE}) {
   if (-e "all.joiner") {
     $ENV{ALL_JOINER_FILE} = "all.joiner";
   } else {
-      my $hgVaiDir = dirname $hgVai;
-      my $joinerFile = $hgVaiDir . "/all.joiner";
+    my $joinerFile =  "$hgVaiDir/all.joiner";
     if (-e $joinerFile) {
       $ENV{ALL_JOINER_FILE} = $joinerFile};
   }
 }
 
+# If env var HGDB_CONF is not already set, try to find an hg.conf to set it to.
+if (! $ENV{HGDB_CONF}) {
+  if (! -e "hg.conf" && ! -e $ENV{HOME}."/.hg.conf") {
+    my $hgConf = "$hgVaiDir/hg.conf";
+    if (-e $hgConf) {
+      $ENV{HGDB_CONF} = $hgConf;
+    }
+  }
+}
+
 my @params = map { "$_=" . $hgVaiParams{$_} } keys %hgVaiParams;
 my $command = "$hgVai '" . join('&', @params) . "'";
 if ($debug) {
   print "$command\n";
 } else {
   delete $ENV{HTTP_COOKIE};
   if (! $ENV{JKTRASH}) {
     # If user has not set JKTRASH, but TMPDIR is defined, then use TMPDIR instead of cwd.
     my $tmpDir = $ENV{TMPDIR};
     if ($tmpDir) {
       $ENV{JKTRASH} = $tmpDir;
     }
   }
   exit runHgVai($command);
 }