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

Last change on this file since 694 was 694, checked in by joergs, on Nov 21, 2004 at 9:00:02 PM

reduced the number of uses directories
buildall and build now uses the same dest directory
added comments
code cleanup
checks if rpm is already available in current release

  • Property svn:executable set to *
  • Property svn:keywords set to Id LastChangedDate LastChangedRevision
File size: 6.4 KB
Line 
1#!/bin/bash
2# build script
3#
4# $Id: build.sh 694 2004-11-21 20:00:02Z 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
27CONFIG_FILE=/usr/local/etc/build
28BUILD_CMD=build
29BUILDUSER=$USER
30
31[ -z "$BUILD_MODE" ] && BUILD_MODE="--verify"
32[ -z "$BUILD_DIST" ] && BUILD_DIST="9.1-i386"
33[ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
34[ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
35
36[ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
37BUILDTEMP=$DEST_DIR/buildsrc/
38BUILDSCRIPT=$BUILDTEMP/buildscript.$$
39
40[ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
41
42
43
44if [ -r $CONFIG_FILE ]; then
45 source $CONFIG_FILE
46 MOD_BUILD_DIST=`echo $BUILD_DIST | sed "s/[-+.]/_/g"`
47 #echo MOD_BUILD_DIST: $MOD_BUILD_DIST
48 #RPMS_PATHS=$[BUILD_RPMS_$MOD_BUILD_DIST]
49 #echo RPMS_PATHS: $RPM_PATHS
50 #if [ -n "$[BUILD_RPMS_$MOD_BUILD_DIST]" ]; then
51 # BUILD_RPMS=$[BUILD_RPMS_$MOD_BUILD_DIST]
52 #fi
53 #echo OUTPUT: $[BUILD_RPMS_$MOD_BUILD_DIST]
54 #:$BUILD_RPMS
55 case "$BUILD_DIST" in
56 "9.0-i386")
57 BUILD_RPMS_TEST=$BUILD_RPMS_9_0_i386 ;;
58 "sles8-i386")
59 BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386 ;;
60 "sles8-i386+update")
61 BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386_update ;;
62 "9.1-i386")
63 BUILD_RPMS_TEST=$BUILD_RPMS_9_1_i386 ;;
64 "sles9-i386")
65 BUILD_RPMS_TEST=$BUILD_RPMS_sles9_i386 ;;
66 esac
67 if [ "$BUILD_RPMS_TEST" ]; then
68 if [ "$BUILD_RPMS" ]; then
69 BUILD_RPMS=$BUILD_RPMS:$BUILD_RPMS_TEST
70 else
71 BUILD_RPMS=$BUILD_RPMS_TEST
72 fi
73 fi
74fi
75
76echo BUILD_RPMS: $BUILD_RPMS
77
78ERROR=0
79
80# Hier gehts los:
81
82if [ -z "$1" ]; then
83 # without parameter, we are in source directory
84 SPECFILE=$(ls *.spec | awk '{print $1}')
85 PACKAGE=$(awk '/^Name:/ {print $2}' <$SPECFILE)
86 VERSION=$(awk '/^Version:/ {print $2}' <$SPECFILE)
87else
88 # parameter is src.rpm file
89 PACKAGE=`echo $1 | sed 's/-[0-9]*\..*.src.rpm//'`
90 VERSION=`echo $1 | sed 's/.*-\([0-9]*\..*\)-.*.src.rpm/\1/'`
91fi
92
93echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
94
95rm -rf ${BUILDTEMP}/src/${PACKAGE};
96mkdir -p ${BUILDTEMP}/src/${PACKAGE}
97# ${BUILDTEMP}/${BUILD_DIST};
98
99if [ "$1" ]; then
100 cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
101 cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
102else
103 cp -a $SPECFILE ${BUILDTEMP}/src/${PACKAGE}
104
105 # uses Subversion (svn) to generate more information for the RPM
106 if [ "$BUILD_USES_SVN" = "yes" ]; then
107 echo "receiving subversion information ..."
108 # set RELEASE number (last modification in this directory)
109 # requires subversion (but connection to server isn't neccessary)
110 SVN_BUILD_RELEASE=$(svn info . | sed -n 's/^Last Changed Rev: \([0-9]*\)/\1/p')
111 # in case of local modification a "m" is added to the release number
112 SVN_BUILD_MODIFIED=$(svn status -v | grep "^ *M" | wc -l)
113 if [ $SVN_BUILD_MODIFIED -gt 0 ]; then
114 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}m
115 else # check if RPM has been build already
116 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-${VERSION}-${SVN_BUILD_RELEASE}.*.rpm
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 "verify if 'svn update' has been performed on the source directory"
121 echo
122 exit
123 fi
124 fi
125 if [ "$SVN_BUILD_RELEASE" ]; then
126 sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/g" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
127 fi
128 # changelog header
129 DATE=`unset LANG; date +"%a %b %d %Y"`
130 echo -e "* $DATE -\n" > Changes
131 echo "- Subversion status:" >> Changes
132 # additional infos for the Changes file (see if everything is checked in)
133 svn status -v | grep -v '^? ' >> Changes
134 echo >> Changes
135 echo "- ChangeLog:" >> Changes
136 # requires connection to the subversion server
137 svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
138 cat ChangeLog >> Changes
139
140 # if there is no changelog section in the spec file,
141 # also append the Changes there
142 if ! grep -q "%changelog" $SPECFILE ; then
143 # paste "Changes" into SPEC file.
144 echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
145 # without trailing *, except for the initial
146 echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
147 cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
148 fi
149 fi
150 # just make sure, that the Changes file exist
151 touch Changes
152
153 # if "SOURCES" file exist, create tar file on the fly
154 if [ -r "SOURCES" ]; then
155 # create a tar file from the sources
156 tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES
157
158 elif [ -r "SPECSOURCES" ]; then
159 # SPECSOURCES have to list the files that are referenced in the .spec file
160 # these ´files are copied to the build environment
161 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
162
163 else
164 # legacy method:
165 # call the existing makefile to generate a tar file
166 test -e Makefile && make
167 TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
168 cp -av $TARFILE ${BUILDTEMP}/src/${PACKAGE}
169 fi
170fi
171
172# create buildscript
173cat > $BUILDSCRIPT <<EOF
174#!/bin/bash
175# local buildscript
176#. /work/src/bin/.profile
177export BUILD_ROOT=$BUILD_ROOT
178export BUILD_DIST=$BUILD_DIST
179export BUILD_RPMS=${DEST_DIR}/${BUILD_DIST}:$BUILD_RPMS
180export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
181
182cd ${BUILDTEMP}/src/${PACKAGE}
183$BUILD_CMD $BUILD_MODE
184EOF
185
186chmod a+x $BUILDSCRIPT
187sudo su -c $BUILDSCRIPT
188rm -f $BUILDSCRIPT
189
190mkdir -p ${DEST_DIR}/src
191# delete all old versions of this package
192rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
193
194if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
195 ERROR=1
196fi
197
198mkdir -p ${DEST_DIR}/${BUILD_DIST}
199# delete all old versions of this package
200rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
201
202if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}*${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
203 ERROR=2
204fi
205
206echo
207if [ $ERROR -ne 0 ]; then
208
209 echo "ERROR while building packet $PACKAGE";
210else
211 echo "Build of \"${PACKAGE}\" completed!"
212 echo "Packages can be found in ${DEST_DIR}"
213fi
214echo
215
216exit $ERROR
Note: See TracBrowser for help on using the repository browser.