source: trunk/technical/common/build/build.sh@ 715

Last change on this file since 715 was 715, checked in by joergs, on Apr 3, 2006 at 3:12:31 PM

better determination of RPM PACKAGE Name and Version

  • Property svn:executable set to *
  • Property svn:keywords set to Id LastChangedDate LastChangedRevision
File size: 7.7 KB
Line 
1#!/bin/bash
2# build script
3#
4# $Id: build.sh 715 2006-04-03 13:12:31Z joergs $
5#
6# builds RPM in an clean chroot build environment.
7# uses the Suse build script.
8#
9# without parameter, it checks the directory for the files
10# SOURCES or SPECSOURCES.
11# The files definied in there are copied to the
12# build system.
13#
14# when used with parameter,
15# this parameter is expected to be a source rpm
16#
17# config file:
18# /usr/local/etc/build
19# lists the sources for the different distributions
20#
21# the rest is controlled by environment variables
22#
23# build.sh uses sudo su. /etc/sudoers needs a line like:
24# %users ALL=(ALL) NOPASSWD: /bin/su
25# for automatic building
26#
27# return codes:
28# 0: success
29# 1: skipped (current RPM already in dest dir)
30# >1: error
31#
32# RPM releases are set
33# to the svn version number of the project directory.
34# Modifiers are:
35# m: release + local modifications
36# p: release + submited modifications. svn update project directory is needed
37
38
39
40
41CONFIG_FILE=/usr/local/etc/build
42BUILD_CMD=build
43BUILDUSER=$USER
44
45[ -z "$BUILD_MODE" ] && BUILD_MODE="--clean"
46[ -z "$BUILD_DIST" ] && BUILD_DIST="sles9-i386"
47[ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
48[ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
49
50[ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
51BUILDTEMP=$DEST_DIR/buildsrc/
52BUILDSCRIPT=$BUILDTEMP/buildscript.$$
53
54[ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
55
56
57
58if [ -r $CONFIG_FILE ]; then
59 source $CONFIG_FILE
60 MOD_BUILD_DIST=`echo $BUILD_DIST | sed "s/[-+.]/_/g"`
61 #echo MOD_BUILD_DIST: $MOD_BUILD_DIST
62 #RPMS_PATHS=$[BUILD_RPMS_$MOD_BUILD_DIST]
63 #echo RPMS_PATHS: $RPM_PATHS
64 #if [ -n "$[BUILD_RPMS_$MOD_BUILD_DIST]" ]; then
65 # BUILD_RPMS=$[BUILD_RPMS_$MOD_BUILD_DIST]
66 #fi
67 #echo OUTPUT: $[BUILD_RPMS_$MOD_BUILD_DIST]
68 #:$BUILD_RPMS
69 case "$BUILD_DIST" in
70 "9.0-i386")
71 BUILD_RPMS_TEST=$BUILD_RPMS_9_0_i386 ;;
72 "sles8-i386")
73 BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386 ;;
74 "sles8-i386+update")
75 BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386_update ;;
76 "9.1-i386")
77 BUILD_RPMS_TEST=$BUILD_RPMS_9_1_i386 ;;
78 "sles9-i386")
79 BUILD_RPMS_TEST=$BUILD_RPMS_sles9_i386 ;;
80 "9.2-i386")
81 BUILD_RPMS_TEST=$BUILD_RPMS_9_2_i386 ;;
82 "9.3-i386")
83 BUILD_RPMS_TEST=$BUILD_RPMS_9_3_i386 ;;
84 "10.0-i386")
85 BUILD_RPMS_TEST=$BUILD_RPMS_10_0_i386 ;;
86 esac
87 if [ "$BUILD_RPMS_TEST" ]; then
88 if [ "$BUILD_RPMS" ]; then
89 BUILD_RPMS=$BUILD_RPMS:$BUILD_RPMS_TEST
90 else
91 BUILD_RPMS=$BUILD_RPMS_TEST
92 fi
93 fi
94fi
95
96echo BUILD_RPMS: $BUILD_RPMS
97
98ERROR=0
99
100# Hier gehts los:
101
102if [ -z "$1" ]; then
103 # without parameter, we are in source directory
104 SPECFILE=$(ls *.spec | awk '{print $1}')
105 PACKAGE=$(awk '/^Name:/ {print $2}' <$SPECFILE)
106 VERSION=$(awk '/^Version:/ {print $2}' <$SPECFILE)
107elif [ -r "$1" ]; then
108 # parameter is src.rpm file
109 PACKAGE=`rpm -qp --qf "%{NAME}" $1`
110 VERSION=`rpm -qp --qf "%{VERSION}" $1`
111fi
112
113echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
114
115if [ -z "$PACKAGE" ]; then
116 echo "nothing to build found!"
117 exit 1
118fi
119
120
121
122rm -rf ${BUILDTEMP}/src/${PACKAGE};
123mkdir -p ${BUILDTEMP}/src/${PACKAGE}
124# ${BUILDTEMP}/${BUILD_DIST};
125
126if [ "$1" ]; then
127 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/`echo $1 | sed 's/\.src\./.*./'`
128 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
129 echo
130 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
131 echo
132 exit 1
133 else
134 cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
135 cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
136 fi
137else
138 cp -a $SPECFILE ${BUILDTEMP}/src/${PACKAGE}
139
140 # uses Subversion (svn) to generate more information for the RPM
141 if [ "$BUILD_USES_SVN" = "yes" ]; then
142 echo "receiving subversion information ..."
143 # set RELEASE number (last modification in this directory)
144 # requires subversion (but connection to server isn't neccessary)
145 SVN_BUILD_RELEASE=$(unset LANG; svn info . | sed -n 's/^Last Changed Rev: \([0-9]*\)/\1/p')
146 # in case of local modification a "m" is added to the release number
147 SVN_BUILD_MODIFIED=$(svn status -v | grep "^ *M" | wc -l)
148 # checks if a file is commited,
149 # but update on its directory is not performed
150 SVN_LAST_MODIFICATION=$(svn status -v | sed -n 's/^ *[0-9]* *\([0-9]*\) .*/\1/p' | sort -n | tail -1)
151 if [ $SVN_BUILD_MODIFIED -gt 0 ]; then
152 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}m
153 elif [ $SVN_LAST_MODIFICATION -ne $SVN_BUILD_RELEASE ]; then
154 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}p
155 else # check if RPM has been build already
156 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-${VERSION}-${SVN_BUILD_RELEASE}.*.rpm
157 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
158 echo
159 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
160 echo
161 exit 1
162 fi
163 fi
164 if [ "$SVN_BUILD_RELEASE" ]; then
165 sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/g" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
166 fi
167 echo "SVN_BUILD_RELEASE: $SVN_BUILD_RELEASE"
168
169 # changelog header
170 DATE=`unset LANG; date +"%a %b %d %Y"`
171 echo -e "* $DATE -\n" > Changes
172 echo "- Subversion status:" >> Changes
173 # additional infos for the Changes file (see if everything is checked in)
174 svn status -v | grep -v '^? ' >> Changes
175 echo >> Changes
176 echo "- ChangeLog:" >> Changes
177 # requires connection to the subversion server
178 svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
179 cat ChangeLog >> Changes
180
181 # if there is no changelog section in the spec file,
182 # also append the Changes there
183 if ! grep -q "%changelog" $SPECFILE ; then
184 # paste "Changes" into SPEC file.
185 echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
186 # without trailing *, except for the initial
187 echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
188 cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
189 fi
190 fi
191 # just make sure, that the Changes file exist
192 touch Changes
193
194 # if "SOURCES" file exist, create tar file on the fly
195 if [ -r "SOURCES" ]; then
196 # create a tar file from the sources
197 tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES --exclude .svn --exclude "*~"
198
199 elif [ -r "SPECSOURCES" ]; then
200 # SPECSOURCES has to list the files
201 # that are referenced in the .spec file
202 # these files are copied to the build environment
203 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
204
205 else
206 # legacy method:
207 # call the existing Makefile
208 # to generate a tar file
209 test -e Makefile && make
210 TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
211 cp -av $TARFILE ${BUILDTEMP}/src/${PACKAGE}
212 fi
213fi
214
215# create buildscript
216cat > $BUILDSCRIPT <<EOF
217#!/bin/bash
218# local buildscript
219export BUILD_ROOT=$BUILD_ROOT
220export BUILD_DIST=$BUILD_DIST
221export BUILD_RPMS=${DEST_DIR}/${BUILD_DIST}:$BUILD_RPMS
222export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
223
224cd ${BUILDTEMP}/src/${PACKAGE}
225$BUILD_CMD $BUILD_MODE
226EOF
227
228chmod a+x $BUILDSCRIPT
229sudo su -c $BUILDSCRIPT
230rm -f $BUILDSCRIPT
231
232mkdir -p ${DEST_DIR}/src
233# delete all old versions of this package
234for i in ${DEST_DIR}/src/${PACKAGE}-*.src.rpm; do
235 if [ -f $i -a ${PACKAGE} = "`rpm -qp --qf "%{NAME}\n" $i`" ]; then
236 rm $i
237 fi
238done
239#rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
240
241if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
242 ERROR=4
243fi
244
245mkdir -p ${DEST_DIR}/${BUILD_DIST}
246# delete all old versions of this package
247for i in ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm; do
248 if [ -f $i -a ${PACKAGE} = "`rpm -qp --qf "%{NAME}\n" $i`" ]; then
249 rm $i
250 fi
251done
252#rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
253
254if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}*${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
255 ERROR=8
256fi
257
258echo
259if [ $ERROR -ne 0 ]; then
260
261 echo "ERROR while building packet $PACKAGE";
262else
263 echo "Build of \"${PACKAGE}\" completed!"
264 echo "Packages can be found in ${DEST_DIR}"
265fi
266echo
267
268exit $ERROR
Note: See TracBrowser for help on using the repository browser.