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