[Fai-commit] r6603 - trunk/lib

Thomas Lange lange at alioth.debian.org
Tue Jul 19 20:37:21 UTC 2011


Author: lange
Date: 2011-07-19 20:37:21 +0000 (Tue, 19 Jul 2011)
New Revision: 6603

Modified:
   trunk/lib/subroutines
Log:
add options -a, -o to ifclass(), check multiple classes (logical AND, OR)


Modified: trunk/lib/subroutines
===================================================================
--- trunk/lib/subroutines	2011-07-19 19:35:47 UTC (rev 6602)
+++ trunk/lib/subroutines	2011-07-19 20:37:21 UTC (rev 6603)
@@ -6,7 +6,7 @@
 # subroutines -- useful subroutines for FAI
 #
 # This script is part of FAI (Fully Automatic Installation)
-# (c) 2000-2010 by Thomas Lange, lange at informatik.uni-koeln.de
+# (c) 2000-2011 by Thomas Lange, lange at informatik.uni-koeln.de
 # Universitaet zu Koeln
 # (c) 2001-2005 by Henning Glawe, glaweh at physik.fu-berlin.de
 # Freie Universitaet Berlin
@@ -58,11 +58,25 @@
 ### BEGIN SUBROUTINE INFO
 # Provides-Var:      none
 # Required-Var:      $classes
-# Short-Description: test if class is defined
+# Short-Description: test if one or multiple classes are defined
 ### END SUBROUTINE INFO
 
 ifclass() {
 
+    if [ $# -eq 1 ]; then
+	_ifclass $1
+	return $?
+    fi
+
+    case $1 in
+	-a) shift ; _ifclass_and $* ; return $? ;;
+	-o) shift ; _ifclass_or $*  ; return $? ;;
+    esac
+}
+
+_ifclass() {
+
+    # check one single class
     [ "$debug" ] && echo "Test if class $1 is in $classes" >&2
     # test if a class is defined
     local cl
@@ -74,6 +88,28 @@
     [ "$debug" ] && echo "ifclass returns $ret" >&2
     return $ret
 }
+
+_ifclass_and() {
+
+    # check if all classes are defined (logical AND)
+    local cl
+
+    for cl in $*; do
+	ifclass $cl || return 1
+    done
+    return 0
+}
+
+_ifclass_or() {
+
+    # check if one of the classes is defined (logical OR)
+    local cl
+
+    for cl in $*; do
+	ifclass $cl && return 0
+    done
+    return 1
+}
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 rwmount() {
 




More information about the Fai-commit mailing list