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