deprecate never-used -r option
[build.git] / vbuild-nightly.sh
index da86c9b..0516c1b 100755 (executable)
@@ -5,11 +5,11 @@ COMMANDPATH=$0
 COMMAND=$(basename $0)
 
 # default values, tunable with command-line options
-DEFAULT_FCDISTRO=f8
+DEFAULT_FCDISTRO=centos5
 DEFAULT_PLDISTRO=planetlab
 DEFAULT_PERSONALITY=linux32
 DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
-DEFAULT_SVNPATH="http://svn.planet-lab.org/svn/build/trunk"
+DEFAULT_build_SVNPATH="http://svn.planet-lab.org/svn/build/trunk"
 DEFAULT_TESTCONFIG="default"
 DEFAULT_IFNAME=eth0
 
@@ -22,8 +22,8 @@ DEFAULT_GPGPATH="/etc/planetlab"
 DEFAULT_GPGUID="root@$( /bin/hostname )"
 
 # for the test part
-TESTBUILDURL="http://build.one-lab.org/"
-TESTBOXSSH=root@testbox.one-lab.org
+DEFAULT_TESTBUILDURL="http://build.onelab.eu/"
+TESTBOXSSH=root@testbox.onelab.eu
 ####################
 # assuming vserver runs in UTC
 DATE=$(date +'%Y.%m.%d')
