source: trunk/technical/common/build/svn_build_prepare.sh@ 723

Last change on this file since 723 was 723, checked in by joergs, on Oct 2, 2008 at 5:51:33 PM

trying to avoid new version for the build server, when nothing has changed. Unfortunally, transfering data to the build server (tar.bz2) changes the file, resulting in a new commit every time the script is called.

  • Property svn:executable set to *
File size: 5.3 KB
Line 
1#!/bin/bash
2
3# build prepare script
4
5# $Id$
6
7BUILDUSER=$USER
8[ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
9BUILDTEMP=$DEST_DIR/buildsrc/
10
11[ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
12
13if [ -z "$1" ]; then
14 # without parameter, we are in source directory
15 SPECFILE=$(ls *.spec | awk '{print $1}')
16 PACKAGE=$(sed -n -e 's/^Name:\W*//pi' <$SPECFILE)
17 VERSION=$(sed -n -e 's/^Version:\W*//pi' <$SPECFILE)
18elif [ -r "$1" ]; then
19 # parameter is src.rpm file
20 PACKAGE=`rpm -qp --qf "%{NAME}" $1`
21 VERSION=`rpm -qp --qf "%{VERSION}" $1`
22fi
23
24
25if [ -z "$PACKAGE" ]; then
26 echo "nothing to build found!"
27 exit 1
28fi
29
30rm -rf ${BUILDTEMP}/src/${PACKAGE}
31mkdir -p ${BUILDTEMP}/src/${PACKAGE}
32
33
34if [ "$1" ]; then
35 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/`echo $1 | sed 's/\.src\./.*./'`
36 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
37 echo
38 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
39 echo
40 exit 1
41 else
42 cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
43 cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
44 fi
45else
46 cp -a $SPECFILE ${BUILDTEMP}/src/${PACKAGE}
47
48 # uses Subversion (svn) to generate more information for the RPM
49 if [ "$BUILD_USES_SVN" = "yes" ]; then
50 echo "receiving subversion information ..."
51 # set RELEASE number (last modification in this directory)
52 # requires subversion (but connection to server isn't neccessary)
53 SVN_BUILD_RELEASE=$(unset LANG; svn info . | sed -n 's/^Last Changed Rev: \([0-9]*\)/\1/p')
54 # in case of local modification a "m" is added to the release number
55 SVN_BUILD_MODIFIED=$(svn status -v | grep "^ *M" | wc -l)
56 # checks if a file is commited,
57 # but update on its directory is not performed
58 SVN_LAST_MODIFICATION=$(svn status -v | sed -n 's/^ *[0-9]* *\([0-9]*\) .*/\1/p' | sort -n | tail -1)
59 if [ $SVN_BUILD_MODIFIED -gt 0 ]; then
60 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}m
61 REBUILD="yes"
62 elif [ $SVN_LAST_MODIFICATION -ne $SVN_BUILD_RELEASE ]; then
63 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}p
64 REBUILD="yes"
65 else # check if RPM has been build already
66 # TODO: this chekc is broken for OpenSUSE build service,
67 # because version is changed later on
68 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-${VERSION}-${SVN_BUILD_RELEASE}.*.rpm
69 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
70 echo
71 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
72 echo
73 exit 1
74 fi
75 fi
76 if [ "$SVN_BUILD_RELEASE" ]; then
77 # Release will be overwritten bei OpenSUSE build service,
78 # therefore we add SVN_BUILD_RELEASE to Version
79 VERSION_ORIG=$VERSION
80 VERSION=$VERSION.$SVN_BUILD_RELEASE
81 #sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
82 #sed -r "s/^(Version:\s*\S*)/\1.$SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
83 sed "s/^Version:.*/Version: $VERSION/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
84 fi
85 echo "SVN_BUILD_RELEASE: $SVN_BUILD_RELEASE"
86
87 printf "adding subversion changelog: "
88 # changelog header
89 DATE=`unset LANG; date +"%a %b %d %Y"`
90 echo -e "* $DATE -\n" > Changes
91 echo "- Subversion status:" >> Changes
92 # additional infos for the Changes file (see if everything is checked in)
93 svn status -v | grep -v '^? ' >> Changes
94 echo >> Changes
95 echo "- ChangeLog:" >> Changes
96 # requires connection to the subversion server
97 svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
98 cat ChangeLog >> Changes
99
100 # if there is no changelog section in the spec file,
101 # also append the Changes there
102 if ! grep -q -i "%changelog" $SPECFILE ; then
103 # paste "Changes" into SPEC file.
104 echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
105 # without trailing *, except for the initial
106 echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
107 cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
108 fi
109 printf "done\n"
110 fi
111 # just make sure, that the Changes file exist
112 touch Changes
113
114 # if "SOURCES" file exist, create tar file on the fly
115 if [ -r "SOURCES" ]; then
116 # create a tar file from the sources
117 printf "creating $PACKAGE-$VERSION.tar.bz2:\n"
118 tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES --exclude .svn --exclude "*~"
119
120 elif [ -r "SPECSOURCES" ]; then
121 # SPECSOURCES has to list the files
122 # that are referenced in the .spec file
123 # these files are copied to the build environment
124 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
125
126 else
127 # legacy method:
128 # call the existing Makefile
129 # to generate a tar file
130 test -e Makefile && make
131 TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
132 cp -av $TARFILE ${BUILDTEMP}/src/${PACKAGE}
133 fi
134fi
Note: See TracBrowser for help on using the repository browser.