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