[Fai-commit] r2939 - in people: . michael michael/bugfixes michael/bugfixes/310999 michael/bugfixes/310999/scripts

fai-repository at svn.debian.org fai-repository at svn.debian.org
Mon Oct 10 07:55:51 UTC 2005


Author: michael-guest
Date: 2005-10-10 07:55:50 +0000 (Mon, 10 Oct 2005)
New Revision: 2939

Added:
   people/michael/
   people/michael/bugfixes/
   people/michael/bugfixes/310999/
   people/michael/bugfixes/310999/scripts/
   people/michael/bugfixes/310999/scripts/fai-do-scripts
Log:
Michael: added a bugfix for #310999, it is the same as posted to debian bts.


Copied: people/michael/bugfixes/310999/scripts/fai-do-scripts (from rev 2938, trunk/scripts/fai-do-scripts)
===================================================================
--- trunk/scripts/fai-do-scripts	2005-10-09 12:52:18 UTC (rev 2938)
+++ people/michael/bugfixes/310999/scripts/fai-do-scripts	2005-10-10 07:55:50 UTC (rev 2939)
@@ -0,0 +1,173 @@
+#! /bin/bash
+
+#*********************************************************************
+#
+# fai-do-scripts - call configuration scripts for every defined class
+#
+# This script is part of FAI (Fully Automatic Installation)
+# (c) 2003-2005 by Thomas Lange, lange at informatik.uni-koeln.de
+# Universitaet zu Koeln
+#
+#*********************************************************************
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+# 
+# A copy of the GNU General Public License is available as
+# `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
+# or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
+# can also obtain it by writing to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#*********************************************************************
+
+version="version 1.3.2, 6-apr-2005"
+
+# variables needed: $classes, $cfclasses, $LOGDIR
+# 
+# And many other variables like:
+
+# execute all scripts that match the name of a class.
+# If class is a directory, execute all $class/[0-9][0-9]* scripts in
+# it, but do not execute files ending in ~
+    
+# TODO: -n only shows which scripts should be executed, but do not execute them
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+fc_check_status() {
+
+    local cmd st res
+    cmd=$1
+    st=$2
+
+    if [ $st -eq 0 ]; then
+	res="OK."
+    else
+	res="FAILED with exit code $st."
+    fi
+    # put result in the log file and write to stdout
+    printf "%-20s $res\n" $cmd | tee -a $LOGDIR/status.log
+}
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+call_conf() {
+
+    local class f
+    cd $1
+    for class in $classes ; do
+	[ -x $class -a -f $class ] && do_script $class
+	if [ -d $class ]; then
+	   for f in $(echo $class/{S,}[0-9][0-9]* ) ; do
+	       [ -x $f -a -f $f ] && do_script $f
+	   done
+	fi
+    done
+}
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+do_script() {
+
+    # execute scripts and save their output in log files
+    # cfengine, shell, perl and expect scripts are known types
+    local shelldebug file filetype
+
+    file=$1
+
+    # may be remove some day
+    case $file in
+	*~) echo "Skipping backup file $file" ; return ;;
+    esac
+    case $file in
+	S[0-9][0-9]*) echo "Script, matching S[0-9][0-9]* will not be executed in the future. Please use names matching [0-9][0-9]*" ;;
+    esac
+
+    filetype=$(file $file)
+
+    if [ "$fake" ]; then
+	echo "Executing $filetype"
+	return
+    fi
+
+    shelldebug=
+    case $filetype in
+	*"Bourne shell script"*)
+	    [ "$debug" ] && shelldebug="sh -x" ;;
+	*"Bourne-Again shell script"*)
+	    [ "$debug" ] && shelldebug="bash -x" ;;
+    esac
+
+    case $filetype in
+
+	*"executable shell script"*|*"/bash script"*|*"Bourne shell script"*|*"Bourne-Again shell script"*)
+	    echo "Executing   $shelldebug shell: $file"
+	    echo "=====   shell: $file   =====" >> $LOGDIR/shell.log 2>&1
+	    $shelldebug ./$file >> $LOGDIR/shell.log 2>&1
+	    fc_check_status $file $? | tee -a $LOGDIR/shell.log
+	;;
+
+	*"cfagent"*)
+	    echo "Executing cfagent: $file"
+	    echo "=====   cfagent: $file   =====" >> $LOGDIR/cfagent.log 2>&1
+	    ./$file --no-lock -v -f $file -D${cfclasses} >> $LOGDIR/cfagent.log 2>&1
+	    fc_check_status $file $? | tee -a $LOGDIR/cfagent.log
+	;;
+
+	*"cfengine script"*)
+	    echo "Executing cfengine: $file"
+	    echo "=====   cfengine: $file   =====" >> $LOGDIR/cfengine.log 2>&1
+	    ./$file --no-lock -v -f $file -D${cfclasses} >> $LOGDIR/cfengine.log 2>&1
+	    fc_check_status $file $? | tee -a $LOGDIR/cfengine.log
+	;;
+
+	*"perl script"*)
+	    echo "Executing    perl: $file"
+	    echo "=====   perl: $file   =====" >> $LOGDIR/perl.log 2>&1
+	    ./$file >> $LOGDIR/perl.log 2>&1
+	    fc_check_status $file $? | tee -a $LOGDIR/perl.log
+	;;
+
+	*"expect script"*)
+	    echo "Executing  expect: $file"
+	    echo "=====   expect: $file   =====" >> $LOGDIR/expect.log 2>&1
+	    ./$file >> $LOGDIR/expect.log 2>&1
+	    fc_check_status $file $? | tee -a $LOGDIR/expect.log
+	;;
+
+	*) echo "File $file has unsupported type $filetype." ;;
+    esac
+}
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+usage() {
+
+    local ex
+    ex=$1
+    cat <<-EOF
+        fai-do-scripts $version. Copyright (C) 2003-2005 Thomas Lange
+        Read the manual page fai-do-scripts(1) for more information.
+
+        Usage: fai-do-scripts [OPTION] DIRECTORY
+
+EOF
+    exit $ex
+}
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ # main program
+
+while getopts "nhL:" opt ; do
+    case "$opt" in
+	h) usage 0 ;;
+        L) LOGDIR=$OPTARG; export LOGDIR ;;
+	n) fake=1 ;;
+    esac
+done
+shift $(($OPTIND - 1))
+[ -z "$1" ] || [ -n "$2" ] && usage 1
+
+if [ "x$classes" = "x" ]; then
+    echo "No classes are defined."
+    exit 9
+fi
+
+call_conf $1




More information about the Fai-commit mailing list