/[fai]/branches/stable/3.4/bin/fai-do-scripts
ViewVC logotype

Diff of /branches/stable/3.4/bin/fai-do-scripts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/scripts/fai-do-scripts revision 2716 by lange, Tue Apr 5 15:48:02 2005 UTC trunk/bin/fai-do-scripts revision 5529 by lange, Fri Oct 9 11:13:48 2009 UTC
# Line 5  Line 5 
5  # fai-do-scripts - call configuration scripts for every defined class  # fai-do-scripts - call configuration scripts for every defined class
6  #  #
7  # This script is part of FAI (Fully Automatic Installation)  # This script is part of FAI (Fully Automatic Installation)
8  # (c) 2003-2005 by Thomas Lange, lange@informatik.uni-koeln.de  # (c) 2003-2009 by Thomas Lange, lange@informatik.uni-koeln.de
9  # Universitaet zu Koeln  # Universitaet zu Koeln
10  #  #
11  #*********************************************************************  #*********************************************************************
# Line 23  Line 23 
23  # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution  # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
24  # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You  # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
25  # can also obtain it by writing to the Free Software Foundation, Inc.,  # can also obtain it by writing to the Free Software Foundation, Inc.,
26  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  #*********************************************************************  #*********************************************************************
28    
29  version="version 1.3.1, 5-apr-2005"  version="version 1.6.5, 9-oct-2009"
30    
31  # variables needed: $classes, $cfclasses, $LOGDIR  # variables needed: $classes, $cfclasses, $LOGDIR
32  #  #
# Line 37  version="version 1.3.1, 5-apr-2005" Line 37  version="version 1.3.1, 5-apr-2005"
37  # it, but do not execute files ending in ~  # it, but do not execute files ending in ~
38    
39  # TODO: -n only shows which scripts should be executed, but do not execute them  # TODO: -n only shows which scripts should be executed, but do not execute them
40    
41    maxstatus=0  # since maxstatus is set inside a pipe, the value is not available at the end
42    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43    savemaxstatus() {
44    
45        # save the highest exit status
46        [ $1 -gt $maxstatus ] && maxstatus=$1
47    }
48  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49  fc_check_status() {  fc_check_status() {
50    
# Line 48  fc_check_status() { Line 56  fc_check_status() {
56          res="OK."          res="OK."
57      else      else
58          res="FAILED with exit code $st."          res="FAILED with exit code $st."
59            savemaxstatus $st
60      fi      fi
61      # put result in the log file and write to stdout      # put result in the log file and write to stdout
62      printf "%-20s $res\n" $cmd | tee -a $LOGDIR/status.log      printf "%-20s $res\n" $cmd | tee -a $LOGDIR/status.log
# Line 60  call_conf() { Line 69  call_conf() {
69      for class in $classes ; do      for class in $classes ; do
70          [ -x $class -a -f $class ] && do_script $class          [ -x $class -a -f $class ] && do_script $class
71          if [ -d $class ]; then          if [ -d $class ]; then
72             for f in $(echo $class/{S,}[0-9][0-9]* | grep -v ~$) ; do             for f in $(echo $class/{S,}[0-9][0-9]* ) ; do
73                 [ -x $f -a -f $f ] && do_script $f                 [ -x $f -a -f $f ] && do_script $f
74             done             done
75          fi          fi
# Line 71  do_script() { Line 80  do_script() {
80    
81      # execute scripts and save their output in log files      # execute scripts and save their output in log files
82      # cfengine, shell, perl and expect scripts are known types      # cfengine, shell, perl and expect scripts are known types
83      local shelldebug file filetype      local shelldebug file filetype name
84    
85      file=$1      file=$1
86    
87      # may be remove some day      # may be remove some day
88      case $file in      case $file in
89          S*) echo "Script, matching S* will not be executed in the future. Please use names matching [0-9][0-9]*" ;;          *~) [ X$debug = X1 ] && echo "Skipping backup file $file";       return ;;
90            *.dpkg-old)  [ X$debug = X1 ] && echo "Skipping file $file";     return ;;
91            *.dpkg-new)  [ X$debug = X1 ] && echo "Skipping file $file";     return ;;
92            *.dpkg-inst) [ X$debug = X1 ] && echo "Skipping file $file"; return ;;
93      esac      esac
94    
95      filetype=$(file $file)      name=${file##*/}  # basename function
96        case $name in
97            S[0-9][0-9]*) echo -e "WARNING: The script $name does not match [0-9][0-9]*.\nIt's not executed. Please rename it."; return ;;
98        esac
99    
100        filetype=$(file -b $file)
101    
102      if [ "$fake" ]; then      if [ "$fake" ]; then
103          echo "Executing $filetype"          echo "Executing $filetype"
# Line 89  do_script() { Line 106  do_script() {
106    
107      shelldebug=      shelldebug=
108      case $filetype in      case $filetype in
109          *"Bourne shell script"*)          *"POSIX shell script"*|*"Bourne shell script"*)
110              [ "$debug" ] && shelldebug="sh -x" ;;              [ X$debug = X1 ] && shelldebug="sh -x" ;;
111          *"Bourne-Again shell script"*)          *"Bourne-Again shell script"*)
112              [ "$debug" ] && shelldebug="bash -x" ;;              [ X$debug = X1 ] && shelldebug="bash -x" ;;
113      esac      esac
114    
115      case $filetype in      case $filetype in
116    
117          *"executable shell script"*|*"/bash script"*|*"Bourne shell script"*|*"Bourne-Again shell script"*)          *"POSIX shell script"*|*"executable shell script"*|*"/bash script"*|*"Bourne shell script"*|*"Bourne-Again shell script"*)
118              echo "Executing   $shelldebug shell: $file"              echo "Executing   $shelldebug shell: $file"
119              echo "=====   shell: $file   =====" >> $LOGDIR/shell.log 2>&1              echo "=====   shell: $file   =====" >> $LOGDIR/shell.log 2>&1
120              $shelldebug ./$file >> $LOGDIR/shell.log 2>&1              $shelldebug ./$file >> $LOGDIR/shell.log 2>&1
# Line 107  do_script() { Line 124  do_script() {
124          *"cfagent"*)          *"cfagent"*)
125              echo "Executing cfagent: $file"              echo "Executing cfagent: $file"
126              echo "=====   cfagent: $file   =====" >> $LOGDIR/cfagent.log 2>&1              echo "=====   cfagent: $file   =====" >> $LOGDIR/cfagent.log 2>&1
127              ./$file --no-lock -v -f $file -D${cfclasses} >> $LOGDIR/cfagent.log 2>&1              ./$file $cfagentdebug -qKI -D${cfclasses} >> $LOGDIR/cfagent.log 2>&1
128              fc_check_status $file $? | tee -a $LOGDIR/cfagent.log              fc_check_status $file $? | tee -a $LOGDIR/cfagent.log
129          ;;          ;;
130    
131          *"cfengine script"*)          *"cfengine script"*)
132              echo "Executing cfengine: $file"              echo "Executing cfengine: $file"
133              echo "=====   cfengine: $file   =====" >> $LOGDIR/cfengine.log 2>&1              echo "=====   cfengine: $file   =====" >> $LOGDIR/cfengine.log 2>&1
134              ./$file --no-lock -v -f $file -D${cfclasses} >> $LOGDIR/cfengine.log 2>&1              ./$file -K -v -f $file -D${cfclasses} >> $LOGDIR/cfengine.log 2>&1
135              fc_check_status $file $? | tee -a $LOGDIR/cfengine.log              fc_check_status $file $? | tee -a $LOGDIR/cfengine.log
136          ;;          ;;
137    
138          *"perl script"*)          *"perl"*"script"*)
139              echo "Executing    perl: $file"              echo "Executing    perl: $file"
140              echo "=====   perl: $file   =====" >> $LOGDIR/perl.log 2>&1              echo "=====   perl: $file   =====" >> $LOGDIR/perl.log 2>&1
141              ./$file >> $LOGDIR/perl.log 2>&1              ./$file >> $LOGDIR/perl.log 2>&1
# Line 141  usage() { Line 158  usage() {
158      local ex      local ex
159      ex=$1      ex=$1
160      cat <<-EOF      cat <<-EOF
161          fai-do-scripts $version. Copyright (C) 2003-2005 Thomas Lange          fai-do-scripts $version. Copyright (C) 2003-2007 Thomas Lange
162          Read the manual page fai-do-scripts(1) for more information.          Read the manual page fai-do-scripts(1) for more information.
163    
164          Usage: fai-do-scripts [OPTION] DIRECTORY          Usage: fai-do-scripts [OPTION] DIRECTORY
# Line 167  if [ "x$classes" = "x" ]; then Line 184  if [ "x$classes" = "x" ]; then
184      exit 9      exit 9
185  fi  fi
186    
187    [ X$debug = X1 ] && cfagentdebug=-v
188    
189  call_conf $1  call_conf $1
190    # move error number from child scripts to 100+x if any error happened
191    # this does not work atm, cause fc_check.. is called inside a pipe
192    # [ $maxstatus -gt 0 ] && maxstatus=$((100+$maxstatus))
193    exit $maxstatus

Legend:
Removed from v.2716  
changed lines
  Added in v.5529

  ViewVC Help
Powered by ViewVC 1.1.5