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