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

Last change on this file since 719 was 719, checked in by joergs, on Oct 2, 2008 at 1:51:24 PM

bugfix: grep case insensitive changelog entry

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