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
RevLine 
[690]1#!/bin/bash
[694]2# build script
3#
[675]4# $Id: build.sh 694 2004-11-21 20:00:02Z 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
[585]26
[668]27CONFIG_FILE=/usr/local/etc/build
[677]28BUILD_CMD=build
[585]29BUILDUSER=$USER
30
[619]31[ -z "$BUILD_MODE" ] && BUILD_MODE="--verify"
[684]32[ -z "$BUILD_DIST" ] && BUILD_DIST="9.1-i386"
[668]33[ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
[586]34[ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
[585]35
[668]36[ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
[694]37BUILDTEMP=$DEST_DIR/buildsrc/
38BUILDSCRIPT=$BUILDTEMP/buildscript.$$
[585]39
[682]40[ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
41
42
43
[668]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 ;;
[679]62 "9.1-i386")
63 BUILD_RPMS_TEST=$BUILD_RPMS_9_1_i386 ;;
[681]64 "sles9-i386")
65 BUILD_RPMS_TEST=$BUILD_RPMS_sles9_i386 ;;
[668]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
[619]78ERROR=0
[585]79
[621]80# Hier gehts los:
[620]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
[622]93echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
[585]94
[682]95rm -rf ${BUILDTEMP}/src/${PACKAGE};
[694]96mkdir -p ${BUILDTEMP}/src/${PACKAGE}
97# ${BUILDTEMP}/${BUILD_DIST};
[585]98
[620]99if [ "$1" ]; then
[682]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')
[694]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
[682]125 if [ "$SVN_BUILD_RELEASE" ]; then
126 sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/g" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
127 fi
[683]128 # changelog header
129 DATE=`unset LANG; date +"%a %b %d %Y"`
130 echo -e "* $DATE -\n" > Changes
131 echo "- Subversion status:" >> Changes
[682]132 # additional infos for the Changes file (see if everything is checked in)
133 svn status -v | grep -v '^? ' >> Changes
134 echo >> Changes
[683]135 echo "- ChangeLog:" >> Changes
[682]136 # requires connection to the subversion server
137 svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
138 cat ChangeLog >> Changes
[684]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
[682]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
[690]157
158 elif [ -r "SPECSOURCES" ]; then
[694]159 # SPECSOURCES have to list the files that are referenced in the .spec file
160 # these ´files are copied to the build environment
[690]161 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
162
[682]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}')
[690]168 cp -av $TARFILE ${BUILDTEMP}/src/${PACKAGE}
[682]169 fi
[620]170fi
171
[585]172# create buildscript
[668]173cat > $BUILDSCRIPT <<EOF
[585]174#!/bin/bash
175# local buildscript
[668]176#. /work/src/bin/.profile
[585]177export BUILD_ROOT=$BUILD_ROOT
178export BUILD_DIST=$BUILD_DIST
[694]179export BUILD_RPMS=${DEST_DIR}/${BUILD_DIST}:$BUILD_RPMS
[586]180export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
181
[668]182cd ${BUILDTEMP}/src/${PACKAGE}
[677]183$BUILD_CMD $BUILD_MODE
[585]184EOF
[681]185
[668]186chmod a+x $BUILDSCRIPT
187sudo su -c $BUILDSCRIPT
188rm -f $BUILDSCRIPT
189
[585]190mkdir -p ${DEST_DIR}/src
[620]191# delete all old versions of this package
192rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
[682]193
[668]194if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
[619]195 ERROR=1
196fi
[585]197
[619]198mkdir -p ${DEST_DIR}/${BUILD_DIST}
[620]199# delete all old versions of this package
200rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
[682]201
[692]202if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}*${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
[619]203 ERROR=2
[591]204fi
205
[694]206echo
[619]207if [ $ERROR -ne 0 ]; then
[694]208
209 echo "ERROR while building packet $PACKAGE";
[619]210else
[694]211 echo "Build of \"${PACKAGE}\" completed!"
[619]212 echo "Packages can be found in ${DEST_DIR}"
[591]213fi
[694]214echo
[585]215
[619]216exit $ERROR
Note: See TracBrowser for help on using the repository browser.