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