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