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