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