]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- don't guess POLDEK_INDEX_DIR, check it
[packages/rpm-build-tools.git] / builder.sh
CommitLineData
b054f772 1#!/bin/sh
33f5276d 2# -----------
25fa34fe 3# $Id$
33f5276d 4# Exit codes:
5# 0 - succesful
10b4dd7f 6# 1 - help displayed
33f5276d 7# 2 - no spec file name in cmdl parameters
8# 3 - spec file not stored in repo
0ad50ce9 9# 4 - some source, patch or icon files not stored in repo
10# 5 - package build failed
10b4dd7f 11# 6 - spec file with errors
da0048be 12# 7 - wrong source in /etc/poldek.conf
5a491465 13
931a4acf
TP
14# Notes (todo):
15# - builder -u fetches current version first
16# - tries to get new version from distfiles without new md5
17# - after fetching new version doesn't update md5
2837871a 18# - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
9308ddd0 19# when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
2837871a 20# - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov
82d4501c 21# - when Icon: field is present, -5 and -a5 doesn't work
931a4acf 22
4003ad8c 23VERSION="\
24Build package utility from PLD CVS repository
6cb7df6d 25V 0.11 (C) 1999-2003 Free Penguins".
5a491465 26PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
a7af9862 27
b03f053b 28COMMAND="build"
29
bde1c404 30SPECFILE=""
d287305c 31BE_VERBOSE=""
4003ad8c 32QUIET=""
5dd89621 33CLEAN=""
7c2dd1b2 34DEBUG=""
cc97f1f3 35NOURLS=""
157dc315 36NOCVS=""
6fc910c7 37NOCVSSPEC=""
fc0e5bb5 38NODIST=""
b130abf2 39UPDATE=""
a9d9a79a 40UPDATE5=""
de6b5b2a 41ADD5=""
81474543 42ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
c61a8d10
AM
43if [ -s CVS/Root ]; then
44 CVSROOT=$(cat CVS/Root)
45else
46 CVSROOT=${CVSROOT:-""}
47fi
d6a75d60 48# Example: LOGFILE='../log.$PACKAGE_NAME'
49# Yes, you can use variable name! Note _single_ quotes!
50LOGFILE=''
00fcec7e 51
52LOGDIR=""
53LOGDIROK=""
54LOGDIRFAIL=""
55LASTLOG_FILE=""
79d76918 56CHMOD="no"
d6a75d60 57CHMOD_MODE="0444"
33a9d2d1 58RPMOPTS=""
6049c3d1 59BCOND=""
d287305c 60
61PATCHES=""
62SOURCES=""
7053d3fd 63ICONS=""
d287305c 64PACKAGE_RELEASE=""
65PACKAGE_VERSION=""
66PACKAGE_NAME=""
d7f490f3 67PROTOCOL="ftp"
34c911e6 68WGET_RETRIES=${MAX_WGET_RETRIES:-0}
b92ecfc9 69CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
5a491465 70
00fcec7e 71CVSTAG=""
72RES_FILE=""
73
62546902 74CVS_SERVER="cvs.pld-linux.org"
d7f490f3 75DISTFILES_SERVER="://distfiles.pld-linux.org"
ea15df77 76
3ae81a20 77DEF_NICE_LEVEL=0
78
c6a390a1
AM
79FAIL_IF_NO_SOURCES="yes"
80
d8140aad
AM
81wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
82wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
83
84GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
85GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
6aefe77b 86GETLOCAL="cp -a"
11f33a0c 87
7147050f
AM
88if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
89 RPM="rpm"
90 RPMBUILD="rpm"
91else
92 RPM="rpm"
93 RPMBUILD="rpmbuild"
94fi
95
c8740da7 96POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
da0048be 97POLDEK_SOURCE="cvs"
98
99# Example grep cvs /etc/poldek.conf:
100# source = cvs /home/users/yoshi/rpm/RPMS/
e33f5c17 101if [ "$UPDATE_POLDEK_INDEXES" == "yes" ]; then
102 POLDEK_SOURCE_VALIDITY="`grep ${POLDEK_SOURCE} /etc/poldek.conf|grep -v ^#`"
103 if [ "${POLDEK_SOURCE_VALIDITY}" == "" ]; then
104 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
105 echo "Fix it and try to contiune"
106 exit 7
107 fi
da0048be 108fi
109
6eb44b93 110if [ -f ~/etc/builderrc ]; then
7922b3ec 111 . ~/etc/builderrc
6eb44b93 112elif [ -f ~/.builderrc ]; then
7922b3ec 113 . ~/.builderrc
5aa0ef93
AF
114fi
115
da946cd6 116#---------------------------------------------
117# functions
118
5a491465 119usage()
120{
7c2dd1b2 121 if [ -n "$DEBUG" ]; then set -xv; fi
122 echo "\
7922b3ec 123Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
81f85806 124
125 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
126 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
d7f490f3 127 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
00fcec7e 128 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
a2164135 129 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
d71ea755
MM
130 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
131 [{-Tp|--tag-prefix} <prefix>]
81f85806 132 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
c9ff8825 133 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
5a491465 134
de6b5b2a 135 -5, --update-md5
afade7dd
JB
136 - update md5 comments in spec, implies -nd -ncs
137 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
a2a9c8df 138 -D, --debug - enable script debugging mode,
5a491465 139 -V, --version - output builder version
62546902 140 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
79b2ec0e 141 -b, -ba,
cc97f1f3 142 --build - get all files from CVS repo or HTTP/FTP and build
5a491465 143 package from <package>.spec,
7922b3ec 144 -bb, --build-binary
145 - get all files from CVS repo or HTTP/FTP and build
79b2ec0e 146 binary only package from <package>.spec,
147 -bs,
cc97f1f3
SZ
148 --build-source - get all files from CVS repo or HTTP/FTP and only
149 pack them into src.rpm,
8ba5cdda 150 -B, --branch - add branch
7922b3ec 151 -c, --clean - clean all temporarily created files (in BUILD,
79b2ec0e 152 SOURCES, SPECS and \$RPM_BUILD_ROOT),
7922b3ec 153 -d <cvsroot>, --cvsroot <cvsroot>
154 - setup \$CVSROOT,
e7bdc1b4 155 --define <macro> <value>
81f85806 156 - define a macro <macro> with value <value>,
11707eb9 157 --nodeps - rpm won't check any dependences
7922b3ec 158 -g, --get - get <package>.spec and all related files from
cc97f1f3 159 CVS repo or HTTP/FTP,
5a491465 160 -h, --help - this message,
d7f490f3 161 --http - use http instead of ftp,
7922b3ec 162 -l <logfile>, --logtofile <logfile>
163 - log all to file,
ff45a501 164 -m, --mr-proper - only remove all files related to spec file and
8bc51224 165 all work resources,
6fc910c7 166 -nc, --no-cvs - don't download sources from CVS, if source URL is
167 given,
168 -ncs, --no-cvs-specs
169 - don't check specs in CVS
fc0e5bb5
TP
170 -nd, --no-distfiles
171 - don't download from distfiles
4ca52257 172 -nm, --no-mirrors - don't download from mirror, if source URL is given,
157dc315 173 -nu, --no-urls - don't try to download from FTP/HTTP location,
0143ec80 174 -ns, --no-srcs - don't download Sources
fd2b5687 175 -ns0, --no-source0
0143ec80 176 - don't download Source0
7922b3ec 177 --opts <rpm opts>
178 - additional options for rpm
5a491465 179 -q, --quiet - be quiet,
448deaa0 180 --date yyyy-mm-dd
181 - build package using resources from specified CVS
182 date,
7922b3ec 183 -r <cvstag>, --cvstag <cvstag>
184 - build package using resources from specified CVS
67fcd1e4 185 tag,
da0048be 186 -R, --fetch-build-requires
187 - fetch what is BuildRequired,
7922b3ec 188 -T <cvstag> , --tag <cvstag>
189 - add cvs tag <cvstag> for files,
78ce14b3 190 -Tvs, --tag-version-stable
191 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
a2164135
MM
192 -Tvn, --tag-version-nest
193 - add cvs tags NEST and NAME-VERSION-RELESE for files,
78ce14b3 194 -Ts, --tag-stable
195 - add cvs tag STABLE for files,
a2164135
MM
196 -Tn, --tag-nest
197 - add cvs tag NEST for files,
7922b3ec 198 -Tv, --tag-version
199 - add cvs tag NAME-VERSION-RELESE for files,
d71ea755
MM
200 -Tp, --tag-prefix <prefix>
201 - add <prefix> to NAME-VERSION-RELEASE tags,
5a491465 202 -v, --verbose - be verbose,
81f85806 203 -u, --try-upgrade
204 - check version, and try to upgrade package
b130abf2
TP
205 -un, --try-upgrade-with-float-version
206 - as above, but allow float version
207 -U, --update
de6b5b2a
MM
208 - refetch sources, don't use distfiles, and update md5
209 comments
da0048be 210 -Upi, --update-poldek-indexes
211 - refresh or make poldek package index files.
d5787aec 212 --with/--without <feature>
81f85806 213 - conditional build package depending on
d5787aec 214 %_with_<feature>/%_without_<feature> macro
da0048be 215 switch.
216 You may now use --with feat1 feat2 feat3 --without feat4
217 feat5 --with feat6 constructions.
5a491465 218"
219}
220
5f26c239
MM
221cache_rpm_dump () {
222 rpm_dump_cache=`
ad6f43de
MM
223 case "$RPMBUILD" in
224 rpm )
ecfecee9 225 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
ad6f43de
MM
226 ;;
227 rpmbuild )
5f26c239 228 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
ad6f43de 229 ;;
15a71f66 230 esac`
5f26c239
MM
231}
232
233rpm_dump () {
234 if [ -z "$rpm_dump_cache" ] ; then
319a7f41 235 echo "internal error: cache_rpm_dump not called!" 1>&2
15a71f66
MM
236 fi
237 echo "$rpm_dump_cache"
ad6f43de
MM
238}
239
59398507 240parse_spec()
241{
c3428d50 242 if [ -n "$DEBUG" ]; then
a7af9862 243 set -x;
244 set -v;
71d62f04 245 fi
7c2dd1b2 246
25fa34fe 247 cd $SPECS_DIR
5f26c239
MM
248
249 cache_rpm_dump
250
72fb89b5 251 if [ "$NOSRCS" != "yes" ]; then
ad6f43de 252 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
72fb89b5 253 fi
ad6f43de 254 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
a7af9862 255 FAIL_IF_NO_SOURCES="no"
c6a390a1
AM
256 fi
257
ad6f43de 258 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
cc97f1f3 259 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
7147050f
AM
260 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
261 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
262 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
79379585 263
9e06e5c3 264 if [ -n "$BE_VERBOSE" ]; then
00fcec7e 265 echo "- Sources : `nourl $SOURCES`"
cc97f1f3 266 if [ -n "$PATCHES" ]; then
a7af9862 267 echo "- Patches : `nourl $PATCHES`"
cc97f1f3 268 else
a7af9862 269 echo "- Patches : *no patches needed*"
cc97f1f3 270 fi
7053d3fd 271 if [ -n "$ICONS" ]; then
a7af9862 272 echo "- Icon : `nourl $ICONS`"
a3df415f 273 else
a7af9862 274 echo "- Icon : *no package icon*"
a3df415f 275 fi
9e06e5c3 276 echo "- Name : $PACKAGE_NAME"
277 echo "- Version : $PACKAGE_VERSION"
39cbc282 278 echo "- Release : $PACKAGE_RELEASE"
d287305c 279 fi
33f5276d 280}
281
282Exit_error()
283{
00fcec7e 284 if [ -n "$DEBUG" ]; then
0dd6320d 285 set -x;
00fcec7e 286 set -v;
71d62f04 287 fi
7c2dd1b2 288
33f5276d 289 cd $__PWD
290
4849ca8d 291 case "$1" in
33f5276d 292 "err_no_spec_in_cmdl" )
293 echo "ERROR: spec file name not specified.";
294 exit 2 ;;
295 "err_no_spec_in_repo" )
296 echo "Error: spec file not stored in CVS repo.";
297 exit 3 ;;
298 "err_no_source_in_repo" )
4849ca8d 299 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
33f5276d 300 exit 4 ;;
301 "err_build_fail" )
298c753e 302 echo "Error: package build failed. (${2:-no more info})";
33f5276d 303 exit 5 ;;
304 esac
305}
bc8d444f 306
33f5276d 307init_builder()
308{
00fcec7e 309 if [ -n "$DEBUG" ]; then
0dd6320d 310 set -x;
00fcec7e 311 set -v;
71d62f04 312 fi
7c2dd1b2 313
7147050f
AM
314 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
315 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
bc8d444f 316
33f5276d 317 __PWD=`pwd`
59398507 318}
319
320get_spec()
321{
00fcec7e 322 if [ -n "$DEBUG" ]; then
0dd6320d 323 set -x;
00fcec7e 324 set -v;
71d62f04 325 fi
7c2dd1b2 326
6fc910c7 327 if [ "$NOCVSSPEC" != "yes" ]; then
328 cd $SPECS_DIR
5644bf7e 329
6fc910c7 330 OPTIONS="up "
67fcd1e4 331
6fc910c7 332 if [ -n "$CVSROOT" ]; then
333 OPTIONS="-d $CVSROOT $OPTIONS"
334 else
335 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
336 echo "warning: No cvs access defined - using local .spec file"
337 NOCVSSPEC="yes"
338 fi
339 fi
00fcec7e 340
72e08ca8 341 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
6fc910c7 342 OPTIONS="$OPTIONS -A"
72e08ca8
AM
343 else
344 if [ -n "$CVSDATE" ]; then
0dd6320d 345 OPTIONS="$OPTIONS -D $CVSDATE"
72e08ca8
AM
346 fi
347 if [ -n "$CVSTAG" ]; then
0dd6320d 348 OPTIONS="$OPTIONS -r $CVSTAG"
72e08ca8 349 fi
6fc910c7 350 fi
33f5276d 351
b92ecfc9
AM
352 result=1
353 retries_counter=0
354 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
355 retries_counter=$(( $retries_counter + 1 ))
356 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
357 result=$?
fef1dc85 358 [ -n "$output" ] && echo "$output"
b92ecfc9 359 if [ "$result" -ne "0" ]; then
5f9b4a6d 360 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
ee004885 361 echo "Trying again [$SPECFILE]... ($retries_counter)"
96686ae5 362 sleep 2
b92ecfc9 363 continue
0dd6320d 364 fi
365 Exit_error err_no_spec_in_repo;
b92ecfc9
AM
366 fi
367 done
33f5276d 368 fi
6fc910c7 369 if [ ! -f "$SPECFILE" ]; then
b857906d 370 Exit_error err_no_spec_in_repo;
6fc910c7 371 fi
a7af9862 372
d013b3df 373 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
7922b3ec 374 chmod $CHMOD_MODE $SPECFILE
5aa0ef93 375 fi
7c2dd1b2 376 unset OPTIONS
67da0368 377 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
59398507 378}
379
4ca52257
JK
380find_mirror(){
381
382 cd "$SPECS_DIR"
00fcec7e 383 url="$1"
6631fc57 384 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
00fcec7e 385 cvs update mirrors >&2
4ca52257
JK
386 fi
387
388 IFS="|"
389 while read origin mirror name rest; do
00fcec7e 390 ol=`echo -n "$origin"|wc -c`
4ca52257
JK
391 prefix="`echo -n "$url" | head -c $ol`"
392 if [ "$prefix" = "$origin" ] ; then
6fc910c7 393 suffix="`echo "$url"|cut -b $ol-`"
394 echo -n "$mirror$suffix"
395 return 0
4ca52257
JK
396 fi
397 done < mirrors
398 echo "$url"
399}
400
00fcec7e 401src_no ()
402{
403 cd $SPECS_DIR
ad6f43de 404 rpm_dump | \
0dd6320d 405 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
406 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
407 head -1 | xargs
00fcec7e 408}
409
410src_md5 ()
411{
412 no=$(src_no "$1")
413 [ -z "$no" ] && return
414 cd $SPECS_DIR
0dd6320d 415 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
416 if [ -z "$spec_rev" ]; then
417 spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
418 fi
419 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
80dcd8ed 420 md5=$(grep -s -v '^#' additional-md5sums | \
0dd6320d 421 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
422 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
423 grep -E '^[0-9a-f]{32}$')
6d2b8f55 424 if [ X"$md5" = X"" ] ; then
0dd6320d 425 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
6d2b8f55 426 else
0dd6320d 427 if [ $(echo "$md5" | wc -l) != 1 ] ; then
428 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
429 fi
430 echo "$md5" | tail -1
6d2b8f55 431 fi
00fcec7e 432}
433
434distfiles_url ()
435{
d7f490f3 436 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
00fcec7e 437}
438
d99ac371
MM
439good_md5 ()
440{
441 md5=$(src_md5 "$1")
442 [ "$md5" = "" ] || \
443 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
444}
445
25fa34fe 446get_files()
59398507 447{
25fa34fe
AM
448 GET_FILES="$@"
449
00fcec7e 450 if [ -n "$DEBUG" ]; then
0dd6320d 451 set -x;
00fcec7e 452 set -v;
71d62f04 453 fi
7c2dd1b2 454
25fa34fe 455 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
7053d3fd 456 cd $SOURCE_DIR
33f5276d 457
82c46005 458 OPTIONS="up "
7053d3fd 459 if [ -n "$CVSROOT" ]; then
c1e79fcd 460 OPTIONS="-d $CVSROOT $OPTIONS"
6fc910c7 461 else
462 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
463 echo "warning: No cvs access defined for SOURCES"
464 NOCVS="yes"
465 fi
67fcd1e4 466 fi
0dd6320d 467 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
468 OPTIONS="$OPTIONS -A"
469 else
470 if [ -n "$CVSDATE" ]; then
471 OPTIONS="$OPTIONS -D $CVSDATE"
472 fi
473 if [ -n "$CVSTAG" ]; then
474 OPTIONS="$OPTIONS -r $CVSTAG"
475 fi
476 fi
25fa34fe 477 for i in $GET_FILES; do
2daea751
TP
478 if [ -n "$UPDATE5" ]; then
479 if [ -n "$ADD5" ]; then
480 [ `nourl $i` = "$i" ] && continue
481 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
482 else
483 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
484 fi
485 fi
2837871a 486 FROM_DISTFILES=0
81474543 487 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
4a0bb672 488 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
6fc910c7 489 echo "Warning: no URL given for $i"
157dc315 490 fi
a7af9862 491
fc0e5bb5 492 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
d99ac371 493 if good_md5 "$i"; then
f67349b7 494 echo "$(nourl "$i") having proper md5sum already exists"
495 continue
496 fi
00fcec7e 497 target=$(nourl "$i")
498 url=$(distfiles_url "$i")
2837871a 499 if [ `echo $url | grep -E '^(\.|/)'` ]; then
6aefe77b
JR
500 ${GETLOCAL} $url $target
501 else
2837871a 502 FROM_DISTFILES=1
503 if [ -z "$NOMIRRORS" ]; then
6aefe77b 504 url="`find_mirror "$url"`"
00fcec7e 505 fi
6aefe77b
JR
506 ${GETURI} -O "$target" "$url" || \
507 if [ `echo $url | grep -E 'ftp://'` ]; then
508 ${GETURI2} -O "$target" "$url"
509 fi
57422365 510 if ! test -s "$target"; then
511 rm -f "$target"
512 FROM_DISTFILES=0
513 fi
6aefe77b 514 fi
c3d441b0
JB
515 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
516 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
b92ecfc9 517 result=1
0dd6320d 518 retries_counter=0
519 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
520 retries_counter=$(( $retries_counter + 1 ))
b92ecfc9 521 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
0dd6320d 522 result=$?
fef1dc85 523 [ -n "$output" ] && echo "$output"
5f9b4a6d 524 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
ee004885 525 echo "Trying again [`nourl $i`]... ($retries_counter)"
96686ae5 526 sleep 2
b92ecfc9 527 continue
711eb1e4
AM
528 else
529 break
b92ecfc9
AM
530 fi
531 done
157dc315 532 fi
a7af9862 533
b130abf2 534 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
2837871a 535 if [ -z "$NOMIRRORS" ]; then
3428d253
JB
536 im="`find_mirror "$i"`"
537 else
538 im="$i"
6fc910c7 539 fi
3428d253
JB
540 ${GETURI} "$im" || \
541 if [ `echo $im | grep -E 'ftp://'` ]; then ${GETURI2} "$im" ; fi
157dc315
SZ
542 fi
543
de6b5b2a 544
422fbc56
TP
545 fi
546 srcno=$(src_no $i)
547 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
548 Exit_error err_no_source_in_repo $i;
549 elif [ -n "$UPDATE5" ] && \
550 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
551 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
552 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
553 then
554 echo "Updating source-$srcno md5."
555 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
82db6b8d
MM
556 perl -i -ne '
557 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
558 print "# Source'$srcno'-md5:\t'$md5'\n"
559 if /^Source'$srcno'\s*:\s+/;
560 ' \
422fbc56
TP
561 $SPECS_DIR/$SPECFILE
562 fi
563
2837871a 564 if good_md5 "$i"; then
565 :
566 elif [ "$FROM_DISTFILES" = 1 ]; then
567 # wrong md5 from distfiles: remove the file and try again
568 # but only once ...
97c857d8 569 echo "MD5 sum mismatch. Trying full fetch."
2837871a 570 FROM_DISTFILES=2
571 rm -f $target
572 ${GETURI} -O "$target" "$url" || \
573 if [ `echo $url | grep -E 'ftp://'` ]; then
574 ${GETURI2} -O "$target" "$url"
575 fi
576 test -s "$target" || rm -f "$target"
577 fi
578
422fbc56
TP
579 if good_md5 "$i"; then
580 :
581 else
582 echo "MD5 sum mismatch. Use -U to refetch sources,"
583 echo "or -5 to update md5 sums, if you're sure files are correct."
584 Exit_error err_no_source_in_repo $i
3ae81a20 585 fi
cc97f1f3 586 done
a7af9862 587
5aa0ef93 588 if [ "$CHMOD" = "yes" ]; then
d013b3df
AM
589 CHMOD_FILES="`nourl $GET_FILES`"
590 if [ -n "$CHMOD_FILES" ]; then
6fc910c7 591 chmod $CHMOD_MODE $CHMOD_FILES
d013b3df 592 fi
5aa0ef93 593 fi
7c2dd1b2 594 unset OPTIONS
7053d3fd 595 fi
59398507 596}
597
1471f6d6 598tag_files()
599{
600 TAG_FILES="$@"
601
00fcec7e 602 if [ -n "$DEBUG" ]; then
0dd6320d 603 set -x;
00fcec7e 604 set -v;
1471f6d6 605 fi
606
607 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
0b9271b0
PG
608 echo "Version: $PACKAGE_VERSION"
609 echo "Release: $PACKAGE_RELEASE"
319a7f41 610 # Check whether first character of PACKAGE_NAME is legal for tag name
c7577806 611 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
612 TAG_PREFIX=tag_
613 fi
d71ea755 614 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"`
657983d5
AM
615 # Remove #kernel.version_release from TAGVER because tagging sources
616 # could occur with different kernel-headers than kernel-headers used at build time.
617 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
01de2036
JB
618 if [ "$TAG_VERSION" = "yes" ]; then
619 echo "CVS tag: $TAGVER"
620 fi
621 if [ -n "$TAG" ]; then
622 echo "CVS tag: $TAG"
623 fi
1471f6d6 624
625 OPTIONS="tag -F"
626 if [ -n "$CVSROOT" ]; then
627 OPTIONS="-d $CVSROOT $OPTIONS"
628 fi
629
630 cd $SOURCE_DIR
631 for i in $TAG_FILES; do
c2a27ba0
AM
632 # don't tag non cvs files (ie. stored on distfiles)
633 [ "`nourl $i`" != "$i" ] && continue
634 if [ -f "`nourl $i`" ]; then
f02788de
JB
635 if [ "$TAG_VERSION" = "yes" ]; then
636 cvs $OPTIONS $TAGVER `nourl $i`
637 fi
638 if [ -n "$TAG" ]; then
639 cvs $OPTIONS $TAG `nourl $i`
640 fi
1471f6d6 641 else
4849ca8d 642 Exit_error err_no_source_in_repo $i
1471f6d6 643 fi
644 done
645
646 cd $SPECS_DIR
f02788de
JB
647 if [ "$TAG_VERSION" = "yes" ]; then
648 cvs $OPTIONS $TAGVER $SPECFILE
649 fi
650 if [ -n "$TAG" ]; then
651 cvs $OPTIONS $TAG $SPECFILE
652 fi
1471f6d6 653
654 unset OPTIONS
655 fi
656}
657
8ba5cdda
PG
658branch_files()
659{
a7af9862 660 TAG=$1
661 echo "CVS branch tag: $TAG"
662 shift;
8ba5cdda 663
a7af9862 664 TAG_FILES="$@"
8ba5cdda 665
a7af9862 666 if [ -n "$DEBUG" ]; then
667 set -x;
668 set -v;
669 fi
8ba5cdda 670
a7af9862 671 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
672
673 OPTIONS="tag -b"
674 if [ -n "$CVSROOT" ]; then
675 OPTIONS="-d $CVSROOT $OPTIONS"
8ba5cdda 676 fi
a7af9862 677 cd $SOURCE_DIR
678 for i in $TAG_FILES; do
679 if [ -f `nourl $i` ]; then
680 cvs $OPTIONS $TAG `nourl $i`
681 else
682 Exit_error err_no_source_in_repo $i
683 fi
684 done
685 cd $SPECS_DIR
686 cvs $OPTIONS $TAG $SPECFILE
687
688 unset OPTIONS
689 fi
8ba5cdda
PG
690}
691
f308b816 692
693
59398507 694build_package()
695{
00fcec7e 696 if [ -n "$DEBUG" ]; then
7922b3ec 697 set -x;
00fcec7e 698 set -v;
71d62f04 699 fi
7c2dd1b2 700
33f5276d 701 cd $SPECS_DIR
3d97a432 702
00fcec7e 703 if [ -n "$TRY_UPGRADE" ]; then
a7af9862 704
1acf51bc 705 if [ -n "$FLOAT_VERSION" ]; then
a7af9862 706 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
707 else
708 TNOTIFY=`./pldnotify.awk $SPECFILE`
709 fi
710
3d97a432 711 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
a7af9862 712
0096b1ae 713 if [ -n "$TNEWVER" ]; then
a7af9862 714
3d97a432 715 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
a7af9862 716
3d97a432 717 echo "New version found, updating spec file to version " $TNEWVER
a7af9862 718
3d97a432 719 cp -f $SPECFILE $SPECFILE.bak
a7af9862 720
3d97a432 721 chmod +w $SPECFILE
a7af9862 722
3d97a432
MK
723 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
724 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
a7af9862 725
3d97a432 726 parse_spec;
a7af9862 727
3d97a432 728 get_files "$SOURCES $PATCHES";
a7af9862 729
3d97a432
MK
730 unset TOLDVER TNEWVER TNOTIFY
731 fi
00fcec7e 732
3d97a432
MK
733 fi
734
735
736 cd $SPECS_DIR
737
79b2ec0e 738 case "$COMMAND" in
739 build )
7922b3ec 740 BUILD_SWITCH="-ba" ;;
79b2ec0e 741 build-binary )
742 BUILD_SWITCH="-bb" ;;
743 build-source )
956d1492 744 BUILD_SWITCH="-bs --nodeps" ;;
79b2ec0e 745 esac
d6a75d60 746 if [ -n "$LOGFILE" ]; then
972bd3c3 747 LOG=`eval echo $LOGFILE`
00fcec7e 748 if [ -n "$LASTLOG_FILE" ]; then
749 echo "LASTLOG=$LOG" > $LASTLOG_FILE
750 fi
751 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
f32dfbda 752 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
00fcec7e 753 RETVAL=`cat $RES_FILE`
754 rm $RES_FILE
755 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
0dd6320d 756 if [ "$RETVAL" -eq "0" ]; then
00fcec7e 757 mv $LOG $LOGDIROK
0dd6320d 758 else
759 mv $LOG $LOGDIRFAIL
00fcec7e 760 fi
761 fi
d6a75d60 762 else
7147050f 763 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
f308b816 764 RETVAL=$?
d6a75d60 765 fi
33f5276d 766
f308b816 767 if [ "$RETVAL" -ne "0" ]; then
a7af9862 768
00fcec7e 769 if [ -n "$TRY_UPGRADE" ]; then
3d97a432 770 echo "\n!!! Package with new version cannot be build automagically\n"
3d97a432 771 mv -f $SPECFILE.bak $SPECFILE
3d97a432 772 fi
a7af9862 773
33f5276d 774 Exit_error err_build_fail;
775 fi
a7af9862 776
79b2ec0e 777 unset BUILD_SWITCH
59398507 778}
779
cc97f1f3
SZ
780nourl()
781{
a7af9862 782 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
cc97f1f3 783}
2daea751 784
da0048be 785set_bconds_values()
786{
787AVAIL_BCONDS_WITHOUT=""
788AVAIL_BCONDS_WITH=""
789for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
790do
791 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
792 if [ "`echo $BCOND|grep -- "--without $AVAIL_BCOND_WITHOUT"`" != "" ];then
793 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
794 else
795 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
796 fi
797done
798
799for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
800do
801 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
802 if [ "`echo $BCOND|grep -- "--with $AVAIL_BCOND_WITH"`" != "" ];then
803 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
804 else
805 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
806 fi
807done
808}
809
810display_bconds()
811{
812if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
813 echo -ne "We are going to build $SPECFILE with the following confitional flags:\n"
814 if [ "$BCOND" != "" ]; then
815 echo -ne "$BCOND"
816 else
817 echo -ne "No --with || --without conditions passed to $0!"
818 fi
819 echo -ne "\n\nfrom available:\n\n"
820 echo -ne "--with :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
821fi
822}
823
824fetch_build_requires()
825{
826if [ "$FETCH_BUILD_REQUIRES" == "yes" ]; then
827 for package_item in `cat $SPECFILE|grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'`
828 do
829 GO="yes"
830 package=`basename "$package_item"|sed -e "s/}$//g"`
831 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
832 mach=`uname -m`
833
834 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
835 if [ "`echo $COND_TST|grep '^BuildRequires:'`" != "" ]; then
836 if [ "$COND_ARCH_TST" != "" ] && [ "`echo $COND_ARCH_TST|sed -e "s/i.86/ix86/g"`" != "`echo $mach|sed -e "s/i.86/ix86/g"`" ]; then
837 GO="yes"
838 fi
839 # bcond:
840 else
841 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
842 GO=""
843 # %{without}
844 if [ "`echo $COND_TST|grep 'without_'`" != "" ]; then
845 COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
846 if [ "`echo $COND_TST|grep !`" != "" ]; then
847 COND_STATE="with"
848 else
849 COND_STATE="wout"
850 fi
851 if [ "`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`" != "" ]; then
852 COND_ARGV="wout"
853 else
854 COND_ARGV="with"
855 fi
856 # %{with}
857 elif [ "`echo $COND_TST|grep 'with_'`" != "" ]; then
858 COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
859 if [ "`echo $COND_TST|grep !`" != "" ]; then
860 COND_STATE="wout"
861 else
862 COND_STATE="with"
863 fi
864 if [ "`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`" != "" ]; then
865 COND_ARGV="with"
866 else
867 COND_ARGV="wout"
868 fi
869 fi
870 RESULT="${COND_STATE}-${COND_ARGV}"
871 case "$RESULT" in
eeebb3bc 872 "with-wout" | "wout-with" )
873 GO=""
874 ;;
875 "wout-wout" | "with-with" )
876 GO="yes"
877 ;;
878 * )
879 echo "Action '$RESULT' was not defined for package '$package_item'"
880 ;;
da0048be 881 esac
882
883 fi
884
885 if [ "$GO" == "yes" ]; then
886 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
887 echo "Package $package is not installed. Attempting to install..."
9e5b68f2 888 poldek -i $package
da0048be 889 case $? in
890 1)
891 echo "Unable to install $package package! Still trying to fetch rest..."
892 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package"
893 ;;
894 0)
e33f5c17 895 INSTALLED_PACKAGES="$package $INSTALLED_PACKAGES"
da0048be 896 ;;
897 esac
898 else
899 echo "Package $package is already installed. BuildRequirement satisfied."
900 fi
901 fi
902 done
903 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
904