cron-script.sh
author laca
Wed, 30 Jul 2003 02:25:18 +0000
changeset 850 9cb957222a98
parent 786 164d94045f68
child 851 c38c68789066
permissions -rwxr-xr-x
added comments

#!/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/gnome-2.2/rpms/nightly
SRPMSDIR=/sgnome/pkgs/gnome-2.2/srpms/nightly

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

# date format used by the nightlies (passed to date on the cmd line)
DATE_FMT="%y%m%d"

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

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
}

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


DATE=`date +$DATE_FMT`

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/*/*

WEBROOT=/scde/web/docs
WEBDIR=gnome/releng/2.2/mercury/nightly
LOGDIR=$WEBDIR/`date +%Y-%m-%d`

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

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

# start the build
./build-gnome2 -v --nightly --date "$DATE" build *.spec \
        --logdir=$WEBROOT/$LOGDIR \
        --logdir-url=`date +%Y-%m-%d` \
        --good-build-dir=/sgnome/pkgs/gnome-2.2/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/sgnome/pkgs/gnome-2.2/rpms/nightly \
        --srpm-url=file:///net/dtserv1.ireland/dtserv1/sgnome/buildenv/sgnome/pkgs/gnome-2.2/srpms/nightly  > /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 "$DATE" install-order \
    --full-path \
    *.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/*.$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>`date +%Y-%m-%d`</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 "mercury nightly build: $FAILED pkgs failed" \
         -R $REPLY_TO $EMAIL_ADDR

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

exit 0