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