@@ -39,7 +39,7 @@ function summary () {
 # read a full log and tries to extract the interesting stuff
 
 import sys,re
-m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*")
+m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*|.*PROPFIND.*|.*Starting.*:runtest.*")
 m_installing_any=re.compile('\r  (Installing:[^\]]*]) ')
 m_installing_err=re.compile('\r  (Installing:[^\]]*])(..+)')
 m_installing_end=re.compile('Installed:.*')
@@ -98,31 +98,53 @@ EOF
 # Notify recipient of failure or success, manage various stamps 
 function failure() {
     set -x
-    WEBLOG=${WEBPATH}/${BASE}.log.txt
-    mkdir -p ${WEBPATH}
+    # early stage ? - let's not create /build/@PLDISTRO@
+    if [ ! -d ${WEBPATH} ] ; then
+       WEBPATH=/tmp
+       WEBLOG=/tmp/vbuild-early.log.txt
+    fi
     cp $LOG ${WEBLOG}
     summary $LOG >> ${WEBLOG}
     (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
     if [ -n "$MAILTO" ] ; then
-       tail -c 30k ${WEBLOG} | mail -s "Failures for build ${BASE}" $MAILTO
+       ( \
+           echo "See full build log at ${LOG_URL}" ; \
+           echo "and tail version at ${LOG_URL}.ko" ; \
+           echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
+           tail -c 30k ${WEBLOG} ) | mail -s "Failures with ${MAIL_SUBJECT}" $MAILTO
     fi
     exit 1
 }
 
 function success () {
     set -x
-    WEBLOG=${WEBPATH}/${BASE}.log.txt
-    mkdir -p ${WEBPATH}
+    # early stage ? - let's not create /build/@PLDISTRO@
+    if [ ! -d ${WEBPATH} ] ; then
+       WEBPATH=/tmp
+       WEBLOG=/tmp/vbuild-early-$(date +%Y-%m-%d).log.txt
+    fi
     cp $LOG ${WEBLOG}
     summary $LOG >> ${WEBLOG}
     if [ -n "$DO_TEST" ] ; then
-       echo "Successfully built and tested - see testlogs for details" > ${WEBLOG}.pass
-       rm -f ${WEBLOG}.ok
+       ( \
+           echo "Successfully built and tested" ; \
+           echo "See full build log at ${LOG_URL}" ; \
+           echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
+           ) > ${WEBLOG}.pass
+       rm -f ${WEBLOG}.pkg-ok ${WEBLOG}.ko
     else
-       echo "Successfully built"> ${WEBLOG}.ok
+       ( \
+           echo "Successful package-only build, no test requested" ; \
+           echo "See full build log at ${LOG_URL}" ; \
+           ) > ${WEBLOG}.pkg-ok
+       rm -f ${WEBLOG}.ko
     fi
     if [ -n "$MAILTO" ] ; then
-       (echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ) | mail -s "Successful build for ${BASE}" $MAILTO
+       ( \
+           echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ; \
+           echo "See full build log at ${LOG_URL}" ; \
+            [ -n "$DO_TEST" ] && echo "See complete set of testlogs at ${TESTLOGS_URL}" ) \
+           | mail -s "Success with ${MAIL_SUBJECT}" $MAILTO
     fi
     exit 0
 }
@@ -136,11 +158,6 @@ function build () {
     date
 
     cd /build
-  # if TAGSRELEASE specified : update PLDISTROTAGS with this tag
-    if [ -n "$TAGSRELEASE" ] ; then
-       svn up -r $TAGSRELEASE $PLDISTROTAGS
-    fi
-
     show_env
     
     echo "Running make IN $(pwd)"
@@ -148,18 +165,20 @@ function build () {
     # stuff our own variable settings
     MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
     MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
-    MAKEVARS=("NIGHTLY_BASE=${BASE}" "${MAKEVARS[@]}")
-    MAKEVARS=("NIGHTLY_PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
-    MAKEVARS=("build-SVNPATH=${SVNPATH}" "${MAKEVARS[@]}")
+    MAKEVARS=("build-SVNPATH=${build_SVNPATH}" "${MAKEVARS[@]}")
+    MAKEVARS=("PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
+    MAKEVARS=("MAILTO=${MAILTO}" "${MAKEVARS[@]}")
+
+    MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
 
     # stage1
     make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true 
-    # versions
-    make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
     # store tests_svnpath
     make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
+    # versions
+    make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
     # actual stuff
-    make -C /build $DRY_RUN "${MAKEVARS[@]}" $MAKETARGETS
+    make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
 
 }
 
@@ -183,7 +202,7 @@ function runtest () {
     # xxx - Thierry - need to rework the test framework in tests/system so it can work
     # with the entire tests/ module checked out, rather than only tests/system/ 
     # ugly workaround for now
-    SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
+    TESTS_SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
 
     ### the URL to the RPMS/<arch> location
     url=""
@@ -206,7 +225,7 @@ function runtest () {
     # clean it
     ssh -n ${TESTBOXSSH} rm -rf ${testdir}
     # check it out 
-    ssh -n ${TESTBOXSSH} svn co ${SYSTEM_SVNPATH} ${testdir}
+    ssh -n ${TESTBOXSSH} svn co ${TESTS_SYSTEM_SVNPATH} ${testdir}
     # check out the entire tests/ module (with system/ duplicated) as a subdir - see xxx above
     ssh -n ${TESTBOXSSH} svn co ${TESTS_SVNPATH} ${testdir}/tests
     # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
@@ -218,14 +237,14 @@ function runtest () {
 
     # need to proceed despite of set -e
     success=true
-    ssh 2>&1 -n ${TESTBOXSSH} ${testdir}/runtest --build ${SVNPATH} --url ${url} $configs $test_env --all || success=
+    ssh 2>&1 -n ${TESTBOXSSH} ${testdir}/runtest --build ${build_SVNPATH} --url ${url} $configs $test_env --all || success=
 
     # gather logs in the vserver
     mkdir -p /vservers/$BASE/build/testlogs
     ssh 2>&1 -n ${TESTBOXSSH} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
     # push them to the build web
+    chmod -R a+r /vservers/$BASE/build/testlogs/
     rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
-    chmod -R a+r $WEBPATH/$BASE/testlogs/
 
     if [ -z "$success" ] ; then
        failure
@@ -238,30 +257,84 @@ function in_root_context () {
     rpm -q util-vserver > /dev/null 
 }
 
+# this part won't work with a remote(rsync) WEBPATH
+function sign_node_packages () {
+
+    echo "Signing node packages"
+    
+    need_createrepo=""
+
+    repository=$WEBPATH/$BASE/RPMS/
+    # the rpms that need signing
+    new_rpms=
+    # and the corresponding stamps
+    new_stamps=
+
+    for package in $(find $repository/ -name '*.rpm') ; do
+        stamp=$repository/signed-stamps/$(basename $package).signed
+        # If package is newer than signature stamp
+        if [ $package -nt $stamp ] ; then
+            new_rpms="$new_rpms $package"
+            new_stamps="$new_stamps $stamp"
+        fi
+        # Or than createrepo database
+        [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
+    done
+
+    if [ -n "$new_rpms" ] ; then
+        # Create a stamp once the package gets signed
+        mkdir $repository/signed-stamps 2> /dev/null
+       
+        # Sign RPMS. setsid detaches rpm from the terminal,
+        # allowing the (hopefully blank) GPG password to be
+        # entered from stdin instead of /dev/tty.
+        echo | setsid rpm \
+            --define "_signature gpg" \
+            --define "_gpg_path $GPGPATH" \
+            --define "_gpg_name $GPGUID" \
+            --resign $new_rpms && touch $new_stamps
+    fi
+
+     # Update repository index / yum metadata. 
+    if [ -n "$need_createrepo" ] ; then
+       echo "Indexing node packages after signing"
+        if [ -f $repository/yumgroups.xml ] ; then
+            createrepo --quiet -g yumgroups.xml $repository
+        else
+            createrepo --quiet $repository
+        fi
+    fi
+}
+
 function show_env () {
     set +x
     echo FCDISTRO=$FCDISTRO
     echo PLDISTRO=$PLDISTRO
+    echo PERSONALITY=$PERSONALITY
     echo BASE=$BASE
-    echo SVNPATH=$SVNPATH
+    echo build_SVNPATH=$build_SVNPATH
     echo MAKEVARS="${MAKEVARS[@]}"
     echo DRY_RUN="$DRY_RUN"
     echo PLDISTROTAGS="$PLDISTROTAGS"
-    echo TAGSRELEASE="$TAGSRELEASE"
-    echo -n "(might be unexpanded)"
-    echo WEBPATH="$WEBPATH"
+    # this does not help, it's not yet set when we run show_env
+    #echo WEBPATH="$WEBPATH"
+    echo TESTBUILDURL="$TESTBUILDURL"
     if in_root_context ; then
        echo PLDISTROTAGS="$PLDISTROTAGS"
     else
-       echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
-       cat /build/$PLDISTROTAGS
-       echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
+       if [ -f /build/$PLDISTROTAGS ] ; then
+           echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
+           cat /build/$PLDISTROTAGS
+           echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
+       else
+           echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
+       fi
     fi
     set -x
 }
 
 function usage () {
-    echo "Usage: $COMMAND [option] make-targets"
+    echo "Usage: $COMMAND [option] [var=value...] make-targets"
     echo "This is $REVISION"
     echo "Supported options"
     echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
@@ -269,22 +342,22 @@ function usage () {
     echo " -p personality - defaults to $DEFAULT_PERSONALITY"
     echo " -b base - defaults to $DEFAULT_BASE"
     echo "    @NAME@ replaced as appropriate"
+    echo " -o base: (overwrite) do not re-create vserver, re-use base instead"
+    echo "    the -f/-d/-t/-s/-p/-m options are uneffective in this case"
     echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
-    echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
-    echo " -s svnpath - where to fetch the build module"
+    echo " -s svnpath - where to fetch the build module - defaults to $DEFAULT_build_SVNPATH"
     echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
     echo " -w webpath - defaults to $DEFAULT_WEBPATH"
-    echo " -y create (and sign) yum repo in webpath"
+    echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL"
+    echo " -y sign yum repo in webpath"
     echo " -g path to gpg secring used to sign rpms.  Defaults to $DEFAULT_GPGPATH" 
     echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
     echo " -m mailto - no default"
-    echo " -O : overwrite - re-run in base directory, do not re-create vserver"
     echo " -B : run build only"
     echo " -T : run test only"
     echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
     echo " -v : be verbose"
     echo " -7 : uses weekday-@FCDISTRO@ as base"
-    echo " -a makevar=value - space in values are not supported"
     echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
     exit 1
 }
@@ -295,31 +368,32 @@ function main () {
 
     # parse arguments
     MAKEVARS=()
+    MAKETARGETS=()
     DRY_RUN=
     DO_BUILD=true
     DO_TEST=true
-    while getopts "f:d:p:b:t:r:s:x:c:w:g:u:m:OBTnyv7a:i:" opt ; do
+    SIGNYUMREPO=""
+    while getopts "f:d:p:b:o:t:s:x:c:w:W:g:u:m:BTnyv7i:" opt ; do
        case $opt in
            f) FCDISTRO=$OPTARG ;;
            d) PLDISTRO=$OPTARG ;;
            p) PERSONALITY=$OPTARG ;;
            b) BASE=$OPTARG ;;
+           o) OVERBASE=$OPTARG ;;
            t) PLDISTROTAGS=$OPTARG ;;
-           r) TAGSRELEASE=$OPTARG ;;
-           s) SVNPATH=$OPTARG ;;
+           s) build_SVNPATH=$OPTARG ;;
            c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
            w) WEBPATH=$OPTARG ;;
-        y) MKYUMREPO=$OPTARG;;
-        g) GPGPATH=$OPTARG;;
-        u) GPGUID=$OPTARG;;
+           W) TESTBUILDURL=$OPTARG ;;
+            y) SIGNYUMREPO=true ;;
+            g) GPGPATH=$OPTARG ;;
+            u) GPGUID=$OPTARG ;;
            m) MAILTO=$OPTARG ;;
