cron-script.sh
author laca
Thu, 13 May 2004 14:41:01 +0000
changeset 2747 5eaa1cc670a0
parent 2236 f83c45aa3d11
child 2749 38af73851743
permissions -rwxr-xr-x
2004-05-14 Laszlo Peter <[email protected]> * build-gnome2: only send out the tail of the log by email and a pointer to the full log. * cron-script.sh, continuous-build.sh: fix log URL.

#!/bin/bash

# host to rcp the rpms to
RHOST=blader

# user to rcp as (has to have root@<this host> in it's .rhosts file)
RUSER=gbuild

# directory to copy rpms/srpms to on the remote host
RPMSDIR=/sgnome/pkgs/jds.next/rpms/nightly
SRPMSDIR=/sgnome/pkgs/jds.next/srpms/nightly
LOCKFILE=/sgnome/pkgs/jds.next/rpms/.build.lock

# reply-to/to address to send the build log as/to
[email protected]
[email protected]

# date format appended to the Release tag in the spec files
# (passed to the date command on the cmd line)
RELEASE_DATE_FMT="%y%m%d"

# date format used for naming the directories
DIR_DATE_FMT="%Y-%m-%d"

RELEASE_DATE=`date +$RELEASE_DATE_FMT`
DIR_DATE=`date +$DIR_DATE_FMT`

# document root of the web server
WEBROOT=/scde/web/docs

# subdir to keep logs and reports on the webserver
WEBDIR=gnome/releng/jds/jds.next/nightly
LOGDIR=$WEBDIR/$DIR_DATE

# ------------ nothing to configure below this line --------------

#if [ "x$I_KNOW_WHAT_IM_DOING" != xyes ]; then
#    echo " ,---------------------------------------------------------------."
#    echo "| This script is intended to be run from cron for producing      |"
#    echo "| official nightly builds. It will mail responsible engineers    |"
#    echo "| if any build failure occurs, sends build reports to            v"
#    echo "| RE and update web pages."
#    echo "|"
#    echo "| Don't run it unless you know what you are doing. Thanks."
#    echo "|"
#    echo "| Mail [email protected] if you need more info."
#    echo "\`------>                                                         +"
#    exit 1
#fi

MYNAME="$0"
MYDIR=$(cd `dirname $0`; pwd)

if [ "x$1" != x ]; then
    SPECDIR="$1"
else
    SPECDIR="$MYDIR"
fi

# remove temporary files on exit
clean_up () {
  case "$MYNAME" in
  /tmp/cron-script.copy.* )
        rm -f $MYNAME
        ;;
  esac
  exit
}

trap clean_up HUP INT TERM QUIT EXIT

# make a copy of the cron script in /tmp and execute that in order to
# avoid disasters caused by cvs update.
case "$MYNAME" in
    /tmp/cron-script.copy.* )
        ;;
    *)
        cp $MYNAME /tmp/cron-script.copy.$$
        chmod 755 /tmp/cron-script.copy.$$
        cd /tmp
        exec /tmp/cron-script.copy.$$ "$MYDIR"
        ;;
esac

fatal_error () {
  echo "ERROR: $*"
  exit 1
}

cd $SPECDIR || fatal_error "$SPECDIR not found"

cvs -q up -Pd > /dev/null 2>&1 || fatal_error "CVS update failed"

# if the script changed during cvs update, restart with the updated script
if ! /usr/bin/cmp -s ./cron-script.sh $MYNAME; then exec ./cron-script.sh; fi

rm -f GNOME*Template*.spec

# uninstall all pkgs left behind by a previous build
./build-gnome2 -q uninstall-pkgs *.spec

rm -f /usr/src/packages/SRPMS/* /usr/src/packages/RPMS/*/*

# if the log directory exists, open a new one with numbered suffix
NEW_LOGDIR=$LOGDIR
N=1
while [ -d $WEBROOT/$NEW_LOGDIR ]; do
    NEW_LOGDIR=$LOGDIR.$N
    N=`expr $N + 1`
done

LOGDIR=$NEW_LOGDIR
mkdir -p $WEBROOT/$LOGDIR

echo '' | rsh $RHOST -l $RUSER "touch $LOCKFILE"

# start the build
./build-gnome2 -v --nightly --date "$RELEASE_DATE" build --target i586 *.spec \
        --logdir=$WEBROOT/$LOGDIR \
        --logdir-url=http://gnome.ireland$LOGDIR \
	--mail-errors-file=MAINTAINERS \
	[email protected] \
        --prodname=jds.next \
        --good-build-dir=/sgnome/pkgs/jds.next/rpms \
        --good-rpms-copy-dir=/tmp/old-rpms-used.$$ \
        --summary-log=$WEBROOT/$LOGDIR.html \
        --summary-title="Nightly Build Report `date +'%d %B %Y'`" \
        --rpm-url=file:///net/dtserv1.ireland/dtserv1/sgnome/buildenv$RPMSDIR \
        --srpm-url=file:///net/dtserv1.ireland/dtserv1/sgnome/buildenv$SRPMSDIR  > /tmp/build.log.$$ 2>&1

# the number of failed pkgs is returned
FAILED=$?

# rotate rpms dir
echo '' | rsh $RHOST -l $RUSER "rm -f $RPMSDIR.prev/*; rmdir $RPMSDIR.prev"
echo '' | rsh $RHOST -l $RUSER "mv $RPMSDIR $RPMSDIR.prev; mkdir -p $RPMSDIR"

# copy new rpms
echo '' | rcp `./build-gnome2 --nightly --date "$RELEASE_DATE" install-order \
    --full-path --target i586 \
    *.spec` $RUSER@$RHOST:$RPMSDIR

if [ -d /tmp/old-rpms-used.$$ ]; then
    echo '' | rcp /tmp/old-rpms-used.$$/*.rpm $RUSER@$RHOST:$RPMSDIR
    rm -rf /tmp/old-rpms-used.$$
fi

# rotate srpms dir
echo '' | rsh $RHOST -l $RUSER "rm -f $SRPMSDIR.prev/*; rmdir $SRPMSDIR.prev"
echo '' | rsh $RHOST -l $RUSER "mv $SRPMSDIR $SRPMSDIR.prev; mkdir -p $SRPMSDIR"
# copy new srpms
echo '' | rcp /usr/src/packages/SRPMS/*.$RELEASE_DATE.src.rpm \
	$RUSER@$RHOST:$SRPMSDIR

ALL_REPORTS=$WEBROOT/$WEBDIR/all_reports.html
touch $ALL_REPORTS

cp $ALL_REPORTS $ALL_REPORTS.old
export FAILED ALL_REPORTS

# update web page
( echo "<TR><TD><A HREF=/$LOGDIR.html>$DIR_DATE</A></TD>"; \
  echo "    <TD>$FAILED package(s) failed</TD></TR>"; \
  cat $ALL_REPORTS.old ) > $ALL_REPORTS

# send log by email
cat /tmp/build.log.$$ | \
    mail -s "JDS.next nightly build: $FAILED pkgs failed" \
         -R $REPLY_TO $EMAIL_ADDR

rm -f /tmp/build.log.$$

echo '' | rsh $RHOST -l $RUSER "rm $LOCKFILE"

exit 0