Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / bin / foamInstallationTest
blob81bc10f6bfe678c03553955fad61d306000d94a9
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration |
6 # \\ / A nd | For copyright notice see file Copyright
7 # \\/ M anipulation |
8 #------------------------------------------------------------------------------
9 # License
10 # This file is part of foam-extend.
12 # foam-extend 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 3 of the License, or (at your
15 # option) any later version.
17 # foam-extend 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 # You should have received a copy of the GNU General Public License
23 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamInstallationTest
28 # Description
29 # Checks the machine system, the installation of foam-extend, and the user's
30 # personal configuration for running foam-extend.
32 #------------------------------------------------------------------------------
34 # Base settings
35 FOAM_VERSION=foam-extend-3.1
36 SUPPLIED_VERSION_GCC=4.3.3
37 MIN_VERSION_GCC=4.3.1
39 # General
40 WIDTH=20
42 # Global variables
43 FATALERROR=0
44 CRITICALERROR=0
45 SSHRSHOK=0
47 # System variables
48 HOST_NAME=`uname -n`
49 OS=`uname -s`
50 USER_NAME=$LOGNAME
51 if [ ! -n $USER_NAME ]; then
52 USER_NAME=$USER
55 #==============================================================================
56 # HELPER FUNCTIONS
57 #==============================================================================
59 hline () {
60 echo "-------------------------------------------------------------------------------"
64 expenv () {
65 eval "echo $1"
69 heading () {
70 echo ""
71 echo ""
72 echo "$1"
76 lenBase () {
77 echo $1 | tr -d " " | wc -m | tr -d " "
81 length () {
82 NOCHAR=`lenBase $1`
83 NOCHAR=`expr $NOCHAR - 1`
84 if [ $NOCHAR -eq -1 ]; then
85 NOCHAR=0
87 echo $NOCHAR
91 stringLength () {
92 echo $1 | wc -m | tr -d " "
96 fixlen () {
97 WORD=$1
98 ONELEN=`stringLength $1`
99 LDIFF=`expr $ONELEN - $2`
100 if [ $LDIFF -le 1 ]; then
101 while [ $LDIFF -lt 0 ] ; do
102 WORD="$WORD "
103 LDIFF=`expr $LDIFF + 1`
104 done
105 echo "$WORD"
106 else
107 LDIFF=`expr $LDIFF + 4`
108 WORD=`echo "$WORD" | cut -c${LDIFF}-`
109 echo "...${WORD}"
114 reportEnv () {
115 EXP_ENV=`eval "echo $1"`
116 EXP_PATH=`eval "echo $2"`
117 CRIT="$3"
118 EXISTS=" no "
119 ON_PATH=""
120 if [ `length $EXP_ENV` -gt 0 ] ; then
121 case $OS in
122 SunOS)
123 if /usr/bin/test -e $EXP_ENV ; then
124 EXISTS=" yes "
125 if [ "$2" != noPath ]; then
126 ON_PATH=" no "
127 OLD_IFS=$IFS
128 IFS=':'
129 for e in $EXP_PATH
131 if \
133 "$e" = "$EXP_ENV" \
134 -o "$e" = "${EXP_ENV}/bin" \
135 -o "${EXP_ENV}/lib" = "$e" \
136 ] ; then
137 ON_PATH="yes "
139 done
140 IFS=$OLD_IFS
141 else
142 CRIT=" $3"
144 else
145 ON_PATH=" "
147 echo "`fixlen "$1" 21` `fixlen "$EXP_ENV" 40` $EXISTS $ON_PATH $CRIT"
150 if [ -e "$EXP_ENV" ] ; then
151 EXISTS=" yes "
152 if [ "$2" != noPath ]; then
153 ON_PATH=" no "
154 OLD_IFS=$IFS
155 IFS=':'
156 for e in $EXP_PATH
158 if \
160 "$e" = "$EXP_ENV" \
161 -o "$e" = "${EXP_ENV}/bin" \
162 -o "${EXP_ENV}/lib" = "$e" \
163 ] ; then
164 ON_PATH="yes "
166 done
167 IFS=$OLD_IFS
168 else
169 CRIT=" $3"
171 else
172 ON_PATH=" "
174 echo "`fixlen "$1" 21` `fixlen "$EXP_ENV" 40` $EXISTS $ON_PATH $CRIT"
176 esac
177 else
178 echo "`fixlen "$1" 21` --------- env variable not set --------- $3"
181 ERROR="false"
182 if [ "$EXISTS" = no ] || [ "$ON_PATH" = no ]; then
183 ERROR="true"
185 if [ "$3" = yes ] && [ "$ERROR" = true ]; then
186 CRITICALERROR=`expr $CRITICALERROR + 1`
187 echo "WARNING: CRITICAL ERROR"
188 echo
194 findExec() {
195 OLD_IFS=$IFS
196 IFS=':'
197 for d in $1
199 case $OS in
200 SunOS)
201 if /usr/bin/test ! -d "$d/$2" -a -x "$d/$2" ; then
202 IFS=$OLD_IFS
203 echo "$d/$2"
204 return 0
208 if [ ! -d "$d/$2" -a -x "$d/$2" ]; then
209 IFS=$OLD_IFS
210 echo "$d/$2"
211 return 0
214 esac
215 done
216 IFS=$OLD_IFS
217 return 1
221 reportExecutable () {
222 APP_PATH=""
223 APP_PATH=`findExec $PATH $1`
224 APP_SPEC="$2"
225 if [ ! -n $APP_PATH ];then
226 echo "`fixlen "$1" 9`" "*** not installed ***"
227 VERSION=""
228 case $1 in
229 icoFoam)
230 echo " CRITICAL ERROR"
231 CRITICALERROR=`expr $CRITICALERROR + 1`
233 gcc)
234 echo " CRITICAL ERROR"
235 CRITICALERROR=`expr $CRITICALERROR + 1`
237 tar) ;;
238 gtar) ;;
239 gzip) ;;
240 dx) ;;
241 esac
242 echo
243 return 1
245 case $1 in
246 icoFoam)
247 VERSION=`$1 2>&1 \
248 | \grep ' Version:' \
249 | sed -e 's/.*Version:/Version:/' \
250 | cut -d" " -f3`
252 gcc)
253 VERSION=`$1 -v 2>&1 \
254 | grep 'gcc version' \
255 | cut -d" " -f3`
256 if [ ! "$VERSION" = "$SUPPLIED_VERSION_GCC" ]; then
257 echo "WARNING: gcc version does not match gcc supplied" \
258 "with this release of foam-extend"
259 echo " Supplied version: $SUPPLIED_VERSION_GCC"
260 echo " User version : $VERSION"
261 echo " Minimum required: $MIN_VERSION_GCC"
262 echo ""
265 gtar)
266 VERSION=`$APP_PATH --version | head -1`
268 tar)
269 VERSION=`$APP_PATH --version | head -1 | cut -d" " -f4`
271 gzip)
272 case $OS in
273 SunOS)
274 VERSION=`$1 --version 2>&1 | grep gzip | cut -d" " -f2`
277 VERSION=`$1 --version | head -1 | cut -d" " -f2`
279 esac
281 esac
282 if [ "$APP_PATH" = "$APP_SPEC" ] || [ ! "$2" ]; then
283 echo "`fixlen "$1" 9` `fixlen "$VERSION" 10` `fixlen "$APP_PATH" 58`"
284 else
285 echo "`fixlen "$1" 9` `fixlen "$VERSION" 10`"
286 echo "WARNING: Conflicting installations:"
287 echo " foam-extend settings : $APP_SPEC"
288 echo " current path : $APP_PATH"
289 case $1 in
290 icoFoam)
291 echo " CRITICAL ERROR"
292 CRITICALERROR=`expr $CRITICALERROR + 1`
294 gcc)
295 echo " CRITICAL ERROR"
296 CRITICALERROR=`expr $CRITICALERROR + 1`
298 gtar) ;;
299 gzip) ;;
300 dx) ;;
301 esac
302 echo ""
307 pingTest () {
308 RESULT=""
309 case $OS in
310 SunOS)
311 PINGTEST=`/usr/sbin/ping $1 2>&1`
312 if [ "`echo $PINGTEST | grep alive`" != "" ] ; then
313 RESULT="Successful"
314 elif [ "`echo $PINGTEST | grep 'unknown host'`" != "" ] ; then
315 RESULT="No_entry_for_\"$1\"_in_/etc/hosts"
316 else
317 RESULT="Networking_cannot_reach_$1"
321 PINGTEST=`/bin/ping -w 3 -c 1 $1 2>&1`
322 if [ "`echo $PINGTEST | grep '1 received'`" != "" ] ; then
323 RESULT="Successful"
324 elif [ "`echo $PINGTEST | grep 'unknown host'`" != "" ] ; then
325 RESULT="No_entry_for_\"$1\"_in_/etc/hosts"
326 else
327 RESULT="Networking_cannot_reach_$1"
330 esac
332 echo "`fixlen "Pinging_$1" 25` `fixlen "$RESULT" 45` `fixlen "$2" 5`"
334 if [ "$2" = yes ] && [ "$RESULT" != Successful ]; then
335 CRITICALERROR=`expr $CRITICALERROR + 1`
336 echo "WARNING: CRITICAL ERROR"
337 echo
342 telnetPortTest () {
343 telnet -e A $1 $2 <<EOF
345 quit
350 checkTelnetPort () {
351 if [ -x "/usr/bin/telnet" ] || [ -x "/bin/telnet" ] ; then
352 RESULT=`telnetPortTest $1 $2 2>&1 | egrep "onnect.* [t|r]"`
353 if [ "`echo $RESULT | grep 'Connected to'`" ] ; then
354 RESULT='Successful'
355 elif [ "`echo $RESULT | grep 'Connection refused'`" ] ; then
356 RESULT='Unsuccessful_connection_refused*'
357 else
358 RESULT="Not_active*"
360 else
361 RESULT='No_telnet_installed:_cannot_check*'
366 checkRsh () {
367 checkTelnetPort $HOST_NAME 222
368 echo "`fixlen "Test_rsh:" 25` `fixlen "$RESULT" 45` "yes""
369 if [ "$RESULT" != Successful ]; then
370 SSHRSHOK=`expr $SSHRSHOK + 1`
375 checkSsh () {
376 checkTelnetPort $HOST_NAME 22
377 echo "`fixlen "Test_ssh:" 25` `fixlen "$RESULT" 45` "yes""
378 if [ "$RESULT" != Successful ]; then
379 SSHRSHOK=`expr $SSHRSHOK + 1`
384 checkFoamEnvironment() {
385 [ -d "$WM_PROJECT_INST_DIR" ] && [ -d "$WM_THIRD_PARTY_DIR" ] || {
386 echo ""
387 echo "FATAL ERROR: foam-extend environment not configured."
388 echo ""
389 echo " Please refer to the installation section of the file:"
390 echo " <foam installation dir>/${FOAM_VERSION}/ReleaseNotes-${FOAM_VERSION}"
391 echo " to source the foam-extend environment."
392 echo ""
393 exit 1
398 checkUserShell() {
399 case $SHELL in
400 */csh | */tcsh)
401 # USER_CONFIG_TYPE="cshrc"
402 echo "`fixlen "Shell:" $WIDTH` ${SHELL##*/}"
404 */bash | */ksh)
405 # USER_CONFIG_TYPE="bashrc"
406 echo "`fixlen "Shell:" $WIDTH` ${SHELL##*/}"
409 # USER_CONFIG_TYPE=""
410 echo "`fixlen "Shell:" $WIDTH` ${SHELL##*/}"
411 echo "FATAL ERROR: Cannot identify the shell you are running."
412 echo " ${FOAM_VERSION} is compatible with "
413 echo " csh, tcsh, ksh and bash."
414 echo
415 FATALERROR=`expr $FATALERROR + 1`;;
416 esac
420 checkHostName() {
421 if [ ! "$HOST_NAME" ]; then
422 echo "`fixlen "Host:" $WIDTH` ${HOST_NAME}"
423 echo "FATAL ERROR: Cannot stat hostname."
424 echo " Contact your system administrator, "
425 echo " ${FOAM_VERSION} needs a valid "
426 echo " hostname to function."
427 echo
428 FATALERROR=`expr $FATALERROR + 1`
429 else
430 echo "`fixlen "Host:" $WIDTH` ${HOST_NAME}"
435 checkOS () {
436 case "$OS" in
437 Linux | LinuxAMD64 | SunOS )
438 echo "`fixlen "OS:" $WIDTH` ${OS} version $(uname -r)"
441 echo "FATAL ERROR: Incompatible operating system \"$OS\"."
442 echo " ${FOAM_VERSION} is currently "
443 echo " available for Linux and SunOS only."
444 echo
445 FATALERROR=`expr $FATALERROR + 1`
447 esac
451 #==============================================================================
452 # MAIN SCRIPT
453 #==============================================================================
455 echo "Executing $0:"
457 #------------------------------------------------------------------------------
458 heading "Checking basic setup..."
459 hline
460 checkFoamEnvironment
461 checkUserShell
462 checkHostName
463 checkOS
464 hline
466 #------------------------------------------------------------------------------
467 heading "Checking main foam-extend env variables..."
468 COL1=`fixlen "Environment_variable" 21`
469 COL2=`fixlen "Set_to_file_or_directory" 40`
470 COL3="Valid"
471 COL4="Path"
472 COL5="Crit"
473 hline
474 echo "$COL1 $COL2 $COL3 $COL5"
475 hline
476 reportEnv '$WM_PROJECT_INST_DIR' 'noPath' "yes"
477 reportEnv '$WM_PROJECT_USER_DIR' 'noPath' "no"
478 reportEnv '$WM_THIRD_PARTY_DIR' 'noPath' "yes"
479 hline
481 #------------------------------------------------------------------------------
482 heading "Checking the foam-extend env variables set on the PATH..."
483 hline
484 echo "$COL1 $COL2 $COL3 $COL4 $COL5"
485 hline
486 reportEnv '$WM_PROJECT_DIR' '$PATH' "yes"
487 echo ""
488 reportEnv '$FOAM_APPBIN' '$PATH' "yes"
489 reportEnv '$FOAM_SITE_APPBIN' '$PATH' "no"
490 reportEnv '$FOAM_USER_APPBIN' '$PATH' "no"
491 reportEnv '$WM_DIR' '$PATH' "yes"
492 hline
494 #------------------------------------------------------------------------------
495 heading "Checking the foam-extend env variables set on the LD_LIBRARY_PATH..."
496 hline
497 echo "$COL1 $COL2 $COL3 $COL4 $COL5"
498 hline
499 reportEnv '$FOAM_LIBBIN' '$LD_LIBRARY_PATH' "yes"
500 reportEnv '$FOAM_SITE_LIBBIN' '$LD_LIBRARY_PATH' "no"
501 reportEnv '$FOAM_USER_LIBBIN' '$LD_LIBRARY_PATH' "no"
502 reportEnv '$MPI_ARCH_PATH' '$LD_LIBRARY_PATH' "yes"
503 hline
505 #------------------------------------------------------------------------------
506 heading "Third party software"
507 COL1=`fixlen "Software" 9`
508 COL2=`fixlen "Version" 10`
509 COL3=`fixlen "Location" 10`
510 hline
511 echo "$COL1 $COL2 $COL3"
512 hline
513 reportExecutable gcc "${WM_COMPILER_DIR}/bin/gcc"
514 reportExecutable gzip
515 if [ "$OS" = Linux ] ; then
516 reportExecutable tar
517 else
518 reportExecutable gtar
520 reportExecutable icoFoam "${FOAM_APPBIN}/icoFoam"
522 hline
524 #------------------------------------------------------------------------------
525 heading "Summary"
526 hline
528 if [ $FATALERROR -gt 0 ] ; then
529 echo "The system test has evoked $FATALERROR fatal error(s)."
530 else
531 echo "Base configuration ok."
533 echo ""
534 if [ $CRITICALERROR -gt 0 ]; then
535 echo "The foam installation contains $CRITICALERROR critical error(s)."
536 else
537 echo "Critical systems ok."
539 echo ""
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 #------------------------------------------------------------------------------