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