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