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