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

Last change on this file since 721 was 721, checked in by joergs, on Oct 2, 2008 at 5:16:21 PM

modify Version, instead of Release, because Release is set by openSUSE build service

  • Property svn:executable set to *
File size: 5.2 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 elif [ $SVN_LAST_MODIFICATION -ne $SVN_BUILD_RELEASE ]; then
62 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}p
63 else # check if RPM has been build already
64 # TODO: this chekc is broken for OpenSUSE build service,
65 # because version is changed later on
66 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-${VERSION}-${SVN_BUILD_RELEASE}.*.rpm
67 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
68 echo
69 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
70 echo
71 exit 1
72 fi
73 fi
74 if [ "$SVN_BUILD_RELEASE" ]; then
75 # Release will be overwritten bei OpenSUSE build service,
76 # therefore we add SVN_BUILD_RELEASE to Version
77 VERSION_ORIG=$VERSION
78 VERSION=$VERSION.$SVN_BUILD_RELEASE
79 #sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
80 #sed -r "s/^(Version:\s*\S*)/\1.$SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
81 sed "s/^Version:.*/Version: $VERSION/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
82 fi
83 echo "SVN_BUILD_RELEASE: $SVN_BUILD_RELEASE"
84
85 printf "adding subversion changelog: "
86 # changelog header
87 DATE=`unset LANG; date +"%a %b %d %Y"`
88 echo -e "* $DATE -\n" > Changes
89 echo "- Subversion status:" >> Changes
90 # additional infos for the Changes file (see if everything is checked in)
91 svn status -v | grep -v '^? ' >> Changes
92 echo >> Changes
93 echo "- ChangeLog:" >> Changes
94 # requires connection to the subversion server
95 svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
96 cat ChangeLog >> Changes
97
98 # if there is no changelog section in the spec file,
99 # also append the Changes there
100 if ! grep -q -i "%changelog" $SPECFILE ; then
101 # paste "Changes" into SPEC file.
102 echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
103 # without trailing *, except for the initial
104 echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
105 cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
106 fi
107 printf "done\n"
108 fi
109 # just make sure, that the Changes file exist
110 touch Changes
111
112 # if "SOURCES" file exist, create tar file on the fly
113 if [ -r "SOURCES" ]; then
114 # create a tar file from the sources
115 tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES --exclude .svn --exclude "*~"
116
117 elif [ -r "SPECSOURCES" ]; then
118 # SPECSOURCES has to list the files
119 # that are referenced in the .spec file
120 # these files are copied to the build environment
121 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
122
123 else
124 # legacy method:
125 # call the existing Makefile
126 # to generate a tar file
127 test -e Makefile && make
128 TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
129 cp -av $TARFILE ${BUILDTEMP}/src/${PACKAGE}
130 fi
131fi
Note: See TracBrowser for help on using the repository browser.