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