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