10140N/A#!/bin/bash
10140N/A
10140N/A# Sample usage in crontab:
10140N/A# Run, Mon-Fri at 1:30am. Add to build user's crontab.
10140N/A# 30 1 * * 1-5 . /jds/cbe/bin/env.sh; I_KNOW_WHAT_IM_DOING=yes myEnv=nightly-beijing.env $0
10140N/A#
10140N/A# The same with a jail. Add to root's crontab. Example assumes 'gbuild' is the
10140N/A# build user
10140N/A# 30 1 * * 1-5 /usr/sbin/chroot /path/to/jail/root /usr/bin/su - gbuild -c ". /jds/cbe/bin/env.sh; I_KNOW_WHAT_IM_DOING=yes myEnv=nightly-beijing.env $0"
10140N/A#
10140N/A# Or - you may choose to only build a particular package
10140N/A# 30 1 * * 1-5 . /jds/cbe/bin/env.sh; thisSpec=SUNWTiff.spec I_KNOW_WHAT_IM_DOING=yes myEnv=nightly-beijing.env $0
10140N/A#
10140N/A# History:
10140N/A# --------
10140N/A#
10140N/A# Damien Carbery:
10140N/A# cron-script.sh, original script
10140N/A#
10140N/A# Alexandre Berman:
10140N/A# based on the original script, created cron-nightly.sh
10140N/A# added/changed features:
10140N/A# - added sub-routines for easy debugging, clarity
10140N/A# - changed to SVN (original script used cvs)
10140N/A# - took all site-dependent variable declarations out of the script and adopted it to use env file
10140N/A# - added support for building individual components (must specify spec file), useful for debugging and others..
10140N/A# - added more verbosity to the script for debugging and clarity
10140N/A
10140N/Aif [ -r $myEnv ]; then
10140N/A . $myEnv # setup our env
10140N/Aelse
10140N/A echo "-- ENV is NOT defined ! Exiting..."
10140N/A exit 1
10140N/Afi
10140N/A
10140N/A# host to rcp the rpms to
10140N/ARHOST="$RHOST"
10140N/A# user to rcp as (has to have root@<this host> in it's .rhosts file)
10140N/ARUSER="$RUSER"
10140N/A# other vars
10140N/ATEMP_DIR="$TEMP_DIR"
10140N/ASPECDIR="$SPECDIR"
10140N/ABUILD_BASE="$BUILD_BASE"
10140N/APRODNAME="$PRODNAME"
10140N/A# directory to copy rpms/srpms to on the remote host
10140N/ARPMSDIR="$RPMSDIR"
10140N/ALOCKFILE="$RPMSDIR/.build.lock"
10140N/A# reply-to/to address to send the build log as/to
10140N/AEMAIL_ERRORS_TO="$EMAIL_ERRORS_TO"
10140N/AEMAIL_NOTIFICATION="$EMAIL_NOTIFICATION"
10140N/A# document root of the web server
10140N/AWEBROOT="$WEBROOT"
10140N/ALOGDIR_BASE_URL="$LOGDIR_BASE_URL"
10140N/A# tarballsdir
10140N/ATARBALLSDIR="$TARBALLSDIR"
10140N/A# subdir to keep logs and reports on the webserver
10140N/AWEBDIR="$WEBDIR"
10140N/A
10140N/A# date format appended to the Release tag in the spec files
10140N/A# (passed to the date command on the cmd line)
10140N/ARELEASE_DATE_FMT="%y%m%d"
10140N/A# date format used for naming the directories
10140N/ADIR_DATE_FMT="%Y-%m-%d"
10140N/ARELEASE_DATE=`date +$RELEASE_DATE_FMT`
10140N/ADIR_DATE=`date +$DIR_DATE_FMT`
10140N/ALOGDIR="$WEBDIR/$DIR_DATE"
10140N/A
10140N/A# ------------ nothing to configure below this line --------------
10140N/A
10140N/Aif [ "x$I_KNOW_WHAT_IM_DOING" != xyes ]; then
10140N/A echo " ,---------------------------------------------------------------."
10140N/A echo "| This script is intended to be run from cron for producing |"
10140N/A echo "| official nightly builds (Beijing site). |"
10140N/A echo "| It will mail responsible engineers |"
10140N/A echo "| if any build failure occurs, sends build reports to |"
10140N/A echo "| RE and update web pages. |"
10140N/A echo "|"
10140N/A echo "| Don't run it unless you know what you are doing. Thanks."
10140N/A echo "|"
10140N/A echo "| Mail jdsbj-re@sun.com if you need more info."
10140N/A echo ".................................................................+"
10140N/A exit 1
10140N/Afi
10140N/A
10140N/AMYNAME="$0"
10140N/AMYDIR=$(cd `dirname $0`; pwd)
10140N/AshortName=`echo $MYNAME | sed -e 's|^.*\/||g'`
10140N/A
10140N/A# remove temporary files on exit
10140N/Aclean_up () {
10140N/A case "$MYNAME" in
10140N/A /tmp/$shortName.copy.* )
10140N/A rm -f $MYNAME
10140N/A ;;
10140N/A esac
10140N/A exit
10140N/A}
10140N/A
10140N/Atrap clean_up HUP INT TERM QUIT EXIT
10140N/A
10140N/A# make a copy of the cron script in /tmp and execute that in order to
10140N/A# avoid disasters caused by cvs update.
10140N/Acase "$MYNAME" in
10140N/A /tmp/*.copy.* )
10140N/A ;;
10140N/A *)
10140N/A cp $MYNAME /tmp/$shortName.copy.$$
10140N/A chmod 755 /tmp/$shortName.copy.$$
10140N/A cd /tmp
10140N/A exec /tmp/$shortName.copy.$$ "$MYDIR"
10140N/A ;;
10140N/Aesac
10140N/A
10140N/Afatal_error () {
10140N/A echo "ERROR: $*"
10140N/A exit 1
10140N/A}
10140N/A
10140N/A# prepare TEMP_DIR and repository - using SVN now
10140N/Aprep_repository() {
10140N/A if [ -d $SPECDIR ]; then
10140N/A cd $SPECDIR || fatal_error "$SPECDIR not found"
10140N/A echo "-- updating SVN rep ..."
10140N/A #revert any local changes
10140N/A svn revert -R .
10140N/A
10140N/A svn -q up > /dev/null 2>&1 || fatal_error "SVN update failed"
10140N/A else
10140N/A echo "-- checking out fresh copy of Spec files from SVN rep ..."
10140N/A rm -rf $TEMP_DIR
10140N/A mkdir $TEMP_DIR; cd $TEMP_DIR
10140N/A svn -q checkout svn://dtsvn.ireland.sun.com/sgnome/svn/repos/jds-spec-files/trunk \
10140N/A > /dev/null 2>&1 || fatal_error "SVN checkout failed"
10140N/A fi
10140N/A # if the script changed during repository update, restart with the updated script
10140N/A if ! /usr/bin/cmp -s $SPECDIR/$shortName $MYNAME; then exec $SPECDIR/$shortName; fi
10140N/A}
10140N/A
10140N/A
10140N/A# uninstall all pkgs left behind by a previous build
10140N/Ado_uninst() {
10140N/A echo "-- uninstalling packages..."
10140N/A pkgtool uninstall-pkgs --with-l10n --with-tjds $thisSpec >/dev/null
10140N/A # remove-gnome will now remove anything left from uninstall-pkgs in case
10140N/A # of a packaging change for example
10143N/A $SPECDIR/scripts/remove-gnome --version jds -q -f --no_extras > /dev/null 2>&1
10140N/A}
10140N/A
10140N/Ado_clean_pkgs() {
10140N/A rm -rf $BUILD_BASE/PKGS/*
10140N/A rm -rf $BUILD_BASE/SPKGS/*
10140N/A rm -rf $BUILD_BASE/BUILD/*
10140N/A rm -rf /var/tmp/*-build
10140N/A}
10140N/A
10140N/A# if the log directory exists, open a new one with numbered suffix
10140N/Ado_log_dir() {
10140N/A echo "-- setting up logs..."
10140N/A NEW_LOGDIR=$LOGDIR
10140N/A N=1
10140N/A while [ -d $WEBROOT/$NEW_LOGDIR ]; do
10140N/A NEW_LOGDIR=$LOGDIR.$N
10140N/A N=`expr $N + 1`
10140N/A echo "-- LOGDIR exists, changing to: $NEW_LOGDIR"
10140N/A done
10140N/A LOGDIR=$NEW_LOGDIR
10140N/A echo "-- LOGDIR: $WEBROOT/$LOGDIR"
10140N/A echo "-- LOGDIR URL: $LOGDIR_BASE_URL/$LOGDIR"
10140N/A mkdir -p $WEBROOT/$LOGDIR || exit 5
10140N/A}
10140N/A
10140N/A# start the build
10140N/Ado_build() {
10140N/A echo "-- build started, using log: /tmp/build.log.$$ ..."
10140N/A cd $SPECDIR || fatal_error "$SPECDIR not found"
10140N/A echo '' | rsh $RHOST -l $RUSER "mkdir -p $RPMSDIR; touch $LOCKFILE"
10140N/A pkgtool -v --nightly --date "$RELEASE_DATE" build $thisSpec \
10140N/A --logdir=$WEBROOT/$LOGDIR \
10140N/A --summary-log=$WEBROOT/$LOGDIR.html \
10140N/A --logdir-url=$LOGDIR_BASE_URL/$LOGDIR \
10140N/A --mail-errors-to=$EMAIL_ERRORS_TO \
10140N/A --prodname="${PRODNAME}/s${OSrel}${OSarch}" \
10140N/A --live --with-l10n --with-tjds \
10140N/A --norc \
10140N/A --tarballdirs=$TARBALLSDIR \
10140N/A --define "nightly 1" \
10140N/A --summary-title="${PRODNAME} S${OSrel}/${OSarch_full} Nightly Build Report `date +'%d %B %Y'`" \
10140N/A > /tmp/build.log.$$ 2>&1
10140N/A # --rpm-url=file:///net/allstar.prc$RPMSDIR/all_pkgs \
10140N/A # the number of failed pkgs is returned
10140N/A FAILED=$?; export FAILED
10140N/A}
10140N/A
10140N/A# choose what to build ?
10140N/A# coices are: everything or specific spec file
10140N/Achoose_build() {
10140N/A if [ "x$thisSpec" = "x" ]; then
10140N/A # no spec file was chosen, build everything
10143N/A thisSpec='*.spec closed/*.spec'; export thisSpec
10140N/A echo "-- building following components: $thisSpec"
10140N/A else
10140N/A # verify chosen spec file
10140N/A if [ ! -f $SPECDIR/$thisSpec ]; then
10140N/A fatal_error "chosen spec file ($thisSpec) does not exist in spec dir ($SPECDIR)"
10140N/A fi
10140N/A echo "-- building following components: $thisSpec"
10140N/A fi
10140N/A}
10140N/A
10140N/A# rotate rpms dir
10140N/Ado_rotate_rpms() {
10140N/A echo '' | rsh $RHOST -l $RUSER "rm -rf $RPMSDIR.prev; mv $RPMSDIR $RPMSDIR.prev; mkdir -p $RPMSDIR"
10140N/A}
10140N/A
10140N/A# make dist
10140N/Ado_make_dist() {
10140N/A echo "-- making dist ..."
10140N/A /sgnome/tools/re-scripts/jds-build/make-jds-dist /jds/packages/PKGS /jds/dist nightly- > /dev/null 2>&1
10140N/A echo '' | rcp -r /jds/dist/nightly-/${OSarch_full}/* /jds/dist/nightly-/${OSarch_full}/.??* ${RUSER}@${RHOST}:$RPMSDIR
10140N/A echo '' | rsh $RHOST -l $RUSER "chmod a+x $RPMSDIR/install-jds"
10140N/A echo '' | rsh $RHOST -l $RUSER "mkdir -p $RPMSDIR/all_pkgs && cd $RPMSDIR/all_pkgs && ln -s ../*/*.tar.gz ."
10140N/A rm -rf /jds/dist/nightly-
10140N/A}
10140N/A
10140N/A# web reports
10140N/Ado_web_reports() {
10140N/A ALL_REPORTS=$WEBROOT/$WEBDIR/all_reports.html
10140N/A echo "-- creating main report in: $ALL_REPORTS"
10140N/A touch $ALL_REPORTS
10140N/A cp $ALL_REPORTS $ALL_REPORTS.old
10140N/A export ALL_REPORTS
10140N/A # update web page
10140N/A ( echo "<A HREF=$LOGDIR_BASE_URL/$LOGDIR.html>$DIR_DATE</A> $FAILED package(s) failed<BR>"; \
10140N/A cat $ALL_REPORTS.old ) > $ALL_REPORTS
10140N/A}
10140N/A
10140N/A# send warnings, errors and summary in email
10140N/Ado_email() {
10140N/A grep -v '^INFO:' /tmp/build.log.$$ | \
10140N/A mailx -s "${PRODNAME} S${OSrel} ${OSarch_full} nightly build: $FAILED pkgs failed" $EMAIL_NOTIFICATION
10140N/A}
10140N/A
10140N/A# final cleanup
10140N/Ado_finally() {
10140N/A rm -f /tmp/build.log.$$
10140N/A echo '' | rsh $RHOST -l $RUSER "rm $LOCKFILE"
10140N/A}
10140N/A
10140N/A# let's do it
10140N/Achoose_build
10140N/Aprep_repository
10140N/Ado_uninst
10140N/Ado_clean_pkgs
10140N/Ado_log_dir
10140N/Ado_build
10140N/Ado_rotate_rpms
10140N/Ado_make_dist
10140N/Ado_web_reports
10140N/Ado_email
10140N/Ado_finally
10140N/A
10140N/Aexit 0