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