# 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; I_KNOW_WHAT_IM_DOING=yes myEnv=nightly-beijing.env $0
#
# 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; I_KNOW_WHAT_IM_DOING=yes myEnv=nightly-beijing.env $0"
#
# Or - you may choose to only build a particular package
# 30 1 * * 1-5 . /jds/cbe/bin/env.sh; thisSpec=SUNWTiff.spec I_KNOW_WHAT_IM_DOING=yes myEnv=nightly-beijing.env $0
#
# History:
# --------
#
# Damien Carbery:
# cron-script.sh, original script
#
# Alexandre Berman:
# based on the original script, created cron-nightly.sh
# - added sub-routines for easy debugging, clarity
# - changed to SVN (original script used cvs)
# - took all site-dependent variable declarations out of the script and adopted it to use env file
# - added support for building individual components (must specify spec file), useful for debugging and others..
# - added more verbosity to the script for debugging and clarity
if [ -r $myEnv ]; then
. $myEnv # setup our env
else
echo "-- ENV is NOT defined ! Exiting..."
exit 1
fi
# host to rcp the rpms to
# user to rcp as (has to have root@<this host> in it's .rhosts file)
# other vars
# document root of the web server
# tarballsdir
# subdir to keep logs and reports on the webserver
# 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"
# ------------ 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 (Beijing site). |"
echo "| It will mail responsible engineers |"
echo "| if any build failure occurs, sends build reports to |"
echo "| RE and update web pages. |"
echo "|"
echo "| Don't run it unless you know what you are doing. Thanks."
echo "|"
echo "| Mail jdsbj-re@sun.com if you need more info."
echo ".................................................................+"
exit 1
fi
MYNAME="$0"
# remove temporary files on exit
/tmp/$shortName.copy.* )
;;
esac
exit
}
# make a copy of the cron script in /tmp and execute that in order to
# avoid disasters caused by cvs update.
;;
*)
cd /tmp
;;
esac
echo "ERROR: $*"
exit 1
}
# prepare TEMP_DIR and repository - using SVN now
if [ -d $SPECDIR ]; then
cd $SPECDIR || fatal_error "$SPECDIR not found"
echo "-- updating SVN rep ..."
#revert any local changes
svn -q up > /dev/null 2>&1 || fatal_error "SVN update failed"
else
echo "-- checking out fresh copy of Spec files from SVN rep ..."
> /dev/null 2>&1 || fatal_error "SVN checkout failed"
fi
# if the script changed during repository update, restart with the updated script
if ! /usr/bin/cmp -s $SPECDIR/$shortName $MYNAME; then exec $SPECDIR/$shortName; fi
}
# uninstall all pkgs left behind by a previous build
echo "-- uninstalling packages..."
# remove-gnome will now remove anything left from uninstall-pkgs in case
# of a packaging change for example
}
rm -rf $BUILD_BASE/PKGS/*
rm -rf $BUILD_BASE/SPKGS/*
rm -rf $BUILD_BASE/BUILD/*
}
# if the log directory exists, open a new one with numbered suffix
echo "-- setting up logs..."
N=1
while [ -d $WEBROOT/$NEW_LOGDIR ]; do
N=`expr $N + 1`
echo "-- LOGDIR exists, changing to: $NEW_LOGDIR"
done
echo "-- LOGDIR URL: $LOGDIR_BASE_URL/$LOGDIR"
}
# start the build
cd $SPECDIR || fatal_error "$SPECDIR not found"
--mail-errors-to=$EMAIL_ERRORS_TO \
--norc \
# --rpm-url=file:///net/allstar.prc$RPMSDIR/all_pkgs \
# the number of failed pkgs is returned
}
# choose what to build ?
# coices are: everything or specific spec file
# no spec file was chosen, build everything
echo "-- building following components: $thisSpec"
else
# verify chosen spec file
fatal_error "chosen spec file ($thisSpec) does not exist in spec dir ($SPECDIR)"
fi
echo "-- building following components: $thisSpec"
fi
}
# rotate rpms dir
}
# make dist
echo "-- making dist ..."
/sgnome/tools/re-scripts/jds-build/make-jds-dist /jds/packages/PKGS /jds/dist nightly- > /dev/null 2>&1
echo '' | rcp -r /jds/dist/nightly-/${OSarch_full}/* /jds/dist/nightly-/${OSarch_full}/.??* ${RUSER}@${RHOST}:$RPMSDIR
echo '' | rsh $RHOST -l $RUSER "mkdir -p $RPMSDIR/all_pkgs && cd $RPMSDIR/all_pkgs && ln -s ../*/*.tar.gz ."
}
# web reports
echo "-- creating main report in: $ALL_REPORTS"
export ALL_REPORTS
# update web page
}
# send warnings, errors and summary in email
mailx -s "${PRODNAME} S${OSrel} ${OSarch_full} nightly build: $FAILED pkgs failed" $EMAIL_NOTIFICATION
}
# final cleanup
}
# let's do it
exit 0