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

Last change on this file since 692 was 692, checked in by pstorz, on Nov 11, 2004 at 4:25:37 PM

added support for packages that create multiple rpms

  • Property svn:executable set to *
  • Property svn:keywords set to Id LastChangedDate LastChangedRevision
File size: 6.3 KB
Line 
1#!/bin/bash
2# Remote build script (iboernig@suse.de)
3# $Id: build.sh 692 2004-11-11 15:25:37Z pstorz $
4#
5# Kurze Featuritis:
6# - build.sh sollte im Pfad liegen.
7# Ein Link von ~/bin/build.sh ist eine gute Wahl ;)
8# - ohne Parameter aufgerufen,
9# erzeugt build.sh mit Hilfe des Makefiles in aktuellen Verzeichnis
10# ein tar-Archiv, bertr�t dieses nach Oldwotan und baut es dort
11# - mit Parameter geht das Skript davon aus,
12# dass der Parameter ein SRPM Paket ist.
13# Dieses wird entpackt und dann gebaut.
14# Wichtige Einstellungen:
15# - Standardm�ig baut build.sh mit --clean, wenns schnell gehen soll, die
16# Umgebungsvariable BUILD_MODE="--no-init" exportieren
17# - BUILD_DIST ist standard sles7-i386, kann auch durch entsprechenden Export
18# berschrieben werden.
19# - die fertigen Pakete werden nach DEST_DIR (kann durch env gesetzt werden) # in die vorgegebene Hierarchie (src, i386/sles/7) auf den lokalen Rechner # kopiert.
20#
21# nutzt sudo
22
23CONFIG_FILE=/usr/local/etc/build
24BUILD_CMD=build
25#SSH_VERSION="1"
26#BUILDHOST="oldwotan"
27#FQBUILDHOST="$BUILDHOST.suse.de"
28#BUILDTEMP=abuildtmp
29BUILDUSER=$USER
30BUILDTEMP=/tmp/abuildtmp/$BUILDUSER
31
32BUILDSCRIPT=$BUILDTEMP/buildscript.$$
33
34[ -z "$BUILD_MODE" ] && BUILD_MODE="--verify"
35[ -z "$BUILD_DIST" ] && BUILD_DIST="9.1-i386"
36[ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
37[ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
38
39[ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
40
41[ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
42
43
44
45if [ -r $CONFIG_FILE ]; then
46 source $CONFIG_FILE
47 MOD_BUILD_DIST=`echo $BUILD_DIST | sed "s/[-+.]/_/g"`
48 #echo MOD_BUILD_DIST: $MOD_BUILD_DIST
49 #RPMS_PATHS=$[BUILD_RPMS_$MOD_BUILD_DIST]
50 #echo RPMS_PATHS: $RPM_PATHS
51 #if [ -n "$[BUILD_RPMS_$MOD_BUILD_DIST]" ]; then
52 # BUILD_RPMS=$[BUILD_RPMS_$MOD_BUILD_DIST]
53 #fi
54 #echo OUTPUT: $[BUILD_RPMS_$MOD_BUILD_DIST]
55 #:$BUILD_RPMS
56 case "$BUILD_DIST" in
57 "9.0-i386")
58 BUILD_RPMS_TEST=$BUILD_RPMS_9_0_i386 ;;
59 "sles8-i386")
60 BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386 ;;
61 "sles8-i386+update")
62 BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386_update ;;
63 "9.1-i386")
64 BUILD_RPMS_TEST=$BUILD_RPMS_9_1_i386 ;;
65 "sles9-i386")
66 BUILD_RPMS_TEST=$BUILD_RPMS_sles9_i386 ;;
67 esac
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=$(awk '/^Name:/ {print $2}' <$SPECFILE)
87 VERSION=$(awk '/^Version:/ {print $2}' <$SPECFILE)
88else
89 # parameter is src.rpm file
90 PACKAGE=`echo $1 | sed 's/-[0-9]*\..*.src.rpm//'`
91 VERSION=`echo $1 | sed 's/.*-\([0-9]*\..*\)-.*.src.rpm/\1/'`
92fi
93
94echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
95
96rm -rf ${BUILDTEMP}/src/${PACKAGE};
97mkdir -p ${BUILDTEMP}/src/${PACKAGE} ${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 if [ "$SVN_BUILD_RELEASE" ]; then
112 sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/g" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
113 fi
114 # changelog header
115 DATE=`unset LANG; date +"%a %b %d %Y"`
116 echo -e "* $DATE -\n" > Changes
117 echo "- Subversion status:" >> Changes
118 # additional infos for the Changes file (see if everything is checked in)
119 svn status -v | grep -v '^? ' >> Changes
120 echo >> Changes
121 echo "- ChangeLog:" >> Changes
122 # requires connection to the subversion server
123 svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
124 cat ChangeLog >> Changes
125
126 # if there is no changelog section in the spec file,
127 # also append the Changes there
128 if ! grep -q "%changelog" $SPECFILE ; then
129 # paste "Changes" into SPEC file.
130 echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
131 # without trailing *, except for the initial
132 echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
133 cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
134 fi
135 fi
136 # just make sure, that the Changes file exist
137 touch Changes
138
139 # if "SOURCES" file exist, create tar file on the fly
140 if [ -r "SOURCES" ]; then
141 # create a tar file from the sources
142 tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES
143
144 elif [ -r "SPECSOURCES" ]; then
145 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
146
147 else
148 # legacy method:
149 # call the existing makefile to generate a tar file
150 test -e Makefile && make
151 TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
152 cp -av $TARFILE ${BUILDTEMP}/src/${PACKAGE}
153
154
155
156 fi
157
158fi
159
160# create buildscript
161cat > $BUILDSCRIPT <<EOF
162#!/bin/bash
163# local buildscript
164#. /work/src/bin/.profile
165export BUILD_ROOT=$BUILD_ROOT
166export BUILD_DIST=$BUILD_DIST
167export BUILD_RPMS=${BUILDTEMP}/${BUILD_DIST}:$BUILD_RPMS
168export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
169
170cd ${BUILDTEMP}/src/${PACKAGE}
171#build $BUILD_MODE --prefer-rpms ${BUILDTEMP}/${BUILD_DIST}
172#build $BUILD_MODE
173$BUILD_CMD $BUILD_MODE
174EOF
175
176chmod a+x $BUILDSCRIPT
177sudo su -c $BUILDSCRIPT
178rm -f $BUILDSCRIPT
179
180rm -f ${BUILDTEMP}/${BUILD_DIST}/${PACKAGE}-*.*.rpm
181cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${BUILDTEMP}/${BUILD_DIST}
182
183mkdir -p ${DEST_DIR}/src
184# delete all old versions of this package
185rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
186
187if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
188 ERROR=1
189fi
190
191mkdir -p ${DEST_DIR}/${BUILD_DIST}
192# delete all old versions of this package
193rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
194
195if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}*${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
196 ERROR=2
197fi
198
199if [ $ERROR -ne 0 ]; then
200 echo "ERROR while building packet $PACKAGE";
201 for i in `seq 5`; do
202 echo -n "";
203 done
204else
205 echo "Build of ${PACKAGE} completed!"
206 echo "Packages can be found in ${DEST_DIR}"
207fi
208
209exit $ERROR
Note: See TracBrowser for help on using the repository browser.