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