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