1#! /bin/sh 2 3######################################################################## 4# 5# /u/sonmi/bin/header - /u/svbld/bin/init/nss/header 6# 7# variables, utilities and shellfunctions global to NSS QA 8# needs to work on all Unix platforms 9# 10# included from (don't expect this to be up to date) 11# -------------------------------------------------- 12# qa_stat 13# mksymlinks 14# nssqa 15# 16# parameters 17# ---------- 18# nssversion (supported: 30b, 31, 332, tip 32) 19# builddate (default - today) 20# 21# options 22# ------- 23# -y answer all questions with y - use at your own risk... ignores warnings 24# -s silent (only usefull with -y) 25# -h, -? - you guessed right - displays this text 26# -d debug 27# -f <filename> - write the (error)output to filename 28# -fcronfile produces the resultfiles in the same locations 29# as would have been produced with -cron 30# -m <mailinglist> - send filename to mailinglist (csl) only useful 31# with -f 32# -ml <mailinglist> - send link to filename to mailinglist (csl) 33# only useful with -f 34# -cron equivalient to -y -s -d -f $RESULTDIR/$HOST.<scriptname> 35# -t run on a tinderbox build that means: local, from the startlocation 36# -l <mozroot directory> run on a local build mozroot 37# -ln <mozroot> copy a networkbuild to a local directory mozroot, 38# used for networkindipendend QA 39# -lt try to copy a networkbuild to a local directory, if not possible 40# run on the network 41# used for networkindipendend QA 42# 43# special strings 44# --------------- 45# FIXME ... known problems, search for this string 46# NOTE .... unexpected behavior 47# 48# moduls (not yet) 49# ---------------- 50# --# INIT 51# --# USERCOM 52# --# UTILS 53# 54# FIXME - split in init / usercom / utils 55# 56######################################################################## 57 58#------------------------------# INIT #------------------------------ 59 60# below the option flags get initialized 61 62if [ -z "$QASCRIPT_DIR" ] 63then 64 QASCRIPT_DIR=`dirname $0` 65 if [ "$QASCRIPT_DIR" = '.' ] 66 then 67 QASCRIPT_DIR=`pwd` 68 fi 69fi 70export QASCRIPT_DIR 71 72O_HWACC=OFF 73if [ -z "$O_ALWAYS_YES" ] ; then 74 O_ALWAYS_YES=OFF # turned on by -y answer all questions with y 75fi 76 77if [ -z "$O_INIT" ] # header is global, some including scripts may not 78then # want the init to run, the others don't need to bother 79 O_INIT=ON 80fi 81if [ -z "$O_PARAM" ] # header is global, some including scripts may not 82then # require parameters, the others don't need to bother 83 O_PARAM=ON 84fi 85if [ -z "$O_OPTIONS" ] # header is global, some including scripts may not 86then # permit options, they don't need to bother 87 O_OPTIONS=OFF 88fi 89O_SILENT=OFF # turned on by -s silent (only usefull with -y) 90if [ -z "$O_DEBUG" ] ; then 91 O_DEBUG=OFF # turned on by -d - calls to Debug produce output when ON 92fi 93O_FILE=OFF # turned on by -f echo all output to a file $FILENAME 94O_CRON=OFF # turned on by -cron cron use only 95O_CRONFILE=OFF # turned on by -cron cron and -fcron 96O_LOCAL=OFF # turned on by -l* run on a local build in $LOCAL_MOZROOT 97O_LN=OFF # turned on by -ln and -lt, test a networkbuild locally 98O_MAIL=OFF # turned on by -m - sends email 99O_MAIL_LINK=OFF # turned on by -ml - sends email 100O_TBX=OFF # turned on by -t run on a tinderbox build 101 # that means: local, from the startlocation 102 103if [ -z "$DOMSUF" ] 104then 105 106 DOMSUF=red.iplanet.com 107 DS_WAS_SET=FALSE 108else 109 DS_WAS_SET=TRUE 110fi 111 112TMPFILES="" 113 114WAIT_FOR=600 # if waiting for an event sleep n seconds before rechecking 115 # recomended value 10 minutes 600 116WAIT_TIMES=30 # recheck n times before giving up - recomended 30 - total of 5h 117 118if [ -z "$QAYEAR" ] # may I introduce - the y2k+1 bug? QA for last year 119then # might not work 120 QAYEAR=`date +%Y` 121fi 122 123if [ -z "$TMP" ] 124then 125 if [ -z "$TEMP" ] 126 then 127 TMP="/tmp" 128 else 129 TMP=$TEMP 130 fi 131fi 132if [ ! -w "$TMP" ] 133then 134 echo "Can't write to tmp directory $TMP - exiting" 135 echo "Can't write to tmp directory $TMP - exiting" >&2 136 exit 1 137fi 138 139KILLPIDS="$TMP/killpids.$$" 140export KILLERPIDS 141TMPFILES="$TMPFILES $KILLPIDS" 142 143KILL_SELFSERV=OFF # if sourcing script sets this to on cleanup will also 144 # kill the running selfserv processes 145 146 # Set the masterbuilds 147if [ -z "$UX_MASTERBUILD" ] 148then 149 UX_MASTERBUILD=booboo_Solaris8 150 #if [ ! -d $UX_MASTERBUILD ] ; then 151 #UX_MASTERBUILD=booboo_Solaris8_forte6 152 #fi 153 UX_MB_WAS_SET=FALSE 154else 155 UX_MB_WAS_SET=TRUE 156fi 157if [ -z "$NT_MASTERBUILD" ] 158then 159 NT_MASTERBUILD=blowfish_NT4.0_Win95 160 NT_MB_WAS_SET=FALSE # in this case later functions can override if 161 # they find a different build that looks like NT 162else 163 NT_MB_WAS_SET=TRUE 164fi 165if [ -z "$MASTERBUILD" ] 166then 167 MASTERBUILD=$UX_MASTERBUILD 168fi 169 170 # Set the default build 171if [ -z "$BUILDNUMBER" ] 172then 173 BUILDNUMBER=1 174fi 175export BUILDNUMBER 176O_LDIR=OFF #local QA dir for NT, temporary 177 178if [ -z "$WIN_WAIT_FOREVER" ] # header is global, some including scripts 179then # want the init to wait forever for directories to 180 # appear (windows only) if OFF exit, if ON wait forever 181 WIN_WAIT_FOREVER=OFF 182fi 183 184 # NOTE: following variables have to change 185 # from release to release 186if [ -z "$BC_MASTER" ] # master directory for backwardscompatibility testing 187then 188 RH="NO" 189 grep 7.1 /etc/redhat-release > /dev/null 2>/dev/null && RH="YES" 190 grep 7.2 /etc/redhat-release > /dev/null 2>/dev/null && RH="YES" 191 192 if [ "$RH" = "YES" ] 193 then # NSS-3-3-1RTM 194 BC_UX_MASTER=nss331/builds/20010928.2.331-RTM/booboo_Solaris8 195 BC_NT_MASTER=nss331/builds/20010928.2.331-RTM/blowfish_NT4.0_Win95 196 else # NSS-3-2-2RTM 197 BC_UX_MASTER=nss322/builds/20010820.1/y2sun2_Solaris8 198 BC_NT_MASTER=nss322/builds/20010820.1/blowfish_NT4.0_Win95 199 fi 200 BC_MASTER=$BC_UX_MASTER 201 BC_MASTER_WAS_SET=FALSE 202else 203 BC_MASTER_WAS_SET=TRUE 204fi 205BC_RELEASE=3.2 206export BC_RELEASE 207 208EARLY_EXIT=TRUE #before the report file has been created, causes Exit to 209 #create it 210 211UX_D0=/share/builds/mccrel3/nss 212 213################################### glob_init ########################## 214# global shell function, main initialisation function 215######################################################################## 216glob_init() 217{ 218 if [ $O_PARAM = "ON" ] ; then 219 eval_opts $* # parse parameters and options - set flags 220 fi 221 # if running from cron HOST needs to be known early, 222 init_host # so the output file name can be constructed. 223 Debug "Setting up environment...( $QASCRIPT_DIR/set_environment) " 224 . $QASCRIPT_DIR/set_environment #finds out if we are running on Windows 225 Debug "OPerating system: $os_name $os_full" 226 umask 0 227 init_dirs 228 init_files 229 init_vars 230} 231 232################################### init_vars ########################### 233# global shell function, sets the environment variables, part of init 234######################################################################## 235init_vars() 236{ 237 if [ -z "$LOGNAME" ] 238 then 239 if [ $O_WIN = "ON" ] 240 then 241 LOGNAME=$USERNAME 242 else 243 LOGNAME=$USER 244 fi 245 if [ -z "$LOGNAME" ] 246 then 247 LOGNAME=$UNAME 248 if [ -z "$LOGNAME" ] 249 then 250 LOGNAME=`basename $HOME` 251 fi 252 fi 253 fi 254 if [ -z "$LOGNAME" ] 255 then 256 Exit "Can't determine current user" 257 fi 258 case $HOST in 259 iws-perf) 260 O_HWACC=ON 261 HWACC_LIST="rainbow ncipher" 262 #MODUTIL="-add rainbow -libfile /usr/lib/libcryptoki22.so" 263 export HWACC_LIST 264 ;; 265 *) 266 O_HWACC=OFF 267 ;; 268 esac 269 export O_HWACC 270} 271 272######################################################################## 273# functions below deal with setting up the directories and PATHs for 274# all different flavors of OS (Unix, Linux, NT MKS, NT Cygnus) and QA 275# (Standard, local tinderbox) 276######################################################################## 277 278########################## find_nt_masterbuild ######################### 279# global shell function, sets the nt masterbuild directories, part of init 280######################################################################## 281find_nt_masterbuild() 282{ 283 NT_MASTERDIR=${DAILY_BUILD}/${NT_MASTERBUILD} 284 if [ "${NT_MB_WAS_SET}" = "FALSE" -a ! -d $NT_MASTERDIR ] ; then 285 if [ -d ${DAILY_BUILD}/*NT4* ] ; then 286 NT_MASTERBUILD=` cd ${DAILY_BUILD}; ls -d *NT4* ` 287 Debug "NT_MASTERBUILD $NT_MASTERBUILD" 288 NT_MASTERDIR=${DAILY_BUILD}/${NT_MASTERBUILD} 289 fi 290 fi 291 Debug "NT_MASTERDIR $NT_MASTERDIR" 292} 293 294################################### set_daily_build_dirs ########################### 295# global shell function, sets directories 296######################################################################## 297set_daily_build_dirs() 298{ 299 if [ "$O_LOCAL" = "ON" -a "$O_LN" = "OFF" ] ; then 300 DAILY_BUILD=${LOCAL_MOZROOT} # on local builds NSS_VER_DIR and DAILY_BUILD are 301 # set to the LOCAL_MOZROOT, since it is not sure 302 # if ../.. (DAILY_BUILD) even exists 303 LOCALDIST=${LOCAL_MOZROOT}/dist 304 elif [ "$O_TBX" = "ON" ] ; then 305 DAILY_BUILD="$TBX_DAILY_BUILD" 306 LOCALDIST=${UXDIST} 307 else 308 DAILY_BUILD=${NSS_VER_DIR}/builds/${QAYEAR}${BUILDDATE}.${BUILDNUMBER} 309 LOCALDIST=${DAILY_BUILD}/${MASTERBUILD}/mozilla/dist 310 fi 311} 312 313map_os64() 314{ 315 IS_64="" 316 case `uname -s` in 317 #OSF1) has been done already - always 64 bit 318 SunOS) 319 MAPPED_OS=Solaris*8 320 IS_64=`(isainfo -v | grep 64)>/dev/null 2>/dev/null && echo 64 bit` 321 if [ "$O_TBX" = "OFF" ] ; then 322 set_osdir 323 if [ -n "$IS_64" ] 324 then #Wait for the 64 bit build to finish... 325 Debug Testing build for $MAPPED_OS in $OSDIR 326 Wait ${OSDIR}/SVbuild.InProgress.1 0 327 fi 328 fi 329 ;; 330 AIX) 331 IS_64=`lslpp -l | grep "bos.64bit"> /dev/null && echo 64 bit` 332 ;; 333 HP-UX) 334 IS_64=`getconf KERNEL_BITS | grep 64 >/dev/null && echo 64 bit` 335 ;; 336 esac 337 Debug "Mapped OS to $MAPPED_OS" 338} 339 340 341 342################################### copy_to_local ######################## 343# global shell function, copies the necessary directories from the 344# daily build aerea to the local disk 345######################################################################## 346copy_to_local() 347{ 348 Debug "Copy network directories to local directories" 349 C2L_ERROR=0 350 if [ ! -d ${LOCAL_MOZROOT}/dist ] ; then 351 mkdir -p ${LOCAL_MOZROOT}/dist || C2L_ERROR=1 352 fi 353 if [ ! -d ${LOCAL_MOZROOT}/security/nss ] ; then 354 mkdir -p ${LOCAL_MOZROOT}/security/nss || C2L_ERROR=2 355 fi 356 if [ $C2L_ERROR != 0 ] ; then 357 Exit "copy_to_local: Can t make necesssary directories ($C2L_ERROR ) " 358 fi 359 if [ ! -d ${LOCAL_MOZROOT}/security/nss/tests ] ; then 360 cp -r ${TESTSCRIPTDIR} ${LOCAL_MOZROOT}/security/nss || C2L_ERROR=1 361 fi 362 if [ ! -d ${LOCAL_MOZROOT}/security/coreconf ] ; then 363 cp -r ${MOZILLA_ROOT}/security/coreconf ${LOCAL_MOZROOT}/security || C2L_ERROR=2 364 fi 365 366 NO_DIRS=0; 367 if [ "$O_WIN" = "ON" ] ; then 368 OS_TARGET=WINNT;export OS_TARGET 369 fi 370 unset BUILD_OPT;export BUILD_OPT; 371 unset USE_64;export USE_64; 372#FIXME only tested on 64 bit Solaris and only got 32 bit builds 373 while [ $NO_DIRS -lt 4 ] ; do 374 # first time thru: Debug 32 bit NT 375 set_objdir 376 Debug "Copying ${OBJDIR}..." 377 if [ ! -d ${LOCAL_MOZROOT}/dist/${OBJDIR} ] ; then 378 cp -r ${LOCALDIST}/${OBJDIR} ${LOCAL_MOZROOT}/dist || C2L_ERROR=3 379 fi 380 NO_DIRS=`expr $NO_DIRS + 1` 381 if [ $NO_DIRS = 1 ] ; then # 2nd time: OPT 32 bit NT 382 BUILD_OPT=1; export BUILD_OPT; 383 elif [ $NO_DIRS = 2 ] ; then # 3rd time: OPT, either 64 bit or Win95 or force exit 384 if [ "$O_WIN" = "ON" ] ; then 385 OS_TARGET=WIN95;export OS_TARGET 386 else 387 map_os64 388 if [ -z "$IS_64" ] ; then #32 bit platform 389 NO_DIRS=4 390 else 391 USE_64=1; export USE_64 392 fi 393 fi 394 elif [ $NO_DIRS = 3 ] ; then # 4th time: Debug either 64 bit or Win95 395 unset BUILD_OPT;export BUILD_OPT; 396 fi 397 398 399 done 400 if [ $C2L_ERROR != 0 ] ; then 401 Exit "copy_to_local: Can t copy necesssary directories ($C2L_ERROR ) " 402 fi 403 unset TESTSCRIPTDIR 404 unset TESTDIR 405 unset RESULTDIR 406 O_LN=OFF #from here on pretend it is regular -l local QA FIXME, might cause 407 #problems with the backwardcompatibility tests 408 Debug "Successfully copied network directories to local directories" 409} 410 411################################### local_dirs ########################### 412# global shell function, sets the directories for local QA 413######################################################################## 414local_dirs() 415{ 416 Debug "Set directories for local QA" 417 #if [ "$O_WIN" = "ON" ] ; then 418 #win_set_tmp 419 #fi 420 NSS_VER_DIR=${LOCAL_MOZROOT} # on local builds NSS_VER_DIR and DAILY_BUILD are 421 # set to the LOCAL_MOZROOT, since it is not sure 422 # if ../../../.. (NSS_VER_DIR) even exists 423 if [ -z "${RESULTDIR}" ] ; then # needs to be local as well 424 Debug "Setting RESULTDIR for local QA" 425 RESULTDIR="${LOCAL_MOZROOT}/tests_results/security/${HOST}-`date +%Y%m%d-%H.%M`" 426 fi 427 set_daily_build_dirs 428 UX_MASTERDIR=`dirname ${LOCAL_MOZROOT}` 429 NT_MASTERDIR=$UX_MASTERDIR 430 MOZILLA_ROOT=${LOCAL_MOZROOT} 431 432 UXDIST=${MOZILLA_ROOT}/dist 433 NTDIST=${UXDIST} 434 435 if [ -z "${TESTDIR}" ] ; then 436 Debug "Setting TESTDIR for local QA" 437 TESTDIR=${RESULTDIR} 438 fi 439 if [ -n "$TESTDIR" ] ; then 440 if [ ! -d $TESTDIR ] ; then 441 Debug "Making TESTDIR for local QA" 442 mkdir -p $TESTDIR 443 fi 444 fi 445 export TESTDIR 446 Debug "RESULTDIR $RESULTDIR TESTDIR $TESTDIR" 447 448 TESTSCRIPTDIR=${LOCAL_MOZROOT}/security/nss/tests 449 COMMON=${TESTSCRIPTDIR}/common 450 451 set_objdir 452 debug_dirs 453 export_dirs 454} 455 456 457################################### tbx_dirs ########################### 458# global shell function, sets the directories for tinderbox QA 459######################################################################## 460tbx_dirs() 461{ 462 Debug "Set directories for tinderbox" 463 if [ "$O_WIN" = "ON" ] ; then 464 win_set_d1 # we need the NSS_VER_DIR later 465 else 466 NSS_VER_DIR="$UX_D0"/nss$NSSVER 467 fi 468 if [ -z "${RESULTDIR}" ] ; then # needs to be different for tinderbox 469 Debug "Setting RESULTDIR for tinderbox" 470 TBX_NOBITS="" 471 echo $QASCRIPT_DIR | grep 64 >/dev/null && TBX_NOBITS=64 472 TRD="${HOST}${TBX_NOBITS}-`date +%Y%m%d-%H.%M`" 473 RESULTDIR="${NSS_VER_DIR}/tinderbox/tests_results/security/${TRD}" 474 if [ ${DOMSUF} = "mcom.com" -o ${DOMSUF} = "netscape.com" -o ${DOMSUF} = "nscp.aoltw.net" ] ; then 475 URL="sbs-rel.nscp.aoltw.net" 476 else 477 URL="cindercone.red.iplanet.com" 478 fi 479 if [ "$O_WIN" = "ON" ] ; then 480 RESULTDIRURL="<a title=\"QA Results\" href=\"http://${URL}${UX_D0}/nsstip/tinderbox/tests_results/security/${TRD}\">QA</a>" 481 else 482 RESULTDIRURL="<a title=\"QA Results\" href=\"http://${URL}${RESULTDIR}\">QA</a>" 483 fi 484 Debug "RESULTDIRURL TinderboxPrint:$RESULTDIRURL" 485 fi 486 TBX_DAILY_BUILD=`cd ../../../../..;pwd` 487 NSS_VER_DIR="${TBX_DAILY_BUILD}/../.." 488 TBX_LOGFILE_DIR=`ls ${NSS_VER_DIR}/logs/tinderbox | sed -e 's/ .*//g'` 489 if [ -z "$TBX_LOGFILE_DIR" ] ; then 490 TBX_LOGFILE_DIR=`ls ${NSS_VER_DIR}/logs/tbx | sed -e 's/ .*//g'` 491 TBX_LOGFILE_DIR="${NSS_VER_DIR}/logs/tbx/${TBX_LOGFILE_DIR}" 492 else 493 TBX_LOGFILE_DIR="${NSS_VER_DIR}/logs/tinderbox/${TBX_LOGFILE_DIR}" 494 fi 495 Debug "Set TBX_LOGFILE_DIR ${TBX_LOGFILE_DIR}" 496 497 set_daily_build_dirs 498 UX_MASTERDIR=`cd ../../../..;pwd` 499 NT_MASTERDIR=$UX_MASTERDIR 500 MOZILLA_ROOT=$UX_MASTERDIR/mozilla 501 502 UXDIST=${MOZILLA_ROOT}/dist 503 NTDIST=${UXDIST} 504 505 if [ -z "${TESTDIR}" ] ; then 506 Debug "Setting TESTDIR for tinderbox" 507 TESTDIR=${RESULTDIR} 508 fi 509 if [ -n "$TESTDIR" ] ; then 510 if [ ! -d $TESTDIR ] ; then 511 Debug "Making TESTDIR for tinderbox" 512 mkdir -p $TESTDIR 513 fi 514 fi 515 Debug "Making QAstatus file" 516 echo "QA running" >${TESTDIR}/QAstatus 517 export TESTDIR 518 Debug "RESULTDIR $RESULTDIR TESTDIR $TESTDIR" 519 520 TESTSCRIPTDIR=`pwd` 521 COMMON=${TESTSCRIPTDIR}/common 522 523 set_objdir 524 debug_dirs 525 export_dirs 526} 527 528################################### init_mcom ########################### 529# global shell function, sets domain specific variables for AOL's 530# domains according to Bishakha's instructions 531######################################################################## 532init_mcom() 533{ 534 Debug "Running in mcom or netscape domain - changing directories..." 535 if [ "${UX_MB_WAS_SET}" = "FALSE" ] ; then #in case it was set 536 # before script was called use these values 537 UX_MASTERBUILD=spd04_Solaris8 538 fi 539 if [ "${NT_MB_WAS_SET}" = "FALSE" ] ; then 540 NT_MASTERBUILD=spd06_NT4 541 fi 542 543 MASTERBUILD=$UX_MASTERBUILD 544 if [ "${BC_MASTER_WAS_SET}" = "FALSE" ] ; then 545 BC_UX_MASTER=nss322/builds/20010820.1/y2sun2_Solaris8 546 BC_NT_MASTER=nss322/builds/20010820.1/blowfish_NT4.0_Win95 547 BC_MASTER=$BC_UX_MASTER 548 fi 549 UX_D0=/share/builds/sbsrel2/nss 550 URL="sbs-rel.nscp.aoltw.net" 551} 552################################### init_dirs ########################### 553# global shell function, sets the directories for standard QA 554# calls special functions for tinderbox, windows or local QA, part of init 555######################################################################## 556init_dirs() 557{ 558 if [ ${DOMSUF} = "mcom.com" -o ${DOMSUF} = "netscape.com" -o ${DOMSUF} = "nscp.aoltw.net" ] ; then 559 init_mcom 560 fi 561 if [ $O_WIN = "ON" ] ; then 562 win_set_tmp 563 write_to_tmpfile 564 MASTERBUILD=$NT_MASTERBUILD 565 BC_MASTER=$BC_NT_MASTER 566 fi 567 if [ "$O_LOCAL" = "ON" -a $O_LN = "OFF" ] ; then # if it is a LN we need to know 568 # all the directories off the network first to copy them 569 local_dirs # O_LOCAL alone assumes that all the directories are already there 570 return 571 elif [ "$O_TBX" = "ON" ] ; then 572 tbx_dirs 573 return 574 elif [ "$O_WIN" = "ON" ] ; then 575 win_set_d1 576 else 577 NSS_VER_DIR="$UX_D0"/nss$NSSVER 578 fi 579 #set -x 580 581 set_daily_build_dirs 582 583 if [ -z "${BCDIST}" ] ; then 584 #BCDIST=/share/builds/mccrel3/nss/${BC_MASTER}/mozilla/dist 585 BCDIST=${NSS_VER_DIR}/../${BC_MASTER}/mozilla/dist 586 if [ ! -d $BCDIST -a `basename $0` != jssqa ] ; then 587 ask "Backward compatibility directory $BCDIST does not exist, continue" "y" "n" || Exit 588 fi 589 fi 590 591 UX_MASTERDIR=${DAILY_BUILD}/${UX_MASTERBUILD} 592 find_nt_masterbuild 593 594 if [ "$O_WIN" = "ON" ] 595 then 596 MOZILLA_ROOT=${NT_MASTERDIR}/mozilla 597 else 598 MOZILLA_ROOT=${UX_MASTERDIR}/mozilla 599 fi 600 601 UXDIST=${UX_MASTERDIR}/mozilla/dist 602 NTDIST=${NT_MASTERDIR}/mozilla/dist 603 604 if [ -z "${RESULTDIR}" ] ; then 605 RESULTDIR=${UX_MASTERDIR}/mozilla/tests_results/security 606 fi 607 608 if [ -n "$PRODUCT_TO_TEST" -a "$PRODUCT_TO_TEST" = "JSS" ] ; then 609 610 if [ "$O_WIN" = "ON" ] ; then 611 JSS_NSS_SRC_DIR=$JSS_NSS_NT_SRC_DIR 612 fi 613 TESTSCRIPTDIR=${NSS_VER_DIR}/../${JSS_NSS_SRC_DIR}/mozilla/security/nss/tests 614 else 615 TESTSCRIPTDIR=${MOZILLA_ROOT}/security/nss/tests 616 fi 617 618 if [ ! -d $TESTSCRIPTDIR -a `basename $0` != jssqa ] ; then 619 if [ "$O_WIN" = "ON" -a "$WIN_WAIT_FOREVER" = "ON" ] 620 then 621 WaitForever $TESTSCRIPTDIR/all.sh 1 622 else 623 Exit "Test directory $TESTSCRIPTDIR does not exist" 624 fi 625 fi 626 627 COMMON=${TESTSCRIPTDIR}/common 628 if [ "$O_LOCAL" = "ON" -a $O_LN = "ON" ] ; then # if it is a LN we need to know 629 # all the directories off the network first to copy them 630 copy_to_local 631 local_dirs 632 fi 633 #set +x 634 635 636 set_objdir 637 debug_dirs 638 export_dirs 639} 640 641debug_dirs() 642{ 643 Debug "NTDIST $NTDIST" 644 Debug "UXDIST $UXDIST" 645 Debug "TESTSCRIPTDIR $TESTSCRIPTDIR" 646 Debug "RESULTDIR $RESULTDIR" 647 Debug "TMP $TMP" 648 Debug "LOCALDIST_BIN $LOCALDIST_BIN" 649 Debug "COMMON $COMMON" 650 Debug "MOZILLA_ROOT $MOZILLA_ROOT" 651 Debug "BCDIST $BCDIST" 652} 653 654export_dirs() 655{ 656 export NSS_VER_DIR DAILY_BUILD NTDIST UXDIST RESULTDIR TESTSCRIPTDIR BCDIST 657 export UX_MASTERDIR NT_MASTERDIR COMMON MOZILLA_ROOT 658} 659 660set_osdir() 661{ 662 OSDIR=${DAILY_BUILD}/*${MAPPED_OS}* 663} 664 665################################### init_files ########################### 666# global shell function, sets filenames, initializes files, part of init 667######################################################################## 668init_files() 669{ 670 if [ $O_CRONFILE = "ON" ] 671 then 672 Debug "attempting to create resultfiles" 673 if [ "$O_TBX" = "ON" ] ; then 674 NEWFILENAME=${TBX_LOGFILE_DIR}/qa.log 675 if [ ! -w ${TBX_LOGFILE_DIR} ] ; then 676 Exit "can't touch $NEWFILENAME" 677 fi 678 else 679 NEWFILENAME=$RESULTDIR/$HOST.`basename $0` 680 fi 681 if [ ! -d $RESULTDIR ] 682 then 683 mkdir -p $RESULTDIR || Exit "Error: can't make $RESULTDIR" 684 fi 685 if [ ! -w $RESULTDIR ] ; then 686 Exit "can't touch $NEWFILENAME" 687 fi 688 Debug "About to touch $NEWFILENAME " 689 touch $NEWFILENAME || Exit "Error: can't touch $NEWFILENAME" 690 if [ "$O_TBX" = "ON" ] ; then 691 echo "QA results in $RESULTDIR" >>$NEWFILENAME || Exit "Error: can't write to $NEWFILENAME" 692 fi 693 Debug "About to cat $FILENAME >>$NEWFILENAME " 694 cat $FILENAME >>$NEWFILENAME || Exit "Error: can't append $FILENAME to $NEWFILENAME" 695 TMPFILES="$TMPFILES $FILENAME" 696 FILENAME=$NEWFILENAME 697 Debug "Writing output to $FILENAME" 698 fi 699 700} 701 702################################### write_to_tmpfile ########################## 703# global shell function, for NT and cron operation, first a tmpfile 704# needs to be created 705######################################################################## 706write_to_tmpfile() 707{ 708 O_CRONFILE=ON 709 O_FILE=ON 710 FILENAME=${TMP}/nsstmp.$$ # for now write to the temporary file 711 # since we don't know the hostname yet 712 # will be inserted to the real file later 713 TMPFILES="$TMPFILES nsstmp.$$" 714 touch $FILENAME || Exit "Error: can't touch $FILENAME" 715 Debug "Writing output to $FILENAME" 716} 717 718############################# turn_on_cronoptions ###################### 719# global shell function, turns on options needed for cron and tinderbox 720######################################################################## 721turn_on_cronoptions() 722{ 723 O_CRON=ON 724 O_SILENT=ON 725 O_DEBUG=ON # FIXME take out! 726 O_ALWAYS_YES=ON 727 write_to_tmpfile 728} 729 730########################## test_mozroot ########################## 731# global shell function, determines if the variable LOCAL_MOZROOT is set, 732# and is usable as mozilla root diretory for a local QA 733################################################################### 734test_mozroot() 735{ 736 PWD=`pwd` 737 Debug "LOCAL_MOZROOT = $LOCAL_MOZROOT" 738 case "$LOCAL_MOZROOT" in 739 [0-9-]*|tip) 740 glob_usage "Error: -"$1" requires a directoryname to follow (start with a letter) " 741 ;; 742 \.\.) 743 LOCAL_MOZROOT=`dirname $PWD` 744 ;; 745 \.) 746 LOCAL_MOZROOT=$PWD 747 ;; 748 \.\/*) 749 LOCAL_MOZROOT=`echo $LOCAL_MOZROOT | sed -e "s/^\.//"` 750 LOCAL_MOZROOT="${PWD}${LOCAL_MOZROOT}" 751 ;; 752 \.\.\/*) 753 LOCAL_MOZROOT="${PWD}/${LOCAL_MOZROOT}" 754 ;; 755 \/*|[a-zA-Z]:\/*) 756 ;; 757 ?*) 758 LOCAL_MOZROOT="${PWD}/${LOCAL_MOZROOT}" 759 ;; 760 *) 761 glob_usage "Error: -"$1" requires a directoryname to follow" 762 ;; 763 esac 764 Debug "Reformated MOZROOT to $LOCAL_MOZROOT" 765 if [ "$1" = "ln" ] ; then 766 LOCAL_MOZROOT_PARENT=`dirname $LOCAL_MOZROOT` 767 if [ ! -d $LOCAL_MOZROOT_PARENT -o ! -w $LOCAL_MOZROOT_PARENT -o \ 768 ! -x $LOCAL_MOZROOT_PARENT ] ; then 769 Exit "Error: Can't create $LOCAL_MOZROOT (permissions)" 770 fi 771 if [ ! -d "$LOCAL_MOZROOT" ] ; then 772 mkdir $LOCAL_MOZROOT || 773 Exit "Error: Can't create mozroot $LOCAL_MOZROOT (mkdir failed)" 774 else 775 ask "mozroot $LOCAL_MOZROOT exists - continue (y will remove dir) ?" \ 776 "y" "n" || Exit 777 rm -rf $LOCAL_MOZROOT/dist $LOCAL_MOZROOT/security $LOCAL_MOZROOT/tests_results || 778 Exit "Error: Can't clean mozroot $LOCAL_MOZROOT" 779 fi 780 fi 781 if [ ! -d "$LOCAL_MOZROOT" ] ; then 782 glob_usage "Error: mozilla root $LOCAL_MOZROOT not a valid directory" 783 fi 784} 785 786################################### eval_opts ########################## 787# global shell function, evapuates options and parameters, sets flags 788# variables and defaults 789######################################################################## 790eval_opts() 791{ 792 while [ -n "$1" ] 793 do 794 case $1 in 795 -cron) 796 turn_on_cronoptions 797 ;; 798 -T*|-t*) 799 O_TBX=ON 800 turn_on_cronoptions 801 O_SILENT=OFF #FIXME debug only 802 ;; 803 -S*|-s*) 804 O_SILENT=ON 805 ;; 806 -Y*|-y) 807 Debug "Option -y dedectet" 808 O_ALWAYS_YES=ON 809 ;; 810 -d*|-D) 811 O_DEBUG=ON 812 #set -x 813 ;; 814 -ml|-ML) 815 O_MAIL_LINK=ON 816 shift 817 MAILINGLIST=$1 818 if [ -z "$MAILINGLIST" ] 819 then 820 glob_usage "Error: -m requires a mailinglist to follow, for example sonmi,wtc,nelsonb " 821 fi 822 Debug "Sending link to result to $MAILINGLIST" 823 ;; 824 -m|-M) 825 O_MAIL=ON 826 shift 827 MAILINGLIST=$1 828 if [ -z "$MAILINGLIST" ] 829 then 830 glob_usage "Error: -m requires a mailinglist to follow, for example sonmi,wtc,nelsonb " 831 fi 832 Debug "Sending result to $MAILINGLIST" 833 ;; 834 -fcron*|-F[Cc][Rr][Oo][Nn]*) 835 write_to_tmpfile 836 ;; 837 -f|-F) 838 O_FILE=ON 839 shift 840 FILENAME=$1 841 if [ -z "$FILENAME" ] 842 then 843 glob_usage "Error: -f requires a filename to follow" 844 fi 845 #rm -f $FILENAME 2>/dev/null 846 touch $FILENAME || Exit "Error: can't touch $FILENAME" 847 #NOTE we append rather that creating 848 Debug "Writing output to $FILENAME" 849 ;; 850 -h|-help|"-?") 851 glob_usage 852 ;; 853 -ln) 854 if [ `basename $0` != nssqa ] ; then 855 glob_usage "Error: Can't handle option $1" 856 fi 857 O_LOCAL=ON 858 O_LN=ON 859 shift 860 LOCAL_MOZROOT=$1 861 test_mozroot ln 862 ;; 863 -lt) 864 if [ `basename $0` != nssqa ] ; then 865 glob_usage "Error: Can't handle option $1" 866 fi 867 O_LN=ON 868 O_LOCAL=ON 869 ;; 870 -l) 871 if [ `basename $0` != nssqa ] ; then 872 glob_usage "Error: Can't handle option $1" 873 fi 874 O_LOCAL=ON 875 shift 876 LOCAL_MOZROOT=$1 877 test_mozroot l 878 ;; 879 -p) 880 shift 881 PORT=$1 882 export PORT 883 ;; 884 -*) 885 glob_usage "Error: Can't handle option $1" 886 ;; 887 tip|3.|3..) 888 NSSVER=$1 889 if [ -z "$NSSVER" ] ; then 890 glob_usage "Error: illegal parameter" 891 fi 892 ;; 893 [01][0-9][0123][0-9]) 894 BUILDDATE=$1 895 if [ -z "$BUILDDATE" ] ; then 896 glob_usage "Error: illegal parameter" 897 fi 898 ;; 899 ?*) 900 glob_usage "Error: Can't handle parameter $1" 901 ;; 902 esac 903 shift 904 done 905 906 if [ -z "$PORT" -a "$O_TBX" = "ON" ] ; then 907 PORT=8444 908 export PORT 909 if [ -z "$NSSVER" ] ; then 910 NSSVER="tip" 911 Debug "NSS Version: Parameters missing - defaulting to tip!" 912 fi 913 elif [ -z "$NSSVER" ] ; then 914 NSSVER="tip" 915 Debug "NSS Version: Parameters missing - defaulting to tip!" 916 fi 917 if [ -z "$BUILDDATE" ] ; then 918 BUILDDATE=`date +%m%d` 919 Debug "Builddate: Parameters missing - defaulting to today!" 920 fi 921 922 Debug "Builddate $BUILDDATE NssVersion $NSSVER" 923 export BUILDDATE NSSVER 924 export O_CRON O_SILENT O_DEBUG O_ALWAYS_YES O_TBX 925} 926 927win_set_tmp() 928{ 929 TMP=`echo "$TMP" | sed -e 's/ /\/t/g' -e 's//\/b/' -e 's/\\\/\//g'` 930 Debug "TMP reformated to $TMP" 931} 932 933######################### win_set_d1 ################################ 934# global shell function, interactively finds the directories in case 935# windows can't get to the default 936######################################################################## 937win_set_d1() 938{ 939 Debug "set Windows Directories..." 940 #win_set_tmp 941 if [ "$O_CYGNUS" = ON ] 942 then 943 NSS_VER_DIR=/cygdrive/w/nss/nss$NSSVER 944 else 945 NSS_VER_DIR=w:/nss/nss$NSSVER 946 fi 947 if [ ! -w $NSS_VER_DIR ] 948 then 949 Echo "Windows special... can't write in $NSS_VER_DIR" 950 if [ "$O_CYGNUS" = ON ] 951 then 952 NSS_VER_DIR=/cygdrive/u/nss/nss$NSSVER 953 else 954 NSS_VER_DIR="u:/nss/nss$NSSVER" 955 fi 956 else 957 Debug "NSS_VER_DIR set to $NSS_VER_DIR" 958 return 959 fi 960 961 while [ ! -w $NSS_VER_DIR ] 962 do 963 if [ "$O_CRONFILE" = "ON" ] 964 then 965 Exit "cant write in $NSS_VER_DIR" 966 fi 967 Warning "cant write in $NSS_VER_DIR" 968 Echo "input start directory (u:/nss, d:/src/nss, f:/shared/nss) " 969 read D 970 if [ -n "$D" ] 971 then 972 NSS_VER_DIR=$D/nss$NSSVER 973 fi 974 done 975 Debug "NSS_VER_DIR set to $NSS_VER_DIR" 976} 977 978########################### init_host ################################## 979# global shell function, sets required variables HOST and DOMSUF, and asks 980# the user if it has been set right 981######################################################################## 982set_host() 983{ 984 init_host 985} 986init_host() 987{ 988 if [ `basename $0` != nssqa ] ; then 989 return 990 fi 991 992 init_host_done=0 993 994 if [ $DS_WAS_SET = FALSE ] #give chance to overwrite, espec. for NT 995 then 996 Debug "Domainname was not set..." 997 DOMSUF=`domainname 2>/dev/null` 998 if [ -z "$DOMSUF" ] 999 then 1000 Debug "domainname command did not work ..." 1001 DOMSUF=`echo $HOST | grep '\.' | sed -e "s/[^\.]*\.//"` 1002 1003 if [ -z "$DOMSUF" ] 1004 then 1005 Debug "Domainname not part of the hostname" 1006 DOMSUF=`cat /etc/defaultdomain 2>/dev/null` 1007 if [ -z "$DOMSUF" ] 1008 then 1009 Debug "Domainname needs to be hardcoded to red.iplanet.com" 1010 DOMSUF="red.iplanet.com" 1011 fi 1012 fi 1013 fi 1014 fi 1015 case $HOST in 1016 *\.*) 1017 Debug "HOSTNAME $HOST contains Dot" 1018 HOST=`echo $HOST | sed -e "s/\..*//"` 1019 ;; 1020 esac 1021 if [ -z "$HOST" ] 1022 then 1023 HOST=`uname -n` 1024 case $HOST in 1025 *\.*) 1026 Debug "HOSTNAME $HOST contains Dot" 1027 HOST=`echo $HOST | sed -e "s/\..*//"` 1028 ;; 1029 esac 1030 fi 1031 if [ $O_DEBUG = "ON" ] 1032 then 1033 while [ $init_host_done -eq 0 ] 1034 do 1035 Echo 1036 ask "DOMSUF=$DOMSUF, HOST=$HOST - OK", "y" "n" && 1037 init_host_done=1 1038 if [ $init_host_done -eq 0 ] 1039 then 1040 Echo "input DOMSUF: " 1041 read D 1042 if [ -n "$D" ] 1043 then 1044 DOMSUF=$D 1045 fi 1046 Echo "input HOST: " 1047 read H 1048 if [ -n "$H" ] 1049 then 1050 HOST=$H 1051 fi 1052 fi 1053 done 1054 fi 1055 export HOST DOMSUF 1056 Debug "HOST: $HOST, DOMSUF: $DOMSUF" 1057} 1058 1059#-----------------------------# UTILS #---------------------------------- 1060 1061########################### qa_stat_get_sysinfo ######################## 1062# local shell function, tries to determine the QA operating system 1063######################################################################## 1064qa_stat_get_sysinfo() 1065{ 1066 case $1 in 1067 ?*) REM_SYS=$1 1068 GET_SYSINFO="rsh $1" 1069 ;; 1070 *) REM_SYS="" 1071 GET_SYSINFO="" 1072 ;; 1073 esac 1074 QA_SYS=`$GET_SYSINFO uname -sr` 1075 echo $QA_SYS | grep Linux >/dev/null && 1076 QA_RHVER=`$GET_SYSINFO cat /etc/redhat-release` 1077 if [ -n "$QA_RHVER" ] 1078 then 1079 QA_OS=`echo $REM_SYS $QA_RHVER | sed -e "s/Red Hat /RH /" \ 1080 -e "s/ release//"` 1081 else 1082 case $QA_SYS in 1083 *SunOS*5.[89]*) 1084 ISAINFO=`$GET_SYSINFO isainfo -v` 1085 IS_64=`echo $ISAINFO | grep 64 >/dev/null && \ 1086 echo 64 bit` 1087 IS_I386=`echo $ISAINFO | grep i386 >/dev/null && \ 1088 echo i86pc` 1089 if [ -n "$IS_I386" ] ; then IS_64="$IS_I386"; fi; 1090 if [ -z "$IS_64" ] ; then IS_64="32 bit"; fi; 1091 ;; 1092 *HP*) 1093 IS_64=`$GET_SYSINFO getconf KERNEL_BITS | 1094 grep 64 >/dev/null && echo 64 bit` 1095 if [ -z "$IS_64" ] ; then IS_64="32 bit"; fi; 1096 ;; 1097 *AIX*) 1098 IS_64=`$GET_SYSINFO lslpp -l | 1099 grep "bos.64bit"> /dev/null && echo 64 bit` 1100 if [ -z "$IS_64" ] ; then IS_64="32 bit"; fi; 1101 ;; 1102 esac 1103 QA_OS=`echo "$REM_SYS $QA_SYS $IS_64"` 1104 fi 1105 if [ "$O_SILENT" != ON ] ; then 1106 echo $QA_OS 1107 fi 1108 QA_OS_STRING=`echo $QA_OS | sed -e "s/^[_ ]//" -e "s/ /_/g"` 1109} 1110 1111################################### set_objdir ######################### 1112# global shell function, sets the object directories and DIST 1113######################################################################## 1114set_objdir() 1115{ 1116 Debug "set object dir" 1117 OBJDIR=`cd ${TESTSCRIPTDIR}/common; gmake objdir_name` 1118 OS_ARCH=`cd ${TESTSCRIPTDIR}/common; gmake os_arch` 1119 1120 #at this point $MASTERBUILD needs to be either NT or unix 1121 1122 set_daily_build_dirs 1123 LOCALDIST_BIN=${LOCALDIST}/${OBJDIR}/bin 1124 DIST=$LOCALDIST 1125 1126 if [ -z "${TEST_LEVEL}" ] ; then 1127 TEST_LEVEL=0 1128 fi 1129 bc ${TEST_LEVEL} #set the path for the backward compatibility test 1130 1131 PATH_CONTAINS_BIN="TRUE" 1132 export PATH_CONTAINS_BIN 1133 1134 export OBJDIR OS_ARCH LOCALDIST LOCALDIST_BIN DIST PATH 1135} 1136 1137########################### bc ######################################### 1138# global shell function , sets paths for the backward compatibility test 1139######################################################################## 1140bc() 1141{ 1142 if [ -n "$PRODUCT_TO_TEST" -a "$PRODUCT_TO_TEST" = "JSS" ] ; then 1143 TESTDIR=${RESULTDIR} 1144 BC_ACTION="" 1145 DON_T_SET_PATHS="FALSE" #let init.sh override - FIXME - check if necessary 1146 return 1147 fi 1148 DON_T_SET_PATHS="TRUE" 1149 case $1 in 1150 0) 1151 #unset TESTDIR 1152 TESTDIR=${RESULTDIR} 1153 if [ "$O_WIN" = "ON" -a "$O_CYGNUS" != ON ] ; then 1154 PATH="$TESTSCRIPTDIR;$LOCALDIST_BIN;$BASEPATH" 1155 else 1156 PATH=$TESTSCRIPTDIR:$LOCALDIST_BIN:$BASEPATH 1157 fi 1158 BC_ACTION="" 1159 DON_T_SET_PATHS="FALSE" #let init.sh override - FIXME - check if necessary 1160 ;; 1161 *) 1162 if [ "$O_LOCAL" = "ON" ] ; then 1163 Exit "FIXME Can't run backwardcompatibility tests locally yet" 1164 fi 1165 TESTSCRIPTDIR=${BCDIST}/../security/nss/tests 1166 COMMON=${TESTSCRIPTDIR}/common 1167 TESTDIR=${RESULTDIR}/bct 1168 BC_ACTION="backward compatibility of binaries in $BC_MASTER to new libs" 1169 BCDIST_BIN=${BCDIST}/${OBJDIR}/bin 1170 LD_LIBRARY_PATH=${LOCALDIST}/${OBJDIR}/lib 1171 if [ "$O_WIN" = "ON" ] ; then 1172 if [ "$O_CYGNUS" = ON ] ; then 1173 PATH=$TESTSCRIPTDIR:$BCDIST_BIN:$BASEPATH:$LD_LIBRARY_PATH 1174 else 1175 PATH="$TESTSCRIPTDIR;$BCDIST_BIN;$BASEPATH;$LD_LIBRARY_PATH" 1176 fi 1177 else 1178 PATH=$TESTSCRIPTDIR:$BCDIST_BIN:$BASEPATH 1179 fi 1180 Debug "1st stage of backward compatibility test" 1181 ;; 1182 esac 1183 if [ -n "$TESTDIR" ] ; then 1184 if [ ! -d $TESTDIR ] ; then 1185 mkdir -p $TESTDIR 1186 fi 1187 export TESTDIR 1188 fi 1189 SHLIB_PATH=${LD_LIBRARY_PATH} 1190 LIBPATH=${LD_LIBRARY_PATH} 1191 Debug "PATH $PATH" 1192 Debug "LD_LIBRARY_PATH $LD_LIBRARY_PATH" 1193 export PATH LD_LIBRARY_PATH SHLIB_PATH LIBPATH 1194 export DON_T_SET_PATHS BC_ACTION 1195 export TESTSCRIPTDIR COMMON 1196} 1197 1198########################### Ps ######################################### 1199# global shell function , attempts a platform specific ps 1200######################################################################## 1201Ps() 1202{ 1203#AIX, OSF ps -ef, solaris /usr/5bin/ps -ef, win ps -ef but no user id 1204#linux ps -ef, HP 1205 1206 if [ $os_name = "SunOS" ] 1207 then 1208 /usr/5bin/ps -ef 1209 else 1210 ps -ef 1211 fi 1212} 1213 1214########################### kill_by_name ################################ 1215# global shell function , kills the process whose name is given as 1216# parameter 1217######################################################################## 1218kill_by_name() 1219{ 1220 for PID in `Ps | grep "$1" | grep -v grep | \ 1221 sed -e "s/^ *//g" -e "s/^[^ ]* //" -e "s/^ *//g" -e "s/ .*//g"` 1222 do 1223 if [ $O_WIN = "ON" -a $O_CYGNUS = "ON" ] 1224 then 1225 ask "Do you want to kill Process $PID (`Ps | grep $PID | \ 1226 grep -v grep | awk '{ print $1, $2, $6, $7, $8, $9 }' | \ 1227 sed -e "s/[0-9]:[0-6][0-9]//g" | grep $PID `)" \ 1228 "y" "n" && { 1229 kill $PID 1230 sleep 1 1231 kill -9 $PID 2>/dev/null 1232 } 1233 else 1234 ask "Do you want to kill Process $PID (`Ps | grep $PID | \ 1235 grep -v grep | awk '{ print $1, $2, $8, $9, $10, $11 }' | \ 1236 sed -e "s/[0-9]:[0-6][0-9]//g" | grep $PID `)" \ 1237 "y" "n" && { 1238 kill $PID 1239 sleep 1 1240 kill -9 $PID 2>/dev/null 1241 } 1242 fi 1243 done 1244} 1245 1246############################### early_exit ################################### 1247# global shell function , attempts a little more usefull user notification 1248# of a complete failure 1249######################################################################## 1250 1251early_exit() 1252{ 1253 if [ -z "$DOCDIR" ] 1254 then 1255 DOCDIR=`dirname $0`/../doc 1256 fi 1257 if [ -f $DOCDIR/QAerror.html ] 1258 then 1259 Debug "Found QA errorheader" 1260 rm ${FILENAME}.err 2>/dev/null 1261 cp $DOCDIR/QAerror.html ${FILENAME}.err 1262 echo "$1" >>${FILENAME}.err 1263 echo '</font></b></h1>' >>${FILENAME}.err 1264 if [ -n "$FILENAME" -a -f "$FILENAME" ] 1265 then 1266 cat $FILENAME | sed -e "s/^/<br>/" >>${FILENAME}.err 1267 fi 1268 echo '</body></html>' >>${FILENAME}.err 1269 cat ${FILENAME}.err | $RMAIL $MAILINGLIST 1270 1271 rm ${FILENAME}.err 2>/dev/null 1272 #echo "cat ${FILENAME}.err | $RMAIL $MAILINGLIST " 1273 fi 1274} 1275 1276############################### Exit ################################### 1277# global shell function , central exiting point 1278# cleanup: temporary files, kill the remaining selfservers if sourcing 1279# script sets KILL_SELFSERV 1280######################################################################## 1281Exit() 1282{ 1283 Echo $1 1284 if [ "$O_CRON" = "OFF" ] 1285 then 1286 echo $1 >&2 1287 fi 1288 if [ -f "${KILLPIDS}" ] 1289 then 1290 Debug "Attempting to kill background processes...`cat ${KILLPIDS}`" 1291 kill `cat "${KILLPIDS}"` 1292 sleep 1 1293 kill -9 `cat "${KILLPIDS}"` 1294 fi 1295 if [ -n "${TMPFILES}" ] 1296 then 1297 Debug "rm -f ${TMPFILES}" 1298 rm -f $TMPFILES 2>/dev/null 1299 fi 1300 O_ALWAYS_YES=ON # set to non-interactive - don't ask anymore questions here 1301 if [ $KILL_SELFSERV = "ON" ] 1302 then 1303 kill_by_name selfserv 1304 fi 1305 if [ $O_MAIL_LINK = "ON" -a $O_FILE = "ON" ] 1306 then 1307 if [ $EARLY_EXIT = TRUE ] #before the report file has been created 1308 then 1309 early_exit "$1" 1310 else 1311 head -3 $FILENAME >$ML_FILE 1312 echo "Content-Type: text/plain; charset=us-ascii; format=flowed 1313 Content-Transfer-Encoding: 7bit 1314 1315" >>$ML_FILE 1316 echo $HREF_TMP_HTML_FILE >>$ML_FILE 1317 cat $ML_FILE | $RMAIL $MAILINGLIST 1318 fi 1319 1320#FIXME - early exit etc 1321 elif [ $O_MAIL = "ON" -a $O_FILE = "ON" ] 1322 then 1323 if [ $EARLY_EXIT = TRUE ] #before the report file has been created 1324 then 1325 early_exit "$1" 1326 elif [ -n "$FILENAME" -a -f "$FILENAME" ] 1327 then 1328 cat $FILENAME | $RMAIL $MAILINGLIST 1329 fi 1330 #rm $FILENAME 2>/dev/null 1331 elif [ $O_MAIL = "ON" -a $EARLY_EXIT = TRUE ] 1332 then 1333 early_exit "$1" 1334 rm $FILENAME 2>/dev/null 1335 fi 1336 #chmod a+rw ${RESULTDIR} ${RESULTDIR}/* ${RESULTDIR}/*/* & 1337 if [ -n "$O_TBX" -a "$O_TBX" = "ON" ] ; then 1338 rm ${TESTDIR}/QAstatus 1339 1340 if [ "$1" = "killed... cleaning up..." ] ; then 1341 echo "QA killed" >${TESTDIR}/QAstatus 1342 elif [ "$TBX_EXIT" = 0 ] ; then 1343 echo "QA passed" >${TESTDIR}/QAstatus 1344 else 1345 echo "QA failed" >${TESTDIR}/QAstatus 1346 fi 1347 1348 exit $TBX_EXIT 1349 1350 else 1351 exit 1352 fi 1353} 1354 1355trap "rm -f ${TMPFILES} 2>/dev/null; Exit 'killed... cleaning up...'" 2 3 15 1356 1357################################ Wait ################################## 1358# global shell function to wait for an event to happen, 1st parameter 1359# filename to watch, 2nd parameter 0 - wait for it to disappear, 1 wait 1360# for it to be created. 1361# uses the variables WAIT_FOR and WAIT_TIMES 1362# WAIT_FOR: if waiting for an event sleep n seconds before rechecking 1363# recomended value 10 minutes 600 1364# WAIT_TIMES: recheck n times before giving up to prevent endless loop 1365# recomended 30 - total of 5h 1366######################################################################## 1367 1368Wait() 1369{ 1370 i=0 1371 Debug "Waiting for $1" 1372 while [ $i -lt $WAIT_TIMES ] 1373 do 1374 i=`expr $i + 1` 1375 if [ -f "$1" -a $2 -eq 1 ] # if file exists and is supposed to 1376 then 1377 return 1378 fi 1379 if [ ! -f "$1" -a $2 -eq 0 ] # not exists and not supposed to exist 1380 then 1381 return 1382 fi 1383 Debug "Waiting for $1, loop #$i, about to sleep $WAIT_FOR seconds zzzz..." 1384 sleep $WAIT_FOR 1385 done 1386 TOTAL=`expr $WAIT_TIMES \* $WAIT_FOR / 60` 1387 Exit "I HAVE WAITED LONG ENOUGH FOR $1 NOW, I'M GONE! (THAT WAS A TOTAL OF $TOTAL MINUTES) I have better things to do... " 1388} 1389 1390################################ WaitForever ################################## 1391# global shell function to wait for an event to happen, 1st parameter 1392# filename to watch, 2nd parameter 0 - wait for it to disappear, 1 wait 1393# for it to be created. 1394# because we daon't have any relyable cron on NT... 1395######################################################################## 1396 1397WaitForever() 1398{ 1399 i=0 1400 Debug "Waiting for $1" 1401 TOTAL=0 1402 while [ 1 ] 1403 do 1404 i=`expr $i + 1` 1405 if [ -f "$1" -a $2 -eq 1 ] # if file exists and is supposed to 1406 then 1407 return 1408 fi 1409 if [ ! -f "$1" -a $2 -eq 0 ] # not exists and not supposed to exist 1410 then 1411 return 1412 fi 1413 Debug "Waiting for $1, loop #$i, about to sleep $WAIT_FOR seconds Total $TOTAL" 1414 sleep $WAIT_FOR 1415 TOTAL=`expr $i \* $WAIT_FOR / 60` 1416 if [ -n "$MAX_FOREVER" ] # we are cheating. Forever can be very short... 1417 then 1418 if [ "$TOTAL" -gt "$MAX_FOREVER" ] 1419 then 1420 Exit "I HAVE WAITED LONG ENOUGH FOR $1 NOW, I'M GONE! (THAT WAS A TOTAL OF $TOTAL MINUTES) I have better things to do... " 1421 fi 1422 fi 1423 done 1424} 1425################################### is_running ######################### 1426# global shell function , implements primitive locking mechanism 1427# filename is passed as a parameter, if filename.* exists we assume calling 1428# script is running already and exit, otherwise filename.processid is 1429# created 1430######################################################################## 1431is_running() 1432{ 1433 Debug "Testing if $0 is already running... file ${1} - ${1}.$$" 1434 if [ -f ${1}.* ] 1435 then 1436 Exit "$0 seems to be running already ($1 exists) - Exiting" 1437 fi 1438 TMPFILES="$TMPFILES ${1}.$$" 1439 echo "running $0 on `date` PID $$" >${1}.$$ 1440 Debug "wrote \"running $0 on `date` PID $$\" to ${1}.$$" 1441 1442} 1443 1444#---------------------------# USERCOM #--------------------------------- 1445############################## Echo ##################################### 1446# global shell function , depending on the options the output gets written 1447# to a file, or is being discarded 1448# FIXME \n and \c are mistreates by differnet shells, and linux has /bin/echo 1449# instead of /usr/bin/echo 1450######################################################################## 1451Echo () 1452{ 1453 if [ $O_SILENT = OFF ] 1454 then 1455 echo "$*" 1456 #/usr/bin/echo "$*" 1457 fi 1458 if [ $O_FILE = ON ] 1459 then 1460 echo "$*" >>$FILENAME 1461 fi 1462} 1463 1464################################### ask ################################ 1465# global shell function, Asks the a question, and gives the returns 0 1466# on the 1st choice, 1 on the 2nd choice 1467# 1468# PARAMETERS: 1469# $1 question text 1470# $2 1st choice 1471# $3 2nd choice 1472# 1473# MODIFIERS: 1474# -y O_ALWAYS_YES will assume a first choice always (not neccessaryly "y") 1475# 1476# RETURN: 1477# 0 - User picked 1st choice 1478# 1 - User picked 2nd choice 1479# 1480# EXAMPLE 1481# ask "Would you like to continue" "y" "n" || Exit 1482# will produce the string "Would you like to continue (y/n) ?", 1483# read input from keyboard (or assume a yes with option -y) 1484# - on a yes it will return 0, on a no it will return 1, the 1485# shell interprets it as error and the || Exit will be executed 1486# 1487# NOTE: NEVER use "n" as the second parameter - it will mess up -y 1488# don't ask "Continue" "n" "y" || Exit # it will Exit on a "y" 1489# 1490######################################################################## 1491Ask() 1492{ 1493 ask $* 1494} 1495 1496ask() 1497{ 1498 if [ $O_ALWAYS_YES = ON ] 1499 then 1500 Echo "$1 ($2/$3) ?" 1501 Echo "YES!" 1502 return 0 1503 fi 1504 A="" 1505 while [ 1 ] 1506 do 1507 1508 Echo "$1 ($2/$3) ?" 1509 read A 1510 if [ -n "$A" ] 1511 then 1512 if [ $A = $2 ] 1513 then 1514 return 0 1515 elif [ $A = $3 ] 1516 then 1517 return 1 1518 fi 1519 fi 1520 done 1521 return 0 1522} 1523 1524################################### Warning ############################ 1525# global shell function, Asks the user a "... continue? (y/n)" question, 1526# and exits when the user answers with no 1527# NOTE -y will answer the warnings always with yes 1528######################################################################## 1529Warning () 1530{ 1531 ask "WARNING: $0: \n $* continue " "y" "n" || Exit 1532} 1533 1534################################### Debug ############################ 1535# global shell function, when option -d Debugging output is written 1536######################################################################## 1537Debug() 1538{ 1539 if [ $O_DEBUG = ON ] 1540 then 1541 Echo "DEBUG: (`date +%H:%M`) $0: $*" 1542 fi 1543} 1544 1545################################### line ############################### 1546# global shell function, supposed to make output more readable... 1547######################################################################## 1548line() 1549{ 1550Echo 1551#Echo "=======================================================================" 1552#Echo 1553} 1554 1555################################### opt_usage ########################## 1556# global shell function, tells user about available options 1557######################################################################## 1558opt_usage() 1559{ 1560 if [ $O_OPTIONS = "ON" ] 1561 then 1562 Echo 1563 line 1564 Echo 1565 Echo " -y answer all questions with y - use at your own risk..." 1566 Echo " -s silent (only usefull with -y)" 1567 Echo " -h, -? - you guessed right - displays this text" 1568 Echo " -d debug" 1569 Echo " -f <filename> - write the (error)output to filename" 1570 Echo " -fcronfile produces the resultfiles in the same locations" 1571 Echo " as would have been produced with -cron" 1572 Echo " -m <mailinglist> - send filename to mailinglist (csl " 1573 Echo " example sonmi,nelsonb,wtc) only useful with -f" 1574 Echo " -ml <mailinglist> - send link to filename to mailinglist " 1575 Echo " (csl example sonmi,nelsonb,wtc) only useful with -f" 1576 Echo " -cron equivalient to -y -s -d -f \$RESULTDIR/\$HOST.nssqa" 1577 Echo " -t run on a tinderbox build (included -cron)" 1578 if [ `basename $0` = nssqa ] ; then 1579 Echo " -l <mozroot> run on a local build" 1580 Echo " -ln <mozroot> copy a networkbuild to a local directory " 1581 Echo " mozroot, used for networkindipendend QA " 1582 Echo " -lt try to copy a networkbuild to a local directory, if" 1583 Echo " not possible run on the network 1584 Echo " used for networkindipendend QA 1585 fi 1586# 1587# special strings 1588 fi 1589 1590} 1591 1592################################### glob_usage ######################### 1593# global shell function, how to use the calling script (parameters, options) 1594######################################################################## 1595glob_usage() 1596{ 1597 line 1598 Echo $1 1599 Echo 1600 if [ $O_OPTIONS = "ON" ] 1601 then 1602 Echo "usage $0 [options] nssversion builddate" 1603 else 1604 Echo "usage $0 nssversion builddate" 1605 fi 1606 1607 Echo " for example: $0 30b 0926" 1608 Echo " $0 31 1002" 1609 opt_usage 1610 Echo 1611 Exit "$1" 1612} 1613 1614tell() 1615{ 1616 if [ $O_SILENT = OFF ] 1617 then 1618 line 1619 pwd 1620 ls -CF 1621 line 1622 fi 1623 if [ $O_FILE = ON ] 1624 then 1625 line 1626 pwd >>$FILENAME 1627 ls -CF >>$FILENAME 1628 line 1629 fi 1630} 1631 1632if [ $O_INIT = "ON" ] 1633then 1634 glob_init $* 1635fi 1636EARLY_EXIT=FALSE 1637