Revision
6450
Author
wsanchez@apple.com
Date
2010-10-21 12:44:16 -0700 (Thu, 21 Oct 2010)

Log Message

Abstract out cmp_version()

Modified Paths

Diff

Modified: CalendarServer/trunk/support/py.sh (6449 => 6450)


--- CalendarServer/trunk/support/py.sh	2010-10-20 19:49:14 UTC (rev 6449)
+++ CalendarServer/trunk/support/py.sh	2010-10-21 19:44:16 UTC (rev 6450)
@@ -102,47 +102,54 @@
     done;
 
     if [ -z "${module_version}" ]; then
-      echo "Unable to determine version for ${module}.";
+      if ! "${print_path}"; then
+        echo "Unable to determine version for ${module}.";
+      fi;
       result=1;
+    elif ! cmp_version "${version}" "${module_version}"; then
+      if ! "${print_path}"; then
+        echo "A system version of ${module} exists, but version is ${module_version} (< ${version}).";
+      fi;
+      result=1;
     fi;
+  fi;
 
-     v="${version}";
-    mv="${module_version}";
+  return ${result};
+}
 
-    no_such_luck="A system version of ${module} exists, but version is ${module_version} (< ${version}).";
+# Compare version numbers
 
-    while [ $result != 1 ]; do
-       vh="${v%%.*}"; # Get highest-order segment
-      mvh="${mv%%.*}";
+cmp_version () {
+  local result=0;
 
-      if [ "$vh" -gt "$mvh" ]; then
-        if ! "${print_path}"; then
-          echo "${no_such_luck}";
-        fi;
-        result=1;
-        break;
-      fi;
+  local  v="$1"; shift;
+  local mv="$1"; shift;
 
-      if [ "${v}" == "${v#*.}" ]; then
-        # No dots left, so we're ok
-        break;
-      fi;
+  while [ $result != 1 ]; do
+     vh="${v%%.*}"; # Get highest-order segment
+    mvh="${mv%%.*}";
 
-      if [ "${mv}" == "${mv#*.}" ]; then
-        # No dots left, so we're not gonna match
-        if ! "${print_path}"; then
-          echo "${no_such_luck}";
-        fi;
-        result=1;
-        break;
-      fi;
+    if [ "${vh}" -gt "${mvh}" ]; then
+      result=1;
+      break;
+    fi;
 
-       v="${v#*.}";
-      mv="${mv#*.}";
-    done;
-  fi;
+    if [ "${v}" == "${v#*.}" ]; then
+      # No dots left, so we're ok
+      break;
+    fi;
 
-  return $result;
+    if [ "${mv}" == "${mv#*.}" ]; then
+      # No dots left, so we're not gonna match
+      result=1;
+      break;
+    fi;
+
+     v="${v#*.}";
+    mv="${mv#*.}";
+  done;
+
+  return ${result};
 }
 
 # Detect which python to use, and store it in the 'python' variable, as well as