checking in more of the rpm build system (is that it?)
[freeside.git] / rpm / build / native / build-from-cvs
1 #!/bin/sh
2 #
3 # Copyright 2008, Elirion, Inc.  All rights reserved.
4 # This software is licensed under the same terms as Freeside itself.
5 #
6 # This script builds SRPMs if the Freeside CVS contents have changed.
7 # It must have reference copies of the Freeside versions it builds.
8 # Each SRPM's "release" is set to the date & time the script is run.
9 # The version number is forced to the CVS version.  The version and release
10 # hard-coded in the last .spec file committed to CVS are NOT used.
11 #
12 source $HOME/freeside-cvs
13 RELEASE=`date +%Y%m%d%H%M%S`
14 QUIET_FLAG=
15 #FORCE_FLAG=0
16 FORCE_FLAG=1
17 #VERSIONS='1.7 1.9'
18 VERSIONS='1.7'
19
20 while getopts "fhqv:" flag
21 do
22         case $flag in
23                 f)
24                         echo "Force mode"
25                         FORCE_FLAG=1;;
26                 q)
27                         echo "Quiet mode"
28                         QUIET_FLAG=-q;;
29                 v)
30                         echo "Changing versions from $VERSIONS to $OPTARG"
31                         VERSIONS=$OPTARG;;
32                 *)
33                         usage;;
34         esac
35 done
36
37 usage() {
38         echo "build-from-cvs: build SRPMs if the Freeside CVS contents have changed"
39         echo "where:"
40         echo " -f: force building SRPMs even if CVS is unchanged"
41         echo " -h: print this usage information"
42         echo " -q: run quietly"
43         echo " -v <versions>: change versions (currently: $VERSIONS)"
44         exit 0
45 }
46
47 for VERSION in $VERSIONS; do
48         echo ${VERSION}
49         /bin/rm -rf ref-${VERSION}
50         cp -pr freeside-${VERSION} ref-${VERSION}
51         cd freeside-${VERSION}
52         cvs update -d -P
53         cd ..
54         diff -qr --exclude=CVS freeside-${VERSION} ref-${VERSION}
55         RETVAL=$?
56         if [ $FORCE_FLAG = 1 -o $RETVAL -gt 0 ]; then
57                 # Build the tarball with the modified .spec file in it, hard-coding the release into the .spec file
58                 cd freeside-${VERSION}
59                 for SPECFILE in install/rpm/freeside.spec rpm/freeside.spec; do
60                 if [ -f $SPECFILE ]; then
61                         cp -pf $SPECFILE ..
62                         perl -p -i -e "s/\d+[^\}]+/${VERSION}/ if /%define\s+version\s+(\d+[^\}]+)\}/;" ${SPECFILE}
63                         perl -pi -e "s/\$1/${RELEASE}/ if /%define\s+release\s+(\d+)/;" $SPECFILE
64                         tar zcvf $HOME/redhat/SOURCES/freeside-${VERSION}.tar.gz --exclude CVS ../freeside-${VERSION}
65                         mv -f ../`basename $SPECFILE` `dirname $SPECFILE`
66                 fi
67                 done
68                 cd ..
69                 rpmbuild -ts $HOME/redhat/SOURCES/freeside-${VERSION}.tar.gz
70                 # Could do a koji-build here
71                 # Or move the SRPM to a staging directory for the build machine to check
72                 # Should make the Bundles and check the dependencies for changes
73         fi
74         /bin/rm -rf ref-${VERSION}
75 done