On 5/3/06, [email protected]
<[email protected]> wrote:
linux-ha CVS committal

Author  : andrew
Host    :
Module  : linux-ha

Dir     : linux-ha


Modified Files:
        bootstrap


Log Message:
Have testProgram() return a simple yes/no
Make sure the call to which is in an if-block to avoid trap being invoked

Matt, I don't know if you had a particular reason for relying only on
the result of "which" but perhaps it might be better to add an extra
if-block for whatever option you need to use to check the program's
version.

Anyway, I'll let you decide that part, but I'm convinced having
testProgram() return a simple yes/no is the way to go.


===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/bootstrap,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -3 -r1.26 -r1.27
--- bootstrap   2 May 2006 20:44:35 -0000       1.26
+++ bootstrap   3 May 2006 07:54:38 -0000       1.27
@@ -24,20 +24,46 @@

 testProgram()
 {
-  if [ -z "$1" ]
-  then
-    return 0;
+  cmd=$1
+  WHICH_OPTS="-s"
+
+  if [ -z "$cmd" ]; then
+    return 1;
   fi

-  cmd=""
   arch=`uname -s`
-  if [ "$arch" = "Linux" -a "$arch" = "Darwin" ]
+  if [ "$arch" = "Darwin" ]; then
+      WHICH_OPTS=""
+  fi
+
+  # Make sure the which is in an if-block... on some platforms it throws 
exceptions
+  #
+  # The ERR trap is not executed if the failed command is part
+  #   of an until or while loop, part of an if statement, part of a &&
+  #   or  ||  list, or if the command's return value is being inverted
+  #   via !.
+  if
+     ! which $WHICH_OPTS $cmd  </dev/null >/dev/null 2>&1
+  then
+      return 1
+  fi
+
+  # The GNU standard is --version
+  if
+      $cmd --version </dev/null >/dev/null 2>&1
+  then
+      return 0
+  fi
+
+  # Maybe it suppports -V instead
+  if
+      $cmd -V </dev/null >/dev/null 2>&1
   then
-    cmd="$1 --version </dev/null >/dev/null 2>&1"
-  else
-    cmd="which -s $1"
+      return 0
   fi

+  # Nope, the program seems broken
+  return 1
 }

 srcdir=`dirname $0`
@@ -76,9 +102,8 @@
 URL=$gnu/$pkg/
 for command in autoconf autoconf213 autoconf253 autoconf259
 do
-  testProgram $command
   if
-       $cmd >/dev/null 2>&1
+      testProgram $command
   then
     : OK $pkg is installed
     autoconf=$command
@@ -111,9 +136,8 @@
 URL=$gnu/$pkg/
 for command in automake automake14 automake15 automake19
 do
-  testProgram $command
   if
-    $cmd  >/dev/null 2>&1
+      testProgram $command
   then
     : OK $pkg is installed
     automake=$command
@@ -142,9 +166,8 @@
 for command in libtool libtool14 libtool15 glibtool
 do
   URL=$gnu/$pkg/
-  testProgram $command
   if
-    $cmd  >/dev/null 2>&1
+    testProgram $command
   then
     : OK $pkg is installed
     libtool=$command


_______________________________________________
Linux-ha-cvs mailing list
[email protected]
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs

_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to