3 # This program is free software, distributed under the terms of
4 # the GNU General Public License Version 2.
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)
22 # - when Icon: field is present, -5 and -a5 doesn't work
23 # - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
24 # - does not respect NoSource: X, and tries to cvs up such files [ example: VirtualBox-bin.spec and its Source0 ]
26 # - ability to do ./builder -bb foo.spec foo2.spec foo3.spec
27 # - funny bug, if source-md5 is set then builder will download from distfiles even if there is no url present:
28 # Source10: forwardfix.pl
29 # # Source10-md5: 8bf85f7368933a4e0cb4f875bac28733
31 # basename: missing operand
32 # Try `basename --help' for more information.
33 # -- and the normal usage info --
36 APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
37 RCSID='$Id$' r=${RCSID#* * } rev=${r%% *}
40 Build package utility from PLD Linux Packages repository
41 $VERSION (C) 1999-2012 Free Penguins".
43 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
45 # required rpm-build-macros
65 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
69 # use rpm 4.4.6+ digest format instead of comments if non-zero
72 # user agent when fetching files
73 USER_AGENT="PLD/Builder($VERSION)"
75 # It can be used i.e. in log file naming.
76 # See LOGFILE example.
77 DATE=`date +%Y-%m-%d_%H-%M-%S`
79 # target arch, can also be used for log file naming
80 TARGET=$(rpm -E %{_target})
82 # Example: LOGFILE='../log.$PACKAGE_NAME'
83 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
84 # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
85 # Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
86 # Yes, you can use variable name! Note _single_ quotes!
101 # create symlinks for tools in PACKAGE_DIR, see get_spec()
113 # use lftp by default when available
115 lftp --version > /dev/null 2>&1 && USE_LFTP=yes
116 PARALLEL_DOWNLOADS=10
118 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
120 CVS_COMMAND=${CVS_COMMAND:-cvs}
123 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
124 CVS_SERVER="cvs.pld-linux.org"
129 DISTFILES_SERVER="://distfiles.pld-linux.org"
130 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
135 FAIL_IF_NO_SOURCES="yes"
137 # let get_files skip over files which are present to get those damn files fetched
138 SKIP_EXISTING_FILES="no"
141 # should the specfile be restored if upgrade failed?
142 REVERT_BROKEN_UPGRADE="yes"
144 if rpm --specsrpm 2>/dev/null; then
145 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
146 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
148 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
149 if [ -x /usr/bin/rpm-getdeps ]; then
150 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
152 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
156 UPDATE_POLDEK_INDEXES_OPTS=""
158 # Here we load saved user environment used to
159 # predefine options set above, or passed to builder
161 # This one reads global system environment settings:
162 if [ -f ~/etc/builderrc ]; then
165 # And this one cascades settings using user personal
167 # Example of ~/.builderrc:
169 #UPDATE_POLDEK_INDEXES="yes"
170 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
171 #FETCH_BUILD_REQUIRES="yes"
172 #REMOVE_BUILD_REQUIRES="force"
174 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
178 if [ -n "$HOME_ETC" ]; then
179 USER_CFG="$HOME_ETC/.builderrc"
180 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
182 USER_CFG=~/.builderrc
183 BUILDER_MACROS=~/.builder-rpmmacros
186 [ -f "$USER_CFG" ] && . "$USER_CFG"
188 if [ "$SCHEDTOOL" = "auto" ]; then
189 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
190 SCHEDTOOL="schedtool -B -e"
196 if [ -n "$USE_PROZILLA" ]; then
197 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
200 elif [ -n "$USE_AXEL" ]; then
201 GETURI="axel -a $AXEL_OPTS"
204 elif [ -n "$USE_LFTP" ]; then
209 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
210 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
211 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
212 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
214 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
215 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
221 if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
232 if [ -d $HOME/rpm/SOURCES ]; then
233 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
234 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
239 # are we using cvs-nserver ?
242 $CVS_COMMAND --version 2>&1 | grep -q 'CVS-nserver'
243 [ $? -eq 0 ] && CVS_NSERVER=1
245 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
246 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
250 if [ -n "$LOGFILE" ]; then
251 LOG=`eval echo $LOGFILE`
252 if [ -n "$LASTLOG_FILE" ]; then
253 echo "LASTLOG=$LOG" > $LASTLOG_FILE
255 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
258 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
259 return `cat ${RES_FILE}`
264 #---------------------------------------------
268 local outfile=$1 url=$2 retval tmpfile
272 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
273 set ssl:verify-certificate no;
274 set net:max-retries $WGET_RETRIES;
275 set http:user-agent \"$USER_AGENT\";
276 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
280 if [ $retval -eq 0 ]; then
281 mv -f "$tmpfile" "$outfile"
289 if [ -n "$DEBUG" ]; then set -xv; fi
291 Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--add_cvs] [-b|-ba|--build]
292 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
293 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
294 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
295 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
296 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
297 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] [--use-greed-sources]
298 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
299 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
300 <package>[.spec][:cvstag]
302 -4 - force ipv4 when transferring files
303 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
304 -6 - force ipv6 when transferring files
305 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
306 -n5, --no-md5 - ignore md5 comments in spec
307 -D, --debug - enable builder script debugging mode,
308 -debug - produce rpm debug package (same as --opts -debug)
309 -V, --version - output builder version string
310 --short-version - output builder short version
311 --as_anon - get files via pserver as cvs@$CVS_SERVER,
312 -a, --add_cvs - try add new package to CVS.
313 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
315 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
316 only package from <package>.spec,
317 -bp, --build-prep - execute the %prep phase of <package>.spec,
318 -bc - execute the %build phase of <package>.spec,
319 -bi - execute the %install phase of <package>.spec
320 -bl - execute the %files phase of <package>.spec
321 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
323 --short-circuit - short-circuit build
324 -B, --branch - add branch
325 -c, --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
326 may be used with building process.
327 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES, SPECS and \$RPM_BUILD_ROOT
328 and CVS/Entries). Doesn't run any rpm building.
329 -cf, --cvs-force - use -F when tagging (useful when moving branches)
330 -d <cvsroot>, --cvsroot <cvsroot>
332 --define <macro> <value> - define a macro <macro> with value <value>,
333 --alt_kernel <kernel> - same as --define 'alt_kernel <kernel>'
334 --nodeps - rpm won't check any dependences
335 -g, --get - get <package>.spec and all related files from CVS repo or HTTP/FTP
336 -h, --help - this message
337 -jN, -j N - set %_smp_mflags to propagate concurrent jobs
338 --ftp, --http - use ftp or http protocol to access distfiles server
339 -l <logfile>, --logtofile <logfile>
341 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
342 -ncs, --no-cvs-specs - don't check specs in CVS
343 -nd, --no-distfiles - don't download from distfiles
344 -nm, --no-mirrors - don't download from mirror, if source URL is given,
345 -nu, --no-urls - don't try to download from FTP/HTTP location,
346 -ns, --no-srcs - don't download Sources/Patches
347 -ns0, --no-source0 - don't download Source0
348 -nn, --no-net - don't download anything from the net
349 -pN, -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
350 -pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES
351 --no-init - don't initialize builder paths (SPECS and SOURCES)
353 --skip-existing-files - skip existing files in get_files
354 --opts <rpm opts> - additional options for rpm
355 -q, --quiet - be quiet,
356 --date yyyy-mm-dd - build package using resources from specified CVS date,
357 -r <cvstag>, --cvstag <cvstag>
358 - build package using resources from specified CVS tag,
359 -A - build package using CVS resources as any sticky tags/date/kopts being reset.
360 -R, --fetch-build-requires
361 - fetch what is BuildRequired,
362 -RB, --remove-build-requires
363 - remove all you fetched with -R or --fetch-build-requires
364 remember, this option requires confirmation,
365 -FRB, --force-remove-build-requires
366 - remove all you fetched with -R or --fetch-build-requires
367 remember, this option works without confirmation,
368 -sd, --source-distfiles - list sources available from distfiles (intended for offline
369 operations; does not work when Icon field is present
370 but icon file is absent),
371 -sc, --source-cvs - list sources available from CVS
372 -sdp, --source-distfiles-paths - list sources available from distfiles -
373 paths relative to distfiles directory (intended for offline
374 operations; does not work when Icon field is present
375 but icon file is absent),
376 -sf, --source-files - list sources - bare filenames (intended for offline
377 operations; does not work when Icon field is present
378 but icon file is absent),
379 -lsp, --source-paths - list sources - filenames with full local paths (intended for
380 offline operations; does not work when Icon field is present
381 but icon file is absent),
382 -su, --source-urls - list urls - urls to sources and patches
383 intended for copying urls with spec with lots of macros in urls
384 -T <cvstag> , --tag <cvstag>
385 - add cvs tag <cvstag> for files,
386 -Tvs, --tag-version-stable
387 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
388 -Ts, --tag-stable - add cvs tag STABLE for files,
389 -Tv, --tag-version - add cvs tag NAME-VERSION-RELEASE for files,
390 -Tp, --tag-prefix <prefix>
391 - add <prefix> to NAME-VERSION-RELEASE tags,
392 -tt, --test-tag <prefix>
393 - fail if tag is already present,
394 -ir, --integer-release-only
395 - allow only integer and snapshot releases
396 -v, --verbose - be verbose,
397 -u, --try-upgrade - check version, and try to upgrade package
398 -un, --try-upgrade-with-float-version
399 - as above, but allow float version
400 php-pear-Services_Digg/
401 --upgrade-version - upgrade to specified version in try-upgrade
403 - try download source from tag head if don't find it in
405 -U, --update - refetch sources, don't use distfiles, and update md5 comments
406 -Upi, --update-poldek-indexes
407 - refresh or make poldek package index files.
408 -sp, --skip-patch <patchnumber>
409 - don't apply <patchnumber>. may be repeated.
410 -np, --nopatch <patchnumber>
411 - abort instead of applying patch <patchnumber>
412 --show-bconds - show available conditional builds, which can be used
413 - with --with and/or --without switches.
414 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
415 In other words, the output is parseable by scripts.
416 --show-avail-bconds - show available bconds
417 --with/--without <feature>
418 - conditional build package depending on %_with_<feature>/
419 %_without_<feature> macro switch. You may now use
420 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
421 constructions. Set GROUP_BCONDS to yes to make use of it.
422 --target <platform>, --target=<platform>
423 - build for platform <platform>.
424 --init-rpm-dir - initialize ~/rpm directory structure
428 # create tempfile. as secure as possible
430 mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
433 # change dependency to specname
435 # - perl(Package::Name) -> perl-Package-Name
439 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
443 update_shell_title() {
445 local len=${COLUMNS:-80}
446 local msg="$(echo "$*" | cut -c-$len)"
448 if [ -n "$BE_VERBOSE" ]; then
449 echo >&2 "$(date +%s.%N) $*"
452 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
454 if [ -n "$PACKAGE_NAME" ]; then
455 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
460 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
461 msg=$(echo $msg | tr -d '\n\r')
464 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
467 echo >&2 -ne "\033]0;$msg\007"
473 # set TARGET from BuildArch: from SPECFILE
475 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
476 tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
478 target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
482 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
484 TARGET_SWITCH="--target=$TARGET" ;;
490 # runs rpm with minimal macroset
492 # we reset macros not to contain macros.build as all the %() macros are
493 # executed here, while none of them are actually needed.
494 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
495 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
497 # TODO: move these to /usr/lib/rpm/macros
498 cat > $BUILDER_MACROS <<'EOF'
499 %x8664 x86_64 amd64 ia32e
502 %bootstrap_release() %{1}
503 %requires_releq_kernel_up(s:n:) %{nil}
504 %requires_releq_kernel_smp(s:n:) %{nil}
505 %requires_releq_kernel(s:n:) %{nil}
506 %requires_releq() %{nil}
507 %pyrequires_eq() %{nil}
508 %requires_eq() %{nil}
509 %requires_eq_to() %{nil}
510 %requires_ge() %{nil}
511 %requires_ge_to() %{nil}
512 %requires_ge() %{nil}
513 %releq_kernel_up(n:) ERROR
514 %releq_kernel_smp(n:) ERROR
515 %releq_kernel(n:) ERROR
519 %ruby_ver_requires_eq() %{nil}
520 %ruby_mod_ver_requires_eq() %{nil}
521 %__php_api_requires() %{nil}
522 %php_major_version ERROR
523 %php_api_version ERROR
524 %requires_xorg_xserver_extension %{nil}
525 %requires_xorg_xserver_xinput %{nil}
526 %requires_xorg_xserver_font %{nil}
527 %requires_xorg_xserver_videodrv %{nil}
529 %perl_vendorarch ERROR
530 %perl_vendorlib ERROR
531 # damn. need it here! - copied from /usr/lib/rpm/macros.build
532 %tmpdir %(echo "${TMPDIR:-/tmp}")
533 %patchset_source(f:b:) %(
534 base=%{-b*}%{!-b*:10000};
535 start=$(expr $base + %1);
536 end=$(expr $base + %{?2}%{!?2:%{1}});
537 # we need to call seq twice as it doesn't allow two formats
538 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
539 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
540 paste %{tmpdir}/__ps{1,2};
541 rm -f %{tmpdir}/__ps{1,2};
544 %add_etc_shells(p) %{p:<lua>}
545 %remove_etc_shells(p) %{p:<lua>}
546 %lua_add_etc_shells() %{nil}
547 %lua_remove_etc_shells() %{nil}
549 %buildrequires_jdk %{nil}
550 %pear_package_print_optionalpackages %{nil}
552 if [ "$NOINIT" = "yes" ] ; then
553 cat >> $BUILDER_MACROS <<'EOF'
558 eval $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
562 if [ -n "$DEBUG" ]; then
567 if [ -x /usr/bin/rpm-specdump ]; then
568 update_shell_title "cache_rpm_dump using rpm-specdump command"
569 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND $SPECFILE)
571 update_shell_title "cache_rpm_dump using rpmbuild command"
574 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
575 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
581 ARGS='--nodigest --nosignature --nobuild'
584 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
586 if [ $? -gt 0 ]; then
587 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
589 Exit_error err_build_fail
592 # make small dump cache
593 rpm_dump_cache=`echo "$rpm_dump" | awk '
594 $2 ~ /^SOURCEURL/ {print}
595 $2 ~ /^PATCHURL/ {print}
596 $2 ~ /^nosource/ {print}
597 $2 ~ /^PACKAGE_/ {print}
601 update_shell_title "cache_rpm_dump: OK!"
605 if [ -z "$rpm_dump_cache" ] ; then
606 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
608 echo "$rpm_dump_cache"
612 update_shell_title "get icons"
613 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
614 if [ -z "$ICONS" ]; then
618 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
622 update_shell_title "parsing specfile"
623 if [ -n "$DEBUG" ]; then
628 # icons are needed for successful spec parse
634 if rpm_dump | grep -qEi ":.*nosource.*1"; then
635 FAIL_IF_NO_SOURCES="no"
638 if [ "$NOSRCS" != "yes" ]; then
639 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
640 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
641 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
644 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
645 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
646 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
648 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
649 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
652 if [ -n "$BE_VERBOSE" ]; then
653 echo "- Sources : `nourl $SOURCES`"
654 if [ -n "$PATCHES" ]; then
655 echo "- Patches : `nourl $PATCHES`"
657 echo "- Patches : *no patches needed*"
659 if [ -n "$ICONS" ]; then
660 echo "- Icon : `nourl $ICONS`"
662 echo "- Icon : *no package icon*"
664 echo "- Name : $PACKAGE_NAME"
665 echo "- Version : $PACKAGE_VERSION"
666 echo "- Release : $PACKAGE_RELEASE"
669 update_shell_title "parse_spec: OK!"
673 if [ -n "$DEBUG" ]; then
681 "err_no_spec_in_cmdl" )
682 remove_build_requires
683 echo >&2 "ERROR: spec file name not specified."
685 "err_invalid_cmdline" )
686 echo >&2 "ERROR: invalid command line arg ($2)."
688 "err_no_spec_in_repo" )
689 remove_build_requires
690 echo >&2 "Error: spec file not stored in CVS repo."
692 "err_no_source_in_repo" )
693 remove_build_requires
694 echo >&2 "Error: some source, patch or icon files not stored in CVS repo. ($2)"
696 "err_cvs_add_failed" )
697 echo >&2 "Error: failed to add package to CVS repo."
700 remove_build_requires
701 echo >&2 "Error: package build failed. (${2:-no more info})"
703 "err_no_package_data" )
704 remove_build_requires
705 echo >&2 "Error: couldn't get out package name/version/release from spec file."
708 remove_build_requires
709 echo >&2 "Tag ${2} already exists (spec release: ${3})."
712 remove_build_requires
713 echo >&2 "Release ${2} not integer and not a snapshot."
715 "err_branch_exists" )
716 remove_build_requires
717 echo >&2 "Tree branch already exists (${2})."
720 remove_build_requires
721 echo >&2 "Error: conditions reject building this spec (${2})."
724 echo >&2 "Unknown error."
729 if [ -n "$DEBUG" ]; then
734 if [ "$NOINIT" != "yes" ] ; then
735 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
737 local macros_ver=$(rpm -E %?rpm_build_macros)
738 if [ -z "$macros_ver" ]; then
739 REPO_DIR=$TOP_DIR/packages
740 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
742 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
743 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
747 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
759 update_shell_title "get_spec"
761 if [ -n "$DEBUG" ]; then
767 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
769 SPECFILE=$(basename $SPECFILE)
772 if [ "$NOCVSSPEC" != "yes" ]; then
773 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
774 echo "Warning: No CVS access defined in $(pwd) (check CVS/Root) - using local .spec file"
778 if [ -d "$ASSUMED_NAME" -a -s "$ASSUMED_NAME/CVS/Root" ]; then
779 cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
780 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
781 if [ ! -r "$ASSUMED_NAME/$SPECFILE" ]; then
782 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
785 if [ ! -s "$ASSUMED_NAME/CVS/Root" ]; then
786 cvsup -a $ASSUMED_NAME || Exit_error err_cvs_add_failed
788 cvsup -a "$ASSUMED_NAME/$SPECFILE" || Exit_error err_cvs_add_failed
790 cvsup -c -d $ASSUMED_NAME "packages/$ASSUMED_NAME/$SPECFILE" || {
791 # softfail if new package, i.e not yet added to cvs
792 [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo
793 echo "Warning: package not in CVS - assuming new package"
798 # remove Entries.Static -- so 'cvs up' would update all files in a repo
799 rm -f "$ASSUMED_NAME/CVS/Entries.Static"
802 cvsignore_df .cvsignore
804 # add default log format to .cvsignore if it is relative to package dir
805 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
806 # substitute known "macros" to glob
807 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\),*,g')
808 if [ "$logfile" ]; then
809 cvsignore_df "$logfile"
813 # create symlinks for tools
814 if [ "$SYMLINK_TOOLS" != "no" ]; then
815 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
816 # skip tools that don't exist in top dir
817 [ -f $a ] || continue
818 # skip tools that already exist
819 [ -f $ASSUMED_NAME/$a ] && continue
820 ln -s ../$a $ASSUMED_NAME
826 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
827 Exit_error err_no_spec_in_repo
830 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
831 chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE
834 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE
842 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
843 $CVS_COMMAND update mirrors >&2
847 local origin mirror name rest ol prefix
848 while read origin mirror name rest; do
849 # skip comments and empty lines
850 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
853 ol=$(echo -n "$origin" | wc -c)
854 prefix=$(echo -n "$url" | head -c $ol)
855 if [ "$prefix" = "$origin" ] ; then
856 suffix=$(echo "$url" | cut -b $((ol+1))-)
857 echo -n "$mirror$suffix"
864 # Warning: unpredictable results if same URL used twice
867 # escape some regexp characters if part of file name
868 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
871 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
872 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
873 head -n 1 | tr OURCEATH ourceath | xargs
877 [ "$NO5" = "yes" ] && return
879 [ -z "$no" ] && return
883 if [ -f additional-md5sums ]; then
884 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
885 if [ -z "$spec_rev" ]; then
886 spec_rev=$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')
888 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
889 md5=$(grep -s -v '^#' additional-md5sums | \
890 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
891 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
892 grep -E '^[0-9a-f]{32}$')
895 if [ $(echo "$md5" | wc -l) != 1 ] ; then
896 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
898 echo "$md5" | tail -n 1
903 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
904 if [ -n "$source_md5" ]; then
907 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
908 if [ -n "$source_md5" ]; then
911 # we have empty SourceX-md5, but it is still possible
912 # that we have NoSourceX-md5 AND NoSource: X
913 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
914 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
922 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
926 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
929 distfiles_attic_url() {
930 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
936 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
940 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
941 [ -n "$size" -a "$size" -gt 0 ]
945 if [ "$CVSIGNORE_DF" != "yes" ]; then
948 cvsignore=${PACKAGE_DIR}/.cvsignore
950 # add only if not yet there
951 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
952 echo "$1" >> $cvsignore
957 update_shell_title "cvsup"
958 local OPTIONS="" ACTION="up"
961 if [ "$1" = "-c" ]; then
966 if [ "$1" = "-a" ]; then
973 if [ -n "$CVSROOT" ]; then
974 OPTIONS="-d $CVSROOT $OPTIONS"
977 if [ "$ACTION" != "add" ]; then
978 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
979 OPTIONS="$OPTIONS -A"
981 if [ -n "$CVSDATE" ]; then
982 OPTIONS="$OPTIONS -D $CVSDATE"
984 if [ -n "$CVSTAG" ]; then
985 # FIXME: cvs add actually works with -r ?
986 OPTIONS="$OPTIONS -r $CVSTAG"
992 local retries_counter=0
994 update_shell_title "cvsup: $*"
996 update_shell_title "cvsup: $# files"
998 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
999 retries_counter=$(( $retries_counter + 1 ))
1000 output=$(LC_ALL=C $CVS_COMMAND $OPTIONS "$@" 2>&1)
1002 [ -n "$output" ] && echo "$output"
1003 if echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)" \
1004 && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
1005 echo "Trying again [$*]... ($retries_counter)"
1006 update_shell_title "cvsup: retry #$retries_counter"
1013 update_shell_title "cvsup: done!"
1017 # returns true if "$1" is ftp, http or https protocol url
1020 ftp://*|http://*|https://*)
1028 if [ $# -eq 0 ]; then
1032 update_shell_title "update md5"
1033 if [ -n "$DEBUG" ]; then
1040 # pass 1: check files to be fetched
1044 local fp=$(nourl "$i")
1045 local srcno=$(src_no "$i")
1046 if [ -n "$ADD5" ]; then
1047 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1048 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1049 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1051 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1053 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1054 need_files="$need_files $i"
1058 # pass 1a: get needed files
1059 if [ "$need_files" ]; then
1060 get_files $need_files
1063 # pass 2: proceed with md5 adding or updating
1065 local fp=$(nourl "$i")
1066 local srcno=$(src_no "$i")
1067 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1068 if [ -z "$md5" ]; then
1069 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1071 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1072 local tag="# $srcno-md5:\t"
1073 if [[ "$md5" == *NoSource* ]]; then
1074 tag="# No$srcno-md5:\t"
1075 elif [ -n "$USEDIGEST" ]; then
1076 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1078 md5=$(md5sum "$fp" | cut -f1 -d' ')
1079 echo "Updating $srcno ($md5: $fp)."
1081 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1082 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1084 $PACKAGE_DIR/$SPECFILE
1091 [ "$NO5" = "yes" ] && return
1093 update_shell_title "check md5"
1097 if ! good_md5 "$i"; then
1098 echo -n "MD5 sum mismatch."
1101 if ! good_size "$i"; then
1102 echo -n "0 sized file."
1106 if [ $bad -eq 1 ]; then
1107 echo " Use -U to refetch sources,"
1108 echo "or -5 to update md5 sums, if you're sure files are correct."
1109 Exit_error err_no_source_in_repo $i
1115 update_shell_title "get_files"
1117 if [ -n "$DEBUG" ]; then
1122 if [ $# -gt 0 ]; then
1125 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
1126 echo "Warning: No CVS access defined for SOURCES"
1131 local get_files_cvs=""
1135 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1136 update_shell_title "$i"
1137 local fp=`nourl "$i"`
1138 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1143 local srcmd5=$(src_md5 "$i")
1145 # we know if source/patch is present in cvs/distfiles
1146 # - has md5 (in distfiles)
1147 # - in cvs... ideas?
1149 # CHECK: local file didn't exist or always cvs up (first) requested.
1150 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1151 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1152 echo "Warning: no URL given for $i"
1156 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1157 if good_md5 "$i" && good_size "$i"; then
1158 echo "$fp having proper md5sum already exists"
1162 # optionally prefer mirror over distfiles if there's mirror
1163 # TODO: build url list and then try each url from the list
1164 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1167 url=$(distfiles_url "$i")
1170 url_attic=$(distfiles_attic_url "$i")
1172 # is $url local file?
1173 if [[ "$url" = [./]* ]]; then
1174 update_shell_title "${GETLOCAL%% *}: $url"
1175 ${GETLOCAL} $url $target
1177 if [ -z "$NOMIRRORS" ]; then
1178 url=$(find_mirror "$url")
1182 # make shorter message for distfiles urls
1183 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1184 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1185 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1188 update_shell_title "${GETURI%% *}: $uri"
1189 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1190 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1191 update_shell_title "${GETURI2%% *}: $url"
1192 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1197 if [ ! -s "$target" ]; then
1199 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1200 update_shell_title "${GETLOCAL%% *}: $url_attic"
1201 ${GETLOCAL} $url_attic $target
1203 if [ -z "$NOMIRRORS" ]; then
1204 url_attic=$(find_mirror "$url_attic")
1206 update_shell_title "${GETURI%% *}: $url_attic"
1207 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1208 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1209 update_shell_title "${GETURI2%% *}: $url_attic"
1210 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1212 test -s "$target" || rm -f "$target"
1216 if [ -s "$target" ]; then
1217 cvsignore_df $target
1222 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
1223 if [ $# -gt 1 ]; then
1224 get_files_cvs="$get_files_cvs $fp"
1225 update_shell_title "$fp (will cvs up later)"
1232 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1233 if [ -z "$NOMIRRORS" ]; then
1234 im=$(find_mirror "$i")
1238 update_shell_title "${GETURI%% *}: $im"
1239 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1240 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1241 update_shell_title "${GETURI2%% *}: $im"
1242 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1244 test -s "$target" || rm -f "$target"
1247 if [ "$cvsup" = 1 ]; then
1253 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1254 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1255 if [ -n "GREEDSRC" ]; then
1256 get_greed_sources $i
1258 Exit_error err_no_source_in_repo $i
1262 # we check md5 here just only to refetch immediately
1263 if good_md5 "$i" && good_size "$i"; then
1265 elif [ "$FROM_DISTFILES" = 1 ]; then
1266 # wrong md5 from distfiles: remove the file and try again
1268 echo "MD5 sum mismatch. Trying full fetch."
1271 update_shell_title "${GETURI%% *}: $url"
1272 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1273 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1274 update_shell_title "${GETURI2%% *}: $url"
1275 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1277 if [ ! -s "$target" ]; then
1279 update_shell_title "${GETURI%% *}: $url_attic"
1280 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1281 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1282 update_shell_title "${GETURI2%% *}: $url_attic"
1283 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1286 test -s "$target" || rm -f "$target"
1289 SHELL_TITLE_PREFIX=""
1291 if [ "$get_files_cvs" ]; then
1292 cvsup $get_files_cvs
1295 if [ "$CHMOD" = "yes" ]; then
1296 CHMOD_FILES=$(nourl "$@")
1297 if [ -n "$CHMOD_FILES" ]; then
1298 chmod $CHMOD_MODE $CHMOD_FILES
1305 if [ -n "$DEBUG" ]; then
1310 # Check whether first character of PACKAGE_NAME is legal for tag name
1311 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1315 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1316 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]')
1318 # Remove #kernel.version_release from TAGVER because tagging sources
1319 # could occur with different kernel-headers than kernel-headers used at build time.
1320 # besides, %{_kernel_ver_str} is not expanded.
1322 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str}
1323 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1329 # bool is_tag_a_branch(tag)
1331 # returns 1 if a tag is a branch set on SPECFILE
1333 if [ -n "$DEBUG" ]; then
1338 if [ $# -ne 1 ]; then
1343 # escape some regexp characters if part of TAG
1344 _TAG=$(echo "$_TAG" | sed -e 's#\([\+\*\.]\)#\\\1#g')
1348 $CVS_COMMAND status -v $SPECFILE | grep -Eiq "${_TAG}.+(branch: [0-9.]+)"
1355 if [ -n "$DEBUG" ]; then
1360 echo "Version: $PACKAGE_VERSION"
1361 echo "Release: $PACKAGE_RELEASE"
1364 if [ "$TAG_VERSION" = "yes" ]; then
1365 TAGVER=`make_tagver`
1366 echo "CVS tag: $TAGVER"
1368 if [ -n "$TAG" ]; then
1369 echo "CVS tag: $TAG"
1372 local OPTIONS="tag $CVS_FORCE"
1373 if [ -n "$CVSROOT" ]; then
1374 OPTIONS="-d $CVSROOT $OPTIONS"
1377 # if a tagname we are about to set already exists
1378 # and happens to be a branch (common case with AC-branch)
1379 # pass -B (allows -F to disturb branch tag)
1381 if [ "$TAG_VERSION" = "yes" ]; then
1384 is_tag_a_branch $_tag
1385 if [ $? -eq 0 -a $CVS_NSERVER -eq 0 ]; then
1386 OPTIONS="$OPTIONS -B"
1391 for i in $TAG_FILES; do
1392 # don't tag files stored on distfiles
1393 [ -n "`src_md5 $i`" ] && continue
1394 local fp=`nourl "$i"`
1395 if [ -f "$fp" ]; then
1396 tag_files="$tag_files $fp"
1397 elif [ -n "GREEDSRC" ]; then
1398 get_greed_sources $i
1400 Exit_error err_no_source_in_repo $i
1404 if [ "$tag_files" ]; then
1405 if [ "$TAG_VERSION" = "yes" ]; then
1406 update_shell_title "tag sources: $TAGVER"
1407 printf "Tagging %d files\n" $(echo $tag_files | wc -w)
1408 $CVS_COMMAND $OPTIONS $TAGVER $tag_files || exit
1410 if [ -n "$TAG" ]; then
1411 update_shell_title "tag sources: $TAG"
1413 while [ "$tag_files" ]; do
1414 local chunk=$(echo $tag_files | tr ' ' '\n' | head -n 100)
1415 printf "Tagging %d files\n" $(echo $chunk | wc -w)
1416 $CVS_COMMAND $OPTIONS $TAG $chunk || exit
1417 tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101)
1423 if [ "$TAG_VERSION" = "yes" ]; then
1424 update_shell_title "tag spec: $TAGVER"
1425 $CVS_COMMAND $OPTIONS $TAGVER $SPECFILE || exit
1427 if [ -n "$TAG" ]; then
1428 update_shell_title "tag spec: $TAG"
1429 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
1435 echo "CVS branch tag: $TAG"
1440 if [ -n "$DEBUG" ]; then
1445 local OPTIONS="tag $CVS_FORCE -b"
1448 is_tag_a_branch $TAG
1449 if [ $? -eq 1 ]; then
1450 OPTIONS="$OPTIONS -B"
1453 if [ -n "$CVSROOT" ]; then
1454 OPTIONS="-d $CVSROOT $OPTIONS"
1458 for i in $TAG_FILES; do
1459 local fp=`nourl "$i"`
1460 if [ -f "$fp" ]; then
1461 tag_files="$tag_files $fp"
1462 elif [ -n "GREEDSRC" ]; then
1463 get_greed_sources $i
1465 Exit_error err_no_source_in_repo $i
1468 if [ "$tag_files" ]; then
1469 $CVS_COMMAND $OPTIONS $TAG $tag_files || exit
1473 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
1477 # this function should exit early if package can't be built for this arch
1478 # this avoids unneccessary BR filling.
1481 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1483 if [ $ret -ne 0 ]; then
1495 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1496 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1502 local ver="$2" subver=$ver
1503 local newver="$3" newsubver=$newver
1505 # try handling subver, everything that's not numeric-dotted in version
1506 if grep -Eq '%define\s+subver' $specfile; then
1507 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1509 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1510 newver=${newver%$newsubver}
1513 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1514 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1515 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1520 if [ -n "$TRY_UPGRADE" ]; then
1521 local TNOTIFY TNEWVER TOLDVER
1522 update_shell_title "build_package: try_upgrade"
1526 if [ "$UPGRADE_VERSION" ]; then
1527 TNEWVER=$UPGRADE_VERSION
1529 if [ -n "$FLOAT_VERSION" ]; then
1530 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1532 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1535 # pldnotify.awk does not set exit codes, but it has match for ERROR
1536 # in output which means so.
1537 if [[ "$TNOTIFY" = *ERROR* ]]; then
1542 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1545 if [ -n "$TNEWVER" ]; then
1546 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1547 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1548 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1549 cp -f $SPECFILE $SPECFILE.bak
1552 set_release $SPECFILE $PACKAGE_RELEASE 1
1553 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1555 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1556 echo >&2 "Upgrading version failed, you need to update spec yourself"
1566 update_shell_title "build_package"
1567 if [ -n "$DEBUG" ]; then
1576 BUILD_SWITCH="-ba" ;;
1578 BUILD_SWITCH="-bb" ;;
1580 BUILD_SWITCH="-bs --nodeps" ;;
1582 BUILD_SWITCH="-bp --nodeps" ;;
1584 BUILD_SWITCH="-bc" ;;
1586 BUILD_SWITCH="-bi" ;;
1588 BUILD_SWITCH="-bl" ;;
1592 update_shell_title "build_package: $COMMAND"
1593 if [ -n "$LOGFILE" ]; then
1594 LOG=`eval echo $LOGFILE`
1595 if [ -d "$LOG" ]; then
1596 echo "Log file $LOG is a directory."
1597 echo "Parse error in the spec?"
1598 Exit_error err_build_fail
1600 if [ -n "$LASTLOG_FILE" ]; then
1601 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1603 RES_FILE=$(tempfile)
1605 (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
1606 RETVAL=`cat $RES_FILE`
1608 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1609 if [ "$RETVAL" -eq "0" ]; then
1616 eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE
1619 if [ "$RETVAL" -ne "0" ]; then
1620 if [ -n "$TRY_UPGRADE" ]; then
1621 echo "\nUpgrade package to new version failed."
1622 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1623 echo "Restoring old spec file."
1624 mv -f $SPECFILE.bak $SPECFILE
1628 Exit_error err_build_fail
1634 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1637 install_required_packages() {
1642 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1645 /^%changelog/ { exit }
1647 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1648 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1649 gsub(/[ \t]+/, "_", bcond);
1651 }' $SPEC | LC_ALL=C sort -u
1655 # expand bconds from ~/.bcondrc
1656 # The file structure is like gentoo's package.use:
1659 # samba -mysql -pgsql
1660 # w32codec-installer license_agreement
1663 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1669 SN=${SPECFILE%%\.spec}
1671 local bcondrc=$HOME/.bcondrc
1672 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1674 local bcond_avail=$(find_spec_bcond $SPECFILE)
1676 while read pkg flags; do
1678 [[ "$pkg" == \#* ]] && continue
1680 # any package or current package?
1681 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1682 for flag in $flags; do
1683 local opt=${flag#[+-]}
1685 # use only flags which are in this package.
1686 if [[ $bcond_avail = *${opt}* ]]; then
1687 if [[ $flag = -* ]]; then
1688 if [[ $BCOND != *--with?${opt}* ]]; then
1689 BCOND="$BCOND --without $opt"
1692 if [[ $BCOND != *--without?${opt}* ]]; then
1693 BCOND="$BCOND --with $opt"
1700 update_shell_title "parse ~/.bcondrc: DONE!"
1703 set_bconds_values() {
1704 update_shell_title "set bcond values"
1706 AVAIL_BCONDS_WITHOUT=""
1707 AVAIL_BCONDS_WITH=""
1709 if grep -Eq '^# *_with' ${SPECFILE}; then
1710 echo >&2 "ERROR: This spec has old style bconds."
1714 if ! grep -q '^%bcond' ${SPECFILE}; then
1718 local bcond_avail=$(find_spec_bcond $SPECFILE)
1719 process_bcondrc "$SPECFILE"
1721 update_shell_title "parse bconds"
1724 for opt in $bcond_avail; do
1727 bcond=${opt#without_}
1729 *--without?${bcond}*)
1730 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1733 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1741 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1744 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1749 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1758 update_shell_title "run_sub_builder $package_name"
1760 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1761 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1762 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1763 # jakby nie bylo tego kawalka kodu.
1765 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1766 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1770 # kurwa. translate that ^^^^
1774 # Istnieje taki spec? ${package}.spec
1775 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1776 parent_spec_name=${package}.spec
1777 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1778 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1780 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1785 if [ "${parent_spec_name}" != "" ]; then
1786 spawn_sub_builder $parent_spec_name
1788 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1791 spawn_sub_builder() {
1793 update_shell_title "spawn_sub_builder $package_name"
1796 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1797 sub_builder_opts="${sub_builder_opts} -R"
1799 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1800 sub_builder_opts="${sub_builder_opts} -RB"
1801 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1802 sub_builder_opts="${sub_builder_opts} -FRB"
1804 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1805 sub_builder_opts="${sub_builder_opts} -Upi"
1809 ./builder ${sub_builder_opts} "$@"
1812 remove_build_requires() {
1813 if [ "$INSTALLED_PACKAGES" != "" ]; then
1814 case "$REMOVE_BUILD_REQUIRES" in
1816 run_poldek --noask -ve $INSTALLED_PACKAGES
1819 run_poldek --ask -ve $INSTALLED_PACKAGES
1822 echo You may want to manually remove following BuildRequires fetched:
1823 echo $INSTALLED_PACKAGES
1824 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1831 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1832 if [ "$BCOND" ]; then
1834 echo "Building $SPECFILE with the following conditional flags:"
1838 echo "No conditional flags passed"
1841 echo "from available:"
1842 echo "--with :\t$AVAIL_BCONDS_WITH"
1843 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1848 display_branches() {
1849 if [ "$NOCVSSPEC" != "yes" ]; then
1850 echo -n "Available branches: "
1851 $CVS_COMMAND status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
1855 # checks a given list of packages/files/provides agains current rpmdb.
1856 # outputs all dependencies which current rpmdb doesn't satisfy.
1857 # input can be either STDIN or parameters
1861 if [ $# -gt 0 ]; then
1867 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1870 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1872 # other deps (files)
1873 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1876 # checks if given package/files/provides exists in rpmdb.
1877 # input can be either stdin or parameters
1878 # returns packages which are present in the rpmdb
1882 if [ $# -gt 0 ]; then
1888 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1891 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1892 install_build_requires_rpmdeps() {
1893 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1894 # TODO: Conflicts list doesn't check versions
1895 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1896 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1898 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1899 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1900 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1903 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1904 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1905 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1906 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1908 if [ -n "$CNFL" ]; then
1909 update_shell_title "uninstall conflicting packages: $CNFL"
1910 echo "Trying to uninstall conflicting packages ($CNFL):"
1911 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1914 while [ "$DEPS" ]; do
1915 update_shell_title "install deps: $DEPS"
1916 echo "Trying to install dependencies ($DEPS):"
1917 local log=.${SPECFILE}_poldek.log
1918 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1919 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1922 if [ -n "$failed" ]; then
1923 for package in $failed; do
1924 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1933 fetch_build_requires()
1935 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1939 update_shell_title "fetch build requires"
1940 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1941 install_build_requires_rpmdeps
1945 # XXX is this ugliest code written in human history still needed?
1946 echo "All packages installed by fetch_build_requires() are written to:"
1947 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1949 echo "If anything fails, you may get rid of them by executing:"
1950 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
1952 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1953 for package_item in $(cat $SPECFILE | grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'|sed -e s,perl\(,perl-,g -e s,::,-,g -e s,\(.*\),,g -e s,%{,,g -e s,},,g|grep -v OpenGL-devel|sed -e s,sh-utils,coreutils,g -e s,fileutils,coreutils,g -e s,textutils,coreutils,g -e s,kgcc_package,gcc,g -e s,\),,g)
1955 package_item=$(echo $package_item|sed -e s,rpmbuild,rpm-build,g |sed -e s,__perl,perl,g |sed -e s,gasp,binutils-gasp,g -e s,binutils-binutils,binutils,g -e s,apxs,apache,g|sed -e s,apache\(EAPI\)-devel,apache-devel,g -e s,kernel-headers\(netfilter\),kernel-headers,g -e s,awk,mawk,g -e s,mmawk,mawk,g -e s,motif,openmotif,g -e s,openopenmotif,openmotif,g)
1957 package=$(basename "$package_item"|sed -e "s/}$//g")
1958 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
1961 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1962 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1963 if [ "$COND_ARCH_TST" != "" ] && [ "`echo $COND_ARCH_TST|sed -e "s/i.86/ix86/g"`" != "`echo $mach|sed -e "s/i.86/ix86/g"`" ]; then
1968 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1971 if `echo $COND_TST|grep -q 'without_'`; then
1972 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1973 if `echo $COND_TST|grep -q !`; then
1978 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1979 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1980 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1986 elif `echo $COND_TST|grep -q 'with_'`; then
1987 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1988 if `echo $COND_TST|grep -q !`; then
1993 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1994 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1995 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
2001 RESULT="${COND_STATE}-${COND_ARGV}"
2003 "with-wout" | "wout-with" )
2006 "wout-wout" | "with-with" )
2010 echo "Action '$RESULT' was not defined for package '$package_item'"
2016 if [ "$GO" = "yes" ]; then
2017 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
2018 echo "Testing if $package has subrequirements..."
2019 run_poldek -t -i $package --dumpn=".$package-req.txt"
2020 if [ -f ".$package-req.txt" ]; then
2021 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2023 if [ "$package_name" = "$package" ]; then
2024 echo "Installing BuildRequired package:\t$package_name"
2025 update_shell_title "Installing BuildRequired package: ${package_name}"
2026 install_required_packages $package
2028 echo "Installing (sub)Required package:\t$package_name"
2029 update_shell_title "Installing (sub)Required package: ${package_name}"
2030 install_required_packages $package_name
2034 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2035 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2038 echo "Attempting to run spawn sub - builder..."
2039 echo "Package installation failed:\t$package_name"
2040 run_sub_builder $package_name
2041 if [ $? -eq 0 ]; then
2042 install_required_packages $package_name
2045 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2046 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2049 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2056 rm -f ".$package-req.txt"
2058 echo "Attempting to run spawn sub - builder..."
2059 echo "Package installation failed:\t$package"
2060 run_sub_builder $package
2061 if [ $? -eq 0 ]; then
2062 install_required_packages $package
2065 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2066 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2069 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2075 echo "Package $package is already installed. BuildRequirement satisfied."
2079 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2080 echo >&2 "Unable to install following packages and their dependencies:"
2081 for pkg in "$NOT_INSTALLED_PACKAGES"
2085 remove_build_requires
2091 local CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
2092 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2093 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2094 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2095 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2098 echo "Initializing rpm directories to $TOP_DIR from $CVSROOT"
2099 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2101 # need to checkout to tmp dir or we can't name our topdir
2102 tmp=$(TMPDIR= TEMPDIR= mktemp -p $TOP_DIR -d) || exit 1
2104 $CVS_COMMAND -d $CVSROOT co packages/{.cvsignore,rpm.groups,dropin,mirrors,md5,adapter{,.awk},fetchsrc_request,builder,{relup,compile,repackage}.sh,ci,civim}
2106 mv $tmp/packages/* $TOP_DIR
2111 echo "To checkout *all* .spec files (read-only):"
2112 echo "- run cvs co SPECS"
2114 echo "To checkout *all* packages:"
2115 echo "- run cvs up -dP in $TOP_DIR dir"
2118 echo "To commit with your developer account:"
2119 echo "- edit $TOP_DIR/CVS/Root"
2122 get_greed_sources() {
2123 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
2124 if [ -n "BE_VERBOSE" ]; then
2125 echo "Try greed download: $1 from: $CVSROOT"
2127 $CVS_COMMAND -d $CVSROOT get SOURCES/$1
2128 if [ $? != 0 ]; then
2129 Exit_error err_no_source_in_repo $1
2134 # remove entries from CVS/Entries
2135 cvs_entry_remove() {
2136 local cvsdir="$1"; shift
2137 if [ ! -d "$cvsdir" ]; then
2138 echo >&2 "cvs_entry_remove: $cvsdir is not a directory"
2142 for file in "$@"; do
2143 rm -f $cvsdir/CVS/Entries.new || return 1
2144 awk -ve="${file##*/}" -F/ '$2 != e {print}' $cvsdir/CVS/Entries > $cvsdir/CVS/Entries.new || return 1
2145 mv -f $cvsdir/CVS/Entries.new $cvsdir/CVS/Entries || return 1
2153 DONT_PRINT_REVISION="yes"
2157 local builddir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2159 # remove from CVS/Entries
2160 cvs_entry_remove $PACKAGE_DIR $SPECFILE $SOURCES $PATCHES
2162 # remove spec and sources
2163 $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $SPECFILE
2166 #---------------------------------------------
2174 while [ $# -gt 0 ]; do
2177 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2178 # unfortunately $GETURI is already formed
2183 COMMAND="update_md5"
2188 COMMAND="update_md5"
2198 DEBUG="yes"; shift ;;
2200 COMMAND="version"; shift ;;
2202 COMMAND="short-version"; shift ;;
2204 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
2208 -b | -ba | --build )
2209 COMMAND="build"; shift ;;
2210 -bb | --build-binary )
2211 COMMAND="build-binary"; shift ;;
2213 COMMAND="build-build"; shift ;;
2215 COMMAND="build-install"; shift ;;
2217 COMMAND="build-list"; shift ;;
2218 -bp | --build-prep )
2219 COMMAND="build-prep"; shift ;;
2220 -bs | --build-source )
2221 COMMAND="build-source"; shift ;;
2223 COMMAND="branch"; shift; TAG="${1}"; shift;;
2225 CLEAN="--clean"; shift ;;
2227 CVS_FORCE="-F"; shift;;
2229 shift; CVSROOT="${1}"; shift ;;
2231 COMMAND="get"; shift ;;
2233 COMMAND="usage"; shift ;;
2235 PROTOCOL="ftp"; shift ;;
2237 PROTOCOL="http"; shift ;;
2239 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2243 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2247 PARALLEL_DOWNLOADS=$2
2251 PARALLEL_DOWNLOADS=${1#-p}
2255 shift; LOGFILE="${1}"; shift ;;
2257 shift; DEF_NICE_LEVEL=${1}; shift ;;
2258 -ske | --skip-existing-files)
2259 SKIP_EXISTING_FILES="yes"; shift ;;
2261 COMMAND="mr-proper"; shift ;;
2263 NOCVS="yes"; shift ;;
2264 -ncs | --no-cvs-specs )
2265 NOCVSSPEC="yes"; shift ;;
2266 -nd | --no-distfiles )
2267 NODIST="yes"; shift ;;
2268 -nm | --no-mirrors )
2269 NOMIRRORS="yes"; shift ;;
2271 NOURLS="yes"; shift ;;
2273 NOSRCS="yes"; shift ;;
2274 -ns0 | --no-source0 )
2275 NOSOURCE0="yes"; shift ;;
2285 -pm | --prefer-mirrors )
2292 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2294 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2295 --skip-patch | -sp )
2296 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2298 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2301 --with | --without )
2302 case $GROUP_BCONDS in
2306 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2307 while ! `echo ${1}|grep -qE '(^-|spec)'`
2309 BCOND="$BCOND $COND $1"
2313 if [[ "$2" = *,* ]]; then
2314 for a in $(echo "$2" | tr , ' '); do
2315 BCOND="$BCOND $1 $a"
2318 BCOND="$BCOND $1 $2"
2324 shift; TARGET="${1}"; shift ;;
2326 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2328 QUIET="--quiet"; shift ;;
2330 CVSDATE="${2}"; shift 2 ;;
2339 -R | --fetch-build-requires)
2340 FETCH_BUILD_REQUIRES="yes"
2341 NOT_INSTALLED_PACKAGES=
2343 -RB | --remove-build-requires)
2344 REMOVE_BUILD_REQUIRES="nice"
2346 -FRB | --force-remove-build-requires)
2347 REMOVE_BUILD_REQUIRES="force"
2350 COMMAND="list-sources-cvs"
2352 -sd | --source-distfiles)
2353 COMMAND="list-sources-distfiles"
2355 -sdp | --source-distfiles-paths)
2356 COMMAND="list-sources-distfiles-paths"
2358 -sf | --source-files)
2359 COMMAND="list-sources-files"
2361 -lsp | --source-paths)
2362 COMMAND="list-sources-local-paths"
2364 -su | --source-urls)
2365 COMMAND="list-sources-urls"
2367 -Tvs | --tag-version-stable )
2372 -Ts | --tag-stable )
2377 -Tv | --tag-version )
2382 -Tp | --tag-prefix )
2394 -ir | --integer-release-only )
2395 INTEGER_RELEASE="yes"
2398 COMMAND="update_md5"
2403 -Upi | --update-poldek-indexes )
2404 UPDATE_POLDEK_INDEXES="yes"
2407 COMMAND="init_rpm_dir"
2409 --use-greed-sources )
2412 -u | --try-upgrade )
2413 TRY_UPGRADE="1"; shift ;;
2415 shift; UPGRADE_VERSION="$1"; shift;;
2416 -un | --try-upgrade-with-float-version )
2417 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2419 BE_VERBOSE="1"; shift ;;
2424 if echo "${MACRO}" | grep -q '\W'; then
2425 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2429 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2434 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2438 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2441 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2442 COMMAND="show_bconds"
2446 COMMAND="show_bcond_args"
2449 --show-avail-bconds)
2450 COMMAND="show_avail_bconds"
2455 RPMOPTS="${RPMOPTS} --nodeps"
2458 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2461 Exit_error err_invalid_cmdline "$1"
2464 SPECFILE=${1%/}; shift
2465 # check if specname was passed as specname:cvstag
2466 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2467 CVSTAG="${SPECFILE##*:}"
2468 SPECFILE="${SPECFILE%%:*}"
2470 # always have SPECFILE ending with .spec extension
2471 SPECFILE=${SPECFILE%%.spec}.spec
2472 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2476 [ -d "$ASSUMED_NAME/CVS" ] && CVS_ENTRIES="$ASSUMED_NAME/CVS/Entries" || CVS_ENTRIES="CVS/Entries"
2477 if [ -f "$CVS_ENTRIES" ] && [ -z "$CVSTAG" ]; then
2478 CVSTAG=$(awk -vSPECFILE=$(basename $SPECFILE) -F/ '$2 == SPECFILE && $6 ~ /^T/{print substr($6, 2)}' ${CVS_ENTRIES})
2479 if [ "$CVSTAG" ]; then
2480 echo >&2 "builder: Sticky tag $CVSTAG active. Use -r TAGNAME to override."
2482 elif [ "$CVSTAG" = "HEAD" ]; then
2483 # assume -r HEAD is same as -A
2487 if [ "$CVSTAG" ]; then
2488 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2489 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2492 if [ -n "$DEBUG" ]; then
2497 if [ -n "$TARGET" ]; then
2500 TARGET_SWITCH="--target $TARGET" ;;
2502 TARGET_SWITCH="--target=$TARGET" ;;
2506 if [ "$SCHEDTOOL" != "no" ]; then
2507 NICE_COMMAND="$SCHEDTOOL"
2509 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2512 update_shell_title "$COMMAND"
2516 if [ -z "$SPECFILE" ]; then
2517 Exit_error err_no_spec_in_cmdl
2519 get_spec > /dev/null
2526 if [ -z "$SPECFILE" ]; then
2527 Exit_error err_no_spec_in_cmdl
2529 get_spec > /dev/null
2534 "show_avail_bconds")
2536 if [ -z "$SPECFILE" ]; then
2537 Exit_error err_no_spec_in_cmdl
2540 get_spec > /dev/null
2542 local bcond_avail=$(find_spec_bcond $SPECFILE)
2543 local opt bcond bconds
2544 for opt in $bcond_avail; do
2547 bcond=${opt#without_}
2548 bconds="$bconds $bcond"
2552 bconds="$bconds $bcond"
2555 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2563 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2565 if [ -z "$SPECFILE" ]; then
2566 Exit_error err_no_spec_in_cmdl
2569 # display SMP make flags if set
2570 smp_mflags=$(rpm -E %{?_smp_mflags})
2571 if [ "$smp_mflags" ]; then
2572 echo "builder: SMP make flags are set to $smp_mflags"
2580 if [ "$COMMAND" != "build-source" ]; then
2583 fetch_build_requires
2584 if [ "$INTEGER_RELEASE" = "yes" ]; then
2585 echo "Checking release $PACKAGE_RELEASE..."
2586 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2587 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2591 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2592 if [ -n "$TEST_TAG" ]; then
2593 local TAGVER=`make_tagver`
2594 # escape some regexp characters if part of TAGVER
2595 TAGVER=$(echo "$TAGVER" | sed -e 's#\([\+\*\.]\)#\\\1#g')
2596 echo "Searching for tag $TAGVER..."
2597 TAGREL=$($CVS_COMMAND status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
2598 if [ -n "$TAGREL" ]; then
2599 Exit_error err_tag_exists "$TAGVER" "$TAGREL"
2602 # - do not allow to build from HEAD when XX-branch exists
2603 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
2604 if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2605 TAG_BRANCH="${TREE_PREFIX}-branch"
2606 TAG_STATUS=$($CVS_COMMAND status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
2607 if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
2608 Exit_error err_branch_exists "$TAG_STATUS"
2614 if [ -n "$NOSOURCE0" ] ; then
2615 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2620 get_files $SOURCES $PATCHES
2624 NODIST="yes" get_files $SOURCES $PATCHES
2625 update_md5 $SOURCES $PATCHES
2629 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2630 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2632 remove_build_requires
2636 if [ -z "$SPECFILE" ]; then
2637 Exit_error err_no_spec_in_cmdl
2642 # don't fetch sources from remote locations
2644 for file in $SOURCES; do
2645 [ -n "`src_md5 $file`" ] && continue
2646 new_SOURCES="$new_SOURCES $file"
2648 SOURCES="$new_SOURCES"
2649 get_files $SOURCES $PATCHES
2651 branch_files $TAG $SOURCES $PATCHES $ICONS
2655 if [ -z "$SPECFILE" ]; then
2656 Exit_error err_no_spec_in_cmdl
2659 ADD_PACKAGE_CVS=yes get_spec
2662 if [ -n "$NOSOURCE0" ] ; then
2663 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2665 get_files $SOURCES $PATCHES
2670 if [ -z "$SPECFILE" ]; then
2671 Exit_error err_no_spec_in_cmdl
2677 if [ -n "$NOSOURCE0" ] ; then
2678 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2680 get_files $SOURCES $PATCHES
2685 if [ -z "$SPECFILE" ]; then
2686 Exit_error err_no_spec_in_cmdl
2692 if [ -n "$NOSOURCE0" ] ; then
2693 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2695 update_md5 $SOURCES $PATCHES
2701 if [ -z "$SPECFILE" ]; then
2702 Exit_error err_no_spec_in_cmdl
2708 # don't fetch sources from remote locations
2710 for file in $SOURCES; do
2711 [ -n "`src_md5 $file`" ] && continue
2712 new_SOURCES="$new_SOURCES $file"
2714 SOURCES="$new_SOURCES"
2715 get_files $SOURCES $PATCHES
2717 tag_files $SOURCES $PATCHES $ICONS
2722 "list-sources-files" )
2725 DONT_PRINT_REVISION="yes"
2728 for SAP in $SOURCES $PATCHES; do
2729 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2732 "list-sources-urls" )
2735 DONT_PRINT_REVISION="yes"
2738 SAPS="$SOURCES $PATCHES"
2739 for SAP in $SAPS ; do
2743 "list-sources-local-paths" )
2746 DONT_PRINT_REVISION="yes"
2749 for SAP in $SOURCES $PATCHES; do
2750 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2753 "list-sources-distfiles-paths" )
2756 DONT_PRINT_REVISION="yes"
2759 for SAP in $SOURCES $PATCHES; do
2760 if [ -n "$(src_md5 "$SAP")" ]; then
2761 distfiles_path "$SAP"
2765 "list-sources-distfiles" )
2768 DONT_PRINT_REVISION="yes"
2771 for SAP in $SOURCES $PATCHES; do
2772 if [ -n "$(src_md5 "$SAP")" ]; then
2773 distfiles_url "$SAP"
2777 "list-sources-cvs" )
2780 DONT_PRINT_REVISION="yes"
2783 for SAP in $SOURCES $PATCHES; do
2784 if [ -z "$(src_md5 "$SAP")" ]; then
2785 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2799 echo "$VERSIONSTRING"
2802 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2803 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2807 # vi:syntax=sh:ts=4:sw=4:noet