Home | History | Annotate | Download | only in trunk
      1 #!/bin/bash
      2 
      3 # Sample usage in crontab:
      4 # Run, Mon-Fri at 1:30am. Add to build user's crontab.
      5 #   30 1 * * 1-5 . /jds/cbe/bin/env.sh; cd /jds/spec-files; I_KNOW_WHAT_IM_DOING=yes ./cron-script.sh
      6 #
      7 # The same with a jail. Add to root's crontab. Example assumes 'gbuild' is the
      8 # build user
      9 #   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"
     10 #
     11 # $Id: cron-script.sh 15365 2008-09-11 06:45:32Z davelam $
     12 
     13 
     14 # Determine whether to do debug or non-debug build.
     15 # On 'even' days of the week (Sun, Tues, Thur, Sat) to a debug build.
     16 DEBUG_BUILD=
     17 DEBUG_DIR=
     18 DOW=$[ $(date +"%w") % 2 ]
     19 #if [ $DOW -eq "0" ]; then
     20 #  DEBUG_BUILD="--with-debug"
     21 #  DEBUG_DIR=.dbg
     22 #fi
     23 
     24 OSrel=`uname -r | cut -f2 -d.`
     25 OSarch_full=`uname -p`
     26 if [ "x$OSarch_full" = "xsparc" ]; then
     27     OSarch=s
     28 else
     29     OSarch_full=x86
     30     OSarch=x
     31 fi
     32 
     33 PRODNAME="G2.24"
     34 
     35 # directory to copy rpms/srpms to on the remote host
     36 RPMSDIR=/sgnome/pkgs/gnome2.24/S${OSrel}${OSarch}/nightly${DEBUG_DIR}
     37 LOCKFILE=/sgnome/pkgs/gnome2.24/S${OSrel}${OSarch}/.build.lock
     38 
     39 # reply-to/to address to send the build log as/to
     40 REPLY_TO=laszlo.peter@sun.com
     41 EMAIL_ADDR=gnome-re@sun.com
     42 
     43 # date format appended to the Release tag in the spec files
     44 # (passed to the date command on the cmd line)
     45 RELEASE_DATE_FMT="%y%m%d"
     46 
     47 # date format used for naming the directories
     48 DIR_DATE_FMT="%Y-%m-%d"
     49 
     50 RELEASE_DATE=`date +$RELEASE_DATE_FMT`
     51 DIR_DATE=`date +$DIR_DATE_FMT`
     52 
     53 # document root of the web server
     54 WEBROOT=/net/jdsserv.ireland/webroots/jds.ireland/htdocs
     55 
     56 # subdir to keep logs and reports on the webserver
     57 WEBDIR=build_reports/gnome2.24/nightly/S${OSrel}${OSarch}
     58 LOGDIR=$WEBDIR/$DIR_DATE
     59 
     60 # ------------ nothing to configure below this line --------------
     61 
     62 if [ "x$I_KNOW_WHAT_IM_DOING" != xyes ]; then
     63     echo " ,---------------------------------------------------------------."
     64     echo "| This script is intended to be run from cron for producing      |"
     65     echo "| official nightly builds. It will mail responsible engineers    |"
     66     echo "| if any build failure occurs, sends build reports to            v"
     67     echo "| RE and update web pages."
     68     echo "|"
     69     echo "| Don't run it unless you know what you are doing. Thanks."
     70     echo "|"
     71     echo "| Mail gnome-re (at] sun.com if you need more info."
     72     echo "\`------>                                                         +"
     73     exit 1
     74 fi
     75 
     76 MYNAME="$0"
     77 MYDIR=$(cd `dirname $0`; pwd)
     78 
     79 if [ "x$1" != x ]; then
     80     SPECDIR="$1"
     81 else
     82     SPECDIR="$MYDIR"
     83 fi
     84 
     85 # remove temporary files on exit
     86 clean_up () {
     87   case "$MYNAME" in
     88   /tmp/cron-script.copy.* )
     89         rm -f $MYNAME
     90         ;;
     91   esac
     92   exit
     93 }
     94 
     95 trap clean_up HUP INT TERM QUIT EXIT
     96 
     97 # make a copy of the cron script in /tmp and execute that in order to
     98 # avoid disasters caused by cvs update.
     99 case "$MYNAME" in
    100     /tmp/cron-script.copy.* )
    101         ;;
    102     *)
    103         cp $MYNAME /tmp/cron-script.copy.$$
    104         chmod 755 /tmp/cron-script.copy.$$
    105         cd /tmp
    106         exec /tmp/cron-script.copy.$$ "$MYDIR"
    107         ;;
    108 esac
    109 
    110 fatal_error () {
    111   echo "ERROR: $*"
    112   exit 1
    113 }
    114 
    115 # Update spec-files-other files and uninstall packages.
    116 cd $SPECDIR/../spec-files-other
    117 
    118 # Revert any local changes
    119 svn revert -R .
    120 
    121 # checkout-out SVN copy *MUST* be read-only, or "update" needs passwd
    122 svn -q up > /dev/null 2>&1 || fatal_error "SVN update of spec-files-other failed"
    123 
    124 # Uninstall the spec-files-other packages.
    125 pkgtool uninstall-pkgs --with-l10n --with-sun-branding core/*.spec experimental/*.spec l10n/*.spec
    126 
    127 # Uninstall and cleanup spec-files packages.
    128 cd $SPECDIR || fatal_error "$SPECDIR not found"
    129 
    130 #revert any local changes
    131 svn revert -R .
    132 
    133 # checkout-out SVN copy *MUST* be read-only, or "update" needs passwd
    134 svn -q up > /dev/null 2>&1 || fatal_error "SVN update failed"
    135 
    136 # change some components to use Sun Studio 12 to 
    137 # workaround the compiler related issue
    138 ss12_env_fl=/home/gbuild/dave/env.sh.ss12.cconly
    139 ss12_specs="SUNWfirefox.spec
    140 SUNWPython25.spec
    141 ../spec-files-other/core/SUNWbrasero.spec"
    142 if [ -f $ss12_env_fl ]; then
    143     cd $SPECDIR
    144     IFS_save=$IFS
    145     IFS="
    146 "
    147     for spec in $ss12_specs; do
    148         sed -e "/^%build/a\\
    149 source $ss12_env_fl" \
    150             -e "/^%install/a\\
    151 source $ss12_env_fl" $spec > ${spec}.tmp.$$
    152         mv ${spec}.tmp.$$ $spec 
    153     done
    154     IFS=$IFS_save
    155 fi
    156 
    157 # if the script changed during cvs update, restart with the updated script
    158 cd $SPECDIR
    159 if ! /usr/bin/cmp -s ./cron-script.sh $MYNAME; then exec ./cron-script.sh; fi
    160 
    161 # uninstall all pkgs left behind by a previous build
    162 pkgtool uninstall-pkgs --with-l10n --with-sun-branding --with-lcms closed/*.spec *.spec >/dev/null
    163 # remove-gnome will now remove anything left from uninstall-pkgs in case
    164 # or a packaging change for example
    165 $SPECDIR/scripts/remove-gnome --version jds -q -f --no_extras > /dev/null 2>&1
    166 
    167 
    168 rm -rf /jds/packages/PKGS/*
    169 rm -rf /jds/packages/SPKGS/*
    170 rm -rf /jds/packages/BUILD/*
    171 rm -rf /var/tmp/pkgbuild-*/*
    172 
    173 # if the log directory exists, open a new one with numbered suffix
    174 NEW_LOGDIR=$LOGDIR
    175 N=1
    176 while [ -d $WEBROOT/$NEW_LOGDIR ]; do
    177     NEW_LOGDIR=$LOGDIR.$N
    178     N=`expr $N + 1`
    179 done
    180 
    181 LOGDIR=$NEW_LOGDIR
    182 mkdir -p $WEBROOT/$LOGDIR || exit 5
    183 
    184 mkdir -p $RPMSDIR
    185 touch $LOCKFILE
    186 
    187 # Rebuild the manpage tarballs
    188 cd $SPECDIR
    189 rm -r po-sun/po-sun-tarballs manpages/sun-manpage-tarballs
    190 make 
    191 cd $SPECDIR/../spec-files-other/manpages
    192 rm -r sun-manpage-tarballs
    193 make
    194 
    195 cd $SPECDIR
    196 
    197 # start the build
    198 pkgtool -v --nightly --date "$RELEASE_DATE" build  closed/SUNWevolution-bdb-devel.spec closed/*.spec *.spec \
    199         --logdir=$WEBROOT/$LOGDIR \
    200         --logdir-url=http://jds.ireland/$LOGDIR \
    201 	--mail-errors-to=gnome-2-10-build-reports (at] sun.com \
    202         --prodname="${PRODNAME}/s${OSrel}${OSarch}" \
    203         --live --with-l10n --with-moz-nss-nspr ${DEBUG_BUILD} \
    204         --define "nightly 1" --with-sun-branding --with-lcms --with-moz-nss-nspr \
    205         --summary-log=$WEBROOT/$LOGDIR.html \
    206         --summary-title="${PRODNAME} S${OSrel}/${OSarch_full} Nightly Build Report `date +'%d %B %Y'`" \
    207         --rpm-url=file:///net/jdsserv.ireland/$RPMSDIR/all_pkgs \
    208          > /tmp/build.log.$$ 2>&1
    209 
    210 # the number of failed pkgs is returned
    211 FAILED=$?
    212 
    213 # Build spec-files-other
    214 cd $SPECDIR/../spec-files-other
    215 
    216 pkgtool -v --nightly --date "$RELEASE_DATE" build core/*.spec experimental/*.spec l10n/*.spec \
    217         --logdir=$WEBROOT/$LOGDIR \
    218         --logdir-url=http://jds.ireland/$LOGDIR \
    219 	--mail-errors-to=gnome-2-10-build-reports (at] sun.com \
    220         --prodname="${PRODNAME}/s${OSrel}${OSarch}" \
    221         --live --with-l10n ${DEBUG_BUILD} \
    222         --define "nightly 1" --with-sun-branding \
    223         --summary-log=$WEBROOT/$LOGDIR-other.html \
    224         --summary-title="${PRODNAME} S${OSrel}/${OSarch_full} SFO Nightly Build Report `date +'%d %B %Y'`" \
    225         --rpm-url=file:///net/jdsserv.ireland/$RPMSDIR/all_pkgs \
    226          >> /tmp/build.log.$$ 2>&1
    227 
    228 # The number of failed pkgs is returned
    229 FAILED_OTHER=$?
    230 # End spec-files-other build.
    231 
    232 # rotate rpms dir
    233 rm -rf $RPMSDIR.prev
    234 mv $RPMSDIR $RPMSDIR.prev; mkdir -p $RPMSDIR
    235 
    236 # make dist
    237 /sgnome/tools/re-scripts/jds-build/make-jds-dist.pl -l /sgnome/tools/re-scripts/jds-build/vermillion-devel.lst --nightly /jds/packages/PKGS /jds/dist nightly- > /dev/null 2>&1
    238 cp -r /jds/dist/nightly-/${OSarch_full}/* /jds/dist/nightly-/${OSarch_full}/.??* $RPMSDIR
    239 chmod a+x $RPMSDIR/install-jds
    240 mkdir -p $RPMSDIR/all_pkgs
    241 cd $RPMSDIR/all_pkgs
    242 ln -s ../*/*.tar.gz .
    243 rm -rf /jds/dist/nightly-
    244 
    245 # Send output of make-jds-dist.pl to GNOME RE for review.
    246 /sgnome/tools/re-scripts/jds-build/make-jds-dist.pl -l /sgnome/tools/re-scripts/jds-build/vermillion-devel.lst --nightly /jds/packages/PKGS /jds/dist nightly- -dryrun 2>&1 | \
    247     mailx -s "${PRODNAME} S${OSrel} ${OSarch_full} nightly build: make-jds-dist.pl output" "gnome-re@sun.com"
    248 
    249 ALL_REPORTS=$WEBROOT/$WEBDIR/all_reports.html
    250 touch $ALL_REPORTS
    251 
    252 cp $ALL_REPORTS $ALL_REPORTS.old
    253 export FAILED FAILED_OTHER ALL_REPORTS
    254 
    255 # update web page
    256 ( echo "<tr><td><a href=/$LOGDIR.html>$DIR_DATE</a></td>"; \
    257   echo "    <td>$FAILED package(s) failed</td></tr>"; \
    258   echo "<tr><td><a href=/$LOGDIR-other.html>$DIR_DATE</a></td>"; \
    259   echo "    <td>$FAILED_OTHER SFO package(s) failed</td></tr>"; \
    260   cat $ALL_REPORTS.old ) > $ALL_REPORTS
    261 
    262 # Report absolute symlinks. These are blockers for Solaris integration.
    263 grep 'is an absolute symlink' $WEBROOT/$LOGDIR/*.log >>/tmp/build.log.$$
    264 
    265 # Count the number of local patches.
    266 patch_count=`ls $SPECDIR/patches/*.diff | wc -l`
    267 echo "PATCH COUNT: $patch_count local patches used in this build.">>/tmp/build.log.$$
    268 
    269 # send warnings, errors and summary in email
    270 grep -v '^INFO:' /tmp/build.log.$$ | \
    271     mailx -s "${PRODNAME} S${OSrel} ${OSarch_full} nightly build: $FAILED pkgs failed" $EMAIL_ADDR
    272 
    273 rm -f /tmp/build.log.$$
    274 
    275 # Email Beijing team to begin downloading packages.
    276 /usr/bin/echo "*Date: `date '+%Y-%m-%d'`*\n${PRODNAME} S${OSrel} ${OSarch_full} Development nightly build finished: jdsserv.ireland:${RPMSDIR}/download" | 
    277     mailx -s "${PRODNAME} S${OSrel} ${OSarch_full} Development nightly build: $FAILED pkgs failed" "sunop@triathlon.prc.sun.com,sunop@mhw.prc.sun.com"
    278 
    279 
    280 rm $LOCKFILE
    281 
    282 # find any differences from the prototype files saved after the
    283 # last milestone build
    284 cd /jds/spec-files/prototypes/${OSarch_full}
    285 for f in *.proto; do
    286     test -f /jds/packages/PKGMAPS/proto/$f || continue
    287     cmp -s $f /jds/packages/PKGMAPS/proto/$f && continue
    288     echo $f:
    289     diff $f /jds/packages/PKGMAPS/proto/$f
    290     echo
    291 done > /tmp/proto-changes.$$
    292 
    293 # if any diffs found mail the result to RE
    294 test -s /tmp/proto-changes.$$ && {
    295     ( echo "Prototype changes found since the last milestone build:"
    296       echo
    297       cat /tmp/proto-changes.$$ ) | \
    298 	  mailx -s "${PRODNAME} S${OSrel} ${OSarch_full} prototype changes" \
    299 	  $EMAIL_ADDR
    300 }
    301 
    302 rm -f /tmp/proto-changes.$$
    303 
    304 exit 0
    305