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