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

Last change on this file since 706 was 705, checked in by joergs, on Mar 16, 2005 at 10:55:13 AM

adapted to 9.2

  • Property svn:executable set to *
  • Property svn:keywords set to Id LastChangedDate LastChangedRevision
File size: 7.5 KB
RevLine 
[690]1#!/bin/bash
[694]2# build script
3#
[675]4# $Id: build.sh 705 2005-03-16 09:55:13Z 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
[619]45[ -z "$BUILD_MODE" ] && BUILD_MODE="--verify"
[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
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 ;;
[679]76 "9.1-i386")
77 BUILD_RPMS_TEST=$BUILD_RPMS_9_1_i386 ;;
[681]78 "sles9-i386")
79 BUILD_RPMS_TEST=$BUILD_RPMS_sles9_i386 ;;
[705]80 "9.2-i386")
81 BUILD_RPMS_TEST=$BUILD_RPMS_9_2_i386 ;;
[668]82 esac
83 if [ "$BUILD_RPMS_TEST" ]; then
84 if [ "$BUILD_RPMS" ]; then
85 BUILD_RPMS=$BUILD_RPMS:$BUILD_RPMS_TEST
86 else
87 BUILD_RPMS=$BUILD_RPMS_TEST
88 fi
89 fi
90fi
91
92echo BUILD_RPMS: $BUILD_RPMS
93
[619]94ERROR=0
[585]95
[621]96# Hier gehts los:
[620]97
98if [ -z "$1" ]; then
99 # without parameter, we are in source directory
100 SPECFILE=$(ls *.spec | awk '{print $1}')
101 PACKAGE=$(awk '/^Name:/ {print $2}' <$SPECFILE)
102 VERSION=$(awk '/^Version:/ {print $2}' <$SPECFILE)
103else
104 # parameter is src.rpm file
105 PACKAGE=`echo $1 | sed 's/-[0-9]*\..*.src.rpm//'`
106 VERSION=`echo $1 | sed 's/.*-\([0-9]*\..*\)-.*.src.rpm/\1/'`
107fi
108
[622]109echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
[585]110
[682]111rm -rf ${BUILDTEMP}/src/${PACKAGE};
[694]112mkdir -p ${BUILDTEMP}/src/${PACKAGE}
113# ${BUILDTEMP}/${BUILD_DIST};
[585]114
[620]115if [ "$1" ]; then
[695]116 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/`echo $1 | sed 's/\.src\./.*./'`
117 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
118 echo
119 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
120 echo
121 exit 1
122 else
123 cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
124 cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
125 fi
[682]126else
127 cp -a $SPECFILE ${BUILDTEMP}/src/${PACKAGE}
128
129 # uses Subversion (svn) to generate more information for the RPM
130 if [ "$BUILD_USES_SVN" = "yes" ]; then
131 echo "receiving subversion information ..."
132 # set RELEASE number (last modification in this directory)
133 # requires subversion (but connection to server isn't neccessary)
134 SVN_BUILD_RELEASE=$(svn info . | sed -n 's/^Last Changed Rev: \([0-9]*\)/\1/p')
[694]135 # in case of local modification a "m" is added to the release number
136 SVN_BUILD_MODIFIED=$(svn status -v | grep "^ *M" | wc -l)
[695]137 # checks if a file is commited,
138 # but update on its directory is not performed
139 SVN_LAST_MODIFICATION=$(svn status -v | sed -n 's/^ *[0-9]* *\([0-9]*\) .*/\1/p' | sort -n | tail -1)
140 if [ $SVN_BUILD_MODIFIED -gt 0 ]; then
[694]141 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}m
[695]142 elif [ $SVN_LAST_MODIFICATION -ne $SVN_BUILD_RELEASE ]; then
143 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}p
[694]144 else # check if RPM has been build already
145 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-${VERSION}-${SVN_BUILD_RELEASE}.*.rpm
146 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
147 echo
148 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
149 echo
[695]150 exit 1
[694]151 fi
152 fi
[682]153 if [ "$SVN_BUILD_RELEASE" ]; then
154 sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/g" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
155 fi
[683]156 # changelog header
157 DATE=`unset LANG; date +"%a %b %d %Y"`
158 echo -e "* $DATE -\n" > Changes
159 echo "- Subversion status:" >> Changes
[682]160 # additional infos for the Changes file (see if everything is checked in)
161 svn status -v | grep -v '^? ' >> Changes
162 echo >> Changes
[683]163 echo "- ChangeLog:" >> Changes
[682]164 # requires connection to the subversion server
165 svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
166 cat ChangeLog >> Changes
[684]167
168 # if there is no changelog section in the spec file,
169 # also append the Changes there
170 if ! grep -q "%changelog" $SPECFILE ; then
171 # paste "Changes" into SPEC file.
172 echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
173 # without trailing *, except for the initial
174 echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
175 cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
176 fi
[682]177 fi
178 # just make sure, that the Changes file exist
179 touch Changes
180
181 # if "SOURCES" file exist, create tar file on the fly
182 if [ -r "SOURCES" ]; then
183 # create a tar file from the sources
[701]184 tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES --exclude .svn --exclude "*~"
[690]185
186 elif [ -r "SPECSOURCES" ]; then
[701]187 # SPECSOURCES has to list the files
188 # that are referenced in the .spec file
189 # these files are copied to the build environment
[690]190 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
191
[682]192 else
193 # legacy method:
[701]194 # call the existing Makefile
195 # to generate a tar file
[682]196 test -e Makefile && make
197 TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
[690]198 cp -av $TARFILE ${BUILDTEMP}/src/${PACKAGE}
[682]199 fi
[620]200fi
201
[585]202# create buildscript
[668]203cat > $BUILDSCRIPT <<EOF
[585]204#!/bin/bash
205# local buildscript
206export BUILD_ROOT=$BUILD_ROOT
207export BUILD_DIST=$BUILD_DIST
[694]208export BUILD_RPMS=${DEST_DIR}/${BUILD_DIST}:$BUILD_RPMS
[586]209export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
210
[668]211cd ${BUILDTEMP}/src/${PACKAGE}
[677]212$BUILD_CMD $BUILD_MODE
[585]213EOF
[681]214
[668]215chmod a+x $BUILDSCRIPT
216sudo su -c $BUILDSCRIPT
217rm -f $BUILDSCRIPT
218
[585]219mkdir -p ${DEST_DIR}/src
[620]220# delete all old versions of this package
[695]221for i in ${DEST_DIR}/src/${PACKAGE}-*.src.rpm; do
222 if [ -f $i -a ${PACKAGE} = "`rpm -qp --qf "%{NAME}\n" $i`" ]; then
223 rm $i
224 fi
225done
226#rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
[682]227
[668]228if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
[695]229 ERROR=4
[619]230fi
[585]231
[619]232mkdir -p ${DEST_DIR}/${BUILD_DIST}
[620]233# delete all old versions of this package
[695]234for i in ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.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}/${BUILD_DIST}/${PACKAGE}-*.rpm
[682]240
[692]241if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}*${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
[695]242 ERROR=8
[591]243fi
244
[694]245echo
[619]246if [ $ERROR -ne 0 ]; then
[694]247
248 echo "ERROR while building packet $PACKAGE";
[619]249else
[694]250 echo "Build of \"${PACKAGE}\" completed!"
[619]251 echo "Packages can be found in ${DEST_DIR}"
[591]252fi
[694]253echo
[585]254
[619]255exit $ERROR
Note: See TracBrowser for help on using the repository browser.