cron-script.sh
author dcarbery
Thu, 08 Mar 2007 11:23:50 +0000
changeset 9493 462f97685f62
parent 9465 b7231955b5f9
child 9648 6bed4d16d590
permissions -rwxr-xr-x
2007-03-08 Damien Carbery <[email protected]> * cron-script.sh: Add --with-apoc-adapter to pkgtool calls for SUNWfirefox.spec/firefox.spec updates.

#!/bin/bash

# Sample usage in crontab:
# Run, Mon-Fri at 1:30am. Add to build user's crontab.
#   30 1 * * 1-5 . /jds/cbe/bin/env.sh; cd /jds/spec-files; I_KNOW_WHAT_IM_DOING=yes ./cron-script.sh
#
# The same with a jail. Add to root's crontab. Example assumes 'gbuild' is the
# build user
#   30 1 * * 1-5 /usr/sbin/chroot /path/to/jail/root /usr/bin/su - gbuild -c ". /jds/cbe/bin/env.sh; cd /jds/spec-files; I_KNOW_WHAT_IM_DOING=yes ./cron-script.sh"
#
# $Id$


OSrel=`uname -r | cut -f2 -d.`
OSarch_full=`uname -p`
if [ "x$OSarch_full" = "xsparc" ]; then
    OSarch=s
else
    OSarch_full=x86
    OSarch=x
fi

PRODNAME="G2.18"

# directory to copy rpms/srpms to on the remote host
RPMSDIR=/sgnome/pkgs/gnome2.18/S${OSrel}${OSarch}/nightly
LOCKFILE=/sgnome/pkgs/gnome2.18/S${OSrel}${OSarch}/.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/gnome2.18/nightly/S${OSrel}${OSarch}
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"

#revert any local changes
svn revert -R .

# checkout-out SVN copy *MUST* be read-only, or "update" needs passwd
svn -q up > /dev/null 2>&1 || fatal_error "SVN update failed"
cd $SPECDIR

# 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

# uninstall all pkgs left behind by a previous build
pkgtool uninstall-pkgs --with-l10n --with-tjds --with-apoc-adapter closed/*.spec *.spec >/dev/null
# remove-gnome will now remove anything left from uninstall-pkgs in case
# or a packaging change for example
$SPECDIR/scripts/remove-gnome --version jds -q -f --no_extras > /dev/null 2>&1

rm -rf /jds/packages/PKGS/*
rm -rf /jds/packages/SPKGS/*
rm -rf /jds/packages/BUILD/*
rm -rf /var/tmp/pkgbuild-*/*

# 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 || exit 5

mkdir -p $RPMSDIR
touch $LOCKFILE

# Rebuild the manpage tarballs
cd $SPECDIR/manpages
make
cd $SPECDIR/po-sun
make clean
make
cd $SPECDIR

# start the build
pkgtool -v --nightly --date "$RELEASE_DATE" build  closed/SUNWevolution-bdb-devel.spec closed/*.spec *.spec \
        --logdir=$WEBROOT/$LOGDIR \
        --logdir-url=http://gnome.ireland/$LOGDIR \
	[email protected] \
        --prodname="${PRODNAME}/s${OSrel}${OSarch}" \
        --live --with-l10n --with-tjds --with-apoc-adapter \
        --define "nightly 1" \
        --summary-log=$WEBROOT/$LOGDIR.html \
        --summary-title="${PRODNAME} S${OSrel}/${OSarch_full} Nightly Build Report `date +'%d %B %Y'`" \
        --rpm-url=file:///net/dtserv1.ireland/dtserv1/sgnome/buildenv$RPMSDIR/all_pkgs \
         > /tmp/build.log.$$ 2>&1

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

# rotate rpms dir
rm -rf $RPMSDIR.prev
mv $RPMSDIR $RPMSDIR.prev; mkdir -p $RPMSDIR

# make dist
/sgnome/tools/re-scripts/jds-build/make-jds-dist.pl -l /sgnome/tools/re-scripts/jds-build/vermillion-devel.lst /jds/packages/PKGS /jds/dist nightly- > /dev/null 2>&1
cp -r /jds/dist/nightly-/${OSarch_full}/* /jds/dist/nightly-/${OSarch_full}/.??* $RPMSDIR
chmod a+x $RPMSDIR/install-jds
mkdir -p $RPMSDIR/all_pkgs
cd $RPMSDIR/all_pkgs
ln -s ../*/*.tar.gz .
# Disable deletion of nightly- dir as network area often full - this is backup.
#rm -rf /jds/dist/nightly-

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

# Report absolute symlinks. These are blockers for Solaris integration.
grep 'is an absolute symlink' $WEBROOT/$LOGDIR/*.log >>/tmp/build.log.$$

# Count the number of local patches.
patch_count=`ls $SPECDIR/patches/*.diff | wc -l`
echo "PATCH COUNT: $patch_count local patches used in this build.">>/tmp/build.log.$$

# send warnings, errors and summary in email
grep -v '^INFO:' /tmp/build.log.$$ | \
    mailx -s "${PRODNAME} S${OSrel} ${OSarch_full} nightly build: $FAILED pkgs failed" $EMAIL_ADDR

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

# Email Beijing team to begin downloading packages.
/usr/bin/echo "*Date: `date '+%Y-%m-%d'`*\n${PRODNAME} S${OSrel} ${OSarch_full} Development nightly build finished: dtserv1.ireland:/sgnome/buildenv${RPMSDIR}/download" | 
    mailx -s "${PRODNAME} S${OSrel} ${OSarch_full} Development nightly build: $FAILED pkgs failed" "[email protected]"


rm $LOCKFILE

# find any differences from the prototype files saved after the
# last milestone build
cd /jds/spec-files/prototypes/${OSarch_full}
for f in *.proto; do
    test -f /jds/packages/PKGMAPS/proto/$f || continue
    cmp -s $f /jds/packages/PKGMAPS/proto/$f && continue
    echo $f:
    diff $f /jds/packages/PKGMAPS/proto/$f
    echo
done > /tmp/proto-changes.$$

# if any diffs found mail the result to RE
test -s /tmp/proto-changes.$$ && {
    ( echo "Prototype changes found since the last milestone build:"
      echo
      cat /tmp/proto-changes.$$ ) | \
	  mailx -s "${PRODNAME} S${OSrel} ${OSarch_full} prototype changes" \
	  $EMAIL_ADDR
}

rm -f /tmp/proto-changes.$$

exit 0