3
#*********************************************************************
5
# fai-do-scripts - call configuration scripts for every defined class
7
# This script is part of FAI (Fully Automatic Installation)
8
# (c) 2003-2005 by Thomas Lange, lange@informatik.uni-koeln.de
9
# Universitaet zu Koeln
11
#*********************************************************************
12
# This program is free software; you can redistribute it and/or modify
13
# it under the terms of the GNU General Public License as published by
14
# the Free Software Foundation; either version 2 of the License, or
15
# (at your option) any later version.
17
# This program is distributed in the hope that it will be useful, but
18
# WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
# General Public License for more details.
22
# A copy of the GNU General Public License is available as
23
# `/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
25
# can also obtain it by writing to the Free Software Foundation, Inc.,
26
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
#*********************************************************************
29
version="version 1.3.2, 6-apr-2005"
31
# variables needed: $classes, $cfclasses, $LOGDIR
33
# And many other variables like:
35
# execute all scripts that match the name of a class.
36
# If class is a directory, execute all $class/[0-9][0-9]* scripts in
37
# it, but do not execute files ending in ~
39
# TODO: -n only shows which scripts should be executed, but do not execute them
40
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47
if [ $st -eq 0 ]; then
50
res="FAILED with exit code $st."
52
# put result in the log file and write to stdout
53
printf "%-20s $res\n" $cmd | tee -a $LOGDIR/status.log
55
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60
for class in $classes ; do
61
[ -x $class -a -f $class ] && do_script $class
62
if [ -d $class ]; then
63
for f in $(echo $class/{S,}[0-9][0-9]* ) ; do
64
[ -x $f -a -f $f ] && do_script $f
69
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72
# execute scripts and save their output in log files
73
# cfengine, shell, perl and expect scripts are known types
74
local shelldebug file filetype
78
# may be remove some day
80
*~) echo "Skipping backup file $file" ; return ;;
83
S*) echo "Script, matching S* will not be executed in the future. Please use names matching [0-9][0-9]*" ;;
86
filetype=$(file $file)
89
echo "Executing $filetype"
95
*"Bourne shell script"*)
96
[ "$debug" ] && shelldebug="sh -x" ;;
97
*"Bourne-Again shell script"*)
98
[ "$debug" ] && shelldebug="bash -x" ;;
103
*"executable shell script"*|*"/bash script"*|*"Bourne shell script"*|*"Bourne-Again shell script"*)
104
echo "Executing $shelldebug shell: $file"
105
echo "===== shell: $file =====" >> $LOGDIR/shell.log 2>&1
106
$shelldebug ./$file >> $LOGDIR/shell.log 2>&1
107
fc_check_status $file $? | tee -a $LOGDIR/shell.log
111
echo "Executing cfagent: $file"
112
echo "===== cfagent: $file =====" >> $LOGDIR/cfagent.log 2>&1
113
./$file --no-lock -v -f $file -D${cfclasses} >> $LOGDIR/cfagent.log 2>&1
114
fc_check_status $file $? | tee -a $LOGDIR/cfagent.log
118
echo "Executing cfengine: $file"
119
echo "===== cfengine: $file =====" >> $LOGDIR/cfengine.log 2>&1
120
./$file --no-lock -v -f $file -D${cfclasses} >> $LOGDIR/cfengine.log 2>&1
121
fc_check_status $file $? | tee -a $LOGDIR/cfengine.log
125
echo "Executing perl: $file"
126
echo "===== perl: $file =====" >> $LOGDIR/perl.log 2>&1
127
./$file >> $LOGDIR/perl.log 2>&1
128
fc_check_status $file $? | tee -a $LOGDIR/perl.log
132
echo "Executing expect: $file"
133
echo "===== expect: $file =====" >> $LOGDIR/expect.log 2>&1
134
./$file >> $LOGDIR/expect.log 2>&1
135
fc_check_status $file $? | tee -a $LOGDIR/expect.log
138
*) echo "File $file has unsupported type $filetype." ;;
141
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147
fai-do-scripts $version. Copyright (C) 2003-2005 Thomas Lange
148
Read the manual page fai-do-scripts(1) for more information.
150
Usage: fai-do-scripts [OPTION] DIRECTORY
155
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
158
while getopts "nhL:" opt ; do
161
L) LOGDIR=$OPTARG; export LOGDIR ;;
165
shift $(($OPTIND - 1))
166
[ -z "$1" ] || [ -n "$2" ] && usage 1
168
if [ "x$classes" = "x" ]; then
169
echo "No classes are defined."