]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- ignore errors from missing python binary
[packages/rpm-build-tools.git] / builder.sh
CommitLineData
cd445739
AM
1#!/bin/sh
2# -----------
3# $Id$
4# Exit codes:
2a5f078d 5# 0 - succesful
6# 1 - help displayed
7# 2 - no spec file name in cmdl parameters
8# 3 - spec file not stored in repo
9# 4 - some source, patch or icon files not stored in repo
10# 5 - package build failed
11# 6 - spec file with errors
12# 7 - wrong source in /etc/poldek.conf
13# 8 - Failed installing buildrequirements and subrequirements
14# 9 - Requested tag already exist
15# 10 - Refused to build fractional release
16# 100 - Unknown error (should not happen)
cd445739
AM
17
18# Notes (todo):
f7b91886 19# - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
cd445739 20# - when Icon: field is present, -5 and -a5 doesn't work
f3ada241 21# - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
931a4acf 22
4003ad8c 23VERSION="\
c9acaed9 24Build package utility from PLD Linux CVS repository
0a302b4e 25v0.16 (C) 1999-2006 Free Penguins".
d6a77ddb 26PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
b03f053b 27
cd445739 28COMMAND="build"
64ea5308 29TARGET=""
cd445739 30
bde1c404 31SPECFILE=""
d287305c 32BE_VERBOSE=""
4003ad8c 33QUIET=""
cd445739
AM
34CLEAN=""
35DEBUG=""
36NOURLS=""
37NOCVS=""
38NOCVSSPEC=""
39NODIST=""
47761337 40NOINIT=""
cd445739
AM
41UPDATE=""
42UPDATE5=""
43ADD5=""
44NO5=""
45ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
c8f50498 46CVSROOT=""
cd445739
AM
47
48# It can be used i.e. in log file naming.
49# See LOGFILE example.
50DATE=`date +%Y-%m-%d_%H-%M-%S`
51
52# Example: LOGFILE='../log.$PACKAGE_NAME'
53# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
54# Yes, you can use variable name! Note _single_ quotes!
55LOGFILE=''
56
57LOGDIR=""
58LOGDIROK=""
59LOGDIRFAIL=""
60LASTLOG_FILE=""
61
62CHMOD="no"
63CHMOD_MODE="0444"
64RPMOPTS=""
d1c5a9a7 65RPMBUILDOPTS=""
cd445739
AM
66BCOND=""
67GROUP_BCONDS="no"
947025e5 68CVSIGNORE_DF="no"
d287305c 69
70PATCHES=""
71SOURCES=""
cd445739 72ICONS=""
d287305c 73PACKAGE_RELEASE=""
74PACKAGE_VERSION=""
75PACKAGE_NAME=""
cd445739
AM
76PROTOCOL="ftp"
77WGET_RETRIES=${MAX_WGET_RETRIES:-0}
78CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
79
80CVSTAG=""
81RES_FILE=""
39dcc7de 82CVS_FORCE=""
cd445739
AM
83
84CVS_SERVER="cvs.pld-linux.org"
85DISTFILES_SERVER="://distfiles.pld-linux.org"
d4730dae 86ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
cd445739 87
36d03934 88DEF_NICE_LEVEL=19
86aafdbe 89SCHEDTOOL="auto"
cd445739
AM
90
91FAIL_IF_NO_SOURCES="yes"
92
18e5347d
ER
93# let get_files skip over files which are present to get those damn files fetched
94SKIP_EXISTING_FILES="no"
95
975d7b23 96TRY_UPGRADE=""
257af81b
ER
97# should the specfile be restored if upgrade failed?
98REVERT_BROKEN_UPGRADE="yes"
99
ab4a2b6e 100if [ -x /usr/bin/rpm-getdeps ]; then
ce40491a 101 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
ab4a2b6e 102else
ce40491a 103 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
ab4a2b6e
ER
104fi
105
cd445739
AM
106# Here we load saved user environment used to
107# predefine options set above, or passed to builder
108# in command line.
109# This one reads global system environment settings:
110if [ -f ~/etc/builderrc ]; then
111 . ~/etc/builderrc
112fi
113# And this one cascades settings using user personal
114# builder settings.
115# Example of ~/.builderrc:
116#
117#UPDATE_POLDEK_INDEXES="yes"
118#FETCH_BUILD_REQUIRES="yes"
119#REMOVE_BUILD_REQUIRES="force"
120#GROUP_BCONDS="yes"
121#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
982e358c 122#TITLECHANGE=no
cd445739 123#
a83e5405 124SU_SUDO=""
cd445739
AM
125if [ -n "$HOME_ETC" ]; then
126 USER_CFG="$HOME_ETC/.builderrc"
127else
128 USER_CFG=~/.builderrc
129fi
130
131[ -f "$USER_CFG" ] && . "$USER_CFG"
132
86aafdbe
ER
133if [ "$SCHEDTOOL" = "auto" ]; then
134 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
135 SCHEDTOOL="schedtool -B -e"
136 else
137 SCHEDTOOL="no"
138 fi
139fi
140
ca2e6c31 141if [ -n "$USE_PROZILLA" ]; then
7e365483
KK
142 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
143 GETURI2="$GETURI"
144 OUTFILEOPT="-O"
ca2e6c31 145elif [ -n "$USE_AXEL" ]; then
cede92b3 146 GETURI="axel -a $AXEL_OPTS"
7e365483
KK
147 GETURI2="$GETURI"
148 OUTFILEOPT="-o"
ca2e6c31 149else
5700ee32
ER
150 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
151 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
152 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
6f9a5d76 153
7e365483
KK
154 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
155 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
156 OUTFILEOPT="-O"
2bc5451f 157fi
11468b23 158
11468b23
AM
159GETLOCAL="cp -a"
160
161if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
162 RPM="rpm"
163 RPMBUILD="rpm"
164else
165 RPM="rpm"
166 RPMBUILD="rpmbuild"
167fi
168
169POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
a83e5405 170POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
11468b23 171
cd445739
AM
172run_poldek()
173{
174 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
175 if [ -n "$LOGFILE" ]; then
176 LOG=`eval echo $LOGFILE`
177 if [ -n "$LASTLOG_FILE" ]; then
178 echo "LASTLOG=$LOG" > $LASTLOG_FILE
179 fi
86aafdbe 180 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
cd445739
AM
181 return $exit_pldk
182 else
86aafdbe 183 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
cd445739
AM
184 return `cat ${RES_FILE}`
185 rm -rf ${RES_FILE}
186 fi
187}
188
cd445739
AM
189#---------------------------------------------
190# functions
da946cd6 191
5a491465 192usage()
193{
cd445739
AM
194 if [ -n "$DEBUG" ]; then set -xv; fi
195 echo "\
196Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
cd445739 197[-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
39dcc7de
AG
198[{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
199[-g|--get] [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
cd445739 200[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
a7b2951c 201[-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
cd445739 202[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
dfe2cb9a 203[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
f19103b5 204[--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag]
2a5f078d 205
cd445739
AM
206-5, --update-md5 - update md5 comments in spec, implies -nd -ncs
207-a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
208-n5, --no-md5 - ignore md5 comments in spec
9243e80b
ER
209-D, --debug - enable builder script debugging mode,
210-debug - produce rpm debug package (same as --opts -debug)
cd445739
AM
211-V, --version - output builder version
212-a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
213-b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
214 from <package>.spec,
215-bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
216 only package from <package>.spec,
c56807e0
ER
217-bp, --build-prep - execute the %prep phase of <package>.spec,
218-bc - reserved (not implemented)
219-bi reserved (not implemented)
cd445739
AM
220-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
221 them into src.rpm,
c56807e0 222--short-circuit - reserved (not implemented)
cd445739
AM
223-B, --branch - add branch
224-c, --clean - clean all temporarily created files (in BUILD, SOURCES,
225 SPECS and \$RPM_BUILD_ROOT),
39dcc7de 226-cf, --cvs-force - use -F when tagging (useful when moving branches)
2a5f078d 227-d <cvsroot>, --cvsroot <cvsroot>
cd445739
AM
228 - setup \$CVSROOT,
229--define <macro> <value>
230 - define a macro <macro> with value <value>,
231--nodeps - rpm won't check any dependences
232-g, --get - get <package>.spec and all related files from CVS repo
233 or HTTP/FTP,
234-h, --help - this message,
235--http - use http instead of ftp,
236-l <logfile>, --logtofile <logfile>
237 - log all to file,
238-m, --mr-proper - only remove all files related to spec file and all work
239 resources,
240-nc, --no-cvs - don't download sources from CVS, if source URL is given,
241-ncs, --no-cvs-specs
242 - don't check specs in CVS
243-nd, --no-distfiles - don't download from distfiles
244-nm, --no-mirrors - don't download from mirror, if source URL is given,
245-nu, --no-urls - don't try to download from FTP/HTTP location,
246-ns, --no-srcs - don't download Sources
247-ns0, --no-source0 - don't download Source0
248-nn, --no-net - don't download anything from the net
b572253e 249--no-init - don't initialize builder paths (SPECS and SOURCES)
18e5347d
ER
250-ske,
251--skip-existing-files - skip existing files in get_files
cd445739
AM
252--opts <rpm opts> - additional options for rpm
253-q, --quiet - be quiet,
254--date yyyy-mm-dd - build package using resources from specified CVS date,
255-r <cvstag>, --cvstag <cvstag>
256 - build package using resources from specified CVS tag,
257-R, --fetch-build-requires
258 - fetch what is BuildRequired,
259-RB, --remove-build-requires
260 - remove all you fetched with -R or --fetch-build-requires
261 remember, this option requires confirmation,
262-FRB, --force-remove-build-requires
263 - remove all you fetched with -R or --fetch-build-requires
264 remember, this option works without confirmation,
06541433
JR
265-sd, --source-distfiles - list sources available from distfiles (intended for offline
266 operations; does not work when Icon field is present
267 but icon file is absent),
268-sdp, --source-distfiles-paths - list sources available from distfiles -
269 paths relative to distfiles directory (intended for offline
270 operations; does not work when Icon field is present
271 but icon file is absent),
a7eefc54 272-sf, --source-files - list sources - bare filenames (intended for offline
273 operations; does not work when Icon field is present
3621e588 274 but icon file is absent),
a7eefc54 275-sp, --source-paths - list sources - filenames with full local paths (intended for
276 offline operations; does not work when Icon field is present
3621e588 277 but icon file is absent),
2dddf439
ER
278-su, --source-urls - list urls - urls to sources and patches
279 intended for copying urls with spec with lots of macros in urls
cd445739
AM
280-T <cvstag> , --tag <cvstag>
281 - add cvs tag <cvstag> for files,
282-Tvs, --tag-version-stable
094bd95b 283 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
cd445739
AM
284-Ts, --tag-stable
285 - add cvs tag STABLE for files,
cd445739 286-Tv, --tag-version
1691a37b 287 - add cvs tag NAME-VERSION-RELEASE for files,
cd445739
AM
288-Tp, --tag-prefix <prefix>
289 - add <prefix> to NAME-VERSION-RELEASE tags,
290-tt, --test-tag <prefix>
291 - fail if tag is already present,
50321881
JK
292-ir, --integer-release-only
293 - allow only integer and snapshot releases
cd445739
AM
294-v, --verbose - be verbose,
295-u, --try-upgrade - check version, and try to upgrade package
296-un, --try-upgrade-with-float-version
297 - as above, but allow float version
deccc50e 298-U, --update - refetch sources, don't use distfiles, and update md5 comments
cd445739
AM
299-Upi, --update-poldek-indexes
300 - refresh or make poldek package index files.
c890b916 301-np, --nopatch <patchnumber>
bed98670 302 - don't apply <patchnumber>
dfe2cb9a
MK
303--show-bconds - show available conditional builds, which can be used
304 - with --with and/or --without switches.
cd445739
AM
305--with/--without <feature>
306 - conditional build package depending on %_with_<feature>/
307 %_without_<feature> macro switch. You may now use
308 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
309 constructions. Set GROUP_BCONDS to yes to make use of it.
6dd19291 310--target <platform>, --target=<platform>
3621e588
ER
311 - build for platform <platform>.
312--init-rpm-dir - initialize ~/rpm directory structure
5a491465 313"
314}
315
c890b916 316update_shell_title() {
a0d6396b 317 [ -t 1 ] || return
0b65d15e
ER
318 local len=${COLUMNS:-80}
319 local msg=$(echo "$*" | cut -c-$len)
320
e225de91
ER
321 if [ -n "$BE_VERBOSE" ]; then
322 echo >&2 "$(date +%s.%N) $*"
323 fi
324
982e358c 325 if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then
138bbc98
ER
326 local pkg
327 if [ -n "$PACKAGE_NAME" ]; then
328 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
329 else
330 pkg=${SPECFILE}
331 fi
332
333 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
10c1e115 334 msg="$(echo $msg | tr -d '\n\r')"
982e358c
MP
335 case "$TERM" in
336 cygwin|xterm*)
337 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
338 ;;
339 screen*)
340 echo >&2 -ne "\033]0;$msg\007"
341 ;;
342 esac
343 fi
c890b916
ER
344}
345
7e40520f
ER
346# set TARGET from BuildArch: from SPECFILE
347set_spec_target() {
ce40491a
ER
348 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
349 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
350 if [ "$tmp" ]; then
7e40520f
ER
351 TARGET="$tmp"
352 case "$RPMBUILD" in
353 "rpmbuild")
ce40491a 354 TARGET_SWITCH="--target $TARGET" ;;
7e40520f 355 "rpm")
ce40491a 356 TARGET_SWITCH="--target=$TARGET" ;;
7e40520f 357 esac
ce40491a
ER
358 fi
359 fi
7e40520f
ER
360}
361
cd445739 362cache_rpm_dump () {
d22150da
ER
363 if [ -n "$DEBUG" ]; then
364 set -x;
365 set -v;
366 fi
7e40520f 367
13974367 368 update_shell_title "cache_rpm_dump"
237bd3f1
ER
369 local rpm_dump
370 rpm_dump=`
d05e8080 371
fa4bf1df 372 # we reset macros not to contain macros.build as all the %() macros are
559d511f 373 # executed here, while none of them are actually needed.
fa4bf1df 374 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
559d511f 375 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
36433112 376 macrofiles="/usr/lib/rpm/macros:$SPECS_DIR/.builder-rpmmacros:~/etc/.rpmmacros:~/.rpmmacros"
237bd3f1 377 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
7cb24972 378 # FIXME: better ideas than .rpmrc?
36433112 379 printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .builder-rpmrc
fb198857 380# TODO: move these to /usr/lib/rpm/macros
36433112 381 cat > .builder-rpmmacros <<'EOF'
fb198857
ER
382%requires_releq_kernel_up %{nil}
383%requires_releq_kernel_smp %{nil}
6b8134e3 384%requires_releq() %{nil}
bb01dee9 385%pyrequires_eq() %{nil}
559d511f 386%requires_eq() %{nil}
c13be3d1 387%requires_eq_to() %{nil}
fb198857
ER
388%releq_kernel_up ERROR
389%releq_kernel_smp ERROR
74d9fd14 390%kgcc_package ERROR
237bd3f1 391%_fontsdir ERROR
7141278d 392%ruby_version ERROR
393%ruby_ver_requires_eq() %{nil}
394%ruby_mod_ver_requires_eq() %{nil}
c13be3d1 395%__php_api_requires() %{nil}
7141278d 396%php_major_version ERROR
397%php_api_version ERROR
398%py_ver ERROR
41035426
ER
399%perl_vendorarch ERROR
400%perl_vendorlib ERROR
fb198857 401EOF
cd445739 402 case "$RPMBUILD" in
237bd3f1
ER
403 rpm)
404 ARGS='-bp'
405 ;;
406 rpmbuild)
407 ARGS='--nodigest --nosignature --nobuild'
408 ;;
409 esac
3d12d055
JR
410 if [ "$NOINIT" = "yes" ] ; then
411 cat >> .builder-rpmmacros <<'EOF'
412%_specdir ./
413%_sourcedir ./
414EOF
c039643c
JR
415 fi
416 $RPMBUILD --rcfile .builder-rpmrc $ARGS $ARGDIRS --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
237bd3f1 417 `
fb198857 418 if [ $? -gt 0 ]; then
237bd3f1
ER
419 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
420 echo "$error" >&2
421 Exit_error err_build_fail;
fb198857 422 fi
d05e8080
ER
423
424 # make small dump cache
425 rpm_dump_cache=`echo "$rpm_dump" | awk '
4e8c3089
ER
426 $2 ~ /^SOURCEURL/ {print}
427 $2 ~ /^PATCHURL/ {print}
428 $2 ~ /^nosource/ {print}
429 $2 ~ /^PACKAGE_/ {print}
d05e8080
ER
430 '`
431
13974367 432 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
433}
434
435rpm_dump () {
436 if [ -z "$rpm_dump_cache" ] ; then
d7b4d36e 437 echo "internal error: cache_rpm_dump not called! (missing %prep?)" 1>&2
cd445739
AM
438 fi
439 echo "$rpm_dump_cache"
440}
441
d05e8080
ER
442get_icons()
443{
444 update_shell_title "get icons"
445 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
446 if [ -z "$ICONS" ]; then
447 return
448 fi
449
975d7b23 450 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
d05e8080
ER
451}
452
59398507 453parse_spec()
454{
af4d5315 455 update_shell_title "parsing specfile"
cd445739
AM
456 if [ -n "$DEBUG" ]; then
457 set -x;
458 set -v;
459 fi
b2975fc3 460
d05e8080
ER
461 # icons are needed for successful spec parse
462 get_icons;
463
cd445739 464 cd $SPECS_DIR
cd445739 465 cache_rpm_dump
00fcec7e 466
cd445739
AM
467 if [ "$NOSRCS" != "yes" ]; then
468 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
469 fi
7cb24972 470
cd445739
AM
471 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
472 FAIL_IF_NO_SOURCES="no"
473 fi
474
475 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
476 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
fa4bf1df
ER
477 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3}')
478 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3}')
479 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3}')
78eab2a1 480
cd445739
AM
481 if [ -n "$BE_VERBOSE" ]; then
482 echo "- Sources : `nourl $SOURCES`"
483 if [ -n "$PATCHES" ]; then
484 echo "- Patches : `nourl $PATCHES`"
485 else
486 echo "- Patches : *no patches needed*"
487 fi
488 if [ -n "$ICONS" ]; then
489 echo "- Icon : `nourl $ICONS`"
490 else
491 echo "- Icon : *no package icon*"
492 fi
493 echo "- Name : $PACKAGE_NAME"
494 echo "- Version : $PACKAGE_VERSION"
495 echo "- Release : $PACKAGE_RELEASE"
496 fi
13974367
ER
497
498 update_shell_title "parse_spec: OK!"
cd445739
AM
499}
500
501Exit_error()
502{
503 if [ -n "$DEBUG" ]; then
504 set -x;
505 set -v;
506 fi
507
508 cd "$__PWD"
509
510 case "$1" in
511 "err_no_spec_in_cmdl" )
512 remove_build_requires
513 echo "ERROR: spec file name not specified.";
514 exit 2 ;;
515 "err_no_spec_in_repo" )
516 remove_build_requires
517 echo "Error: spec file not stored in CVS repo.";
518 exit 3 ;;
519 "err_no_source_in_repo" )
520 remove_build_requires
521 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
522 exit 4 ;;
523 "err_build_fail" )
524 remove_build_requires
525 echo "Error: package build failed. (${2:-no more info})";
526 exit 5 ;;
78eab2a1
AM
527 "err_no_package_data" )
528 remove_build_requires
529 echo "Error: couldn't get out package name/version/release from spec file."
530 exit 6 ;;
ce40491a 531 "err_tag_exists" )
50321881
JK
532 remove_build_requires
533 echo "Tag ${2} already exists (spec release: ${3}).";
534 exit 9 ;;
ce40491a 535 "err_fract_rel" )
50321881
JK
536 remove_build_requires
537 echo "Release ${2} not integer and not a snapshot.";
538 exit 10 ;;
fb96e0b5
AM
539 "err_branch_exists" )
540 remove_build_requires
541 echo "Tree branch already exists (${2}).";
542 exit 11 ;;
50321881 543
cd445739 544 esac
73848362
ER
545 echo "Unknown error."
546 exit 100
cd445739
AM
547}
548
549init_builder()
550{
551 if [ -n "$DEBUG" ]; then
552 set -x;
553 set -v;
0dd6320d 554 fi
cd445739 555
4aeb9973 556 if [ "$NOINIT" != "yes" ] ; then
29e90b02
JR
557 SOURCE_DIR="`eval $RPM $RPMOPTS --eval '%{_sourcedir}'`"
558 SPECS_DIR="`eval $RPM $RPMOPTS --eval '%{_specdir}'`"
559 else
560 SOURCE_DIR="."
561 SPECS_DIR="."
562 fi
cd445739
AM
563
564 __PWD="`pwd`"
00fcec7e 565}
566
d6a77ddb 567get_spec()
1471f6d6 568{
c890b916 569
2e5be021 570 update_shell_title "get_spec"
c890b916 571
cd445739
AM
572 if [ -n "$DEBUG" ]; then
573 set -x;
574 set -v;
575 fi
576
577 cd "$SPECS_DIR"
049ab214 578 if [ ! -f "$SPECFILE" ]; then
cd445739
AM
579 SPECFILE="`basename $SPECFILE .spec`.spec";
580 fi
581 if [ "$NOCVSSPEC" != "yes" ]; then
cd445739 582
049ab214
ER
583 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
584 echo "Warning: No CVS access defined - using local .spec file"
585 NOCVSSPEC="yes"
cd445739
AM
586 fi
587
049ab214 588 cvsup "$SPECFILE" || Exit_error err_no_spec_in_repo
cd445739 589 fi
049ab214 590
cd445739
AM
591 if [ ! -f "$SPECFILE" ]; then
592 Exit_error err_no_spec_in_repo;
593 fi
594
595 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
596 chmod $CHMOD_MODE $SPECFILE
597 fi
598 unset OPTIONS
a7eefc54 599 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
7e40520f 600
ce40491a 601 set_spec_target
cd445739
AM
602}
603
604find_mirror()
605{
606 cd "$SPECS_DIR"
782518da 607 local url="$1"
cd445739
AM
608 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
609 cvs update mirrors >&2
610 fi
611
612 IFS="|"
782518da
ER
613 local origin mirror name rest ol prefix
614 while read origin mirror name rest; do
615 # skip comments and empty lines
616 if [ -z "$origin" ] || [[ $origin == \#* ]]; then
617 continue
618 fi
cd445739
AM
619 ol=`echo -n "$origin"|wc -c`
620 prefix="`echo -n "$url" | head -c $ol`"
621 if [ "$prefix" = "$origin" ] ; then
782518da 622 suffix="`echo "$url"|cut -b $((ol+1))-`"
cd445739
AM
623 echo -n "$mirror$suffix"
624 return 0
625 fi
626 done < mirrors
627 echo "$url"
628}
629
e7e0d4ec 630# Warning: unpredictable results if same URL used twice
cd445739
AM
631src_no ()
632{
633 cd $SPECS_DIR
634 rpm_dump | \
635 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
636 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
637 head -n 1 | xargs
1471f6d6 638}
639
e7e0d4ec 640src_md5()
8ba5cdda 641{
e7e0d4ec 642 [ "$NO5" = "yes" ] && return
cd445739
AM
643 no=$(src_no "$1")
644 [ -z "$no" ] && return
645 cd $SPECS_DIR
e7e0d4ec
ER
646 local md5
647
648 if [ -f additional-md5sums ]; then
649 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
650 if [ -z "$spec_rev" ]; then
651 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
652 fi
653 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
654 md5=$(grep -s -v '^#' additional-md5sums | \
655 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
656 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
657 grep -E '^[0-9a-f]{32}$')
658
659 if [ "$md5" ]; then
660 if [ $(echo "$md5" | wc -l) != 1 ] ; then
661 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
662 fi
663 echo "$md5" | tail -n 1
664 return
665 fi
cd445739 666 fi
e7e0d4ec
ER
667
668 source_md5=`grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
669 if [ -n "$source_md5" ]; then
670 echo $source_md5
cd445739 671 else
e7e0d4ec
ER
672 # we have empty SourceX-md5, but it is still possible
673 # that we have NoSourceX-md5 AND NoSource: X
674 nosource_md5=`grep -i "#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
03db3356 675 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
e7e0d4ec 676 echo $nosource_md5
cd445739 677 fi
cd445739
AM
678 fi
679}
680
06541433
JR
681distfiles_path ()
682{
683 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
684}
685
cd445739
AM
686distfiles_url ()
687{
06541433 688 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
cd445739
AM
689}
690
691distfiles_attic_url ()
692{
06541433 693 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
cd445739
AM
694}
695
696good_md5 ()
697{
698 md5=$(src_md5 "$1")
699 [ "$md5" = "" ] || \
700 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
8ba5cdda
PG
701}
702
a4b50627
AF
703good_size ()
704{
ce40491a
ER
705 size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
706 [ -n "$size" -a "$size" -gt 0 ]
a4b50627
AF
707}
708
947025e5 709cvsignore_df ()
710{
711 if [ "$CVSIGNORE_DF" != "yes" ]; then
712 return
713 fi
714 cvsignore=${SOURCE_DIR}/.cvsignore
715 if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
716 echo "$1" >> $cvsignore
717 fi
718}
719
e7fa3b9f
ER
720cvsup()
721{
ce40491a
ER
722 update_shell_title "cvsup"
723 local OPTIONS="up "
724 if [ -n "$CVSROOT" ]; then
725 OPTIONS="-d $CVSROOT $OPTIONS"
726 fi
b1c6aace 727
ce40491a
ER
728 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
729 OPTIONS="$OPTIONS -A"
730 else
731 if [ -n "$CVSDATE" ]; then
732 OPTIONS="$OPTIONS -D $CVSDATE"
733 fi
734 if [ -n "$CVSTAG" ]; then
735 OPTIONS="$OPTIONS -r $CVSTAG"
736 fi
737 fi
e7fa3b9f 738
ce40491a
ER
739 local result=1
740 local retries_counter=0
741 if [ $# = 1 ]; then
742 update_shell_title "cvsup: $*"
743 else
744 update_shell_title "cvsup: $# files"
745 fi
746 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
747 retries_counter=$(( $retries_counter + 1 ))
748 output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1)
749 result=$?
750 [ -n "$output" ] && echo "$output"
751 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
752 echo "Trying again [$*]... ($retries_counter)"
753 update_shell_title "cvsup: retry #$retries_counter"
754 sleep 2
755 continue
756 else
757 break
758 fi
759 done
760 update_shell_title "cvsup: done!"
761 return $result
e7fa3b9f
ER
762}
763
ecba6ad5
ER
764update_md5()
765{
766 if [ $# -eq 0 ]; then
767 return
768 fi
769
770 update_shell_title "update md5"
771 if [ -n "$DEBUG" ]; then
772 set -x;
773 set -v;
774 fi
775
776 cd "$SOURCE_DIR"
777
778 # pass 1: check files to be fetched
779 local todo
780 local need_files
781 for i in "$@"; do
782 local fp=$(nourl "$i")
783 local srcno=$(src_no "$i")
784 if [ -n "$UPDATE5" ]; then
785 if [ -n "$ADD5" ]; then
786 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
787 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
788 else
789 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
790 fi
791 fi
792 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
793 need_files="$need_files $i"
794 fi
795 done
796
797 # pass 1a: get needed files
798 if [ "$need_files" ]; then
799 get_files $need_files
800 fi
801
802 # pass 2: proceed with md5 adding or updating
803 for i in "$@"; do
804 local fp=$(nourl "$i")
805 local srcno=$(src_no "$i")
806 if [ -n "$UPDATE5" ] && \
807 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
808 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
809 grep -q -i -E '^#[ ]*source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
810 then
811 echo "Updating source-$srcno md5."
812 md5=$(md5sum "$fp" | cut -f1 -d' ')
813 perl -i -ne '
814 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
815 print "# Source'$srcno'-md5:\t'$md5'\n"
816 if /^Source'$srcno'\s*:\s+/;
817 ' \
818 $SPECS_DIR/$SPECFILE
819 fi
820 done
821}
822
823check_md5()
824{
825 update_shell_title "check md5"
826
827 for i in "$@"; do
828 if good_md5 "$i" && good_size "$i"; then
829 continue
830 fi
831
832 echo "MD5 sum mismatch or 0 size. Use -U to refetch sources,"
833 echo "or -5 to update md5 sums, if you're sure files are correct."
834 Exit_error err_no_source_in_repo $i
835 done
836}
837
cd445739
AM
838get_files()
839{
7cb24972 840 update_shell_title "get_files"
cd445739
AM
841
842 if [ -n "$DEBUG" ]; then
843 set -x;
844 set -v;
845 fi
846
f09c0772 847 if [ $# -gt 0 ]; then
cd445739
AM
848 cd "$SOURCE_DIR"
849
b1c6aace 850 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
049ab214 851 echo "Warning: No CVS access defined for SOURCES"
b1c6aace
ER
852 NOCVS="yes"
853 fi
854
f2e42a41 855 local nc=0
e7fa3b9f 856 local get_files_cvs=""
3815b69a 857 for i in "$@"; do
f2e42a41 858 nc=$((nc + 1))
dcebdffb 859 local cvsup=0
3815b69a 860 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
f2e42a41 861 update_shell_title "$i"
f09c0772 862 local fp=`nourl "$i"`
ecba6ad5 863 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
ce40491a 864 continue
18e5347d 865 fi
ecba6ad5 866
cd445739 867 FROM_DISTFILES=0
e7e0d4ec 868 local srcmd5=$(src_md5 "$i")
ecba6ad5
ER
869
870 # we know if source/patch is present in cvs/distfiles
871 # - has md5 (in distfiles)
872 # - in cvs... ideas?
873
874 # CHECK: local file didn't exist or always cvs up (first) requested.
f09c0772 875 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
cd445739
AM
876 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
877 echo "Warning: no URL given for $i"
878 fi
879
e7e0d4ec 880 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
a4b50627 881 if good_md5 "$i" && good_size "$i"; then
e7e0d4ec 882 echo "$fp having proper md5sum already exists"
cd445739
AM
883 continue
884 fi
4ea1c265 885 target="$fp"
cd445739
AM
886 url=$(distfiles_url "$i")
887 url_attic=$(distfiles_attic_url "$i")
888 FROM_DISTFILES=1
ecba6ad5
ER
889 # is $url local file?
890 if [[ "$url" = [./]* ]]; then
18a52930 891 update_shell_title "${GETLOCAL%% *}: $url"
cd445739
AM
892 ${GETLOCAL} $url $target
893 else
894 if [ -z "$NOMIRRORS" ]; then
895 url="`find_mirror "$url"`"
896 fi
18a52930 897 update_shell_title "${GETURI%% *}: $url"
ca2e6c31 898 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 899 if [ "`echo $url | grep -E 'ftp://'`" ]; then
18a52930 900 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 901 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739
AM
902 fi
903 fi
ecba6ad5
ER
904
905 # is it empty file?
906 if [ ! -s "$target" ]; then
cd445739
AM
907 rm -f "$target"
908 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
18a52930 909 update_shell_title "${GETLOCAL%% *}: $url_attic"
cd445739
AM
910 ${GETLOCAL} $url_attic $target
911 else
912 if [ -z "$NOMIRRORS" ]; then
913 url_attic="`find_mirror "$url_attic"`"
914 fi
18a52930 915 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 916 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 917 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
ce40491a 918 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 919 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739
AM
920 fi
921 fi
922 fi
ecba6ad5
ER
923
924 if [ -s "$target" ]; then
947025e5 925 cvsignore_df $target
926 else
cd445739
AM
927 rm -f "$target"
928 FROM_DISTFILES=0
929 fi
e7e0d4ec 930 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
d05e8080
ER
931 if [ $# -gt 1 ]; then
932 get_files_cvs="$get_files_cvs $fp"
933 update_shell_title "$fp (will cvs up later)"
934 cvsup=1
935 else
936 cvsup $fp
937 fi
cd445739
AM
938 fi
939
f09c0772 940 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
cd445739
AM
941 if [ -z "$NOMIRRORS" ]; then
942 im="`find_mirror "$i"`"
943 else
944 im="$i"
945 fi
ce40491a 946 update_shell_title "${GETURI%% *}: $im"
cd445739 947 ${GETURI} "$im" || \
33da77c4 948 if [ "`echo $im | grep -E 'ftp://'`" ]; then
ce40491a 949 update_shell_title "${GETURI2%% *}: $im"
cd445739 950 ${GETURI2} "$im"
7e365483 951 fi
cd445739
AM
952 fi
953
dcebdffb
ER
954 if [ "$cvsup" = 1 ]; then
955 continue
956 fi
957
cd445739 958 fi
ecba6ad5
ER
959
960 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
f09c0772 961 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
cd445739 962 Exit_error err_no_source_in_repo $i;
cd445739 963 fi
2a5f078d 964
ecba6ad5 965 # we check md5 here just only to refetch immediately
a4b50627 966 if good_md5 "$i" && good_size "$i"; then
cd445739
AM
967 :
968 elif [ "$FROM_DISTFILES" = 1 ]; then
deccc50e 969 # wrong md5 from distfiles: remove the file and try again
cd445739 970 # but only once ...
deccc50e 971 echo "MD5 sum mismatch. Trying full fetch."
cd445739
AM
972 FROM_DISTFILES=2
973 rm -f $target
18a52930 974 update_shell_title "${GETURI%% *}: $url"
ca2e6c31 975 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 976 if [ "`echo $url | grep -E 'ftp://'`" ]; then
ce40491a 977 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 978 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739 979 fi
ecba6ad5 980 if [ ! -s "$target" ]; then
cd445739 981 rm -f "$target"
18a52930 982 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 983 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 984 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
ce40491a 985 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 986 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739
AM
987 fi
988 fi
989 test -s "$target" || rm -f "$target"
990 fi
cd445739 991 done
e7fa3b9f
ER
992 SHELL_TITLE_PREFIX=""
993
994 if [ "$get_files_cvs" ]; then
ce40491a 995 cvsup $get_files_cvs
e7fa3b9f 996 fi
cd445739
AM
997
998 if [ "$CHMOD" = "yes" ]; then
3815b69a 999 CHMOD_FILES="`nourl "$@"`"
cd445739
AM
1000 if [ -n "$CHMOD_FILES" ]; then
1001 chmod $CHMOD_MODE $CHMOD_FILES
1002 fi
1003 fi
cd445739
AM
1004 fi
1005}
1006
1007make_tagver() {
ce40491a
ER
1008 if [ -n "$DEBUG" ]; then
1009 set -x;
1010 set -v;
1011 fi
78eab2a1 1012
ce40491a
ER
1013 # Check whether first character of PACKAGE_NAME is legal for tag name
1014 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1015 TAG_PREFIX=tag_
1016 fi
1017 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"`
1018 # Remove #kernel.version_release from TAGVER because tagging sources
1019 # could occur with different kernel-headers than kernel-headers used at build time.
1020 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
1021 echo -n "$TAGVER"
cd445739
AM
1022}
1023
1024tag_files()
1025{
1026 TAG_FILES="$@"
1027
1028 if [ -n "$DEBUG" ]; then
1029 set -x;
1030 set -v;
1031 fi
1032
73ef63d8
ER
1033 echo "Version: $PACKAGE_VERSION"
1034 echo "Release: $PACKAGE_RELEASE"
cd445739 1035
73ef63d8 1036 TAGVER=`make_tagver`
cd445739 1037
73ef63d8
ER
1038 if [ "$TAG_VERSION" = "yes" ]; then
1039 echo "CVS tag: $TAGVER"
1040 fi
1041 if [ -n "$TAG" ]; then
1042 echo "CVS tag: $TAG"
1043 fi
cd445739 1044
39dcc7de 1045 local OPTIONS="tag $CVS_FORCE"
73ef63d8
ER
1046 if [ -n "$CVSROOT" ]; then
1047 OPTIONS="-d $CVSROOT $OPTIONS"
1048 fi
cd445739 1049
73ef63d8
ER
1050 cd "$SOURCE_DIR"
1051 local tag_files
1052 for i in $TAG_FILES; do
1053 # don't tag files stored on distfiles
1054 [ -n "`src_md5 $i`" ] && continue
1055 local fp=`nourl "$i"`
1056 if [ -f "$fp" ]; then
1057 tag_files="$tag_files $fp"
1058 else
1059 Exit_error err_no_source_in_repo $i
03db3356 1060 fi
73ef63d8 1061 done
03db3356 1062
73ef63d8 1063 if [ "$tag_files" ]; then
cd445739 1064 if [ "$TAG_VERSION" = "yes" ]; then
73ef63d8
ER
1065 update_shell_title "tag sources: $TAGVER"
1066 cvs $OPTIONS $TAGVER $tag_files
cd445739
AM
1067 fi
1068 if [ -n "$TAG" ]; then
73ef63d8
ER
1069 update_shell_title "tag sources: $TAG"
1070 cvs $OPTIONS $TAG $tag_files
cd445739 1071 fi
73ef63d8
ER
1072 fi
1073
1074 cd "$SPECS_DIR"
1075 if [ "$TAG_VERSION" = "yes" ]; then
1076 update_shell_title "tag spec: $TAGVER"
1077 cvs $OPTIONS $TAGVER $SPECFILE
1078 fi
1079 if [ -n "$TAG" ]; then
1080 update_shell_title "tag spec: $TAG"
1081 cvs $OPTIONS $TAG $SPECFILE
1082 fi
cd445739
AM
1083}
1084
1085branch_files()
1086{
1087 TAG=$1
1088 echo "CVS branch tag: $TAG"
1089 shift;
1090
1091 TAG_FILES="$@"
1092
1093 if [ -n "$DEBUG" ]; then
1094 set -x;
1095 set -v;
1096 fi
1097
78a5a506
ER
1098 local OPTIONS="tag $CVS_FORCE -b"
1099 if [ -n "$CVSROOT" ]; then
1100 OPTIONS="-d $CVSROOT $OPTIONS"
1101 fi
1102 cd "$SOURCE_DIR"
1103 local tag_files
1104 for i in $TAG_FILES; do
1105 local fp=`nourl "$i"`
1106 if [ -f "$fp" ]; then
1107 tag_files="$tag_files $fp"
1108 else
1109 Exit_error err_no_source_in_repo $i
c10fa4fa 1110 fi
78a5a506
ER
1111 done
1112 if [ "$tag_files" ]; then
1113 cvs $OPTIONS $TAG $tag_files
1114 fi
c10fa4fa 1115
78a5a506
ER
1116 cd "$SPECS_DIR"
1117 cvs $OPTIONS $TAG $SPECFILE
cd445739
AM
1118}
1119
1120
1121
59398507 1122build_package()
1123{
2e5be021 1124 update_shell_title "build_package"
cd445739
AM
1125 if [ -n "$DEBUG" ]; then
1126 set -x;
1127 set -v;
1128 fi
5a491465 1129
cd445739
AM
1130 cd "$SPECS_DIR"
1131
1132 if [ -n "$TRY_UPGRADE" ]; then
ce40491a 1133 update_shell_title "build_package: try_upgrade"
cd445739 1134 if [ -n "$FLOAT_VERSION" ]; then
cc538c24 1135 TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1
cd445739 1136 else
cc538c24 1137 TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1
cd445739
AM
1138 fi
1139
1140 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
1141
1142 if [ -n "$TNEWVER" ]; then
1143 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1144 echo "New version found, updating spec file to version " $TNEWVER
257af81b
ER
1145 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1146 cp -f $SPECFILE $SPECFILE.bak
1147 fi
cd445739
AM
1148 chmod +w $SPECFILE
1149 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
f7b91886 1150 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
cd445739 1151 parse_spec;
975d7b23
ER
1152 NODIST="yes" get_files $SOURCES $PATCHES;
1153 UPDATE5="yes" update_md5 $SOURCES
1154
cd445739
AM
1155 unset TOLDVER TNEWVER TNOTIFY
1156 fi
1157 fi
1158 cd "$SPECS_DIR"
2a5f078d 1159
cd445739
AM
1160 case "$COMMAND" in
1161 build )
1162 BUILD_SWITCH="-ba" ;;
1163 build-binary )
1164 BUILD_SWITCH="-bb" ;;
1165 build-source )
1166 BUILD_SWITCH="-bs --nodeps" ;;
1167 build-prep )
1168 BUILD_SWITCH="-bp --nodeps" ;;
1169 esac
c890b916 1170
2e5be021 1171 update_shell_title "build_package: $COMMAND"
cd445739
AM
1172 if [ -n "$LOGFILE" ]; then
1173 LOG=`eval echo $LOGFILE`
1174 if [ -d "$LOG" ]; then
1175 echo "Log file $LOG is a directory."
1176 echo "Parse error in the spec?"
1177 Exit_error err_build_fail;
1178 fi
1179 if [ -n "$LASTLOG_FILE" ]; then
1180 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1181 fi
1182 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
86aafdbe 1183 (time eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
cd445739
AM
1184 RETVAL=`cat $RES_FILE`
1185 rm $RES_FILE
1186 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1187 if [ "$RETVAL" -eq "0" ]; then
1188 mv $LOG $LOGDIROK
1189 else
1190 mv $LOG $LOGDIRFAIL
1191 fi
1192 fi
8ba5cdda 1193 else
86aafdbe 1194 eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE
cd445739 1195 RETVAL=$?
8ba5cdda 1196 fi
cd445739
AM
1197 if [ "$RETVAL" -ne "0" ]; then
1198 if [ -n "$TRY_UPGRADE" ]; then
796a8a95 1199 echo "\n!!! Package with new version cannot be built automagically\n"
257af81b
ER
1200 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1201 mv -f $SPECFILE.bak $SPECFILE
1202 fi
cd445739
AM
1203 fi
1204 Exit_error err_build_fail;
1205 fi
1206 unset BUILD_SWITCH
1207}
1208
1209nourl()
1210{
1211 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1212}
1213
cd445739
AM
1214install_required_packages()
1215{
1216 run_poldek -vi $1
1217 return $?
1218}
1219
fa4bf1df
ER
1220find_spec_bcond() {
1221 # taken from find-spec-bcond, but with just getting the list
1222 local SPEC="$1"
1223 # quick revert hint: '$RPMBUILD --bcond $SPEC'
1224 awk -F"\n" '
1225 /^%changelog/ { exit }
1226 /_with(out)?_[_a-zA-Z0-9]+/{
1227 match($0, /_with(out)?_[_a-zA-Z0-9]+/);
1228 print substr($0, RSTART, RLENGTH);
1229 }
1230 /^%bcond_with/{
1231 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1232 bcond = substr($0, RSTART +5 , RLENGTH -5);
1233 gsub(/[ \t]+/,"_",bcond);
1234 print bcond
1235 }' $SPEC | LC_ALL=C sort -u
1236}
1237
cd445739
AM
1238set_bconds_values()
1239{
0b65d15e 1240 update_shell_title "set bcond values"
c890b916 1241
cd445739
AM
1242 AVAIL_BCONDS_WITHOUT=""
1243 AVAIL_BCONDS_WITH=""
1244 if `grep -q ^%bcond ${SPECFILE}`; then
1245 BCOND_VERSION="NEW"
36d03934 1246 elif `egrep -q ^#\ *_with ${SPECFILE}`; then
cd445739
AM
1247 BCOND_VERSION="OLD"
1248 else
fa4bf1df 1249 return
cd445739 1250 fi
301cbfd4 1251
fa4bf1df
ER
1252 local bcond_avail=$(find_spec_bcond $SPECFILE)
1253
301cbfd4
ER
1254 # expand bconds from ~/.bcondrc
1255 # The file structure is like gentoo's package.use:
1256 # ---
1257 # * -selinux
1258 # samba -mysql -pgsql
47a8df12 1259 # w32codec-installer license_agreement
301cbfd4
ER
1260 # php +mysqli
1261 # ---
fa4bf1df 1262 if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
3e1cbfe0 1263 SN=${SPECFILE%%\.spec}
301cbfd4 1264
fa4bf1df
ER
1265 local bcondrc=$HOME/.bcondrc
1266 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
c8a3e2ac 1267
301cbfd4
ER
1268 while read pkg flags; do
1269 # ignore comments
1270 [[ "$pkg" == \#* ]] && continue
1271
1272 # any package or current package?
fa4bf1df 1273 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
301cbfd4 1274 for flag in $flags; do
fa4bf1df 1275 local opt=${flag#[+-]}
301cbfd4
ER
1276
1277 # use only flags which are in this package.
fa4bf1df 1278 if [[ $bcond_avail = *${opt}* ]]; then
3b5101f0 1279 if [[ $flag = -* ]]; then
3f73a917 1280 if [[ $BCOND != *--with?${opt}* ]]; then
1281 BCOND="$BCOND --without $opt"
1282 fi
301cbfd4 1283 else
3f73a917 1284 if [[ $BCOND != *--without?${opt}* ]]; then
1285 BCOND="$BCOND --with $opt"
1286 fi
301cbfd4
ER
1287 fi
1288 fi
1289 done
1290 fi
fa4bf1df
ER
1291 done < $bcondrc
1292 update_shell_title "parse ~/.bcondrc: DONE!"
301cbfd4
ER
1293 fi
1294
fa4bf1df 1295 update_shell_title "parse bconds"
cd445739 1296 case "${BCOND_VERSION}" in
fa4bf1df 1297 NONE)
7e365483 1298 :
cd445739 1299 ;;
7e365483 1300 OLD)
cd445739 1301 echo "Warning: This spec has old style bconds. Fix it || die."
fa4bf1df 1302 for opt in `echo "$bcond_avail" | grep ^_without_`
cd445739 1303 do
fa4bf1df
ER
1304 AVAIL_BCOND_WITHOUT=${opt#_without_}
1305 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
cd445739
AM
1306 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1307 else
1308 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1309 fi
1310 done
2a5f078d 1311
fa4bf1df 1312 for opt in `echo "$bcond_avail" | grep ^_with_`
cd445739 1313 do
fa4bf1df
ER
1314 AVAIL_BCOND_WITH=${opt#_with_}
1315 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
cd445739
AM
1316 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1317 else
1318 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1319 fi
1320 done
1321 ;;
1322 NEW)
fa4bf1df
ER
1323 local cond_type="" # with || without
1324 for opt in $bcond_avail; do
cd445739
AM
1325 case "$opt" in
1326 _without)
1327 cond_type="without"
1328 ;;
1329 _with)
1330 cond_type="with"
1331 ;;
f8d24cee 1332 _without_*)
fa4bf1df
ER
1333 AVAIL_BCOND_WITHOUT=${opt#_without_}
1334 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
f8d24cee 1335 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1336 else
1337 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1338 fi
1339 ;;
1340 _with_*)
fa4bf1df
ER
1341 AVAIL_BCOND_WITH=${opt#_with_}
1342 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
f8d24cee 1343 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1344 else
1345 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1346 fi
1347 ;;
cd445739
AM
1348 *)
1349 case "$cond_type" in
1350 with)
1351 cond_type=''
1352 AVAIL_BCOND_WITH="$opt"
fa4bf1df 1353 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
cd445739
AM
1354 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1355 else
1356 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1357 fi
7e365483 1358 ;;
cd445739
AM
1359 without)
1360 cond_type=''
1361 AVAIL_BCOND_WITHOUT="$opt"
fa4bf1df 1362 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
cd445739
AM
1363 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1364 else
1365 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1366 fi
1367 ;;
1368 esac
1369 ;;
1370 esac
1371 done
1372 ;;
1373 esac
1374}
1375
1376run_sub_builder()
1377{
1378 package_name="${1}"
af6b168f 1379 update_shell_title "run_sub_builder $package_name"
cd445739
AM
1380 #
1381