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

Last change on this file since 687 was 684, checked in by joergs, on Aug 14, 2004 at 3:57:44 PM

only modify %changelog section in spec file, if this section doesn't already exists

  • Property svn:executable set to *
  • Property svn:keywords set to Id LastChangedDate LastChangedRevision
File size: 6.2 KB
Line 
1#!/bin/bash
2# Remote build script (iboernig@suse.de)
3# $Id: build.sh 684 2004-08-14 13:57:44Z joergs $
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 else
144 # legacy method:
145 # call the existing makefile to generate a tar file
146 test -e Makefile && make
147 TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
148 cp -a $TARFILE ${BUILDTEMP}/src/${PACKAGE}
149 fi
150fi
151
152# create buildscript
153cat > $BUILDSCRIPT <<EOF
154#!/bin/bash
155# local buildscript
156#. /work/src/bin/.profile
157export BUILD_ROOT=$BUILD_ROOT
158export BUILD_DIST=$BUILD_DIST
159export BUILD_RPMS=${BUILDTEMP}/${BUILD_DIST}:$BUILD_RPMS
160export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
161
162cd ${BUILDTEMP}/src/${PACKAGE}
163#build $BUILD_MODE --prefer-rpms ${BUILDTEMP}/${BUILD_DIST}
164#build $BUILD_MODE
165$BUILD_CMD $BUILD_MODE
166EOF
167
168chmod a+x $BUILDSCRIPT
169sudo su -c $BUILDSCRIPT
170rm -f $BUILDSCRIPT
171
172rm -f ${BUILDTEMP}/${BUILD_DIST}/${PACKAGE}-*.*.rpm
173cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${BUILDTEMP}/${BUILD_DIST}
174
175mkdir -p ${DEST_DIR}/src
176# delete all old versions of this package
177rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
178
179if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
180 ERROR=1
181fi
182
183mkdir -p ${DEST_DIR}/${BUILD_DIST}
184# delete all old versions of this package
185rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
186
187if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
188 ERROR=2
189fi
190
191if [ $ERROR -ne 0 ]; then
192 echo "ERROR while building packet $PACKAGE";
193 for i in `seq 5`; do
194 echo -n "";
195 done
196else
197 echo "Build of ${PACKAGE} completed!"
198 echo "Packages can be found in ${DEST_DIR}"
199fi
200
201exit $ERROR
Note: See TracBrowser for help on using the repository browser.