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