]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- Updating source- md5 and size.
[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
84309f3c 251-U, --update - refetch sources, don't use distfiles, and update md5 and size 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
a4b50627
AF
486src_size ()
487{
488 [ X"$NO5" = X"yes" ] && return
489 no=$(src_no "$1")
490 [ -z "$no" ] && return
491 cd $SPECS_DIR
492 grep -i "#[ ]*Source$no-size[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
493}
494
cd445739
AM
495distfiles_url ()
496{
497 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
498}
499
500distfiles_attic_url ()
501{
502 echo "$PROTOCOL$DISTFILES_SERVER/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
503}
504
505good_md5 ()
506{
507 md5=$(src_md5 "$1")
508 [ "$md5" = "" ] || \
509 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
8ba5cdda
PG
510}
511
a4b50627
AF
512good_size ()
513{
514 size=$(src_size "$1")
515 [ "$size" = "" ] || \
516 [ "$size" = "$(find $(nourl "$1") -printf "%s" 2>/dev/null)" ]
517}
518
947025e5 519cvsignore_df ()
520{
521 if [ "$CVSIGNORE_DF" != "yes" ]; then
522 return
523 fi
524 cvsignore=${SOURCE_DIR}/.cvsignore
525 if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
526 echo "$1" >> $cvsignore
527 fi
528}
529
cd445739
AM
530get_files()
531{
532 GET_FILES="$@"
533
534 if [ -n "$DEBUG" ]; then
535 set -x;
536 set -v;
537 fi
538
539 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
540 cd "$SOURCE_DIR"
541
542 OPTIONS="up "
543 if [ -n "$CVSROOT" ]; then
544 OPTIONS="-d $CVSROOT $OPTIONS"
545 else
546 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
547 echo "warning: No cvs access defined for SOURCES"
548 NOCVS="yes"
549 fi
550 fi
551 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
552 OPTIONS="$OPTIONS -A"
553 else
554 if [ -n "$CVSDATE" ]; then
555 OPTIONS="$OPTIONS -D $CVSDATE"
556 fi
557 if [ -n "$CVSTAG" ]; then
558 OPTIONS="$OPTIONS -r $CVSTAG"
559 fi
560 fi
561 for i in $GET_FILES
562 do
563 if [ -n "$UPDATE5" ]; then
564 if [ -n "$ADD5" ]; then
565 [ `nourl $i` = "$i" ] && continue
566 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
567 else
568 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
569 fi
570 fi
571 FROM_DISTFILES=0
572 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
573 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
574 echo "Warning: no URL given for $i"
575 fi
576
577 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
a4b50627
AF
578 if good_md5 "$i" && good_size "$i"; then
579 echo "$(nourl "$i") having proper md5sum and size already exists"
cd445739
AM
580 continue
581 fi
582 target=$(nourl "$i")
583 url=$(distfiles_url "$i")
584 url_attic=$(distfiles_attic_url "$i")
585 FROM_DISTFILES=1
586 if [ `echo $url | grep -E '^(\.|/)'` ]; then
587 ${GETLOCAL} $url $target
588 else
589 if [ -z "$NOMIRRORS" ]; then
590 url="`find_mirror "$url"`"
591 fi
592 ${GETURI} -O "$target" "$url" || \
593 if [ `echo $url | grep -E 'ftp://'` ]; then
594 ${GETURI2} -O "$target" "$url"
595 fi
596 fi
597 if ! test -s "$target"; then
598 rm -f "$target"
599 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
600 ${GETLOCAL} $url_attic $target
601 else
602 if [ -z "$NOMIRRORS" ]; then
603 url_attic="`find_mirror "$url_attic"`"
604 fi
605 ${GETURI} -O "$target" "$url_attic" || \
606 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
607 ${GETURI2} -O "$target" "$url_attic"
608 fi
609 fi
610 fi
947025e5 611 if test -s "$target"; then
612 cvsignore_df $target
613 else
cd445739
AM
614 rm -f "$target"
615 FROM_DISTFILES=0
616 fi
617 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
618 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
619 result=1
620 retries_counter=0
621 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
622 do
623 retries_counter=$(( $retries_counter + 1 ))
624 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
625 result=$?
626 [ -n "$output" ] && echo "$output"
627 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
628 echo "Trying again [`nourl $i`]... ($retries_counter)"
629 sleep 2
630 continue
631 else
632 break
633 fi
634 done
635 fi
636
637 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
638 if [ -z "$NOMIRRORS" ]; then
639 im="`find_mirror "$i"`"
640 else
641 im="$i"
642 fi
643 ${GETURI} "$im" || \
644 if [ `echo $im | grep -E 'ftp://'` ]; then
645 ${GETURI2} "$im"
646 fi
647 fi
648
649 fi
650 srcno=$(src_no $i)
651 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
652 Exit_error err_no_source_in_repo $i;
653 elif [ -n "$UPDATE5" ] && \
654 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
655 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
656 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
657 then
83a56c8a 658 echo "Updating source-$srcno md5 and size."
cd445739 659 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
664125b9 660 size=$(find $(nourl "$i") -printf "%s" 2>/dev/null)
cd445739 661 perl -i -ne '
a4b50627
AF
662 print unless /^\s*#\s*Source'$srcno'-(md5|size)\s*:/i;
663 print "# Source'$srcno'-md5:\t'$md5'\n# Source'$srcno'-size:\t'$size'\n"
cd445739
AM
664 if /^Source'$srcno'\s*:\s+/;
665 ' \
666 $SPECS_DIR/$SPECFILE
667 fi
668
a4b50627 669 if good_md5 "$i" && good_size "$i"; then
cd445739
AM
670 :
671 elif [ "$FROM_DISTFILES" = 1 ]; then
a4b50627 672 # wrong md5 or size from distfiles: remove the file and try again
cd445739 673 # but only once ...
a4b50627 674 echo "MD5 sum or size mismatch. Trying full fetch."
cd445739
AM
675 FROM_DISTFILES=2
676 rm -f $target
677 ${GETURI} -O "$target" "$url" || \
678 if [ `echo $url | grep -E 'ftp://'` ]; then
679 ${GETURI2} -O "$target" "$url"
680 fi
681 if ! test -s "$target"; then
682 rm -f "$target"
683 ${GETURI} -O "$target" "$url_attic" || \
684 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
685 ${GETURI2} -O "$target" "$url_attic"
686 fi
687 fi
688 test -s "$target" || rm -f "$target"
689 fi
690
a4b50627 691 if good_md5 "$i" && good_size "$i" ; then
cd445739
AM
692 :
693 else
a4b50627
AF
694 echo "MD5 sum or size mismatch. Use -U to refetch sources,"
695 echo "or -5 to update md5 sums and size info, if you're sure files are correct."
cd445739
AM
696 Exit_error err_no_source_in_repo $i
697 fi
698 done
699
700 if [ "$CHMOD" = "yes" ]; then
701 CHMOD_FILES="`nourl $GET_FILES`"
702 if [ -n "$CHMOD_FILES" ]; then
703 chmod $CHMOD_MODE $CHMOD_FILES
704 fi
705 fi
706 unset OPTIONS
707 fi
708}
709
710make_tagver() {
711 # Check whether first character of PACKAGE_NAME is legal for tag name
712 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
713 TAG_PREFIX=tag_
714 fi
715 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"`
716 # Remove #kernel.version_release from TAGVER because tagging sources
717 # could occur with different kernel-headers than kernel-headers used at build time.
718 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
719 echo -n "$TAGVER"
720}
721
722tag_files()
723{
724 TAG_FILES="$@"
725
726 if [ -n "$DEBUG" ]; then
727 set -x;
728 set -v;
729 fi
730
731 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
732 echo "Version: $PACKAGE_VERSION"
733 echo "Release: $PACKAGE_RELEASE"
734
735 TAGVER=`make_tagver`
736
737 if [ "$TAG_VERSION" = "yes" ]; then
738 echo "CVS tag: $TAGVER"
739 fi
740 if [ -n "$TAG" ]; then
741 echo "CVS tag: $TAG"
742 fi
743
744 OPTIONS="tag -F"
745 if [ -n "$CVSROOT" ]; then
746 OPTIONS="-d $CVSROOT $OPTIONS"
747 fi
748
749 cd "$SOURCE_DIR"
750 for i in $TAG_FILES
751 do
752 # don't tag files stored on distfiles
753 [ -n "`src_md5 $i`" ] && continue
754 if [ -f "`nourl $i`" ]; then
755 if [ "$TAG_VERSION" = "yes" ]; then
756 cvs $OPTIONS $TAGVER `nourl $i`
757 fi
758 if [ -n "$TAG" ]; then
759 cvs $OPTIONS $TAG `nourl $i`
760 fi
761 else
762 Exit_error err_no_source_in_repo $i
763 fi
764 done
765
766 cd "$SPECS_DIR"
767 if [ "$TAG_VERSION" = "yes" ]; then
768 cvs $OPTIONS $TAGVER $SPECFILE
769 fi
770 if [ -n "$TAG" ]; then
771 cvs $OPTIONS $TAG $SPECFILE
772 fi
773
774 unset OPTIONS
775 fi
776}
777
778branch_files()
779{
780 TAG=$1
781 echo "CVS branch tag: $TAG"
782 shift;
783
784 TAG_FILES="$@"
785
786 if [ -n "$DEBUG" ]; then
787 set -x;
788 set -v;
789 fi
790
791 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
792
793 OPTIONS="tag -b"
794 if [ -n "$CVSROOT" ]; then
795 OPTIONS="-d $CVSROOT $OPTIONS"
796 fi
797 cd "$SOURCE_DIR"
798 for i in $TAG_FILES
799 do
800 if [ -f `nourl $i` ]; then
801 cvs $OPTIONS $TAG `nourl $i`
802 else
803 Exit_error err_no_source_in_repo $i
804 fi
805 done
806 cd "$SPECS_DIR"
807 cvs $OPTIONS $TAG $SPECFILE
808
809 unset OPTIONS
810 fi
811}
812
813
814
59398507 815build_package()
816{
cd445739
AM
817 if [ -n "$DEBUG" ]; then
818 set -x;
819 set -v;
820 fi
5a491465 821
cd445739
AM
822 cd "$SPECS_DIR"
823
824 if [ -n "$TRY_UPGRADE" ]; then
825 if [ -n "$FLOAT_VERSION" ]; then
826 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
827 else
828 TNOTIFY=`./pldnotify.awk $SPECFILE`
829 fi
830
831 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
832
833 if [ -n "$TNEWVER" ]; then
834 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
835 echo "New version found, updating spec file to version " $TNEWVER
836 cp -f $SPECFILE $SPECFILE.bak
837 chmod +w $SPECFILE
838 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
839 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
840 parse_spec;
841 get_files "$SOURCES $PATCHES";
842 unset TOLDVER TNEWVER TNOTIFY
843 fi
844 fi
845 cd "$SPECS_DIR"
64ea5308 846
847 if [ -n "$TARGET" ]; then
848 TARGET_SWITCH="--target $TARGET"
849 fi
850
cd445739
AM
851 case "$COMMAND" in
852 build )
853 BUILD_SWITCH="-ba" ;;
854 build-binary )
855 BUILD_SWITCH="-bb" ;;
856 build-source )
857 BUILD_SWITCH="-bs --nodeps" ;;
858 build-prep )
859 BUILD_SWITCH="-bp --nodeps" ;;
860 esac
861 if [ -n "$LOGFILE" ]; then
862 LOG=`eval echo $LOGFILE`
863 if [ -d "$LOG" ]; then
864 echo "Log file $LOG is a directory."
865 echo "Parse error in the spec?"
866 Exit_error err_build_fail;
867 fi
868 if [ -n "$LASTLOG_FILE" ]; then
869 echo "LASTLOG=$LOG" > $LASTLOG_FILE
870 fi
871 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
64ea5308 872 (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
873 RETVAL=`cat $RES_FILE`
874 rm $RES_FILE
875 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
876 if [ "$RETVAL" -eq "0" ]; then
877 mv $LOG $LOGDIROK
878 else
879 mv $LOG $LOGDIRFAIL
880 fi
881 fi
8ba5cdda 882 else
64ea5308 883 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH $TARGET_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
cd445739 884 RETVAL=$?
8ba5cdda 885 fi
cd445739
AM
886 if [ "$RETVAL" -ne "0" ]; then
887 if [ -n "$TRY_UPGRADE" ]; then
888 echo "\n!!! Package with new version cannot be build automagically\n"
889 mv -f $SPECFILE.bak $SPECFILE
890 fi
891 Exit_error err_build_fail;
892 fi
893 unset BUILD_SWITCH
64ea5308 894 unset TARGET_SWITCH
cd445739
AM
895}
896
897nourl()
898{
899 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
900}
901
902
903install_required_packages()
904{
905 run_poldek -vi $1
906 return $?
907}
908
909set_bconds_values()
910{
911 AVAIL_BCONDS_WITHOUT=""
912 AVAIL_BCONDS_WITH=""
913 if `grep -q ^%bcond ${SPECFILE}`; then
914 BCOND_VERSION="NEW"
36d03934 915 elif `egrep -q ^#\ *_with ${SPECFILE}`; then
cd445739
AM
916 BCOND_VERSION="OLD"
917 else
918 BCOND_VERSION="NONE"
919 fi
920 case "${BCOND_VERSION}" in
921 NONE)
922 :
923 ;;
924 OLD)
925 echo "Warning: This spec has old style bconds. Fix it || die."
926 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
927 do
928 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
929 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
930 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
931 else
932 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
933 fi
934 done
935
936 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
937 do
938 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
939 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
940 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
941 else
942 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
943 fi
944 done
945 ;;
946 NEW)
947 cond_type="" # with || without
948 for opt in `$RPMBUILD --bcond $SPECFILE`
949 do
950 case "$opt" in
951 _without)
952 cond_type="without"
953 ;;
954 _with)
955 cond_type="with"
956 ;;
957 *)
958 case "$cond_type" in
959 with)
960 cond_type=''
961 AVAIL_BCOND_WITH="$opt"
962 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
963 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
964 else
965 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
966 fi
967 ;;
968 without)
969 cond_type=''
970 AVAIL_BCOND_WITHOUT="$opt"
971 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
972 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
973 else
974 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
975 fi
976 ;;
977 esac
978 ;;
979 esac
980 done
981 ;;
982 esac
983}
984
985run_sub_builder()
986{
987 package_name="${1}"
988 echo -ne "Package installation failed:\t$package_name\n"
989 #
990