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