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)
20 # 110 - Functions not yet implemented
23 # - when Icon: field is present, -5 and -a5 doesn't work
24 # - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
25 # - does not respect NoSource: X, and tries to cvs up such files [ example: VirtualBox-bin.spec and its Source0 ]
27 # - ability to do ./builder -bb foo.spec foo2.spec foo3.spec
28 # - funny bug, if source-md5 is set then builder will download from distfiles even if there is no url present:
29 # Source10: forwardfix.pl
30 # # Source10-md5: 8bf85f7368933a4e0cb4f875bac28733
32 # basename: missing operand
33 # Try `basename --help' for more information.
34 # -- and the normal usage info --
37 APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
38 RCSID='$Id: builder,v 1.645 2011/02/13 17:54:10 glen Exp $' r=${RCSID#* * } rev=${r%% *}
41 Build package utility from PLD Linux Packages repository
42 $VERSION (C) 1999-2013 Free Penguins".
44 CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
46 # required rpm-build-macros
65 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
67 # use rpm 4.4.6+ digest format instead of comments if non-zero
70 # user agent when fetching files
71 USER_AGENT="TLD/Builder($VERSION)"
73 # It can be used i.e. in log file naming.
74 # See LOGFILE example.
75 DATE=`date +%Y-%m-%d_%H-%M-%S`
77 # target arch, can also be used for log file naming
78 TARGET=$(rpm -E %{_target})
80 # Example: LOGFILE='../log.$PACKAGE_NAME'
81 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
82 # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
83 # Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
84 # Yes, you can use variable name! Note _single_ quotes!
87 # use teeboth Perl wrapper
88 # temporary option to disable if broken
103 # create symlinks for tools in PACKAGE_DIR, see get_spec()
115 # use lftp by default when available
117 lftp --version > /dev/null 2>&1 && USE_LFTP=yes
118 PARALLEL_DOWNLOADS=10
120 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
122 # rsync repository with git refs of packages
123 PKGREVS_URL="http://pkgrevs.tld-linux.org"
126 TLD_GIT_SERVER="git://git.tld-linux.org"
127 TLD_GIT_PUSH="git@git.tld-linux.org"
128 TLD_PACKAGES_DIR="packages"
129 TLD_DISTFILES_SERVER="://df.tld-linux.org"
130 TLD_ATTICDISTFILES_SERVER=""
133 PLD_GIT_SERVER="git://git.pld-linux.org"
134 PLD_GIT_PUSH="git@git.pld-linux.org"
135 PLD_PACKAGES_DIR="packages"
136 PLD_DISTFILES_SERVER="://distfiles.pld-linux.org"
137 PLD_ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
142 GIT_SERVER=${TLD_GIT_SERVER}
143 GIT_PUSH=${TLD_GIT_PUSH}
144 PACKAGES_DIR=${TLD_PACKAGES_DIR}
153 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
154 ATTICDISTFILES_SERVER=${TLD_ATTICDISTFILES_SERVER}
159 FAIL_IF_NO_SOURCES="yes"
161 # let get_files skip over files which are present to get those damn files fetched
162 SKIP_EXISTING_FILES="no"
165 # should the specfile be restored if upgrade failed?
166 REVERT_BROKEN_UPGRADE="yes"
168 if rpm --specsrpm 2>/dev/null; then
169 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
170 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
172 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
173 if [ -x /usr/bin/rpm-getdeps ]; then
174 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
176 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
180 UPDATE_POLDEK_INDEXES_OPTS=""
182 # Here we load saved user environment used to
183 # predefine options set above, or passed to builder
185 # This one reads global system environment settings:
186 if [ -f ~/etc/builderrc ]; then
189 # And this one cascades settings using user personal
191 # Example of ~/.builderrc:
193 #UPDATE_POLDEK_INDEXES="yes"
194 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
195 #FETCH_BUILD_REQUIRES="yes"
196 #REMOVE_BUILD_REQUIRES="force"
198 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
202 if [ -n "$HOME_ETC" ]; then
203 USER_CFG="$HOME_ETC/.builderrc"
204 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
206 USER_CFG=~/.builderrc
207 BUILDER_MACROS=~/.builder-rpmmacros
210 [ -f "$USER_CFG" ] && . "$USER_CFG"
212 if [ "$SCHEDTOOL" = "auto" ]; then
213 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
214 SCHEDTOOL="schedtool -B -e"
220 if [ -n "$USE_PROZILLA" ]; then
221 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
224 elif [ -n "$USE_AXEL" ]; then
225 GETURI="axel -a $AXEL_OPTS"
228 elif [ -n "$USE_LFTP" ]; then
233 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
234 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
235 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
236 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
238 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
239 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
245 if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
256 if [ -d $HOME/rpm/SOURCES ]; then
257 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
258 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
262 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
263 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
268 if [ -n "$LOGFILE" ]; then
269 LOG=`eval echo $LOGFILE`
270 if [ -n "$LASTLOG_FILE" ]; then
271 echo "LASTLOG=$LOG" > $LASTLOG_FILE
273 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
274 # FIXME $exit_pldk undefined
277 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
278 return `cat ${RES_FILE}`
283 #---------------------------------------------
287 local outfile=$1 url=$2 retval tmpfile
291 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
292 set ssl:verify-certificate no;
293 set net:max-retries $WGET_RETRIES;
294 set http:user-agent \"$USER_AGENT\";
295 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
299 if [ $retval -eq 0 ]; then
300 mv -f "$tmpfile" "$outfile"
308 if [ -n "$DEBUG" ]; then set -xv; fi
310 # to make this output parseable by bash-completion _parse_help()
311 # if the line contains short and long option, it will take only the long option
312 # but if you want both being completed, put the short option to separate line
314 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
315 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
316 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
317 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
318 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
319 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
320 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
321 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
322 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
323 [--git-pld|--git-tld] [--pkgrev]
324 <package>[.spec][:tag]
326 -4 - force IPv4 when transferring files
327 -6 - force IPv6 when transferring files
329 --update-md5 - update md5 comments in spec, implies -nd -ncs
331 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
332 --all-branches - make shallow fetch of all branches; --depth required
333 -n5, --no-md5 - ignore md5 comments in spec
334 -D, --debug - enable builder script debugging mode,
335 -debug - produce rpm debug package (same as --opts -debug)
336 -V, --version - output builder version string
337 --short-version - output builder short version
338 -a - try add new package to PLD repo.
341 - get all files from PLD repo or HTTP/FTP and build package
343 -bb - get all files from PLD repo or HTTP/FTP and build binary
344 only package from <package>.spec,
345 -bp - execute the %prep phase of <package>.spec,
346 -bc - execute the %build phase of <package>.spec,
347 -bi - execute the %install phase of <package>.spec
348 -bl - execute the %files phase of <package>.spec
349 -bs - get all files from PLD repo or HTTP/FTP and only pack
351 --short-circuit - short-circuit build
352 -B, --branch - add branch
354 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
355 may be used with building process.
356 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
357 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
358 -cf, --cvs-force - use -f when tagging
359 --define '<macro> <value>'
360 - define a macro <macro> with value <value>,
361 --depth <number> - make shallow fetch
362 --alt_kernel <kernel>
363 - same as --define 'alt_kernel <kernel>'
364 --nodeps - rpm won't check any dependences
366 --get - get <package>.spec and all related files from PLD repo
367 -h, --help - this message,
368 -j N - set %_smp_mflags to propagate concurrent jobs
369 --ftp - use FTP protocol to access distfiles server
370 --http - use HTTP protocol to access distfiles server
371 -l <logfile>, --logtofile=<logfile>
374 - don't pull from PLD repo
375 -nd, --no-distfiles - don't download from distfiles
376 -nm, --no-mirrors - don't download from mirror, if source URL is given,
377 -nu, --no-urls - don't try to download from FTP/HTTP location,
378 -ns, --no-srcs - don't download Sources/Patches
379 -ns0, --no-source0 - don't download Source0
380 -nn, --no-net - don't download anything from the net
381 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
382 -pm, --prefer-mirrors
383 - prefer mirrors (if any) over distfiles for SOURCES
384 --no-init - don't initialize builder paths (SPECS and SOURCES)
386 --skip-existing-files
387 - skip existing files in get_files
388 --opts <rpm opts> - additional options for rpm
389 -q, --quiet - be quiet,
390 --date yyyy-mm-dd - build package using resources from specified date,
391 -r <tag>, --cvstag <ref>
392 - build package using resources from specified branch/tag,
393 -A - build package using master branch as any sticky tags/branch/date being reset.
394 -R, --fetch-build-requires
395 - fetch what is BuildRequired,
396 -RB, --remove-build-requires
397 - remove all you fetched with -R or --fetch-build-requires
398 remember, this option requires confirmation,
399 -FRB, --force-remove-build-requires
400 - remove all you fetched with -R or --fetch-build-requires
401 remember, this option works without confirmation,
402 -sd, --source-distfiles
403 - list sources available from distfiles (intended for offline
404 operations; does not work when Icon field is present
405 but icon file is absent),
406 -sc, --source-cvs - list sources available from PLD repo
407 -sdp, --source-distfiles-paths
408 - list sources available from distfiles -
409 paths relative to distfiles directory (intended for offline
410 operations; does not work when Icon field is present
411 but icon file is absent),
412 -sf, --source-files - list sources - bare filenames (intended for offline
413 operations; does not work when Icon field is present
414 but icon file is absent),
416 - list sources - filenames with full local paths (intended for
417 offline operations; does not work when Icon field is present
418 but icon file is absent),
419 -su, --source-urls - list urls - urls to sources and patches
420 intended for copying urls with spec with lots of macros in urls
421 -T <tag> , --tag <tag>
422 - add git tag <tag> for files,
423 -Tvs, --tag-version-stable
424 - add git tags STABLE and NAME-VERSION-RELEASE for files,
426 - add git tag STABLE for files,
428 --tag-version - add git tag NAME-VERSION-RELEASE for files,
429 -Tp, --tag-prefix <prefix>
430 - add <prefix> to NAME-VERSION-RELEASE tags,
431 -tt, --test-tag <prefix>
432 - fail if tag is already present,
433 -ir, --integer-release-only
434 - allow only integer and snapshot releases
435 -v, --verbose - be verbose,
436 -u, --try-upgrade - check version, and try to upgrade package
437 -un, --try-upgrade-with-float-version
438 - as above, but allow float version
439 php-pear-Services_Digg/
440 --upgrade-version - upgrade to specified version in try-upgrade
441 -U, --update - refetch sources, don't use distfiles, and update md5 comments
442 -Upi, --update-poldek-indexes
443 - refresh or make poldek package index files.
445 --skip-patch <patchnumber>
446 - don't apply <patchnumber>. may be repeated.
448 --nopatch <patchnumber>
449 - abort instead of applying patch <patchnumber>
451 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
452 --show-bconds - show available conditional builds, which can be used
453 - with --with and/or --without switches.
454 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
455 In other words, the output is parseable by scripts.
456 --show-avail-bconds - show available bconds
459 - conditional build package depending on %_with_<feature>/
460 %_without_<feature> macro switch. You may now use
461 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
462 constructions. Set GROUP_BCONDS to yes to make use of it.
463 --target <platform>, --target=<platform>
464 - build for platform <platform>.
465 --init-rpm-dir - initialize ~/rpm directory structure
466 --git-pld - force use of PLD git and distfiles
467 --git-tld - force use of TLD git and distfiles (note: it will fall
468 back to PLD git/df if package doesn't exist in TLD git)
469 --pkgrev - write git revision of package being built into rsync repo
470 (note: only official TLD source builders are allowed to do so)
474 # create tempfile. as secure as possible
476 mktemp --tmpdir -t builder.$PACKAGE_NAME.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
480 mktemp --tmpdir -d builder.$PACKAGE_NAME.XXXXXX
483 # inserts git log instead of %changelog
484 # outputs name of modified file created by tempfile
486 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
488 # allow this being customized
489 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
491 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
492 # otherwise i'd use --date=iso here
493 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
494 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
495 # NOTE: changelog date is always in UTC for rpmbuild
496 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
497 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
499 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
500 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
503 # add link to full git logs
504 local giturl="http://git.tld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
505 if [ -n "$CVSTAG" ]; then
506 giturl="$giturl;h=$CVSTAG"
508 local gitauthor="TLD Linux <feedback@tld-linux.org>"
509 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
510 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
515 LC_ALL=C gawk '/^\* /{printf("* %s %s\n", strftime("%a %b %d %Y", $2), substr($0, length($1)+length($2)+length($3)+4)); next}{print}' $gitlog >> $speclog
516 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
520 " > $specdir/$SPECFILE
521 rm -f $gitlog $speclog
525 # @param string logfile
526 # @param varargs... commands to execute
529 # use teeboth from toys/cleanbuild, if available and enabled
530 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
534 local efile rc logfile=$1; shift
535 if [ "$logfile" ]; then
537 { "$@" 2>&1; echo $? > $efile; } | tee $logfile
548 # change dependency to specname
550 # - perl(Package::Name) -> perl-Package-Name
554 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
558 update_shell_title() {
560 local len=${COLUMNS:-80}
561 local msg="$(echo "$*" | cut -c-$len)"
563 if [ -n "$BE_VERBOSE" ]; then
564 echo >&2 "$(date +%s.%N) $*"
567 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
569 if [ -n "$PACKAGE_NAME" ]; then
570 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
575 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
576 msg=$(echo $msg | tr -d '\n\r')
579 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
582 echo >&2 -ne "\033]0;$msg\007"
588 # set TARGET from BuildArch: from SPECFILE
590 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
591 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
593 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
597 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
599 TARGET_SWITCH="--target=$TARGET" ;;
605 # runs rpm with minimal macroset
607 # we reset macros not to contain macros.build as all the %() macros are
608 # executed here, while none of them are actually needed.
609 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
610 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
612 # TODO: move these to /usr/lib/rpm/macros
613 cat > $BUILDER_MACROS <<'EOF'
614 %x8664 x86_64 amd64 ia32e
617 %bootstrap_release() %{1}
618 %requires_releq_kernel_up(s:n:) %{nil}
619 %requires_releq_kernel_smp(s:n:) %{nil}
620 %requires_releq_kernel(s:n:) %{nil}
621 %requires_releq() %{nil}
622 %pyrequires_eq() %{nil}
623 %requires_eq() %{nil}
624 %requires_eq_to() %{nil}
625 %requires_ge() %{nil}
626 %requires_ge_to() %{nil}
627 %requires_ge() %{nil}
628 %releq_kernel_up(n:) ERROR
629 %releq_kernel_smp(n:) ERROR
630 %releq_kernel(n:) ERROR
631 %py_postclean(x:) ERROR
635 %ruby_ver_requires_eq() %{nil}
636 %ruby_mod_ver_requires_eq() %{nil}
637 %__php_api_requires() %{nil}
638 %php_major_version ERROR
639 %php_api_version ERROR
640 %requires_xorg_xserver_extension %{nil}
641 %requires_xorg_xserver_xinput %{nil}
642 %requires_xorg_xserver_font %{nil}
643 %requires_xorg_xserver_videodrv %{nil}
645 %perl_vendorarch ERROR
646 %perl_vendorlib ERROR
647 # damn. need it here! - copied from /usr/lib/rpm/macros.build
648 %tmpdir %(echo "${TMPDIR:-/tmp}")
649 %patchset_source(f:b:) %(
650 base=%{-b*}%{!-b*:10000};
651 start=$(expr $base + %1);
652 end=$(expr $base + %{?2}%{!?2:%{1}});
653 # we need to call seq twice as it doesn't allow two formats
654 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
655 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
656 paste %{tmpdir}/__ps{1,2};
657 rm -f %{tmpdir}/__ps{1,2};
660 %add_etc_shells(p) %{p:<lua>}
661 %remove_etc_shells(p) %{p:<lua>}
662 %lua_add_etc_shells() %{nil}
663 %lua_remove_etc_shells() %{nil}
665 %buildrequires_jdk %{nil}
666 %pear_package_print_optionalpackages %{nil}
668 if [ "$NOINIT" = "yes" ] ; then
669 cat >> $BUILDER_MACROS <<'EOF'
674 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
678 if [ -n "$DEBUG" ]; then
683 if [ -x /usr/bin/rpm-specdump ]; then
684 update_shell_title "cache_rpm_dump using rpm-specdump command"
685 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
687 update_shell_title "cache_rpm_dump using rpmbuild command"
690 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
691 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
697 ARGS='--nodigest --nosignature --nobuild'
700 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
702 if [ $? -gt 0 ]; then
703 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
705 Exit_error err_build_fail
708 # make small dump cache
709 rpm_dump_cache=`echo "$rpm_dump" | awk '
710 $2 ~ /^SOURCEURL/ {print}
711 $2 ~ /^PATCHURL/ {print}
712 $2 ~ /^nosource/ {print}
713 $2 ~ /^PACKAGE_/ {print}
717 update_shell_title "cache_rpm_dump: OK!"
721 if [ -z "$rpm_dump_cache" ] ; then
722 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
724 echo "$rpm_dump_cache"
728 update_shell_title "get icons"
729 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
730 if [ -z "$ICONS" ]; then
734 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
738 update_shell_title "parsing specfile"
739 if [ -n "$DEBUG" ]; then
744 # icons are needed for successful spec parse
750 if rpm_dump | grep -qEi ":.*nosource.*1"; then
751 FAIL_IF_NO_SOURCES="no"
754 if [ "$NOSRCS" != "yes" ]; then
755 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
756 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
757 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
760 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
761 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
762 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
764 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
765 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
768 if [ -n "$BE_VERBOSE" ]; then
769 echo "- Sources : `nourl $SOURCES`"
770 if [ -n "$PATCHES" ]; then
771 echo "- Patches : `nourl $PATCHES`"
773 echo "- Patches : *no patches needed*"
775 if [ -n "$ICONS" ]; then
776 echo "- Icon : `nourl $ICONS`"
778 echo "- Icon : *no package icon*"
780 echo "- Name : $PACKAGE_NAME"
781 echo "- Version : $PACKAGE_VERSION"
782 echo "- Release : $PACKAGE_RELEASE"
785 update_shell_title "parse_spec: OK!"
789 if [ -n "$DEBUG" ]; then
797 "err_no_spec_in_cmdl" )
798 remove_build_requires
799 echo >&2 "ERROR: spec file name not specified."
801 "err_invalid_cmdline" )
802 echo >&2 "ERROR: invalid command line arg ($2)."
804 "err_no_spec_in_repo" )
805 remove_build_requires
806 echo >&2 "Error: spec file not stored in PLD repo."
808 "err_no_source_in_repo" )
809 remove_build_requires
810 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
812 "err_cvs_add_failed" )
813 echo >&2 "Error: failed to add package to PLD repo."
816 remove_build_requires
817 echo >&2 "Error: package build failed. (${2:-no more info})"
819 "err_no_package_data" )
820 remove_build_requires
821 echo >&2 "Error: couldn't get out package name/version/release from spec file."
824 remove_build_requires
825 echo >&2 "Tag ${2} already exists"
828 remove_build_requires
829 echo >&2 "Release ${2} not integer and not a snapshot."
831 "err_branch_exists" )
832 remove_build_requires
833 echo >&2 "Tree branch already exists (${2})."
836 remove_build_requires
837 echo >&2 "Error: conditions reject building this spec (${2})."
839 "err_remote_problem" )
840 remove_build_requires
841 echo >&2 "Error: problem with remote (${2})"
844 echo >&2 "Error: cannot checkout ${2}"
847 echo >&2 "Error: failed to set package revision for tag ${2}"
850 echo >&2 "Error: failed to get package revision for tag ${2}"
852 "err_not_implemented" )
853 remove_build_requires
854 echo >&2 "Error: functionality not yet imlemented"
857 echo >&2 "Unknown error."
862 if [ -n "$DEBUG" ]; then
867 if [ "$NOINIT" != "yes" ] ; then
868 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
870 local macros_ver=$(rpm -E %?rpm_build_macros)
871 if [ -z "$macros_ver" ]; then
872 REPO_DIR=$TOP_DIR/packages
873 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
875 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
876 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
880 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
886 export GIT_WORK_TREE=$PACKAGE_DIR
887 export GIT_DIR=$PACKAGE_DIR/.git
889 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
890 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
891 CVSTAG=${CVSTAG#refs/heads/}
892 if [ "$CVSTAG" != "master" ]; then
893 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
896 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
899 elif [ "$CVSTAG" = "HEAD" ]; then
900 # assume -r HEAD is same as -A
908 update_shell_title "add_package"
910 if [ -n "$DEBUG" ]; then
916 SPECFILE=$(basename $SPECFILE)
917 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
918 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
921 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
922 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
924 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git && \
925 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} \
926 || Exit_error err_remote_problem $REMOTE_PLD
931 update_shell_title "get_spec"
933 if [ -n "$DEBUG" ]; then
939 SPECFILE=$(basename $SPECFILE)
940 if [ "$NOCVSSPEC" != "yes" ]; then
941 if [ -z "$DEPTH" ]; then
942 if [ -d "$PACKAGE_DIR/.git" ]; then
943 git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
944 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
945 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
946 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
949 Exit_error err_not_implemented
953 git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
954 # softfail if new package, i.e not yet added to PLD rep
955 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
956 echo "Warning: package not in CVS - assuming new package"
959 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
960 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
964 if [ ! -d "$PACKAGE_DIR/.git" ]; then
965 if [ ! -d "$PACKAGE_DIR" ]; then
966 install -d $PACKAGE_DIR
969 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
970 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
971 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
972 CVSTAG=${CVSTAG:-"master"}
975 if [ -z "$ALL_BRANCHES" ]; then
976 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
978 git fetch $DEPTH $REMOTE_PLD $refs || {
979 echo >&2 "Error: branch $CVSTAG does not exist"
983 git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*'
985 cvsignore_df .gitignore
987 # add default log format to .gitignore if it is relative to package dir
988 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
989 # substitute known "macros" to glob
990 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\|TARGET\),*,g')
991 if [ "$logfile" ]; then
992 cvsignore_df "$logfile"
996 # create symlinks for tools
997 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
998 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
999 # skip tools that don't exist in top dir
1000 [ -f $a ] || continue
1001 # skip tools that already exist
1002 [ -f $PACKAGE_DIR/$a ] && continue
1003 ln -s ../$a $PACKAGE_DIR
1009 if [ -n "$CVSTAG" ]; then
1010 local _rev=$(get_pkgrev "$CVSTAG")
1011 echo "$_rev" | grep -q -E "^ERROR$" || CVSTAG="$_rev"
1012 if git rev-parse --verify -q "$CVSTAG"; then
1013 git checkout "$CVSTAG" --
1014 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1015 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1017 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1018 Exit_error "err_no_checkut" "$CVSTAG"
1020 git merge --ff-only '@{u}'
1021 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1022 if [ -n "$CVSDATE" ]; then
1023 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1027 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1028 Exit_error err_no_spec_in_repo
1031 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1032 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1035 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1043 if [ ! -f "mirrors" ] ; then
1044 ln -s ../rpm-build-tools/mirrors .
1048 local origin mirror name rest ol prefix
1049 while read origin mirror name rest; do
1050 # skip comments and empty lines
1051 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1054 ol=$(echo -n "$origin" | wc -c)
1055 prefix=$(echo -n "$url" | head -c $ol)
1056 if [ "$prefix" = "$origin" ] ; then
1057 suffix=$(echo "$url" | cut -b $((ol+1))-)
1058 echo -n "$mirror$suffix"
1065 # Warning: unpredictable results if same URL used twice
1068 # escape some regexp characters if part of file name
1069 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1072 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1073 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1074 head -n 1 | tr OURCEATH ourceath | xargs
1078 [ "$NO5" = "yes" ] && return
1080 [ -z "$no" ] && return
1084 # use "sources" file from package dir, like vim
1085 if [ -f sources ]; then
1086 md5=$(grep -s -v '^#' sources | \
1087 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1088 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1089 grep -E '^[0-9a-f]{32}$')
1092 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1093 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1095 echo "$md5" | tail -n 1
1100 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1101 if [ -n "$source_md5" ]; then
1104 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1105 if [ -n "$source_md5" ]; then
1108 # we have empty SourceX-md5, but it is still possible
1109 # that we have NoSourceX-md5 AND NoSource: X
1110 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1111 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1119 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1123 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1126 distfiles_attic_url() {
1127 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
1132 [ "$md5" = "" ] || \
1133 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1137 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1138 [ -n "$size" -a "$size" -gt 0 ]
1142 if [ "$CVSIGNORE_DF" != "yes" ]; then
1145 cvsignore=${PACKAGE_DIR}/.gitignore
1147 # add only if not yet there
1148 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1149 echo "$1" >> $cvsignore
1153 # returns true if "$1" is ftp, http or https protocol url
1156 ftp://*|http://*|https://*)
1164 if [ $# -eq 0 ]; then
1168 update_shell_title "update md5"
1169 if [ -n "$DEBUG" ]; then
1176 # pass 1: check files to be fetched
1180 local fp=$(nourl "$i")
1181 local srcno=$(src_no "$i")
1182 if [ -n "$ADD5" ]; then
1183 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1184 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1185 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1187 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1189 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1190 need_files="$need_files $i"
1194 # pass 1a: get needed files
1195 if [ "$need_files" ]; then
1196 get_files $need_files
1199 # pass 2: proceed with md5 adding or updating
1201 local fp=$(nourl "$i")
1202 local srcno=$(src_no "$i")
1203 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1204 if [ -z "$md5" ]; then
1205 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1207 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1208 local tag="# $srcno-md5:\t"
1209 if [[ "$md5" == *NoSource* ]]; then
1210 tag="# No$srcno-md5:\t"
1211 elif [ -n "$USEDIGEST" ]; then
1212 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1214 md5=$(md5sum "$fp" | cut -f1 -d' ')
1215 echo "Updating $srcno ($md5: $fp)."
1217 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1218 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1220 $PACKAGE_DIR/$SPECFILE
1227 [ "$NO5" = "yes" ] && return
1229 update_shell_title "check md5"
1233 if ! good_md5 "$i"; then
1234 echo -n "MD5 sum mismatch."
1237 if ! good_size "$i"; then
1238 echo -n "0 sized file."
1242 if [ $bad -eq 1 ]; then
1243 echo " Use -U to refetch sources,"
1244 echo "or -5 to update md5 sums, if you're sure files are correct."
1245 Exit_error err_no_source_in_repo $i
1251 update_shell_title "get_files"
1253 if [ -n "$DEBUG" ]; then
1258 if [ $# -gt 0 ]; then
1262 local get_files_cvs=""
1266 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1267 update_shell_title "$i"
1268 local fp=`nourl "$i"`
1269 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1274 local srcmd5=$(src_md5 "$i")
1276 # we know if source/patch is present in cvs/distfiles
1277 # - has md5 (in distfiles)
1278 # - in cvs... ideas?
1280 # CHECK: local file didn't exist or always cvs up (first) requested.
1281 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1282 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1283 echo "Warning: no URL given for $i"
1287 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1288 if good_md5 "$i" && good_size "$i"; then
1289 echo "$fp having proper md5sum already exists"
1293 # optionally prefer mirror over distfiles if there's mirror
1294 # TODO: build url list and then try each url from the list
1295 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1298 url=$(distfiles_url "$i")
1301 url_attic=$(distfiles_attic_url "$i")
1303 # is $url local file?
1304 if [[ "$url" = [./]* ]]; then
1305 update_shell_title "${GETLOCAL%% *}: $url"
1306 ${GETLOCAL} $url $target
1309 # make shorter message for distfiles urls
1310 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1311 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1312 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1315 update_shell_title "${GETURI%% *}: $uri"
1316 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1317 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1318 update_shell_title "${GETURI2%% *}: $url"
1319 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1324 if [ ! -s "$target" ]; then
1326 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1327 update_shell_title "${GETLOCAL%% *}: $url_attic"
1328 ${GETLOCAL} $url_attic $target
1330 update_shell_title "${GETURI%% *}: $url_attic"
1331 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1332 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1333 update_shell_title "${GETURI2%% *}: $url_attic"
1334 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1336 test -s "$target" || rm -f "$target"
1340 if [ -s "$target" ]; then
1341 cvsignore_df $target
1348 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1349 if [ -z "$NOMIRRORS" ]; then
1350 im=$(find_mirror "$i")
1354 update_shell_title "${GETURI%% *}: $im"
1355 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1356 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1357 update_shell_title "${GETURI2%% *}: $im"
1358 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1360 test -s "$target" || rm -f "$target"
1363 if [ "$cvsup" = 1 ]; then
1369 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1370 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1371 Exit_error err_no_source_in_repo $i
1374 # we check md5 here just only to refetch immediately
1375 if good_md5 "$i" && good_size "$i"; then
1377 elif [ "$FROM_DISTFILES" = 1 ]; then
1378 # wrong md5 from distfiles: remove the file and try again
1380 echo "MD5 sum mismatch. Trying full fetch."
1383 update_shell_title "${GETURI%% *}: $url"
1384 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1385 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1386 update_shell_title "${GETURI2%% *}: $url"
1387 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1389 if [ ! -s "$target" ]; then
1391 update_shell_title "${GETURI%% *}: $url_attic"
1392 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1393 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1394 update_shell_title "${GETURI2%% *}: $url_attic"
1395 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1398 test -s "$target" || rm -f "$target"
1401 SHELL_TITLE_PREFIX=""
1404 if [ "$CHMOD" = "yes" ]; then
1405 CHMOD_FILES=$(nourl "$@")
1406 if [ -n "$CHMOD_FILES" ]; then
1407 chmod $CHMOD_MODE $CHMOD_FILES
1414 # If tag exists and points to other commit exit with error
1415 # If it existsts and points to HEAD return 1
1416 # If it doesn't exist return 0
1418 local sha1=$(git rev-parse HEAD)
1419 echo "Searching for tag $_tag..."
1420 if [ -n "$DEPTH" ]; then
1421 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1423 local ref=$(git show-ref -s "refs/tags/$_tag")
1425 [ -z "$ref" ] && return 0
1426 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1431 if [ -n "$DEBUG" ]; then
1436 # Check whether first character of PACKAGE_NAME is legal for tag name
1437 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1441 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1442 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1444 # Remove @kernel.version_release from TAGVER because tagging sources
1445 # could occur with different kernel-headers than kernel-headers used at build time.
1446 # besides, %{_kernel_ver_str} is not expanded.
1448 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1449 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1456 if [ -n "$DEBUG" ]; then
1461 echo "Version: $PACKAGE_VERSION"
1462 echo "Release: $PACKAGE_RELEASE"
1465 if [ "$TAG_VERSION" = "yes" ]; then
1468 if [ -n "$TAG" ]; then
1473 local OPTIONS="tag $CVS_FORCE"
1477 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1478 update_shell_title "tag sources: $_tag"
1479 git $OPTIONS $_tag || exit
1480 git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1482 echo "Tag $_tag already exists and points to the same commit"
1487 [ -z "$1" ] && return 1
1488 local _tmp=$(mktemp /tmp/.builder-XXXX)
1489 rm $_tmp 2>/dev/null
1490 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/get/$1 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1491 local result=$(cat $_tmp)
1492 rm $_tmp 2>/dev/null
1498 if [ "$TAG_VERSION" = "yes" ]; then
1501 if [ -n "$TAG" ]; then
1504 echo "Writing git revision for tag $_tag"
1505 local _tmp=$(mktemp /tmp/.builder-XXXX)
1506 rm $_tmp 2>/dev/null
1507 local _rev=$(git rev-parse HEAD)
1508 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/set/$_rev/$_tag 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1509 local result=$(cat $_tmp)
1510 rm $_tmp 2>/dev/null
1511 echo "$result" | grep -q -E "^OK$" && return 0
1512 echo "$result" | grep -q -E "^EXISTS$" && Exit_error err_tag_exists "$_tag"
1513 Exit_error err_pkgrev_set
1518 echo "Git branch: $TAG"
1521 if [ -n "$DEBUG" ]; then
1526 local OPTIONS="branch $CVS_FORCE"
1529 git $OPTIONS $TAG || exit
1533 # this function should exit early if package can't be built for this arch
1534 # this avoids unneccessary BR filling.
1537 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1539 if [ $ret -ne 0 ]; then
1551 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1552 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1558 local ver="$2" subver=$ver
1559 local newver="$3" newsubver=$newver
1561 # try handling subver, everything that's not numeric-dotted in version
1562 if grep -Eq '%define\s+subver' $specfile; then
1563 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1565 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1566 newver=${newver%$newsubver}
1569 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1570 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1571 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1576 if [ -n "$TRY_UPGRADE" ]; then
1577 local TNOTIFY TNEWVER TOLDVER
1578 update_shell_title "build_package: try_upgrade"
1582 if [ "$UPGRADE_VERSION" ]; then
1583 TNEWVER=$UPGRADE_VERSION
1585 if [ -n "$FLOAT_VERSION" ]; then
1586 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1588 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1591 # pldnotify.awk does not set exit codes, but it has match for ERROR
1592 # in output which means so.
1593 if [[ "$TNOTIFY" = *ERROR* ]]; then
1598 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1601 if [ -n "$TNEWVER" ]; then
1602 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1603 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1604 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1605 cp -f $SPECFILE $SPECFILE.bak
1608 set_release $SPECFILE $PACKAGE_RELEASE 1
1609 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1611 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1612 echo >&2 "Upgrading version failed, you need to update spec yourself"
1622 update_shell_title "build_package"
1623 if [ -n "$DEBUG" ]; then
1632 BUILD_SWITCH="-ba" ;;
1634 BUILD_SWITCH="-bb" ;;
1636 BUILD_SWITCH="-bs --nodeps" ;;
1638 BUILD_SWITCH="-bp --nodeps" ;;
1640 BUILD_SWITCH="-bc" ;;
1642 BUILD_SWITCH="-bi" ;;
1644 BUILD_SWITCH="-bl" ;;
1648 update_shell_title "build_package: $COMMAND"
1649 local logfile retval
1650 if [ -n "$LOGFILE" ]; then
1651 logfile=`eval echo $LOGFILE`
1652 if [ -d "$logfile" ]; then
1653 echo "Log file $logfile is a directory."
1654 echo "Parse error in the spec?"
1655 Exit_error err_build_fail
1657 if [ -n "$LASTLOG_FILE" ]; then
1658 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1662 local specdir=$(insert_gitlog $SPECFILE)
1663 # FIXME: eval here is exactly why?
1664 PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE
1668 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1669 if [ "$retval" -eq "0" ]; then
1670 mv $logfile $LOGDIROK
1672 mv $logfile $LOGDIRFAIL
1676 if [ "$retval" -ne "0" ]; then
1677 if [ -n "$TRY_UPGRADE" ]; then
1678 echo "\nUpgrade package to new version failed."
1679 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1680 echo "Restoring old spec file."
1681 mv -f $SPECFILE.bak $SPECFILE
1685 Exit_error err_build_fail
1691 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1694 install_required_packages() {
1699 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1702 /^%changelog/ { exit }
1704 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1705 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1706 gsub(/[ \t]+/, "_", bcond);
1708 }' $SPEC | LC_ALL=C sort -u
1712 # expand bconds from ~/.bcondrc
1713 # The file structure is like gentoo's package.use:
1716 # samba -mysql -pgsql
1717 # w32codec-installer license_agreement
1720 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1726 SN=${SPECFILE%%\.spec}
1728 local bcondrc=$HOME/.bcondrc
1729 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1731 local bcond_avail=$(find_spec_bcond $SPECFILE)
1733 while read pkg flags; do
1735 [[ "$pkg" == \#* ]] && continue
1737 # any package or current package?
1738 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1739 for flag in $flags; do
1740 local opt=${flag#[+-]}
1742 # use only flags which are in this package.
1743 if [[ $bcond_avail = *${opt}* ]]; then
1744 if [[ $flag = -* ]]; then
1745 if [[ $BCOND != *--with?${opt}* ]]; then
1746 BCOND="$BCOND --without $opt"
1749 if [[ $BCOND != *--without?${opt}* ]]; then
1750 BCOND="$BCOND --with $opt"
1757 update_shell_title "parse ~/.bcondrc: DONE!"
1760 set_bconds_values() {
1761 update_shell_title "set bcond values"
1763 AVAIL_BCONDS_WITHOUT=""
1764 AVAIL_BCONDS_WITH=""
1766 if grep -Eq '^# *_with' ${SPECFILE}; then
1767 echo >&2 "ERROR: This spec has old style bconds."
1771 if ! grep -q '^%bcond' ${SPECFILE}; then
1775 local bcond_avail=$(find_spec_bcond $SPECFILE)
1776 process_bcondrc "$SPECFILE"
1778 update_shell_title "parse bconds"
1781 for opt in $bcond_avail; do
1784 bcond=${opt#without_}
1786 *--without?${bcond}*)
1787 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1790 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1798 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1801 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1806 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1815 update_shell_title "run_sub_builder $package_name"
1817 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1818 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1819 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1820 # jakby nie bylo tego kawalka kodu.
1822 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1823 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1827 # kurwa. translate that ^^^^
1831 # Istnieje taki spec? ${package}.spec
1832 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1833 parent_spec_name=${package}.spec
1834 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1835 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1837 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1842 if [ "${parent_spec_name}" != "" ]; then
1843 spawn_sub_builder $parent_spec_name
1845 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1848 spawn_sub_builder() {
1850 update_shell_title "spawn_sub_builder $package_name"
1853 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1854 sub_builder_opts="${sub_builder_opts} -R"
1856 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1857 sub_builder_opts="${sub_builder_opts} -RB"
1858 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1859 sub_builder_opts="${sub_builder_opts} -FRB"
1861 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1862 sub_builder_opts="${sub_builder_opts} -Upi"
1866 ./builder ${sub_builder_opts} "$@"
1869 remove_build_requires() {
1870 if [ "$INSTALLED_PACKAGES" != "" ]; then
1871 case "$REMOVE_BUILD_REQUIRES" in
1873 run_poldek --noask -ve $INSTALLED_PACKAGES
1876 run_poldek --ask -ve $INSTALLED_PACKAGES
1879 echo You may want to manually remove following BuildRequires fetched:
1880 echo $INSTALLED_PACKAGES
1881 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1888 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1889 if [ "$BCOND" ]; then
1891 echo "Building $SPECFILE with the following conditional flags:"
1895 echo "No conditional flags passed"
1898 echo "from available:"
1899 echo "--with :\t$AVAIL_BCONDS_WITH"
1900 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1905 display_branches() {
1906 echo -n "Available branches: "
1907 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1910 # checks a given list of packages/files/provides agains current rpmdb.
1911 # outputs all dependencies which current rpmdb doesn't satisfy.
1912 # input can be either STDIN or parameters
1916 if [ $# -gt 0 ]; then
1922 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1925 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1927 # other deps (files)
1928 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1931 # checks if given package/files/provides exists in rpmdb.
1932 # input can be either stdin or parameters
1933 # returns packages which are present in the rpmdb
1937 if [ $# -gt 0 ]; then
1943 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1946 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1947 install_build_requires_rpmdeps() {
1948 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1949 # TODO: Conflicts list doesn't check versions
1950 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1951 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1953 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1954 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1955 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1958 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1959 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1960 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1961 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1963 if [ -n "$CNFL" ]; then
1964 update_shell_title "uninstall conflicting packages: $CNFL"
1965 echo "Trying to uninstall conflicting packages ($CNFL):"
1966 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1969 while [ "$DEPS" ]; do
1970 update_shell_title "install deps: $DEPS"
1971 echo "Trying to install dependencies ($DEPS):"
1972 local log=.${SPECFILE}_poldek.log
1973 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1974 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1977 if [ -n "$failed" ]; then
1978 for package in $failed; do
1979 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1988 fetch_build_requires()
1990 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1994 update_shell_title "fetch build requires"
1995 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1996 install_build_requires_rpmdeps
2000 # XXX is this ugliest code written in human history still needed?
2001 echo "All packages installed by fetch_build_requires() are written to:"
2002 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2004 echo "If anything fails, you may get rid of them by executing:"
2005 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
2007 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2008 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)
2010 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)
2012 package=$(basename "$package_item"|sed -e "s/}$//g")
2013 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
2016 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
2017 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
2018 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
2023 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
2026 if `echo $COND_TST|grep -q 'without_'`; then
2027 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
2028 if `echo $COND_TST|grep -q !`; then
2033 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
2034 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
2035 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
2041 elif `echo $COND_TST|grep -q 'with_'`; then
2042 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
2043 if `echo $COND_TST|grep -q !`; then
2048 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
2049 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
2050 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
2056 RESULT="${COND_STATE}-${COND_ARGV}"
2058 "with-wout" | "wout-with" )
2061 "wout-wout" | "with-with" )
2065 echo "Action '$RESULT' was not defined for package '$package_item'"
2071 if [ "$GO" = "yes" ]; then
2072 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
2073 echo "Testing if $package has subrequirements..."
2074 run_poldek -t -i $package --dumpn=".$package-req.txt"
2075 if [ -f ".$package-req.txt" ]; then
2076 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2078 if [ "$package_name" = "$package" ]; then
2079 echo "Installing BuildRequired package:\t$package_name"
2080 update_shell_title "Installing BuildRequired package: ${package_name}"
2081 install_required_packages $package
2083 echo "Installing (sub)Required package:\t$package_name"
2084 update_shell_title "Installing (sub)Required package: ${package_name}"
2085 install_required_packages $package_name
2089 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2090 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2093 echo "Attempting to run spawn sub - builder..."
2094 echo "Package installation failed:\t$package_name"
2095 run_sub_builder $package_name
2096 if [ $? -eq 0 ]; then
2097 install_required_packages $package_name
2100 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2101 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2104 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2111 rm -f ".$package-req.txt"
2113 echo "Attempting to run spawn sub - builder..."
2114 echo "Package installation failed:\t$package"
2115 run_sub_builder $package
2116 if [ $? -eq 0 ]; then
2117 install_required_packages $package
2120 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2121 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2124 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2130 echo "Package $package is already installed. BuildRequirement satisfied."
2134 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2135 echo >&2 "Unable to install following packages and their dependencies:"
2136 for pkg in "$NOT_INSTALLED_PACKAGES"
2140 remove_build_requires
2146 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2147 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2148 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2149 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2152 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2153 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2156 if [ ! -e ../rpm-build-tools ]; then
2157 git clone ${GIT_SERVER}/${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2159 for a in adapter builder fetchsrc_request compile repackage; do
2160 ln -sf ../rpm-build-tools/${a}.sh $a
2163 ln -sf ../rpm-build-tools/${a} $a
2165 ln -sf ../rpm-build-tools/mirrors mirrors
2172 DONT_PRINT_REVISION="yes"
2174 # remove spec and sources
2175 PATH=$CLEAN_PATH $RPMBUILD --clean --rmsource --rmspec --nodeps --define "__urlgetfile() %nil" --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $PACKAGE_DIR/$SPECFILE
2176 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2177 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2180 #---------------------------------------------
2188 while [ $# -gt 0 ]; do
2191 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2192 # unfortunately $GETURI is already formed
2197 COMMAND="update_md5"
2202 COMMAND="update_md5"
2211 DEBUG="yes"; shift ;;
2213 COMMAND="version"; shift ;;
2215 COMMAND="short-version"; shift ;;
2222 -b | -ba | --build )
2223 COMMAND="build"; shift ;;
2224 -bb | --build-binary )
2225 COMMAND="build-binary"; shift ;;
2227 COMMAND="build-build"; shift ;;
2229 COMMAND="build-install"; shift ;;
2231 COMMAND="build-list"; shift ;;
2232 -bp | --build-prep )
2233 COMMAND="build-prep"; shift ;;
2234 -bs | --build-source )
2235 COMMAND="build-source"; shift ;;
2237 COMMAND="branch"; shift; TAG="${1}"; shift;;
2239 CLEAN="--clean"; shift ;;
2241 CVS_FORCE="-f"; shift;;
2247 COMMAND="get"; shift ;;
2249 COMMAND="usage"; shift ;;
2251 PROTOCOL="ftp"; shift ;;
2253 PROTOCOL="http"; shift ;;
2255 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2259 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2263 PARALLEL_DOWNLOADS=$2
2267 PARALLEL_DOWNLOADS=${1#-p}
2271 shift; LOGFILE="${1}"; shift ;;
2273 shift; DEF_NICE_LEVEL=${1}; shift ;;
2274 -ske | --skip-existing-files)
2275 SKIP_EXISTING_FILES="yes"; shift ;;
2277 COMMAND="mr-proper"; shift ;;
2278 -ncs | --no-cvs-specs )
2279 NOCVSSPEC="yes"; shift ;;
2280 -nd | --no-distfiles )
2281 NODIST="yes"; shift ;;
2282 -nm | --no-mirrors )
2283 NOMIRRORS="yes"; shift ;;
2285 NOURLS="yes"; shift ;;
2287 NOSRCS="yes"; shift ;;
2288 -ns0 | --no-source0 )
2289 NOSOURCE0="yes"; shift ;;
2298 -pm | --prefer-mirrors )
2301 --noinit | --no-init )
2305 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2307 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2308 --skip-patch | -sp )
2309 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2311 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2314 --with | --without )
2315 case $GROUP_BCONDS in
2319 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2320 while ! `echo ${1}|grep -qE '(^-|spec)'`
2322 BCOND="$BCOND $COND $1"
2326 if [[ "$2" = *,* ]]; then
2327 for a in $(echo "$2" | tr , ' '); do
2328 BCOND="$BCOND $1 $a"
2331 BCOND="$BCOND $1 $2"
2337 shift; TARGET="${1}"; shift ;;
2339 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2341 QUIET="--quiet"; shift ;;
2343 CVSDATE="${2}"; shift 2
2344 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2354 -R | --fetch-build-requires)
2355 FETCH_BUILD_REQUIRES="yes"
2356 NOT_INSTALLED_PACKAGES=
2358 -RB | --remove-build-requires)
2359 REMOVE_BUILD_REQUIRES="nice"
2361 -FRB | --force-remove-build-requires)
2362 REMOVE_BUILD_REQUIRES="force"
2365 COMMAND="list-sources-cvs"
2367 -sd | --source-distfiles)
2368 COMMAND="list-sources-distfiles"
2370 -sdp | --source-distfiles-paths)
2371 COMMAND="list-sources-distfiles-paths"
2373 -sf | --source-files)
2374 COMMAND="list-sources-files"
2376 -lsp | --source-paths)
2377 COMMAND="list-sources-local-paths"
2379 -su | --source-urls)
2380 COMMAND="list-sources-urls"
2382 -Tvs | --tag-version-stable )
2387 -Ts | --tag-stable )
2392 -Tv | --tag-version )
2397 -Tp | --tag-prefix )
2409 -ir | --integer-release-only )
2410 INTEGER_RELEASE="yes"
2413 COMMAND="update_md5"
2418 -Upi | --update-poldek-indexes )
2419 UPDATE_POLDEK_INDEXES="yes"
2422 COMMAND="init_rpm_dir"
2424 -u | --try-upgrade )
2425 TRY_UPGRADE="1"; shift ;;
2427 shift; UPGRADE_VERSION="$1"; shift;;
2428 -un | --try-upgrade-with-float-version )
2429 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2431 BE_VERBOSE="1"; shift ;;
2436 if echo "${MACRO}" | grep -q '\W'; then
2437 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2441 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2446 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2450 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2453 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2454 COMMAND="show_bconds"
2458 COMMAND="show_bcond_args"
2461 --show-avail-bconds)
2462 COMMAND="show_avail_bconds"
2467 RPMOPTS="${RPMOPTS} --nodeps"
2470 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2474 GIT_SERVER=${PLD_GIT_SERVER}
2475 GIT_PUSH=${PLD_GIT_PUSH}
2476 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2477 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2478 ATTICDISTFILES_SERVER=${PLD_ATTICDISTFILES_SERVER}
2482 GIT_SERVER=${TLD_GIT_SERVER}
2483 GIT_PUSH=${TLD_GIT_PUSH}
2484 PACKAGES_DIR=${TLD_PACKAGES_DIR}
2485 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
2486 ATTICDISTFILES_SERVER=${TLD_ATTICDISTFILES_SERVER}
2489 COMMAND="set_pkgrev"
2492 Exit_error err_invalid_cmdline "$1"
2495 SPECFILE=${1%/}; shift
2496 # check if specname was passed as specname:cvstag
2497 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2498 CVSTAG="${SPECFILE##*:}"
2499 SPECFILE="${SPECFILE%%:*}"
2501 # always have SPECFILE ending with .spec extension
2502 SPECFILE=${SPECFILE%%.spec}.spec
2503 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2507 # Check if given package exists in TLD git
2508 if ! git ls-remote --heads ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME} 1>/dev/null 2>&1; then
2509 # Nope, we don't have it in TLD, switch to PLD repositories
2510 GIT_SERVER=${PLD_GIT_SERVER}
2511 GIT_PUSH=${PLD_GIT_PUSH}
2512 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2513 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2514 ATTICDISTFILES_SERVER=${PLD_ATTICDISTFILES_SERVER}
2517 if [ "$CVSTAG" ]; then
2518 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2519 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2522 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2523 echo >&2 "--all branches requires --depth <number>"
2524 Exit_error err_invalid_cmdline
2527 if [ -n "$DEBUG" ]; then
2532 if [ -n "$TARGET" ]; then
2535 TARGET_SWITCH="--target $TARGET" ;;
2537 TARGET_SWITCH="--target=$TARGET" ;;
2541 if [ "$SCHEDTOOL" != "no" ]; then
2542 NICE_COMMAND="$SCHEDTOOL"
2544 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2547 update_shell_title "$COMMAND"
2551 if [ -z "$SPECFILE" ]; then
2552 Exit_error err_no_spec_in_cmdl
2554 get_spec > /dev/null
2561 if [ -z "$SPECFILE" ]; then
2562 Exit_error err_no_spec_in_cmdl
2564 get_spec > /dev/null
2569 "show_avail_bconds")
2571 if [ -z "$SPECFILE" ]; then
2572 Exit_error err_no_spec_in_cmdl
2575 get_spec > /dev/null
2577 local bcond_avail=$(find_spec_bcond $SPECFILE)
2578 local opt bcond bconds
2579 for opt in $bcond_avail; do
2582 bcond=${opt#without_}
2583 bconds="$bconds $bcond"
2587 bconds="$bconds $bcond"
2590 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2598 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2600 if [ -z "$SPECFILE" ]; then
2601 Exit_error err_no_spec_in_cmdl
2604 # display SMP make flags if set
2605 smp_mflags=$(rpm -E %{?_smp_mflags})
2606 if [ "$smp_mflags" ]; then
2607 echo "builder: SMP make flags are set to $smp_mflags"
2615 if [ "$COMMAND" != "build-source" ]; then
2618 fetch_build_requires
2619 if [ "$INTEGER_RELEASE" = "yes" ]; then
2620 echo "Checking release $PACKAGE_RELEASE..."
2621 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2622 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2626 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2627 if [ -n "$TEST_TAG" ]; then
2630 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2631 # check also tags created in CVS
2632 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2633 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2634 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2635 || Exit_error err_tag_exists $TAGVER_CVS
2636 # - do not allow to build from HEAD when XX-branch exists
2637 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2638 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2639 TAG_BRANCH="${TREE_PREFIX}-branch"
2640 if [ -n "$DEPTH" ]; then
2641 cmd_branches="git ls-remote --heads"
2642 ref_prefix=refs/heads
2644 cmd_branches="git show-ref"
2645 ref_prefix=refs/remotes/${REMOTE_PLD}
2647 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2648 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2649 Exit_error err_branch_exists "$TAG_STATUS"
2655 if [ -n "$NOSOURCE0" ] ; then
2656 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2661 get_files $SOURCES $PATCHES
2662 check_md5 $SOURCES $PATCHES
2665 NODIST="yes" get_files $SOURCES $PATCHES
2666 update_md5 $SOURCES $PATCHES
2670 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2671 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2673 remove_build_requires
2677 if [ -z "$SPECFILE" ]; then
2678 Exit_error err_no_spec_in_cmdl
2687 if [ -z "$SPECFILE" ]; then
2688 Exit_error err_no_spec_in_cmdl
2692 if [ -n "$NEW_REPO" ]; then
2695 for file in $SOURCES $PATCHES; do
2696 if [ -z $(src_md5 "$file") ]; then
2697 git add $file || Exit_error err_no_source_in_repo $file
2699 cvsignore_df `nourl $file`
2703 echo "When you are ready commit your changes and run git push origin master"
2705 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2710 if [ -z "$SPECFILE" ]; then
2711 Exit_error err_no_spec_in_cmdl
2717 if [ -n "$NOSOURCE0" ] ; then
2718 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2720 get_files $SOURCES $PATCHES
2725 if [ -z "$SPECFILE" ]; then
2726 Exit_error err_no_spec_in_cmdl
2732 if [ -n "$NOSOURCE0" ] ; then
2733 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2735 update_md5 $SOURCES $PATCHES
2741 if [ -z "$SPECFILE" ]; then
2742 Exit_error err_no_spec_in_cmdl
2746 if [ ! -d .git ]; then
2747 echo "No git reposiotory" >&2
2755 "list-sources-files" )
2758 DONT_PRINT_REVISION="yes"
2761 for SAP in $SOURCES $PATCHES; do
2762 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2765 "list-sources-urls" )
2768 DONT_PRINT_REVISION="yes"
2771 SAPS="$SOURCES $PATCHES"
2772 for SAP in $SAPS; do
2776 "list-sources-local-paths" )
2779 DONT_PRINT_REVISION="yes"
2782 for SAP in $SOURCES $PATCHES; do
2783 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2786 "list-sources-distfiles-paths" )
2789 DONT_PRINT_REVISION="yes"
2792 for SAP in $SOURCES $PATCHES; do
2793 if [ -n "$(src_md5 "$SAP")" ]; then
2794 distfiles_path "$SAP"
2798 "list-sources-distfiles" )
2801 DONT_PRINT_REVISION="yes"
2804 for SAP in $SOURCES $PATCHES; do
2805 if [ -n "$(src_md5 "$SAP")" ]; then
2806 distfiles_url "$SAP"
2810 "list-sources-cvs" )
2813 DONT_PRINT_REVISION="yes"
2816 for SAP in $SOURCES $PATCHES; do
2817 if [ -z "$(src_md5 "$SAP")" ]; then
2818 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2832 echo "$VERSIONSTRING"
2836 if [ -z "$SPECFILE" ]; then
2837 Exit_error err_no_spec_in_cmdl
2839 get_spec > /dev/null
2846 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2847 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2851 # vi:syntax=sh:ts=4:sw=4:noet