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