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