source: trunk/dassbuild/build.sh@ 738

Last change on this file since 738 was 735, checked in by joergs, on Jan 26, 2009 at 4:45:04 PM

set paths for security

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