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