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