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

Last change on this file since 727 was 727, checked in by joergs, on Oct 4, 2008 at 4:36:03 PM

added missing '-' for Changelog entry

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