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