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