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