ENH: RASModel.C: clipping input to log
[OpenFOAM-1.7.x.git] / bin / foamInstallationTest
blobaa1d9a3923627994ca55e4a87c09850d7015d2e3
1 #!/bin/sh
2 #---------------------------------*- sh -*-------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
7 # \\/ M anipulation |
8 #------------------------------------------------------------------------------
9 # License
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamInstallationTest
28 # Description
29 # Checks the machine system, the installation of OpenFOAM, and the user's
30 # personal configuration for running OpenFOAM.
32 #------------------------------------------------------------------------------
34 # Base settings
35 FOAM_VERSION=1.7.x
36 MIN_VERSION_GCC=4.3.1
38 # General
39 WIDTH=20
41 # Global variables
42 FATALERROR=0
43 CRITICALERROR=0
44 SSHRSHOK=0
46 # System variables
47 HOST_NAME=`uname -n`
48 OS=`uname -s`
49 USER_NAME=$LOGNAME
50 if [ ! -n $USER_NAME ]; then
51 USER_NAME=$USER
54 #==============================================================================
55 # HELPER FUNCTIONS
56 #==============================================================================
58 hline () {
59 echo "-------------------------------------------------------------------------------"
63 expenv () {
64 eval "echo $1"
68 heading () {
69 echo ""
70 echo ""
71 echo "$1"
75 lenBase () {
76 echo $1 | tr -d " " | wc -m | tr -d " "
80 length () {
81 NOCHAR=`lenBase $1`
82 NOCHAR=`expr $NOCHAR - 1`
83 if [ $NOCHAR -eq -1 ]; then
84 NOCHAR=0
86 echo $NOCHAR
90 stringLength () {
91 echo $1 | wc -m | tr -d " "
95 fixlen () {
96 WORD=$1
97 ONELEN=`stringLength $1`
98 LDIFF=`expr $ONELEN - $2`
99 if [ $LDIFF -le 1 ]; then
100 while [ $LDIFF -lt 0 ] ; do
101 WORD="$WORD "
102 LDIFF=`expr $LDIFF + 1`
103 done
104 echo "$WORD"
105 else
106 LDIFF=`expr $LDIFF + 4`
107 WORD=`echo "$WORD" | cut -c${LDIFF}-`
108 echo "...${WORD}"
113 reportEnv () {
114 EXP_ENV=`eval "echo $1"`
115 EXP_PATH=`eval "echo $2"`
116 CRIT="$3"
117 EXISTS=" no "
118 ON_PATH=""
119 if [ `length $EXP_ENV` -gt 0 ] ; then
120 case $OS in
121 SunOS)
122 if /usr/bin/test -e $EXP_ENV ; then
123 EXISTS=" yes "
124 if [ "$2" != noPath ]; then
125 ON_PATH=" no "
126 OLD_IFS=$IFS
127 IFS=':'
128 for e in $EXP_PATH
130 if \
132 "$e" = "$EXP_ENV" \
133 -o "$e" = "${EXP_ENV}/bin" \
134 -o "${EXP_ENV}/lib" = "$e" \
135 ] ; then
136 ON_PATH="yes "
138 done
139 IFS=$OLD_IFS
140 else
141 CRIT=" $3"
143 else
144 ON_PATH=" "
146 echo "`fixlen "$1" 21` `fixlen "$EXP_ENV" 40` $EXISTS $ON_PATH $CRIT"
149 if [ -e "$EXP_ENV" ] ; then
150 EXISTS=" yes "
151 if [ "$2" != noPath ]; then
152 ON_PATH=" no "
153 OLD_IFS=$IFS
154 IFS=':'
155 for e in $EXP_PATH
157 if \
159 "$e" = "$EXP_ENV" \
160 -o "$e" = "${EXP_ENV}/bin" \
161 -o "${EXP_ENV}/lib" = "$e" \
162 ] ; then
163 ON_PATH="yes "
165 done
166 IFS=$OLD_IFS
167 else
168 CRIT=" $3"
170 else
171 ON_PATH=" "
173 echo "`fixlen "$1" 21` `fixlen "$EXP_ENV" 40` $EXISTS $ON_PATH $CRIT"
175 esac
176 else
177 echo "`fixlen "$1" 21` --------- env variable not set --------- $3"
180 ERROR="false"
181 if [ "$EXISTS" = no ] || [ "$ON_PATH" = no ]; then
182 ERROR="true"
184 if [ "$3" = yes ] && [ "$ERROR" = true ]; then
185 CRITICALERROR=`expr $CRITICALERROR + 1`
186 echo "WARNING: CRITICAL ERROR"
187 echo
193 findExec() {
194 OLD_IFS=$IFS
195 IFS=':'
196 for d in $1
198 case $OS in
199 SunOS)
200 if /usr/bin/test ! -d "$d/$2" -a -x "$d/$2" ; then
201 IFS=$OLD_IFS
202 echo "$d/$2"
203 return 0
207 if [ ! -d "$d/$2" -a -x "$d/$2" ]; then
208 IFS=$OLD_IFS
209 echo "$d/$2"
210 return 0
213 esac
214 done
215 IFS=$OLD_IFS
216 return 1
220 reportExecutable () {
221 APP_PATH=""
222 APP_PATH=`findExec $PATH $1`
223 APP_SPEC="$2"
224 if [ ! -n $APP_PATH ];then
225 echo "`fixlen "$1" 9`" "*** not installed ***"
226 VERSION=""
227 case $1 in
228 icoFoam)
229 echo " CRITICAL ERROR"
230 CRITICALERROR=`expr $CRITICALERROR + 1`
232 gcc)
233 echo " CRITICAL ERROR"
234 CRITICALERROR=`expr $CRITICALERROR + 1`
236 tar) ;;
237 gtar) ;;
238 gzip) ;;
239 dx) ;;
240 esac
241 echo
242 return 1
244 case $1 in
245 icoFoam)
246 VERSION=`$1 2>&1 \
247 | \grep ' Version:' \
248 | sed -e 's/.*Version:/Version:/' \
249 | cut -d" " -f3`
251 gcc)
252 VERSION=`$1 -v 2>&1 \
253 | grep 'gcc version' \
254 | cut -d" " -f3`
255 verNum=`echo "$VERSION" | sed s/[.]//g`
256 minVerNum=`echo "$MIN_VERSION_GCC" | sed s/[.]//g`
258 if [ $verNum -lt $minVerNum ]; then
259 echo "CRITICAL ERROR: gcc version lower than required"
260 echo " Supplied version: $VERSION"
261 echo " Minimum required: $MIN_VERSION_GCC"
262 echo ""
263 CRITICALERROR=`expr $CRITICALERROR + 1`
266 gtar)
267 VERSION=`$APP_PATH --version | head -1`
269 tar)
270 VERSION=`$APP_PATH --version | head -1 | cut -d" " -f4`
272 gzip)
273 case $OS in
274 SunOS)
275 VERSION=`$1 --version 2>&1 | grep gzip | cut -d" " -f2`
278 VERSION=`$1 --version | head -1 | cut -d" " -f2`
280 esac
282 esac
283 if [ "$APP_PATH" = "$APP_SPEC" ] || [ ! "$2" ]; then
284 echo "`fixlen "$1" 9` `fixlen "$VERSION" 10` `fixlen "$APP_PATH" 58`"
285 else
286 echo "`fixlen "$1" 9` `fixlen "$VERSION" 10`"
287 echo "WARNING: Conflicting installations:"
288 echo " OpenFOAM settings : $APP_SPEC"
289 echo " current path : $APP_PATH"
290 case $1 in
291 icoFoam)
292 echo " CRITICAL ERROR"
293 CRITICALERROR=`expr $CRITICALERROR + 1`
295 gcc)
296 echo " CRITICAL ERROR"
297 CRITICALERROR=`expr $CRITICALERROR + 1`
299 gtar) ;;
300 gzip) ;;
301 dx) ;;
302 esac
303 echo ""
308 pingTest () {
309 RESULT=""
310 case $OS in
311 SunOS)
312 PINGTEST=`/usr/sbin/ping $1 2>&1`
313 if [ "`echo $PINGTEST | grep alive`" != "" ] ; then
314 RESULT="Successful"
315 elif [ "`echo $PINGTEST | grep 'unknown host'`" != "" ] ; then
316 RESULT="No_entry_for_\"$1\"_in_/etc/hosts"
317 else
318 RESULT="Networking_cannot_reach_$1"
322 PINGTEST=`/bin/ping -w 3 -c 1 $1 2>&1`
323 if [ "`echo $PINGTEST | grep '1 received'`" != "" ] ; then
324 RESULT="Successful"
325 elif [ "`echo $PINGTEST | grep 'unknown host'`" != "" ] ; then
326 RESULT="No_entry_for_\"$1\"_in_/etc/hosts"
327 else
328 RESULT="Networking_cannot_reach_$1"
331 esac
333 echo "`fixlen "Pinging_$1" 25` `fixlen "$RESULT" 45` `fixlen "$2" 5`"
335 if [ "$2" = yes ] && [ "$RESULT" != Successful ]; then
336 CRITICALERROR=`expr $CRITICALERROR + 1`
337 echo "WARNING: CRITICAL ERROR"
338 echo
343 telnetPortTest () {
344 telnet -e A $1 $2 <<EOF
346 quit
351 checkTelnetPort () {
352 if [ -x "/usr/bin/telnet" ] || [ -x "/bin/telnet" ] ; then
353 RESULT=`telnetPortTest $1 $2 2>&1 | egrep "onnect.* [t|r]"`
354 if [ "`echo $RESULT | grep 'Connected to'`" ] ; then
355 RESULT='Successful'
356 elif [ "`echo $RESULT | grep 'Connection refused'`" ] ; then
357 RESULT='Unsuccessful_connection_refused*'
358 else
359 RESULT="Not_active*"
361 else
362 RESULT='No_telnet_installed:_cannot_check*'
367 checkRsh () {
368 checkTelnetPort $HOST_NAME 222
369 echo "`fixlen "Test_rsh:" 25` `fixlen "$RESULT" 45` "yes""
370 if [ "$RESULT" != Successful ]; then
371 SSHRSHOK=`expr $SSHRSHOK + 1`
376 checkSsh () {
377 checkTelnetPort $HOST_NAME 22
378 echo "`fixlen "Test_ssh:" 25` `fixlen "$RESULT" 45` "yes""
379 if [ "$RESULT" != Successful ]; then
380 SSHRSHOK=`expr $SSHRSHOK + 1`
385 checkOpenFOAMEnvironment() {
386 [ -d "$WM_PROJECT_INST_DIR" ] && [ -d "$WM_THIRD_PARTY_DIR" ] || {
387 echo ""
388 echo "FATAL ERROR: OpenFOAM environment not configured."
389 echo ""
390 echo " Please refer to the installation section of the README file:"
391 echo " <OpenFOAM installation dir>/OpenFOAM-${FOAM_VERSION}/README"
392 echo " to source the OpenFOAM environment."
393 echo ""
394 exit 1
399 checkUserShell() {
400 case $SHELL in
401 */csh | */tcsh)
402 # USER_CONFIG_TYPE="cshrc"
403 echo "`fixlen "Shell:" $WIDTH` ${SHELL##*/}"
405 */bash | */ksh)
406 # USER_CONFIG_TYPE="bashrc"
407 echo "`fixlen "Shell:" $WIDTH` ${SHELL##*/}"
410 # USER_CONFIG_TYPE=""
411 echo "`fixlen "Shell:" $WIDTH` ${SHELL##*/}"
412 echo "FATAL ERROR: Cannot identify the shell you are running."
413 echo " OpenFOAM ${FOAM_VERSION} is compatible with "
414 echo " csh, tcsh, ksh and bash."
415 echo
416 FATALERROR=`expr $FATALERROR + 1`;;
417 esac
421 checkHostName() {
422 if [ ! "$HOST_NAME" ]; then
423 echo "`fixlen "Host:" $WIDTH` ${HOST_NAME}"
424 echo "FATAL ERROR: Cannot stat hostname."
425 echo " Contact your system administrator, "
426 echo " OpenFOAM ${FOAM_VERSION} needs a valid "
427 echo " hostname to function."
428 echo
429 FATALERROR=`expr $FATALERROR + 1`
430 else
431 echo "`fixlen "Host:" $WIDTH` ${HOST_NAME}"
436 checkOS () {
437 case "$OS" in
438 Linux | LinuxAMD64 | SunOS )
439 echo "`fixlen "OS:" $WIDTH` ${OS} version $(uname -r)"
442 echo "FATAL ERROR: Incompatible operating system \"$OS\"."
443 echo " OpenFOAM ${FOAM_VERSION} is currently "
444 echo " available for Linux and SunOS only."
445 echo
446 FATALERROR=`expr $FATALERROR + 1`
448 esac
452 #==============================================================================
453 # MAIN SCRIPT
454 #==============================================================================
456 echo "Executing $0:"
458 #------------------------------------------------------------------------------
459 heading "Checking basic setup..."
460 hline
461 checkOpenFOAMEnvironment
462 checkUserShell
463 checkHostName
464 checkOS
465 hline
467 #------------------------------------------------------------------------------
468 heading "Checking main OpenFOAM env variables..."
469 COL1=`fixlen "Environment_variable" 21`
470 COL2=`fixlen "Set_to_file_or_directory" 40`
471 COL3="Valid"
472 COL4="Path"
473 COL5="Crit"
474 hline
475 echo "$COL1 $COL2 $COL3 $COL5"
476 hline
477 reportEnv '$WM_PROJECT_INST_DIR' 'noPath' "yes"
478 reportEnv '$WM_PROJECT_USER_DIR' 'noPath' "no"
479 reportEnv '$WM_THIRD_PARTY_DIR' 'noPath' "yes"
480 hline
482 #------------------------------------------------------------------------------
483 heading "Checking the OpenFOAM env variables set on the PATH..."
484 hline
485 echo "$COL1 $COL2 $COL3 $COL4 $COL5"
486 hline
487 reportEnv '$WM_PROJECT_DIR' '$PATH' "yes"
488 echo ""
489 reportEnv '$FOAM_APPBIN' '$PATH' "yes"
490 reportEnv '$FOAM_SITE_APPBIN' '$PATH' "no"
491 reportEnv '$FOAM_USER_APPBIN' '$PATH' "no"
492 reportEnv '$WM_DIR' '$PATH' "yes"
493 hline
495 #------------------------------------------------------------------------------
496 heading "Checking the OpenFOAM env variables set on the LD_LIBRARY_PATH..."
497 hline
498 echo "$COL1 $COL2 $COL3 $COL4 $COL5"
499 hline
500 reportEnv '$FOAM_LIBBIN' '$LD_LIBRARY_PATH' "yes"
501 reportEnv '$FOAM_SITE_LIBBIN' '$LD_LIBRARY_PATH' "no"
502 reportEnv '$FOAM_USER_LIBBIN' '$LD_LIBRARY_PATH' "no"
503 reportEnv '$MPI_ARCH_PATH' '$LD_LIBRARY_PATH' "yes"
504 hline
506 #------------------------------------------------------------------------------
507 heading "Third party software"
508 COL1=`fixlen "Software" 9`
509 COL2=`fixlen "Version" 10`
510 COL3=`fixlen "Location" 10`
511 hline
512 echo "$COL1 $COL2 $COL3"
513 hline
514 reportExecutable gcc
515 reportExecutable gzip
516 if [ "$OS" = Linux ] ; then
517 reportExecutable tar
518 else
519 reportExecutable gtar
521 reportExecutable icoFoam "${FOAM_APPBIN}/icoFoam"
523 hline
525 #------------------------------------------------------------------------------
526 heading "Summary"
527 hline
529 if [ $FATALERROR -gt 0 ] ; then
530 echo "The system test has evoked $FATALERROR fatal error(s)."
531 else
532 echo "Base configuration ok."
534 echo ""
535 if [ $CRITICALERROR -gt 0 ]; then
536 echo "*** The foam installation contains $CRITICALERROR critical error(s)"
537 else
538 echo "Critical systems ok."
540 if [ $CRITICALERROR -gt 0 ] || [ $FATALERROR -gt 0 ]; then
541 echo "*** Review the output for warning messages and consult "
542 echo "*** the installation guide for trouble shooting."
544 echo ""
546 echo "done."
548 echo ""
550 exit 0
552 #------------------------------------------------------------------------------