initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / bin / foamInstallationTest
blobeacda19ccea72367443d72532d9685f17b2927b0
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2009 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 the
14 # Free Software Foundation; either version 2 of the License, or (at your
15 # 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, write to the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 # Script
27 # foamInstallationTest
29 # Description
30 # Checks the machine system, the installation of OpenFOAM, and the user's
31 # personal configuration for running OpenFOAM.
33 #------------------------------------------------------------------------------
35 # Base settings
36 FOAM_VERSION=1.6
37 SUPPLIED_VERSION_GCC=4.3.3
38 MIN_VERSION_GCC=4.3.1
40 # General
41 WIDTH=20
43 # Global variables
44 FATALERROR=0
45 CRITICALERROR=0
46 SSHRSHOK=0
48 # System variables
49 HOST_NAME=`uname -n`
50 OS=`uname -s`
51 USER_NAME=$LOGNAME
52 if [ ! -n $USER_NAME ]; then
53 USER_NAME=$USER
56 #==============================================================================
57 # HELPER FUNCTIONS
58 #==============================================================================
60 hline () {
61 echo "-------------------------------------------------------------------------------"
65 expenv () {
66 eval "echo $1"
70 heading () {
71 echo ""
72 echo ""
73 echo "$1"
77 lenBase () {
78 echo $1 | tr -d " " | wc -m | tr -d " "
82 length () {
83 NOCHAR=`lenBase $1`
84 NOCHAR=`expr $NOCHAR - 1`
85 if [ $NOCHAR -eq -1 ]; then
86 NOCHAR=0
88 echo $NOCHAR
92 stringLength () {
93 echo $1 | wc -m | tr -d " "
97 fixlen () {
98 WORD=$1
99 ONELEN=`stringLength $1`
100 LDIFF=`expr $ONELEN - $2`
101 if [ $LDIFF -le 1 ]; then
102 while [ $LDIFF -lt 0 ] ; do
103 WORD="$WORD "
104 LDIFF=`expr $LDIFF + 1`
105 done
106 echo "$WORD"
107 else
108 LDIFF=`expr $LDIFF + 4`
109 WORD=`echo "$WORD" | cut -c${LDIFF}-`
110 echo "...${WORD}"
115 reportEnv () {
116 EXP_ENV=`eval "echo $1"`
117 EXP_PATH=`eval "echo $2"`
118 CRIT="$3"
119 EXISTS=" no "
120 ON_PATH=""
121 if [ `length $EXP_ENV` -gt 0 ] ; then
122 case $OS in
123 SunOS)
124 if /usr/bin/test -e $EXP_ENV ; then
125 EXISTS=" yes "
126 if [ "$2" != noPath ]; then
127 ON_PATH=" no "
128 OLD_IFS=$IFS
129 IFS=':'
130 for e in $EXP_PATH
132 if \
134 "$e" = "$EXP_ENV" \
135 -o "$e" = "${EXP_ENV}/bin" \
136 -o "${EXP_ENV}/lib" = "$e" \
137 ] ; then
138 ON_PATH="yes "
140 done
141 IFS=$OLD_IFS
142 else
143 CRIT=" $3"
145 else
146 ON_PATH=" "
148 echo "`fixlen "$1" 21` `fixlen "$EXP_ENV" 40` $EXISTS $ON_PATH $CRIT"
151 if [ -e "$EXP_ENV" ] ; then
152 EXISTS=" yes "
153 if [ "$2" != noPath ]; then
154 ON_PATH=" no "
155 OLD_IFS=$IFS
156 IFS=':'
157 for e in $EXP_PATH
159 if \
161 "$e" = "$EXP_ENV" \
162 -o "$e" = "${EXP_ENV}/bin" \
163 -o "${EXP_ENV}/lib" = "$e" \
164 ] ; then
165 ON_PATH="yes "
167 done
168 IFS=$OLD_IFS
169 else
170 CRIT=" $3"
172 else
173 ON_PATH=" "
175 echo "`fixlen "$1" 21` `fixlen "$EXP_ENV" 40` $EXISTS $ON_PATH $CRIT"
177 esac
178 else
179 echo "`fixlen "$1" 21` --------- env variable not set --------- $3"
182 ERROR="false"
183 if [ "$EXISTS" = no ] || [ "$ON_PATH" = no ]; then
184 ERROR="true"
186 if [ "$3" = yes ] && [ "$ERROR" = true ]; then
187 CRITICALERROR=`expr $CRITICALERROR + 1`
188 echo "WARNING: CRITICAL ERROR"
189 echo
195 findExec() {
196 OLD_IFS=$IFS
197 IFS=':'
198 for d in $1
200 case $OS in
201 SunOS)
202 if /usr/bin/test ! -d "$d/$2" -a -x "$d/$2" ; then
203 IFS=$OLD_IFS
204 echo "$d/$2"
205 return 0
209 if [ ! -d "$d/$2" -a -x "$d/$2" ]; then
210 IFS=$OLD_IFS
211 echo "$d/$2"
212 return 0
215 esac
216 done
217 IFS=$OLD_IFS
218 return 1
222 reportExecutable () {
223 APP_PATH=""
224 APP_PATH=`findExec $PATH $1`
225 APP_SPEC="$2"
226 if [ ! -n $APP_PATH ];then
227 echo "`fixlen "$1" 9`" "*** not installed ***"
228 VERSION=""
229 case $1 in
230 icoFoam)
231 echo " CRITICAL ERROR"
232 CRITICALERROR=`expr $CRITICALERROR + 1`
234 gcc)
235 echo " CRITICAL ERROR"
236 CRITICALERROR=`expr $CRITICALERROR + 1`
238 tar) ;;
239 gtar) ;;
240 gzip) ;;
241 dx) ;;
242 esac
243 echo
244 return 1
246 case $1 in
247 icoFoam)
248 VERSION=`$1 2>&1 \
249 | \grep ' Version:' \
250 | sed -e 's/.*Version:/Version:/' \
251 | cut -d" " -f3`
253 gcc)
254 VERSION=`$1 -v 2>&1 \
255 | grep 'gcc version' \
256 | cut -d" " -f3`
257 if [ ! "$VERSION" = "$SUPPLIED_VERSION_GCC" ]; then
258 echo "WARNING: gcc version does not match gcc supplied" \
259 "with this release of OpenFOAM"
260 echo " Supplied version: $SUPPLIED_VERSION_GCC"
261 echo " User version : $VERSION"
262 echo " Minimum required: $MIN_VERSION_GCC"
263 echo ""
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 "${WM_COMPILER_DIR}/bin/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 echo ""
541 if [ $CRITICALERROR -gt 0 ] || [ $FATALERROR -gt 0 ]; then
542 echo "Review the output for warning messages and consult "
543 echo "the installation guide for trouble shooting."
545 echo ""
547 echo "done."
549 echo ""
551 exit 0
553 #------------------------------------------------------------------------------