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