Debian Codegraph @

bin/fai-do-scripts

raw symbols SCIP
1 #! /bin/bashscip-shell filesystem . . `/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-2022 by Thomas Lange, [email protected]
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 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 #*********************************************************************
28
29 # variables needed: $classes, $cfclasses, $LOGDIR, $FAI_USE_OLD_SCRIPT_LOGS
30 #
31 # And many other variables like:
32
33 # execute all scripts that match the name of a class.
34 # If class is a directory, execute all $class/[0-9][0-9]* scripts in
35 # it, but do not execute files ending in ~
36
37 maxstatus=0
38 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 savemaxstatusscip-shell shell fai 6.6 savemaxstatus().() {
40
41 exitcode=$1 # set global variable
42 # save the highest exit status
43 [scip-shell system . . `[`. $1 -gt $maxstatus ] && maxstatus=$1
44 }
45 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46 fc_check_statusscip-shell shell fai 6.6 fc_check_status().() {
47
48 local cmd st res
49 cmd=$1
50 st=$2
51
52 if [scip-shell system . . `[`. $st -eq 0 ]; then
53 res="OK."
54 else
55 res="FAILED with exit code $st."
56 fi
57 # put result in the log file and write to stdout
58 printfscip-shell system . . printf. "%-20s $res\n" $cmd | teescip-shell system . . tee. -a $LOGDIR/status.log
59 }
60 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
61 call_confscip-shell shell fai 6.6 call_conf().() {
62
63 local class f
64 cd $1
65 for class in $classes ; do
66 [scip-shell system . . `[`. -x $class -a -f $class ] && do_scriptscip-shell shell fai 6.6 do_script(). $class
67 if [scip-shell system . . `[`. -d $class ]; then
68 for f in $(echoscip-shell system . . echo. $class/[0-9][0-9]* ) ; do
69 [scip-shell system . . `[`. -x $f -a -f $f ] && do_scriptscip-shell shell fai 6.6 do_script(). $f
70 done
71 fi
72 done
73 }
74 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75 vechoscip-shell shell fai 6.6 vecho().() {
76
77 if [scip-shell system . . `[`. X$verbose = X1 ]; then
78 echoscip-shell system . . echo. $*
79 fi
80 }
81
82 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83 do_scriptscip-shell shell fai 6.6 do_script().() {
84
85 # execute scripts and save their output in log files
86 # cfengine, shell, perl and expect scripts are known types
87 local shelldebug file filetype name
88 local -r slog=$LOGDIR/scripts.log
89
90 file=$1
91
92 # may be remove some day
93 case $file in
94 *~) [scip-shell system . . `[`. X$debug = X1 ] && echoscip-shell system . . echo. "Skipping backup file $file"; return ;;
95 *.dpkg-old) [scip-shell system . . `[`. X$debug = X1 ] && echoscip-shell system . . echo. "Skipping file $file"; return ;;
96 *.dpkg-new) [scip-shell system . . `[`. X$debug = X1 ] && echoscip-shell system . . echo. "Skipping file $file"; return ;;
97 *.dpkg-inst) [scip-shell system . . `[`. X$debug = X1 ] && echoscip-shell system . . echo. "Skipping file $file"; return ;;
98 *.dpkg-tmp) [scip-shell system . . `[`. X$debug = X1 ] && echoscip-shell system . . echo. "Skipping file $file"; return ;;
99 *.dpkg-dist) [scip-shell system . . `[`. X$debug = X1 ] && echoscip-shell system . . echo. "Skipping file $file"; return ;;
100 esac
101
102 name=${file##*/} # basename function
103 filetype=$(filescip-shell system . . file. -bL $file)
104
105 if [scip-shell system . . `[`. "$fake" ]; then
106 echoscip-shell system . . echo. "Executing $filetype"
107 return
108 fi
109
110 shelldebug=
111 case $filetype in
112 *"POSIX shell script"*|*"Bourne shell script"*)
113 [scip-shell system . . `[`. X$debug = X1 ] && shelldebug="sh -x" ;;
114 *"Bourne-Again shell script"*)
115 [scip-shell system . . `[`. X$debug = X1 ] && shelldebug="bash -x" ;;
116 *"zsh script"*)
117 [scip-shell system . . `[`. X$debug = X1 ] && shelldebug="zsh -x" ;;
118 esac
119
120
121 if [scip-shell system . . `[`. X$FAI_USE_OLD_SCRIPT_LOGS = X1 ]; then
122 echoscip-shell system . . echo. "WARNING. Old style log file names for custom scripts may be removed in the future."
123 echoscip-shell system . . echo. "unset FAI_USE_OLD_SCRIPT_LOGS for writing output to scripts.log."
124 # use old code below
125 else
126
127 # always write to scripts.log
128 case $filetype in
129 *"POSIX shell script"*|*"executable shell script"*|*"/bash script"*|*"Bourne shell script"*|*"Bourne-Again shell script"*|*"zsh script"*)
130 vechoscip-shell shell fai 6.6 vecho(). "Executing $shelldebug shell: $file"
131 echoscip-shell system . . echo. "===== shell: $file =====" >> $slog 2>&1
132 $shelldebug ./$file >> $slog 2>&1
133 savemaxstatusscip-shell shell fai 6.6 savemaxstatus(). $?
134 fc_check_statusscip-shell shell fai 6.6 fc_check_status(). $file $exitcode | teescip-shell system . . tee. -a $slog
135 ;;
136 *)
137 vechoscip-shell shell fai 6.6 vecho(). "Executing: $file"
138 echoscip-shell system . . echo. "===== $filetype $file =====" >> $slog 2>&1
139 ./$file >> $slog 2>&1
140 savemaxstatusscip-shell shell fai 6.6 savemaxstatus(). $?
141 fc_check_statusscip-shell shell fai 6.6 fc_check_status(). $file $exitcode | teescip-shell system . . tee. -a $slog
142 ;;
143 esac
144 return
145 fi
146
147 case $filetype in
148
149 *"POSIX shell script"*|*"executable shell script"*|*"/bash script"*|*"Bourne shell script"*|*"Bourne-Again shell script"*|*"zsh script"*)
150 vechoscip-shell shell fai 6.6 vecho(). "Executing $shelldebug shell: $file"
151 echoscip-shell system . . echo. "===== shell: $file =====" >> $LOGDIR/shell.log 2>&1
152 $shelldebug ./$file >> $LOGDIR/shell.log 2>&1
153 savemaxstatusscip-shell shell fai 6.6 savemaxstatus(). $?
154 fc_check_statusscip-shell shell fai 6.6 fc_check_status(). $file $exitcode | teescip-shell system . . tee. -a $LOGDIR/shell.log
155 ;;
156
157 *"cf-agent"*)
158 vechoscip-shell shell fai 6.6 vecho(). "Executing cf-agent: $file"
159 echoscip-shell system . . echo. "===== cf-agent: $file =====" >> $LOGDIR/cfagent.log 2>&1
160 ./$file $cfagentdebug -KI -D${cfclasses} >> $LOGDIR/cfagent.log 2>&1
161 savemaxstatusscip-shell shell fai 6.6 savemaxstatus(). $?
162 fc_check_statusscip-shell shell fai 6.6 fc_check_status(). $file $exitcode | teescip-shell system . . tee. -a $LOGDIR/cfagent.log
163 ;;
164
165 *[Pp]erl*script*)
166 vechoscip-shell shell fai 6.6 vecho(). "Executing perl: $file"
167 echoscip-shell system . . echo. "===== perl: $file =====" >> $LOGDIR/perl.log 2>&1
168 ./$file >> $LOGDIR/perl.log 2>&1
169 savemaxstatusscip-shell shell fai 6.6 savemaxstatus(). $?
170 fc_check_statusscip-shell shell fai 6.6 fc_check_status(). $file $exitcode | teescip-shell system . . tee. -a $LOGDIR/perl.log
171 ;;
172
173 *"expect script"*)
174 vechoscip-shell shell fai 6.6 vecho(). "Executing expect: $file"
175 echoscip-shell system . . echo. "===== expect: $file =====" >> $LOGDIR/expect.log 2>&1
176 ./$file >> $LOGDIR/expect.log 2>&1
177 savemaxstatusscip-shell shell fai 6.6 savemaxstatus(). $?
178 fc_check_statusscip-shell shell fai 6.6 fc_check_status(). $file $exitcode | teescip-shell system . . tee. -a $LOGDIR/expect.log
179 ;;
180
181 *[Pp]ython*script*)
182 vechoscip-shell shell fai 6.6 vecho(). "Executing python: $file"
183 echoscip-shell system . . echo. "===== python: $file =====" >> $LOGDIR/python.log 2>&1
184 ./$file >> $LOGDIR/python.log 2>&1
185 savemaxstatusscip-shell shell fai 6.6 savemaxstatus(). $?
186 fc_check_statusscip-shell shell fai 6.6 fc_check_status(). $file $exitcode | teescip-shell system . . tee. -a $LOGDIR/python.log
187 ;;
188
189 *[Rr]uby*script*)
190 vechoscip-shell shell fai 6.6 vecho(). "Executing ruby: $file"
191 echoscip-shell system . . echo. "===== ruby: $file =====" >> $LOGDIR/ruby.log 2>&1
192 ./$file >> $LOGDIR/ruby.log 2>&1
193 savemaxstatusscip-shell shell fai 6.6 savemaxstatus(). $?
194 fc_check_statusscip-shell shell fai 6.6 fc_check_status(). $file $exitcode | teescip-shell system . . tee. -a $LOGDIR/ruby.log
195 ;;
196
197 *)
198 vechoscip-shell shell fai 6.6 vecho(). "Executing: $file"
199 echoscip-shell system . . echo. "===== $filetype $file =====" >> $LOGDIR/scripts.log 2>&1
200 ./$file >> $LOGDIR/scripts.log 2>&1
201 savemaxstatusscip-shell shell fai 6.6 savemaxstatus(). $?
202 fc_check_statusscip-shell shell fai 6.6 fc_check_status(). $file $exitcode | teescip-shell system . . tee. -a $LOGDIR/scripts.log
203 ;;
204 esac
205 }
206 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207 usagescip-shell shell fai 6.6 usage().() {
208
209 local ex
210 ex=$1
211 catscip-shell system . . cat. <<-EOF
212 fai-do-scripts Copyright (C) 2003-2010 Thomas Lange
213 Read the manual page fai-do-scripts(1) for more information.
214
215 Usage: fai-do-scripts [OPTION] DIRECTORY
216
217 EOF
218 exit $ex
219 }
220 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
221 # main program
222
223 while getopts "nhL:" opt ; do
224 case "$opt" in
225 h) usagescip-shell shell fai 6.6 usage(). 0 ;;
226 L) LOGDIR=$OPTARG; export LOGDIR ;;
227 n) fake=1 ;;
228 esac
229 done
230 shift $((OPTIND - 1))
231 [scip-shell system . . `[`. -z "$1" ] || [scip-shell system . . `[`. -n "$2" ] && usagescip-shell shell fai 6.6 usage(). 1
232
233 if [scip-shell system . . `[`. "x$classes" = "x" ]; then
234 echoscip-shell system . . echo. "No classes are defined."
235 exit 9
236 fi
237
238 [scip-shell system . . `[`. X$debug = X1 ] && cfagentdebug=-v
239
240 call_confscip-shell shell fai 6.6 call_conf(). $1
241 # move error number from child scripts to 100+x if any error happened
242 [scip-shell system . . `[`. $maxstatus -gt 0 ] && maxstatus=$((100+maxstatus))
243 exit $maxstatus