]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- allow --target=... syntax
[packages/rpm-build-tools.git] / builder.sh
CommitLineData
cd445739
AM
1#!/bin/sh
2# -----------
3# $Id$
4# Exit codes:
2a5f078d 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
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]
2a5f078d 183
cd445739
AM
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),
2a5f078d 200-d <cvsroot>, --cvsroot <cvsroot>
cd445739
AM
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.
6dd19291 265--target <platform>, --target=<platform>
64ea5308 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 )
2a5f078d 278 rpm -bp --nodeps --define 'prep %dump' $BCOND $TARGET_SWITCH $SPECFILE 2>&1
cd445739
AM
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
78eab2a1 320
cd445739
AM
321 if [ -n "$BE_VERBOSE" ]; then
322 echo "- Sources : `nourl $SOURCES`"
323 if [ -n "$PATCHES" ]; then
324 echo "- Patches : `nourl $PATCHES`"
325 else
326 echo "- Patches : *no patches needed*"
327 fi
328 if [ -n "$ICONS" ]; then
329 echo "- Icon : `nourl $ICONS`"
330 else
331 echo "- Icon : *no package icon*"
332 fi
333 echo "- Name : $PACKAGE_NAME"
334 echo "- Version : $PACKAGE_VERSION"
335 echo "- Release : $PACKAGE_RELEASE"
336 fi
337}
338
339Exit_error()
340{
341 if [ -n "$DEBUG" ]; then
342 set -x;
343 set -v;
344 fi
345
346 cd "$__PWD"
347
348 case "$1" in
349 "err_no_spec_in_cmdl" )
350 remove_build_requires
351 echo "ERROR: spec file name not specified.";
352 exit 2 ;;
353 "err_no_spec_in_repo" )
354 remove_build_requires
355 echo "Error: spec file not stored in CVS repo.";
356 exit 3 ;;
357 "err_no_source_in_repo" )
358 remove_build_requires
359 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
360 exit 4 ;;
361 "err_build_fail" )
362 remove_build_requires
363 echo "Error: package build failed. (${2:-no more info})";
364 exit 5 ;;
78eab2a1
AM
365 "err_no_package_data" )
366 remove_build_requires
367 echo "Error: couldn't get out package name/version/release from spec file."
368 exit 6 ;;
50321881
JK
369 "err_tag_exists" )
370 remove_build_requires
371 echo "Tag ${2} already exists (spec release: ${3}).";
372 exit 9 ;;
373 "err_fract_rel" )
374 remove_build_requires
375 echo "Release ${2} not integer and not a snapshot.";
376 exit 10 ;;
377
cd445739 378 esac
50321881 379 echo "Unknown error."
2a5f078d 380 exit 100
cd445739
AM
381}
382
383init_builder()
384{
385 if [ -n "$DEBUG" ]; then
386 set -x;
387 set -v;
0dd6320d 388 fi
cd445739
AM
389
390 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
391 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
392
393 __PWD="`pwd`"
00fcec7e 394}
395
d6a77ddb 396get_spec()
1471f6d6 397{
cd445739
AM
398 if [ -n "$DEBUG" ]; then
399 set -x;
400 set -v;
401 fi
402
403 cd "$SPECS_DIR"
404 if [ \! -f "$SPECFILE" ]; then
405 SPECFILE="`basename $SPECFILE .spec`.spec";
406 fi
407 if [ "$NOCVSSPEC" != "yes" ]; then
408 OPTIONS="up "
409
410 if [ -n "$CVSROOT" ]; then
411 OPTIONS="-d $CVSROOT $OPTIONS"
412 else
413 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
414 echo "warning: No cvs access defined - using local .spec file"
415 NOCVSSPEC="yes"
416 fi
417 fi
418
419 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
420 OPTIONS="$OPTIONS -A"
421 else
422 if [ -n "$CVSDATE" ]; then
423 OPTIONS="$OPTIONS -D $CVSDATE"
424 fi
425 if [ -n "$CVSTAG" ]; then
426 OPTIONS="$OPTIONS -r $CVSTAG"
427 fi
428 fi
429
430 result=1
431 retries_counter=0
432 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
433 do
434 retries_counter=$(( $retries_counter + 1 ))
435 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
436 result=$?
437 [ -n "$output" ] && echo "$output"
438 if [ "$result" -ne "0" ]; then
439 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
440 echo "Trying again [$SPECFILE]... ($retries_counter)"
441 sleep 2
442 continue
443 fi
444 Exit_error err_no_spec_in_repo;
445 fi
446 done
447 fi
448 if [ ! -f "$SPECFILE" ]; then
449 Exit_error err_no_spec_in_repo;
450 fi
451
452 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
453 chmod $CHMOD_MODE $SPECFILE
454 fi
455 unset OPTIONS
456 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
457}
458
459find_mirror()
460{
461 cd "$SPECS_DIR"
462 url="$1"
463 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
464 cvs update mirrors >&2
465 fi
466
467 IFS="|"
468 while read origin mirror name rest
469 do
470 ol=`echo -n "$origin"|wc -c`
471 prefix="`echo -n "$url" | head -c $ol`"
472 if [ "$prefix" = "$origin" ] ; then
473 suffix="`echo "$url"|cut -b $ol-`"
474 echo -n "$mirror$suffix"
475 return 0
476 fi
477 done < mirrors
478 echo "$url"
479}
480
481src_no ()
482{
483 cd $SPECS_DIR
484 rpm_dump | \
485 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
486 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
487 head -n 1 | xargs
1471f6d6 488}
489
cd445739 490src_md5 ()
8ba5cdda 491{
cd445739
AM
492 [ X"$NO5" = X"yes" ] && return
493 no=$(src_no "$1")
494 [ -z "$no" ] && return
495 cd $SPECS_DIR
496 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
497 if [ -z "$spec_rev" ]; then
498 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
499 fi
500 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
501 md5=$(grep -s -v '^#' additional-md5sums | \
502 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
503 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
504 grep -E '^[0-9a-f]{32}$')
505 if [ X"$md5" = X"" ] ; then
506 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
507 else
508 if [ $(echo "$md5" | wc -l) != 1 ] ; then
509 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
510 fi
511 echo "$md5" | tail -n 1
512 fi
513}
514
515distfiles_url ()
516{
517 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
518}
519
520distfiles_attic_url ()
521{
d4730dae 522 echo "$PROTOCOL$ATTICDISTFILES_SERVER/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
cd445739
AM
523}
524
525good_md5 ()
526{
527 md5=$(src_md5 "$1")
528 [ "$md5" = "" ] || \
529 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
8ba5cdda
PG
530}
531
a4b50627
AF
532good_size ()
533{
deccc50e
AM
534 size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
535 [ -n "$size" -a "$size" -gt 0 ]
a4b50627
AF
536}
537
947025e5 538cvsignore_df ()
539{
540 if [ "$CVSIGNORE_DF" != "yes" ]; then
541 return
542 fi
543 cvsignore=${SOURCE_DIR}/.cvsignore
544 if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
545 echo "$1" >> $cvsignore
546 fi
547}
548
cd445739
AM
549get_files()
550{
551 GET_FILES="$@"
552
553 if [ -n "$DEBUG" ]; then
554 set -x;
555 set -v;
556 fi
557
558 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
559 cd "$SOURCE_DIR"
560
561 OPTIONS="up "
562 if [ -n "$CVSROOT" ]; then
563 OPTIONS="-d $CVSROOT $OPTIONS"
564 else
565 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
566 echo "warning: No cvs access defined for SOURCES"
567 NOCVS="yes"
568 fi
569 fi
570 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
571 OPTIONS="$OPTIONS -A"
572 else
573 if [ -n "$CVSDATE" ]; then
574 OPTIONS="$OPTIONS -D $CVSDATE"
575 fi
576 if [ -n "$CVSTAG" ]; then
577 OPTIONS="$OPTIONS -r $CVSTAG"
578 fi
579 fi
580 for i in $GET_FILES
581 do
582 if [ -n "$UPDATE5" ]; then
583 if [ -n "$ADD5" ]; then
584 [ `nourl $i` = "$i" ] && continue
585 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
586 else
587 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
588 fi
589 fi
590 FROM_DISTFILES=0
591 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
592 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
593 echo "Warning: no URL given for $i"
594 fi
595
596 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
a4b50627 597 if good_md5 "$i" && good_size "$i"; then
deccc50e 598 echo "$(nourl "$i") having proper md5sum already exists"
cd445739
AM
599 continue
600 fi
601 target=$(nourl "$i")
602 url=$(distfiles_url "$i")
603 url_attic=$(distfiles_attic_url "$i")
604 FROM_DISTFILES=1
605 if [ `echo $url | grep -E '^(\.|/)'` ]; then
606 ${GETLOCAL} $url $target
607 else
608 if [ -z "$NOMIRRORS" ]; then
609 url="`find_mirror "$url"`"
610 fi
611 ${GETURI} -O "$target" "$url" || \
612 if [ `echo $url | grep -E 'ftp://'` ]; then
613 ${GETURI2} -O "$target" "$url"
614 fi
615 fi
616 if ! test -s "$target"; then
617 rm -f "$target"
618 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
619 ${GETLOCAL} $url_attic $target
620 else
621 if [ -z "$NOMIRRORS" ]; then
622 url_attic="`find_mirror "$url_attic"`"
623 fi
624 ${GETURI} -O "$target" "$url_attic" || \
625 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
626 ${GETURI2} -O "$target" "$url_attic"
627 fi
628 fi
629 fi
947025e5 630 if test -s "$target"; then
631 cvsignore_df $target
632 else
cd445739
AM
633 rm -f "$target"
634 FROM_DISTFILES=0
635 fi
636 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
637 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
638 result=1
639 retries_counter=0
640 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
641 do
642 retries_counter=$(( $retries_counter + 1 ))
643 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
644 result=$?
645 [ -n "$output" ] && echo "$output"
646 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
647 echo "Trying again [`nourl $i`]... ($retries_counter)"
648 sleep 2
649 continue
650 else
651 break
652 fi
653 done
654 fi
655
656 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
657 if [ -z "$NOMIRRORS" ]; then
658 im="`find_mirror "$i"`"
659 else
660 im="$i"
661 fi
662 ${GETURI} "$im" || \
663 if [ `echo $im | grep -E 'ftp://'` ]; then
664 ${GETURI2} "$im"
665 fi
666 fi
667
668 fi
669 srcno=$(src_no $i)
670 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
671 Exit_error err_no_source_in_repo $i;
672 elif [ -n "$UPDATE5" ] && \
673 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
674 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
675 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
676 then
deccc50e 677 echo "Updating source-$srcno md5."
cd445739
AM
678 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
679 perl -i -ne '
deccc50e
AM
680 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
681 print "# Source'$srcno'-md5:\t'$md5'\n"
cd445739
AM
682 if /^Source'$srcno'\s*:\s+/;
683 ' \
684 $SPECS_DIR/$SPECFILE
685 fi
2a5f078d 686
a4b50627 687 if good_md5 "$i" && good_size "$i"; then
cd445739
AM
688 :
689 elif [ "$FROM_DISTFILES" = 1 ]; then
deccc50e 690 # wrong md5 from distfiles: remove the file and try again
cd445739 691 # but only once ...
deccc50e 692 echo "MD5 sum mismatch. Trying full fetch."
cd445739
AM
693 FROM_DISTFILES=2
694 rm -f $target
695 ${GETURI} -O "$target" "$url" || \
696 if [ `echo $url | grep -E 'ftp://'` ]; then
697 ${GETURI2} -O "$target" "$url"
698 fi
699 if ! test -s "$target"; then
700 rm -f "$target"
701 ${GETURI} -O "$target" "$url_attic" || \
702 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
703 ${GETURI2} -O "$target" "$url_attic"
704 fi
705 fi
706 test -s "$target" || rm -f "$target"
707 fi
708
a4b50627 709 if good_md5 "$i" && good_size "$i" ; then
cd445739
AM
710 :
711 else
deccc50e
AM
712 echo "MD5 sum mismatch or 0 size. Use -U to refetch sources,"
713 echo "or -5 to update md5 sums, if you're sure files are correct."
cd445739
AM
714 Exit_error err_no_source_in_repo $i
715 fi
716 done
717
718 if [ "$CHMOD" = "yes" ]; then
719 CHMOD_FILES="`nourl $GET_FILES`"
720 if [ -n "$CHMOD_FILES" ]; then
721 chmod $CHMOD_MODE $CHMOD_FILES
722 fi
723 fi
724 unset OPTIONS
725 fi
726}
727
728make_tagver() {
78eab2a1
AM
729
730 if [ -n "$DEBUG" ]; then
731 set -x;
732 set -v;
733 fi
2a5f078d 734
cd445739
AM
735 # Check whether first character of PACKAGE_NAME is legal for tag name
736 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
737 TAG_PREFIX=tag_
738 fi
739 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"`
740 # Remove #kernel.version_release from TAGVER because tagging sources
741 # could occur with different kernel-headers than kernel-headers used at build time.
742 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
743 echo -n "$TAGVER"
744}
745
746tag_files()
747{
748 TAG_FILES="$@"
749
750 if [ -n "$DEBUG" ]; then
751 set -x;
752 set -v;
753 fi
754
755 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
756 echo "Version: $PACKAGE_VERSION"
757 echo "Release: $PACKAGE_RELEASE"
758
759 TAGVER=`make_tagver`
760
761 if [ "$TAG_VERSION" = "yes" ]; then
762 echo "CVS tag: $TAGVER"
763 fi
764 if [ -n "$TAG" ]; then
765 echo "CVS tag: $TAG"
766 fi
767
768 OPTIONS="tag -F"
769 if [ -n "$CVSROOT" ]; then
770 OPTIONS="-d $CVSROOT $OPTIONS"
771 fi
772
773 cd "$SOURCE_DIR"
774 for i in $TAG_FILES
775 do
776 # don't tag files stored on distfiles
777 [ -n "`src_md5 $i`" ] && continue
778 if [ -f "`nourl $i`" ]; then
779 if [ "$TAG_VERSION" = "yes" ]; then
780 cvs $OPTIONS $TAGVER `nourl $i`
781 fi
782 if [ -n "$TAG" ]; then
783 cvs $OPTIONS $TAG `nourl $i`
784 fi
785 else
786 Exit_error err_no_source_in_repo $i
787 fi
788 done
789
790 cd "$SPECS_DIR"
791 if [ "$TAG_VERSION" = "yes" ]; then
792 cvs $OPTIONS $TAGVER $SPECFILE
793 fi
794 if [ -n "$TAG" ]; then
795 cvs $OPTIONS $TAG $SPECFILE
796 fi
797
798 unset OPTIONS
799 fi
800}
801
802branch_files()
803{
804 TAG=$1
805 echo "CVS branch tag: $TAG"
806 shift;
807
808 TAG_FILES="$@"
809
810 if [ -n "$DEBUG" ]; then
811 set -x;
812 set -v;
813 fi
814
815 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
816
817 OPTIONS="tag -b"
818 if [ -n "$CVSROOT" ]; then
819 OPTIONS="-d $CVSROOT $OPTIONS"
820 fi
821 cd "$SOURCE_DIR"
822 for i in $TAG_FILES
823 do
824 if [ -f `nourl $i` ]; then
825 cvs $OPTIONS $TAG `nourl $i`
826 else
827 Exit_error err_no_source_in_repo $i
828 fi
829 done
830 cd "$SPECS_DIR"
831 cvs $OPTIONS $TAG $SPECFILE
832
833 unset OPTIONS
834 fi
835}
836
837
838
59398507 839build_package()
840{
cd445739
AM
841 if [ -n "$DEBUG" ]; then
842 set -x;
843 set -v;
844 fi
5a491465 845
cd445739
AM
846 cd "$SPECS_DIR"
847
848 if [ -n "$TRY_UPGRADE" ]; then
849 if [ -n "$FLOAT_VERSION" ]; then
850 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
851 else
852 TNOTIFY=`./pldnotify.awk $SPECFILE`
853 fi
854
855 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
856
857 if [ -n "$TNEWVER" ]; then
858 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
859 echo "New version found, updating spec file to version " $TNEWVER
860 cp -f $SPECFILE $SPECFILE.bak
861 chmod +w $SPECFILE
862 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
863 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
864 parse_spec;
865 get_files "$SOURCES $PATCHES";
866 unset TOLDVER TNEWVER TNOTIFY
867 fi
868 fi
869 cd "$SPECS_DIR"
2a5f078d 870
cd445739
AM
871 case "$COMMAND" in
872 build )
873 BUILD_SWITCH="-ba" ;;
874 build-binary )
875 BUILD_SWITCH="-bb" ;;
876 build-source )
877 BUILD_SWITCH="-bs --nodeps" ;;
878 build-prep )
879 BUILD_SWITCH="-bp --nodeps" ;;
880 esac
881 if [ -n "$LOGFILE" ]; then
882 LOG=`eval echo $LOGFILE`
883 if [ -d "$LOG" ]; then
884 echo "Log file $LOG is a directory."
885 echo "Parse error in the spec?"
886 Exit_error err_build_fail;
887 fi
888 if [ -n "$LASTLOG_FILE" ]; then
889 echo "LASTLOG=$LOG" > $LASTLOG_FILE
890 fi
891 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
8f96ab6c 892 (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
893 RETVAL=`cat $RES_FILE`
894 rm $RES_FILE
895 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
896 if [ "$RETVAL" -eq "0" ]; then
897 mv $LOG $LOGDIROK
898 else
899 mv $LOG $LOGDIRFAIL
900 fi
901 fi
8ba5cdda 902 else
8f96ab6c 903 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE
cd445739 904 RETVAL=$?
8ba5cdda 905 fi
cd445739
AM
906 if [ "$RETVAL" -ne "0" ]; then
907 if [ -n "$TRY_UPGRADE" ]; then
908 echo "\n!!! Package with new version cannot be build automagically\n"
909 mv -f $SPECFILE.bak $SPECFILE
910 fi
911 Exit_error err_build_fail;
912 fi
913 unset BUILD_SWITCH
914}
915
916nourl()
917{
918 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
919}
920
cd445739
AM
921install_required_packages()
922{
923 run_poldek -vi $1
924 return $?
925}
926
927set_bconds_values()
928{
929 AVAIL_BCONDS_WITHOUT=""
930 AVAIL_BCONDS_WITH=""
931 if `grep -q ^%bcond ${SPECFILE}`; then
932 BCOND_VERSION="NEW"
36d03934 933 elif `egrep -q ^#\ *_with ${SPECFILE}`; then
cd445739
AM
934 BCOND_VERSION="OLD"
935 else
936 BCOND_VERSION="NONE"
937 fi
938 case "${BCOND_VERSION}" in
939 NONE)
940 :
941 ;;
942 OLD)
943 echo "Warning: This spec has old style bconds. Fix it || die."
944 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
945 do
946 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
947 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
948 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
949 else
950 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
951 fi
952 done
2a5f078d 953
cd445739
AM
954 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
955 do
956 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
957 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
958 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
959 else
960 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
961 fi
962 done
963 ;;
964 NEW)
965 cond_type="" # with || without
966 for opt in `$RPMBUILD --bcond $SPECFILE`
967 do
968 case "$opt" in
969 _without)
970 cond_type="without"
971 ;;
972 _with)
973 cond_type="with"
974 ;;
975 *)
976 case "$cond_type" in
977 with)
978 cond_type=''
979 AVAIL_BCOND_WITH="$opt"
980 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
981 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
982 else
983 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
984 fi
985 ;;
986 without)
987 cond_type=''
988 AVAIL_BCOND_WITHOUT="$opt"
989 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
990 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
991 else
992 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
993 fi
994 ;;
995 esac
996 ;;
997 esac
998 done
999 ;;
1000 esac
1001}
1002
1003run_sub_builder()
1004{
1005 package_name="${1}"
1006 echo -ne "Package installation failed:\t$package_name\n"
1007 #
1008