[PATCH] more that one scripts for the same class

Phil pbi at cartel-info.fr
Tue Jan 22 13:29:02 CET 2002


Hi,

I wanted to use a shell script and a cfengine script for the same class.
Moreover I needed to control the execution order of them.

This patch will do the following, when it's time to execute scripts in
/fai/script : for each class, if there is a script with the same name, it
is executed, as usual. But now, if there is a directory with this name,
fai will execute each S??* script inside this directory, following the
order of ??.



-- 
Philippe Biondi <biondi@ cartel-securite.fr> Cartel Sécurité
Security Consultant/R&D                      http://www.cartel-securite.fr
Phone: +33 1 44 06 97 94                     Fax: +33 1 44 06 97 99
PGP KeyID:3D9A43E2  FingerPrint:C40A772533730E39330DC0985EE8FF5F3D9A43E2


-------------- next part --------------
--- subroutines~	Mon Jan 21 23:46:12 2002
+++ subroutines	Mon Jan 21 23:47:21 2002
@@ -572,17 +572,11 @@
     fi
 }
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-task_configure() {
-
-# execute scripts; cfengine, shell, perl and expect scripts are known types
-cd /fai/scripts
-
-local class filetype shelldebug
-
-for class in $classes ; do
-if [ -x $class -a -f $class ]; then
-    filetype=`file $class`
+do_script() {
+    local file
 
+    file=$1
+    filetype=`file $file`
     shelldebug=
     case $filetype in
 	*"Bourne shell script"*)
@@ -594,34 +588,56 @@
     case $filetype in
 
 	*"Bourne shell script"*|*"Bourne-Again shell script"*)
-	    echo "Executing $shelldebug shell: $class"
-	    echo "=====   shell: $class   =====" >> /tmp/shell.log 2>&1
-	    $shelldebug ./$class >> /tmp/shell.log 2>&1
+	    echo "Executing $shelldebug shell: $file"
+	    echo "=====   shell: $file   =====" >> /tmp/shell.log 2>&1
+	    $shelldebug ./$file >> /tmp/shell.log 2>&1
 	;;
 
 	*"cfengine script"*)
-	    echo "Executing cfengine: $class"
-	    echo "=====   cfengine: $class   =====" >> /tmp/cfengine.log 2>&1
-	    ./$class --no-lock -v -f $class -D${cfclasses} >> /tmp/cfengine.log 2>&1
+	    echo "Executing cfengine: $file"
+	    echo "=====   cfengine: $file   =====" >> /tmp/cfengine.log 2>&1
+	    ./$file --no-lock -v -f $file -D${cfclasses} >> /tmp/cfengine.log 2>&1
 	;;
 
 	*"perl script"*)
-	    echo "Executing perl: $class"
-	    echo "=====   perl: $class   =====" >> /tmp/perl.log 2>&1
-	    ./$class >> /tmp/perl.log 2>&1
+	    echo "Executing perl: $file"
+	    echo "=====   perl: $file   =====" >> /tmp/perl.log 2>&1
+	    ./$file >> /tmp/perl.log 2>&1
 	;;
 
 	*"expect script"*)
-	    echo "Executing expect: $class"
-	    echo "=====   expect: $class   =====" >> /tmp/expect.log 2>&1
-	    ./$class >> /tmp/expect.log 2>&1
+	    echo "Executing expect: $file"
+	    echo "=====   expect: $file   =====" >> /tmp/expect.log 2>&1
+	    ./$file >> /tmp/expect.log 2>&1
 	;;
 
-	*) echo "File $class has unsupported type $filetype." ;;
+	*) echo "File $file has unsupported type $filetype." ;;
     esac
+}
+
+task_configure() {
+
+# execute scripts; cfengine, shell, perl and expect scripts are known types
+cd /fai/scripts
+
+local class filetype shelldebug
+
+for class in $classes ; do
+if [ -x $class -a -f $class ]; then
+	do_script $class
+elif [ -d $class ]; then
+    [ "$verbose" ] && echo "Executing scripts of $class"
+    cd $class
+    for f in `ls S[0-9]*` ; do
+        if [ -x $f -a -f $f ]; then
+		do_script $f
+        fi
+    done
+    cd ..
 fi
 done
 }
+
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 task_finish() {
 


More information about the linux-fai mailing list