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