]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- Fixed behaviour when no bcond were found.
[packages/rpm-build-tools.git] / builder.sh
CommitLineData
b054f772 1#!/bin/sh
33f5276d 2# -----------
25fa34fe 3# $Id$
33f5276d 4# Exit codes:
5# 0 - succesful
10b4dd7f 6# 1 - help displayed
33f5276d 7# 2 - no spec file name in cmdl parameters
8# 3 - spec file not stored in repo
0ad50ce9 9# 4 - some source, patch or icon files not stored in repo
10# 5 - package build failed
10b4dd7f 11# 6 - spec file with errors
da0048be 12# 7 - wrong source in /etc/poldek.conf
5a491465 13
931a4acf
TP
14# Notes (todo):
15# - builder -u fetches current version first
16# - tries to get new version from distfiles without new md5
17# - after fetching new version doesn't update md5
2837871a 18# - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
9308ddd0 19# when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
2837871a 20# - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov
82d4501c 21# - when Icon: field is present, -5 and -a5 doesn't work
931a4acf 22
4003ad8c 23VERSION="\
24Build package utility from PLD CVS repository
6cb7df6d 25V 0.11 (C) 1999-2003 Free Penguins".
5a491465 26PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
a7af9862 27
b03f053b 28COMMAND="build"
29
bde1c404 30SPECFILE=""
d287305c 31BE_VERBOSE=""
4003ad8c 32QUIET=""
5dd89621 33CLEAN=""
7c2dd1b2 34DEBUG=""
cc97f1f3 35NOURLS=""
157dc315 36NOCVS=""
6fc910c7 37NOCVSSPEC=""
fc0e5bb5 38NODIST=""
b130abf2 39UPDATE=""
a9d9a79a 40UPDATE5=""
de6b5b2a 41ADD5=""
81474543 42ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
c8f50498 43CVSROOT=""
b2975fc3 44
45# It can be used i.e. in log file naming.
46# See LOGFILE example.
47DATE=`date +%Y-%m-%d_%H-%M-%S`
48
d6a75d60 49# Example: LOGFILE='../log.$PACKAGE_NAME'
b2975fc3 50# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
d6a75d60 51# Yes, you can use variable name! Note _single_ quotes!
52LOGFILE=''
00fcec7e 53
54LOGDIR=""
55LOGDIROK=""
56LOGDIRFAIL=""
57LASTLOG_FILE=""
b2975fc3 58
79d76918 59CHMOD="no"
d6a75d60 60CHMOD_MODE="0444"
33a9d2d1 61RPMOPTS=""
6049c3d1 62BCOND=""
a6253cb6 63GROUP_BCONDS="no"
d287305c 64
65PATCHES=""
66SOURCES=""
7053d3fd 67ICONS=""
d287305c 68PACKAGE_RELEASE=""
69PACKAGE_VERSION=""
70PACKAGE_NAME=""
d7f490f3 71PROTOCOL="ftp"
34c911e6 72WGET_RETRIES=${MAX_WGET_RETRIES:-0}
b92ecfc9 73CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
5a491465 74
00fcec7e 75CVSTAG=""
76RES_FILE=""
77
62546902 78CVS_SERVER="cvs.pld-linux.org"
d7f490f3 79DISTFILES_SERVER="://distfiles.pld-linux.org"
ea15df77 80
3ae81a20 81DEF_NICE_LEVEL=0
82
c6a390a1
AM
83FAIL_IF_NO_SOURCES="yes"
84
d8140aad
AM
85wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
86wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
87
88GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
89GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
6aefe77b 90GETLOCAL="cp -a"
11f33a0c 91
7147050f
AM
92if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
93 RPM="rpm"
94 RPMBUILD="rpm"
95else
96 RPM="rpm"
97 RPMBUILD="rpmbuild"
98fi
99
c8740da7 100POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
da0048be 101POLDEK_SOURCE="cvs"
102
b2975fc3 103# Here we load saved user environment used to
104# predefine options set above, or passed to builder
105# in command line.
106# This one reads global system environment settings:
6eb44b93 107if [ -f ~/etc/builderrc ]; then
7922b3ec 108 . ~/etc/builderrc
5aa0ef93 109fi
b2975fc3 110# And this one cascades settings using user personal
111# builder settings.
112# Example of ~/.builderrc:
113#
114#UPDATE_POLDEK_INDEXES="yes"
115#FETCH_BUILD_REQUIRES="yes"
116#REMOVE_BUILD_REQUIRES="force"
117#GROUP_BCONDS="yes"
118#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
119#
541008f6 120if [ -n "$HOME_ETC" ]; then
b2975fc3 121 USER_CFG=$HOME_ETC/.builderrc
541008f6 122else
b2975fc3 123 USER_CFG=~/.builderrc
541008f6 124fi
125
126[ -f $USER_CFG ] && . $USER_CFG
127
a9914892 128# Example grep cvs /etc/poldek.conf:
129# source = cvs /home/users/yoshi/rpm/RPMS/
130if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
131 POLDEK_SOURCE_VALIDITY="`grep ${POLDEK_SOURCE} /etc/poldek.conf|grep -v ^#`"
132 if [ "${POLDEK_SOURCE_VALIDITY}" = "" ]; then
133 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
134 echo "Fix it and try to continue"
135 exit 7
136 fi
137fi
138
da946cd6 139#---------------------------------------------
140# functions
141
5a491465 142usage()
143{
b2975fc3 144 if [ -n "$DEBUG" ]; then set -xv; fi
145 echo "\
7922b3ec 146Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
81f85806 147
b2975fc3 148[-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
149[{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
150[-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
151[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
152[-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
153[-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
154[{-Tp|--tag-prefix} <prefix>]
155[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
156[--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
157
158-5, --update-md5 - update md5 comments in spec, implies -nd -ncs
159-a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
160-D, --debug - enable script debugging mode,
161-V, --version - output builder version
162-a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
163-b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
164 from <package>.spec,
165-bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
166 only package from <package>.spec,
167-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
168 them into src.rpm,
169-bp, --build-prep - execute the %prep phase of <package>.spec,
170-B, --branch - add branch
171-c, --clean - clean all temporarily created files (in BUILD, SOURCES,
172 SPECS and \$RPM_BUILD_ROOT),
173-d <cvsroot>, --cvsroot <cvsroot>
174 - setup \$CVSROOT,
175--define <macro> <value>
176 - define a macro <macro> with value <value>,
177--nodeps - rpm won't check any dependences
178-g, --get - get <package>.spec and all related files from CVS repo
179 or HTTP/FTP,
180-h, --help - this message,
181--http - use http instead of ftp,
182-l <logfile>, --logtofile <logfile>
183 - log all to file,
184-m, --mr-proper - only remove all files related to spec file and all work
185 resources,
186-nc, --no-cvs - don't download sources from CVS, if source URL is given,
187-ncs, --no-cvs-specs
188 - don't check specs in CVS
189-nd, --no-distfiles - don't download from distfiles
190-nm, --no-mirrors - don't download from mirror, if source URL is given,
191-nu, --no-urls - don't try to download from FTP/HTTP location,
192-ns, --no-srcs - don't download Sources
193-ns0, --no-source0 - don't download Source0
194--opts <rpm opts> - additional options for rpm
195-q, --quiet - be quiet,
196--date yyyy-mm-dd - build package using resources from specified CVS date,
197-r <cvstag>, --cvstag <cvstag>
198 - build package using resources from specified CVS tag,
199-R, --fetch-build-requires
200 - fetch what is BuildRequired,
201-RB, --remove-build-requires
202 - remove all you fetched with -R or --fetch-build-requires
203 remember, this option requires confirmation,
204-FRB, --force-remove-build-requires
205 - remove all you fetched with -R or --fetch-build-requires
206 remember, this option works without confirmation,
207-T <cvstag> , --tag <cvstag>
208 - add cvs tag <cvstag> for files,
209-Tvs, --tag-version-stable
210 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
211-Tvn, --tag-version-nest
212 - add cvs tags NEST and NAME-VERSION-RELESE for files,
213-Ts, --tag-stable
214 - add cvs tag STABLE for files,
215-Tn, --tag-nest
216 - add cvs tag NEST for files,
217-Tv, --tag-version
218 - add cvs tag NAME-VERSION-RELESE for files,
219-Tp, --tag-prefix <prefix>
220 - add <prefix> to NAME-VERSION-RELEASE tags,
221-v, --verbose - be verbose,
222-u, --try-upgrade - check version, and try to upgrade package
223-un, --try-upgrade-with-float-version
224 - as above, but allow float version
225-U, --update - refetch sources, don't use distfiles, and update md5 comments
226-Upi, --update-poldek-indexes
227 - refresh or make poldek package index files.
228--with/--without <feature>
229 - conditional build package depending on %_with_<feature>/
230 %_without_<feature> macro switch. You may now use
231 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
232 constructions. Set GROUP_BCONDS to yes to make use of it.
5a491465 233"
234}
235
5f26c239 236cache_rpm_dump () {
b2975fc3 237rpm_dump_cache=`
ad6f43de 238 case "$RPMBUILD" in
b2975fc3 239 rpm )
240 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
241 ;;
242 rpmbuild )
243 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
244 ;;
15a71f66 245 esac`
5f26c239
MM
246}
247
248rpm_dump () {
b2975fc3 249 if [ -z "$rpm_dump_cache" ] ; then
250 echo "internal error: cache_rpm_dump not called!" 1>&2
251 fi
252 echo "$rpm_dump_cache"
ad6f43de
MM
253}
254
59398507 255parse_spec()
256{
b2975fc3 257 if [ -n "$DEBUG" ]; then
258 set -x;
259 set -v;
260 fi
7c2dd1b2 261
b2975fc3 262 cd $SPECS_DIR
5f26c239 263
b2975fc3 264 cache_rpm_dump
5f26c239 265
b2975fc3 266 if [ "$NOSRCS" != "yes" ]; then
267 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
268 fi
269 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
270 FAIL_IF_NO_SOURCES="no"
271 fi
c6a390a1 272
b2975fc3 273 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
274 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
275 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
276 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
277 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
79379585 278
b2975fc3 279 if [ -n "$BE_VERBOSE" ]; then
280 echo "- Sources : `nourl $SOURCES`"
281 if [ -n "$PATCHES" ]; then
282 echo "- Patches : `nourl $PATCHES`"
283 else
284 echo "- Patches : *no patches needed*"
285 fi
286 if [ -n "$ICONS" ]; then
287 echo "- Icon : `nourl $ICONS`"
288 else
289 echo "- Icon : *no package icon*"
290 fi
291 echo "- Name : $PACKAGE_NAME"
292 echo "- Version : $PACKAGE_VERSION"
293 echo "- Release : $PACKAGE_RELEASE"
a3df415f 294 fi
33f5276d 295}
296
297Exit_error()
298{
b2975fc3 299 if [ -n "$DEBUG" ]; then
300 set -x;
301 set -v;
302 fi
303
304 cd $__PWD
305
306 case "$1" in
307 "err_no_spec_in_cmdl" )
308 remove_build_requires
309 echo "ERROR: spec file name not specified.";
310 exit 2 ;;
311 "err_no_spec_in_repo" )
312 remove_build_requires
313 echo "Error: spec file not stored in CVS repo.";
314 exit 3 ;;
315 "err_no_source_in_repo" )
316 remove_build_requires
317 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
318 exit 4 ;;
319 "err_build_fail" )
320 remove_build_requires
321 echo "Error: package build failed. (${2:-no more info})";
322 exit 5 ;;
323 esac
33f5276d 324}
bc8d444f 325
33f5276d 326init_builder()
327{
b2975fc3 328 if [ -n "$DEBUG" ]; then
329 set -x;
330 set -v;
331 fi
7c2dd1b2 332
b2975fc3 333 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
334 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
bc8d444f 335
b2975fc3 336 __PWD=`pwd`
59398507 337}
338
339get_spec()
340{
b2975fc3 341 if [ -n "$DEBUG" ]; then
342 set -x;
343 set -v;
344 fi
5644bf7e 345
b2975fc3 346 if [ "$NOCVSSPEC" != "yes" ]; then
347 cd $SPECS_DIR
67fcd1e4 348
b2975fc3 349 OPTIONS="up "
00fcec7e 350
b2975fc3 351 if [ -n "$CVSROOT" ]; then
352 OPTIONS="-d $CVSROOT $OPTIONS"
353 else
354 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
355 echo "warning: No cvs access defined - using local .spec file"
356 NOCVSSPEC="yes"
357 fi
358 fi
33f5276d 359
b2975fc3 360 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
361 OPTIONS="$OPTIONS -A"
362 else
363 if [ -n "$CVSDATE" ]; then
364 OPTIONS="$OPTIONS -D $CVSDATE"
365 fi
366 if [ -n "$CVSTAG" ]; then
367 OPTIONS="$OPTIONS -r $CVSTAG"
368 fi
0dd6320d 369 fi
b2975fc3 370
371 result=1
372 retries_counter=0
373 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
374 do
375 retries_counter=$(( $retries_counter + 1 ))
376 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
377 result=$?
378 [ -n "$output" ] && echo "$output"
379 if [ "$result" -ne "0" ]; then
380 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
381 echo "Trying again [$SPECFILE]... ($retries_counter)"
382 sleep 2
383 continue
384 fi
385 Exit_error err_no_spec_in_repo;
386 fi
387 done
388 fi
389 if [ ! -f "$SPECFILE" ]; then
0dd6320d 390 Exit_error err_no_spec_in_repo;
b2975fc3 391 fi
392
393 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
394 chmod $CHMOD_MODE $SPECFILE
395 fi
396 unset OPTIONS
397 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
59398507 398}
399
b2975fc3 400find_mirror()
401{
402 cd "$SPECS_DIR"
403 url="$1"
404 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
405 cvs update mirrors >&2
4ca52257 406 fi
b2975fc3 407
408 IFS="|"
409 while read origin mirror name rest
410 do
411 ol=`echo -n "$origin"|wc -c`
412 prefix="`echo -n "$url" | head -c $ol`"
413 if [ "$prefix" = "$origin" ] ; then
414 suffix="`echo "$url"|cut -b $ol-`"
415 echo -n "$mirror$suffix"
416 return 0
417 fi
418 done < mirrors
419 echo "$url"
4ca52257
JK
420}
421
00fcec7e 422src_no ()
423{
b2975fc3 424 cd $SPECS_DIR
425 rpm_dump | \
0dd6320d 426 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
427 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
428 head -1 | xargs
00fcec7e 429}
430
431src_md5 ()
432{
b2975fc3 433 no=$(src_no "$1")
434 [ -z "$no" ] && return
435 cd $SPECS_DIR
436 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
437 if [ -z "$spec_rev" ]; then
438 spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
439 fi
440 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
441 md5=$(grep -s -v '^#' additional-md5sums | \
0dd6320d 442 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
443 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
444 grep -E '^[0-9a-f]{32}$')
b2975fc3 445 if [ X"$md5" = X"" ] ; then
446 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
447 else
448 if [ $(echo "$md5" | wc -l) != 1 ] ; then
449 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
450 fi
451 echo "$md5" | tail -1
0dd6320d 452 fi
00fcec7e 453}
454
455distfiles_url ()
456{
b2975fc3 457 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
00fcec7e 458}
459
d99ac371
MM
460good_md5 ()
461{
b2975fc3 462 md5=$(src_md5 "$1")
463 [ "$md5" = "" ] || \
464 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
d99ac371
MM
465}
466
25fa34fe 467get_files()
59398507 468{
b2975fc3 469 GET_FILES="$@"
25fa34fe 470
b2975fc3 471 if [ -n "$DEBUG" ]; then
472 set -x;
473 set -v;
474 fi
7c2dd1b2 475
b2975fc3 476 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
477 cd $SOURCE_DIR
33f5276d 478
b2975fc3 479 OPTIONS="up "
480 if [ -n "$CVSROOT" ]; then
481 OPTIONS="-d $CVSROOT $OPTIONS"
2daea751 482 else
b2975fc3 483 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
484 echo "warning: No cvs access defined for SOURCES"
485 NOCVS="yes"
00fcec7e 486 fi
b2975fc3 487 fi
488 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
489 OPTIONS="$OPTIONS -A"
490 else
491 if [ -n "$CVSDATE" ]; then
492 OPTIONS="$OPTIONS -D $CVSDATE"
57422365 493 fi
b2975fc3 494 if [ -n "$CVSTAG" ]; then
495 OPTIONS="$OPTIONS -r $CVSTAG"
b92ecfc9 496 fi
157dc315 497 fi
b2975fc3 498 for i in $GET_FILES
499 do
500 if [ -n "$UPDATE5" ]; then
501 if [ -n "$ADD5" ]; then
502 [ `nourl $i` = "$i" ] && continue
503 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
504 else
505 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
506 fi
507 fi
508 FROM_DISTFILES=0
509 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
510 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
511 echo "Warning: no URL given for $i"
512 fi
a7af9862 513
b2975fc3 514 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
515 if good_md5 "$i"; then
516 echo "$(nourl "$i") having proper md5sum already exists"
517 continue
518 fi
519 target=$(nourl "$i")
520 url=$(distfiles_url "$i")
521 if [ `echo $url | grep -E '^(\.|/)'` ]; then
522 ${GETLOCAL} $url $target
523 else
524 FROM_DISTFILES=1
525 if [ -z "$NOMIRRORS" ]; then
526 url="`find_mirror "$url"`"
527 fi
528 ${GETURI} -O "$target" "$url" || \
529 if [ `echo $url | grep -E 'ftp://'` ]; then
530 ${GETURI2} -O "$target" "$url"
531 fi
532 if ! test -s "$target"; then
533 rm -f "$target"
534 FROM_DISTFILES=0
535 fi
536 fi
537 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
538 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
539 result=1
540 retries_counter=0
541 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
542 do
543 retries_counter=$(( $retries_counter + 1 ))
544 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
545 result=$?
546 [ -n "$output" ] && echo "$output"
547 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
548 echo "Trying again [`nourl $i`]... ($retries_counter)"
549 sleep 2
550 continue
551 else
552 break
553 fi
554 done
555 fi
556
557 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
558 if [ -z "$NOMIRRORS" ]; then
559 im="`find_mirror "$i"`"
560 else
561 im="$i"
562 fi
563 ${GETURI} "$im" || \
564 if [ `echo $im | grep -E 'ftp://'` ]; then
565 ${GETURI2} "$im"
566 fi
567 fi
157dc315 568
de6b5b2a 569
b2975fc3 570 fi
571 srcno=$(src_no $i)
572 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
573 Exit_error err_no_source_in_repo $i;
574 elif [ -n "$UPDATE5" ] && \
575 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
576 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
577 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
578 then
579 echo "Updating source-$srcno md5."
580 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
581 perl -i -ne '
82db6b8d
MM
582 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
583 print "# Source'$srcno'-md5:\t'$md5'\n"
b2975fc3 584 if /^Source'$srcno'\s*:\s+/;
82db6b8d 585 ' \
422fbc56 586 $SPECS_DIR/$SPECFILE
b2975fc3 587 fi
588
589 if good_md5 "$i"; then
590 :
591 elif [ "$FROM_DISTFILES" = 1 ]; then
592 # wrong md5 from distfiles: remove the file and try again
593 # but only once ...
594 echo "MD5 sum mismatch. Trying full fetch."
595 FROM_DISTFILES=2
596 rm -f $target
597 ${GETURI} -O "$target" "$url" || \
598 if [ `echo $url | grep -E 'ftp://'` ]; then
599 ${GETURI2} -O "$target" "$url"
600 fi
601 test -s "$target" || rm -f "$target"
602 fi
603
604 if good_md5 "$i"; then
605 :
606 else
607 echo "MD5 sum mismatch. Use -U to refetch sources,"
608 echo "or -5 to update md5 sums, if you're sure files are correct."
609 Exit_error err_no_source_in_repo $i
610 fi
611 done
a7af9862 612
b2975fc3 613 if [ "$CHMOD" = "yes" ]; then
614 CHMOD_FILES="`nourl $GET_FILES`"
615 if [ -n "$CHMOD_FILES" ]; then
616 chmod $CHMOD_MODE $CHMOD_FILES
617 fi
618 fi
619 unset OPTIONS
5aa0ef93 620 fi
59398507 621}
622
1471f6d6 623tag_files()
624{
b2975fc3 625 TAG_FILES="$@"
1471f6d6 626
b2975fc3 627 if [ -n "$DEBUG" ]; then
628 set -x;
629 set -v;
01de2036 630 fi
1471f6d6 631
b2975fc3 632 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
633 echo "Version: $PACKAGE_VERSION"
634 echo "Release: $PACKAGE_RELEASE"
635 # Check whether first character of PACKAGE_NAME is legal for tag name
636 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
637 TAG_PREFIX=tag_
638 fi
639 TAGVER=$TAG_PREFIX$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
640 # Remove #kernel.version_release from TAGVER because tagging sources
641 # could occur with different kernel-headers than kernel-headers used at build time.
642 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
643 if [ "$TAG_VERSION" = "yes" ]; then
644 echo "CVS tag: $TAGVER"
645 fi
646 if [ -n "$TAG" ]; then
647 echo "CVS tag: $TAG"
648 fi
649
650 OPTIONS="tag -F"
651 if [ -n "$CVSROOT" ]; then
652 OPTIONS="-d $CVSROOT $OPTIONS"
653 fi
654
655 cd $SOURCE_DIR
656 for i in $TAG_FILES
657 do
658 # don't tag non cvs files (ie. stored on distfiles)
659 [ "`nourl $i`" != "$i" ] && continue
660 if [ -f "`nourl $i`" ]; then
661 if [ "$TAG_VERSION" = "yes" ]; then
662 cvs $OPTIONS $TAGVER `nourl $i`
663 fi
664 if [ -n "$TAG" ]; then
665 cvs $OPTIONS $TAG `nourl $i`
666 fi
667 else
668 Exit_error err_no_source_in_repo $i
669 fi
670 done
1471f6d6 671
b2975fc3 672 cd $SPECS_DIR
f02788de 673 if [ "$TAG_VERSION" = "yes" ]; then
b2975fc3 674 cvs $OPTIONS $TAGVER $SPECFILE
f02788de
JB
675 fi
676 if [ -n "$TAG" ]; then
b2975fc3 677 cvs $OPTIONS $TAG $SPECFILE
f02788de 678 fi
1471f6d6 679
b2975fc3 680 unset OPTIONS
f02788de 681 fi
1471f6d6 682}
683
8ba5cdda
PG
684branch_files()
685{
b2975fc3 686 TAG=$1
687 echo "CVS branch tag: $TAG"
688 shift;
8ba5cdda 689
b2975fc3 690 TAG_FILES="$@"
8ba5cdda 691
b2975fc3 692 if [ -n "$DEBUG" ]; then
693 set -x;
694 set -v;
695 fi
8ba5cdda 696
b2975fc3 697 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
a7af9862 698
b2975fc3 699 OPTIONS="tag -b"
700 if [ -n "$CVSROOT" ]; then
701 OPTIONS="-d $CVSROOT $OPTIONS"
702 fi
703 cd $SOURCE_DIR
704 for i in $TAG_FILES
705 do
706 if [ -f `nourl $i` ]; then
707 cvs $OPTIONS $TAG `nourl $i`
708 else
709 Exit_error err_no_source_in_repo $i
710 fi
711 done
712 cd $SPECS_DIR
713 cvs $OPTIONS $TAG $SPECFILE
a7af9862 714
b2975fc3 715 unset OPTIONS
716 fi
8ba5cdda
PG
717}
718
f308b816 719
720
59398507 721build_package()
722{
b2975fc3 723 if [ -n "$DEBUG" ]; then
724 set -x;
725 set -v;
a7af9862 726 fi
727
b2975fc3 728 cd $SPECS_DIR
a7af9862 729
b2975fc3 730 if [ -n "$TRY_UPGRADE" ]; then
731 if [ -n "$FLOAT_VERSION" ]; then
732 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
733 else
734 TNOTIFY=`./pldnotify.awk $SPECFILE`
735 fi
a7af9862 736
b2975fc3 737 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
a7af9862 738
b2975fc3 739 if [ -n "$TNEWVER" ]; then
740 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
741 echo "New version found, updating spec file to version " $TNEWVER
742 cp -f $SPECFILE $SPECFILE.bak
743 chmod +w $SPECFILE
744 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
745 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
746 parse_spec;
747 get_files "$SOURCES $PATCHES";
748 unset TOLDVER TNEWVER TNOTIFY
749 fi
3d97a432 750 fi
b2975fc3 751 cd $SPECS_DIR
00fcec7e 752
b2975fc3 753 case "$COMMAND" in
754 build )
755 BUILD_SWITCH="-ba" ;;
756 build-binary )
757 BUILD_SWITCH="-bb" ;;
758 build-source )
759 BUILD_SWITCH="-bs --nodeps" ;;
760 build-prep )
761 BUILD_SWITCH="-bp --nodeps" ;;
762 esac
763 if [ -n "$LOGFILE" ]; then
764 LOG=`eval echo $LOGFILE`
765 if [ -n "$LASTLOG_FILE" ]; then
766 echo "LASTLOG=$LOG" > $LASTLOG_FILE
767 fi
768 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
769 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
770 RETVAL=`cat $RES_FILE`
771 rm $RES_FILE
772 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
773 if [ "$RETVAL" -eq "0" ]; then
774 mv $LOG $LOGDIROK
775 else
776 mv $LOG $LOGDIRFAIL
777 fi
778 fi
779 else
780 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
781 RETVAL=$?
00fcec7e 782 fi
b2975fc3 783 if [ "$RETVAL" -ne "0" ]; then
784 if [ -n "$TRY_UPGRADE" ]; then
785 echo "\n!!! Package with new version cannot be build automagically\n"
786 mv -f $SPECFILE.bak $SPECFILE
787 fi
788 Exit_error err_build_fail;
3d97a432 789 fi
b2975fc3 790 unset BUILD_SWITCH
59398507 791}
792
cc97f1f3
SZ
793nourl()
794{
b2975fc3 795 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
cc97f1f3 796}
2daea751 797
e79b53b6 798install_required_packages()
799{
800 poldek -i $package
801 exit $?
802}
803
da0048be 804set_bconds_values()
805{
b2975fc3 806 AVAIL_BCONDS_WITHOUT=""
807 AVAIL_BCONDS_WITH=""
ff5f7ec0 808 TEST_BCOND_VERSION="`grep ^%bcond ${SPECFILE}`"
809 if [ "${TEST_BCOND_VERSION}" == "" ]; then
801f1540 810 TEST_BCOND_VERSION="`grep bcond ${SPECFILE}`"
811 if [ "${TEST_BCOND_VERSION}" == "" ]; then
812 BCOND_VERSION="NONE"
813 fi
ff5f7ec0 814 else
815 BCOND_VERSION="NEW"
816 fi
817 case "${BCOND_VERSION}" in
801f1540 818 NONE)
819 :
820 ;;
ff5f7ec0 821 OLD)
e79b53b6 822 echo "Warning: This spec has old style bconds. Fix it || die."
ff5f7ec0 823 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
824 do
825 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
826 if [ "`echo $BCOND|grep -- "--without $AVAIL_BCOND_WITHOUT"`" != "" ];then
827 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
828 else
829 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
830 fi
831 done
832
833 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
834 do
835 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
836 if [ "`echo $BCOND|grep -- "--with $AVAIL_BCOND_WITH"`" != "" ];then
837 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
838 else
839 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
840 fi
841 done
842 ;;
843 NEW)
844 cond_type="" # with || without
845 for opt in `$RPMBUILD --bcond $SPECFILE`
846 do
847 case "$opt" in
848 _without)
849 cond_type="without"
850 ;;
851 _with)
852 cond_type="with"
853 ;;
854 *)
855 case "$cond_type" in
856 with)
857 cond_type=''
858 AVAIL_BCOND_WITH="$opt"
859 if [ "`echo $BCOND|grep -- "--with $AVAIL_BCOND_WITH"`" != "" ];then
860 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
861 else
862 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
863 fi
864 ;;
865 without)
866 cond_type=''
867 AVAIL_BCOND_WITHOUT="$opt"
868 if [ "`echo $BCOND|grep -- "--without $AVAIL_BCOND_WITHOUT"`" != "" ];then
869 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
870 else
871 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
872 fi
873 ;;
874 esac
875 ;;
876 esac
877 done
878 ;;
879 esac
da0048be 880}
881
d79f7220 882run_sub_builder()
883{
b2975fc3 884 package_name="${1}"
885 echo -ne "Package installation failed:\t$package_name\n"
886 #
887