-           O) OVERWRITEMODE=true ;;
            B) DO_TEST= ;;
-           T) DO_BUILD= ; OVERWRITEMODE=true ;;
+           T) DO_BUILD= ;;
            n) DRY_RUN="-n" ;;
            v) set -x ;;
            7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
-           a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
            i) IFNAME=$OPTARG ;;
            h|*) usage ;;
        esac
@@ -330,7 +404,16 @@ function main () {
     toshift=$(($OPTIND - 1))
     arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
 
-    MAKETARGETS="$@"
+    # allow var=value stuff; 
+    for target in "$@" ; do
+       # check if contains '='
+       target1=$(echo $target | sed -e s,=,,)
+       if [ "$target" = "$target1" ] ; then
+           MAKETARGETS=(${MAKETARGETS[@]} "$target")
+       else
+           MAKEVARS=(${MAKEVARS[@]} "$target")
+       fi
+    done
     
     # set defaults
     [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
@@ -339,18 +422,37 @@ function main () {
     [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
     [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
     [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
+    [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
     [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
     [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
     [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
-    [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
+    [ -z "$build_SVNPATH" ] && build_SVNPATH="$DEFAULT_build_SVNPATH"
     [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
 
     [ -n "$DRY_RUN" ] && MAILTO=""
        
-    ### set BASE from DISTRO, if unspecified
-    sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
-    BASE=$(echo ${BASE} | sed $sedargs)
-    WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
+    if [ -n "$OVERBASE" ] ; then
+       sedargs="-e s,@DATE@,${DATE},g"
+       BASE=$(echo ${OVERBASE} | sed $sedargs)
+    else
+       sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
+       BASE=$(echo ${BASE} | sed $sedargs)
+    fi
+
+    ### elaborate mail subject
+    if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
+       MAIL_SUBJECT="complete"
+    elif [ -n "$DO_BUILD" ] ; then
+       MAIL_SUBJECT="package-only"
+    elif [ -n "$DO_TEST" ] ; then
+       MAIL_SUBJECT="test-only"
+    fi
+    if [ -n "$OVERBASE" ] ; then
+       MAIL_SUBJECT="$MAIL_SUBJECT incremental run on"
+    else
+       MAIL_SUBJECT="$MAIL_SUBJECT fresh build"
+    fi
+    MAIL_SUBJECT="$MAIL_SUBJECT ${BASE}"
 
     if ! in_root_context ; then
         # in the vserver
@@ -365,7 +467,7 @@ function main () {
         # (*) copy this command in the vserver
         # (*) invoke it
        
-       if [ -n "$OVERWRITEMODE" ] ; then
+       if [ -n "$OVERBASE" ] ; then
             ### Re-use a vserver (finish an unfinished build..)
            if [ ! -d /vservers/${BASE} ] ; then
                echo $COMMAND : cannot find vserver $BASE
@@ -377,11 +479,19 @@ function main () {
            exec > $LOG 2>&1
            set -x
            echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
-           show_env
            # start in case e.g. we just rebooted
            vserver ${BASE} start || :
            # update build
            vserver ${BASE} exec svn update /build
+           # get environment from the first run 
+           FCDISTRO=$(vserver ${BASE} exec /build/getdistroname.sh)
+
+           PLDISTRO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTRO)
+           PLDISTROTAGS=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTROTAGS)
+           build_SVNPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +build-SVNPATH)
+           PERSONALITY=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PERSONALITY)
+           MAILTO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +MAILTO)
+           show_env
        else
            # create vserver: check it does not exist yet
            i=
@@ -406,7 +516,7 @@ function main () {
 
            ### extract the whole build - much simpler
            tmpdir=/tmp/$COMMAND-$$
-           svn export $SVNPATH $tmpdir
+           svn export $build_SVNPATH $tmpdir
             # Create vserver
            cd $tmpdir
            ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE} 
@@ -414,7 +524,7 @@ function main () {
            cd -
            rm -rf $tmpdir
            # Extract build again - in the vserver
-           vserver ${BASE} exec svn checkout ${SVNPATH} /build
+           vserver ${BASE} exec svn checkout ${build_SVNPATH} /build
        fi
        echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
 
@@ -430,13 +540,23 @@ function main () {
        # redirect log again
        exec >> $LOG 2>&1 
 
+       sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
+       WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
+       mkdir -p ${WEBPATH}
+
+        # where to store the log for web access
+       WEBLOG=${WEBPATH}/${BASE}.log.txt
+        # compute the log URL - inserted in the mail messages for convenience
+       LOG_URL=$(echo ${WEBLOG} | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
+       TESTLOGS_URL=$(echo ${WEBPATH}/${BASE}/testlogs | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
+    
        if [ -n "$DO_BUILD" ] ; then 
 
            cp $COMMANDPATH /vservers/${BASE}/build/
 
            # invoke this command in the vserver for building (-T)
            vserver ${BASE} exec chmod +x /build/$COMMAND
-           vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" $MAKETARGETS
+           vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
        fi
 
        # publish to the web so runtest can find them
@@ -446,75 +566,10 @@ function main () {
        # publish myplc-release
        rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
 
-    # create yum repo and sign packages.
-    if [ -n $MKYUMREPO ] ; then
-        echo "Signing signing node packages"
-
-        ### availability of repo indexing tools
-        # old one - might be needed for old-style nodes
-        type -p yum-arch > /dev/null && have_yum_arch="true"
-        # new one
-        type -p createrepo > /dev/null && have_createrepo="true"
-
-        repository=$WEBPATH/$BASE/RPMS/
-        # the rpms that need signing
-        new_rpms=
-        # and the corresponding stamps
-        new_stamps=
-        # is there a need to refresh yum metadata
-        need_yum_arch=
-        need_createrepo=
-
-        # right after installation, no package is present
-        # but we still need to create index 
-        [ -n "$have_yum_arch" -a ! -f $repository/headers/header.info ] && need_yum_arch=true
-        [ -n "$have_createrepo" -a ! -f $repository/repodata/repomd.xml ] && need_createrepo=true
-
-        for package in $(find $repository/ -name '*.rpm') ; do
-            stamp=$repository/signed-stamps/$(basename $package).signed
-            # If package is newer than signature stamp
-            if [ $package -nt $stamp ] ; then
-                new_rpms="$new_rpms $package"
-                new_stamps="$new_stamps $stamp"
-            fi
-            # Or than yum-arch headers
-            [ -n "$have_yum_arch" ] && [ $package -nt $repository/headers/header.info ] && need_yum_arch=true
-            # Or than createrepo database
-            [ -n "$have_createrepo" ] && [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
-        done
-
-        if [ -n "$new_rpms" ] ; then
-            # Create a stamp once the package gets signed
-            mkdir $repository/signed-stamps 2> /dev/null
-
-            # Sign RPMS. setsid detaches rpm from the terminal,
-            # allowing the (hopefully blank) GPG password to be
-            # entered from stdin instead of /dev/tty.
-            echo | setsid rpm \
-                --define "_signature gpg" \
-                --define "_gpg_path $GPGPATH" \
-                --define "_gpg_name $GPGUID" \
-                --resign $new_rpms && touch $new_stamps
-        fi
-
-         # Update repository index / yum metadata. 
-
-        if [ -n "$need_yum_arch" ] ; then
-            # yum-arch sometimes leaves behind
-            # .oldheaders and .olddata directories accidentally.
-            rm -rf $repository/{.oldheaders,.olddata}
-            yum-arch $repository
-        fi
-
-        if [ -n "$need_createrepo" ] ; then
-            if [ -f $repository/yumgroups.xml ] ; then
-                createrepo --quiet -g yumgroups.xml $repository
-            else
-                createrepo --quiet $repository
-            fi
-        fi
-
-    fi
+        # create yum repo and sign packages.
+       if [ -n "$SIGNYUMREPO" ] ; then
+           sign_node_packages
+       fi
 
        if [ -n "$DO_TEST" ] ; then 
            runtest