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