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