~vcs-imports/fai/trunk

« back to all changes in this revision

Viewing changes to bin/fai-do-scripts

  • Committer: lange
  • Date: 2005-11-10 12:47:47 UTC
  • Revision ID: svn-v4:ba5ec265-b0fb-0310-8e1a-cf9e4c2b1591:trunk:3022
rename directory scripts to bin, fix pathes in Makefile

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/bash
 
2
 
 
3
#*********************************************************************
 
4
#
 
5
# fai-do-scripts - call configuration scripts for every defined class
 
6
#
 
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
 
10
#
 
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.
 
16
#
 
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.
 
21
 
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
#*********************************************************************
 
28
 
 
29
version="version 1.3.2, 6-apr-2005"
 
30
 
 
31
# variables needed: $classes, $cfclasses, $LOGDIR
 
32
 
33
# And many other variables like:
 
34
 
 
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 ~
 
38
    
 
39
# TODO: -n only shows which scripts should be executed, but do not execute them
 
40
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
41
fc_check_status() {
 
42
 
 
43
    local cmd st res
 
44
    cmd=$1
 
45
    st=$2
 
46
 
 
47
    if [ $st -eq 0 ]; then
 
48
        res="OK."
 
49
    else
 
50
        res="FAILED with exit code $st."
 
51
    fi
 
52
    # put result in the log file and write to stdout
 
53
    printf "%-20s $res\n" $cmd | tee -a $LOGDIR/status.log
 
54
}
 
55
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
56
call_conf() {
 
57
 
 
58
    local class f
 
59
    cd $1
 
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
 
65
           done
 
66
        fi
 
67
    done
 
68
}
 
69
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
70
do_script() {
 
71
 
 
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
 
75
 
 
76
    file=$1
 
77
 
 
78
    # may be remove some day
 
79
    case $file in
 
80
        *~) echo "Skipping backup file $file" ; return ;;
 
81
    esac
 
82
    case $file in
 
83
        S*) echo "Script, matching S* will not be executed in the future. Please use names matching [0-9][0-9]*" ;;
 
84
    esac
 
85
 
 
86
    filetype=$(file $file)
 
87
 
 
88
    if [ "$fake" ]; then
 
89
        echo "Executing $filetype"
 
90
        return
 
91
    fi
 
92
 
 
93
    shelldebug=
 
94
    case $filetype in
 
95
        *"Bourne shell script"*)
 
96
            [ "$debug" ] && shelldebug="sh -x" ;;
 
97
        *"Bourne-Again shell script"*)
 
98
            [ "$debug" ] && shelldebug="bash -x" ;;
 
99
    esac
 
100
 
 
101
    case $filetype in
 
102
 
 
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
 
108
        ;;
 
109
 
 
110
        *"cfagent"*)
 
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
 
115
        ;;
 
116
 
 
117
        *"cfengine script"*)
 
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
 
122
        ;;
 
123
 
 
124
        *"perl script"*)
 
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
 
129
        ;;
 
130
 
 
131
        *"expect script"*)
 
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
 
136
        ;;
 
137
 
 
138
        *) echo "File $file has unsupported type $filetype." ;;
 
139
    esac
 
140
}
 
141
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
142
usage() {
 
143
 
 
144
    local ex
 
145
    ex=$1
 
146
    cat <<-EOF
 
147
        fai-do-scripts $version. Copyright (C) 2003-2005 Thomas Lange
 
148
        Read the manual page fai-do-scripts(1) for more information.
 
149
 
 
150
        Usage: fai-do-scripts [OPTION] DIRECTORY
 
151
 
 
152
EOF
 
153
    exit $ex
 
154
}
 
155
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
156
 # main program
 
157
 
 
158
while getopts "nhL:" opt ; do
 
159
    case "$opt" in
 
160
        h) usage 0 ;;
 
161
        L) LOGDIR=$OPTARG; export LOGDIR ;;
 
162
        n) fake=1 ;;
 
163
    esac
 
164
done
 
165
shift $(($OPTIND - 1))
 
166
[ -z "$1" ] || [ -n "$2" ] && usage 1
 
167
 
 
168
if [ "x$classes" = "x" ]; then
 
169
    echo "No classes are defined."
 
170
    exit 9
 
171
fi
 
172
 
 
173
call_conf $1