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 [ "$(get_pkgrev "$_tag")" = "$CVSTAG" ] && return 0
1512 echo "$result" | grep -q -E "^OK$" && return 0
1513 echo "$result" | grep -q -E "^EXISTS$" && Exit_error err_tag_exists "$_tag"
1514 Exit_error err_pkgrev_set
1519 echo "Git branch: $TAG"
1522 if [ -n "$DEBUG" ]; then
1527 local OPTIONS="branch $CVS_FORCE"
1530 git $OPTIONS $TAG || exit
1534 # this function should exit early if package can't be built for this arch
1535 # this avoids unneccessary BR filling.
1538 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1540 if [ $ret -ne 0 ]; then
1552 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1553 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1559 local ver="$2" subver=$ver
1560 local newver="$3" newsubver=$newver
1562 # try handling subver, everything that's not numeric-dotted in version
1563 if grep -Eq '%define\s+subver' $specfile; then
1564 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1566 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1567 newver=${newver%$newsubver}
1570 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1571 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1572 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1577 if [ -n "$TRY_UPGRADE" ]; then
1578 local TNOTIFY TNEWVER TOLDVER
1579 update_shell_title "build_package: try_upgrade"
1583 if [ "$UPGRADE_VERSION" ]; then
1584 TNEWVER=$UPGRADE_VERSION
1586 if [ -n "$FLOAT_VERSION" ]; then
1587 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1589 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1592 # pldnotify.awk does not set exit codes, but it has match for ERROR
1593 # in output which means so.
1594 if [[ "$TNOTIFY" = *ERROR* ]]; then
1599 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1602 if [ -n "$TNEWVER" ]; then
1603 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1604 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1605 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1606 cp -f $SPECFILE $SPECFILE.bak
1609 set_release $SPECFILE $PACKAGE_RELEASE 1
1610 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1612 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1613 echo >&2 "Upgrading version failed, you need to update spec yourself"
1623 update_shell_title "build_package"
1624 if [ -n "$DEBUG" ]; then
1633 BUILD_SWITCH="-ba" ;;
1635 BUILD_SWITCH="-bb" ;;
1637 BUILD_SWITCH="-bs --nodeps" ;;
1639 BUILD_SWITCH="-bp --nodeps" ;;
1641 BUILD_SWITCH="-bc" ;;
1643 BUILD_SWITCH="-bi" ;;
1645 BUILD_SWITCH="-bl" ;;
1649 update_shell_title "build_package: $COMMAND"
1650 local logfile retval
1651 if [ -n "$LOGFILE" ]; then
1652 logfile=`eval echo $LOGFILE`
1653 if [ -d "$logfile" ]; then
1654 echo "Log file $logfile is a directory."
1655 echo "Parse error in the spec?"
1656 Exit_error err_build_fail
1658 if [ -n "$LASTLOG_FILE" ]; then
1659 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1663 local specdir=$(insert_gitlog $SPECFILE)
1664 # FIXME: eval here is exactly why?
1665 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
1669 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1670 if [ "$retval" -eq "0" ]; then
1671 mv $logfile $LOGDIROK
1673 mv $logfile $LOGDIRFAIL
1677 if [ "$retval" -ne "0" ]; then
1678 if [ -n "$TRY_UPGRADE" ]; then
1679 echo "\nUpgrade package to new version failed."
1680 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1681 echo "Restoring old spec file."
1682 mv -f $SPECFILE.bak $SPECFILE
1686 Exit_error err_build_fail
1692 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1695 install_required_packages() {
1700 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1703 /^%changelog/ { exit }
1705 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1706 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1707 gsub(/[ \t]+/, "_", bcond);
1709 }' $SPEC | LC_ALL=C sort -u
1713 # expand bconds from ~/.bcondrc
1714 # The file structure is like gentoo's package.use:
1717 # samba -mysql -pgsql
1718 # w32codec-installer license_agreement
1721 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1727 SN=${SPECFILE%%\.spec}
1729 local bcondrc=$HOME/.bcondrc
1730 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1732 local bcond_avail=$(find_spec_bcond $SPECFILE)
1734 while read pkg flags; do
1736 [[ "$pkg" == \#* ]] && continue
1738 # any package or current package?
1739 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1740 for flag in $flags; do
1741 local opt=${flag#[+-]}
1743 # use only flags which are in this package.
1744 if [[ $bcond_avail = *${opt}* ]]; then
1745 if [[ $flag = -* ]]; then
1746 if [[ $BCOND != *--with?${opt}* ]]; then
1747 BCOND="$BCOND --without $opt"
1750 if [[ $BCOND != *--without?${opt}* ]]; then
1751 BCOND="$BCOND --with $opt"
1758 update_shell_title "parse ~/.bcondrc: DONE!"
1761 set_bconds_values() {
1762 update_shell_title "set bcond values"
1764 AVAIL_BCONDS_WITHOUT=""
1765 AVAIL_BCONDS_WITH=""
1767 if grep -Eq '^# *_with' ${SPECFILE}; then
1768 echo >&2 "ERROR: This spec has old style bconds."
1772 if ! grep -q '^%bcond' ${SPECFILE}; then
1776 local bcond_avail=$(find_spec_bcond $SPECFILE)
1777 process_bcondrc "$SPECFILE"
1779 update_shell_title "parse bconds"
1782 for opt in $bcond_avail; do
1785 bcond=${opt#without_}
1787 *--without?${bcond}*)
1788 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1791 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1799 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1802 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1807 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1816 update_shell_title "run_sub_builder $package_name"
1818 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1819 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1820 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1821 # jakby nie bylo tego kawalka kodu.
1823 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1824 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1828 # kurwa. translate that ^^^^
1832 # Istnieje taki spec? ${package}.spec
1833 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1834 parent_spec_name=${package}.spec
1835 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1836 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1838 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1843 if [ "${parent_spec_name}" != "" ]; then
1844 spawn_sub_builder $parent_spec_name
1846 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1849 spawn_sub_builder() {
1851 update_shell_title "spawn_sub_builder $package_name"
1854 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1855 sub_builder_opts="${sub_builder_opts} -R"
1857 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1858 sub_builder_opts="${sub_builder_opts} -RB"
1859 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1860 sub_builder_opts="${sub_builder_opts} -FRB"
1862 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1863 sub_builder_opts="${sub_builder_opts} -Upi"
1867 ./builder ${sub_builder_opts} "$@"
1870 remove_build_requires() {
1871 if [ "$INSTALLED_PACKAGES" != "" ]; then
1872 case "$REMOVE_BUILD_REQUIRES" in
1874 run_poldek --noask -ve $INSTALLED_PACKAGES
1877 run_poldek --ask -ve $INSTALLED_PACKAGES
1880 echo You may want to manually remove following BuildRequires fetched:
1881 echo $INSTALLED_PACKAGES
1882 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1889 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1890 if [ "$BCOND" ]; then
1892 echo "Building $SPECFILE with the following conditional flags:"
1896 echo "No conditional flags passed"
1899 echo "from available:"
1900 echo "--with :\t$AVAIL_BCONDS_WITH"
1901 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1906 display_branches() {
1907 echo -n "Available branches: "
1908 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1911 # checks a given list of packages/files/provides agains current rpmdb.
1912 # outputs all dependencies which current rpmdb doesn't satisfy.
1913 # input can be either STDIN or parameters
1917 if [ $# -gt 0 ]; then
1923 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1926 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1928 # other deps (files)
1929 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1932 # checks if given package/files/provides exists in rpmdb.
1933 # input can be either stdin or parameters
1934 # returns packages which are present in the rpmdb
1938 if [ $# -gt 0 ]; then
1944 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1947 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1948 install_build_requires_rpmdeps() {
1949 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1950 # TODO: Conflicts list doesn't check versions
1951 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1952 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1954 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1955 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1956 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1959 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1960 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1961 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1962 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1964 if [ -n "$CNFL" ]; then
1965 update_shell_title "uninstall conflicting packages: $CNFL"
1966 echo "Trying to uninstall conflicting packages ($CNFL):"
1967 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1970 while [ "$DEPS" ]; do
1971 update_shell_title "install deps: $DEPS"
1972 echo "Trying to install dependencies ($DEPS):"
1973 local log=.${SPECFILE}_poldek.log
1974 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1975 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1978 if [ -n "$failed" ]; then
1979 for package in $failed; do
1980 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1989 fetch_build_requires()
1991 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1995 update_shell_title "fetch build requires"
1996 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1997 install_build_requires_rpmdeps
2001 # XXX is this ugliest code written in human history still needed?
2002 echo "All packages installed by fetch_build_requires() are written to:"
2003 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2005 echo "If anything fails, you may get rid of them by executing:"
2006 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
2008 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2009 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)
2011 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)
2013 package=$(basename "$package_item"|sed -e "s/}$//g")
2014 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
2017 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
2018 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
2019 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
2024 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
2027 if `echo $COND_TST|grep -q 'without_'`; then
2028 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
2029 if `echo $COND_TST|grep -q !`; then
2034 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
2035 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
2036 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
2042 elif `echo $COND_TST|grep -q 'with_'`; then
2043 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
2044 if `echo $COND_TST|grep -q !`; then
2049 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
2050 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
2051 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
2057 RESULT="${COND_STATE}-${COND_ARGV}"
2059 "with-wout" | "wout-with" )
2062 "wout-wout" | "with-with" )
2066 echo "Action '$RESULT' was not defined for package '$package_item'"
2072 if [ "$GO" = "yes" ]; then
2073 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
2074 echo "Testing if $package has subrequirements..."
2075 run_poldek -t -i $package --dumpn=".$package-req.txt"
2076 if [ -f ".$package-req.txt" ]; then
2077 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2079 if [ "$package_name" = "$package" ]; then
2080 echo "Installing BuildRequired package:\t$package_name"
2081 update_shell_title "Installing BuildRequired package: ${package_name}"
2082 install_required_packages $package
2084 echo "Installing (sub)Required package:\t$package_name"
2085 update_shell_title "Installing (sub)Required package: ${package_name}"
2086 install_required_packages $package_name
2090 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2091 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2094 echo "Attempting to run spawn sub - builder..."
2095 echo "Package installation failed:\t$package_name"
2096 run_sub_builder $package_name
2097 if [ $? -eq 0 ]; then
2098 install_required_packages $package_name
2101 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2102 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2105 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2112 rm -f ".$package-req.txt"
2114 echo "Attempting to run spawn sub - builder..."
2115 echo "Package installation failed:\t$package"
2116 run_sub_builder $package
2117 if [ $? -eq 0 ]; then
2118 install_required_packages $package
2121 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2122 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2125 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2131 echo "Package $package is already installed. BuildRequirement satisfied."
2135 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2136 echo >&2 "Unable to install following packages and their dependencies:"
2137 for pkg in "$NOT_INSTALLED_PACKAGES"
2141 remove_build_requires
2147 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2148 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2149 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2150 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2153 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2154 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2157 if [ ! -e ../rpm-build-tools ]; then
2158 git clone ${GIT_SERVER}/${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2160 for a in adapter builder fetchsrc_request compile repackage; do
2161 ln -sf ../rpm-build-tools/${a}.sh $a
2164 ln -sf ../rpm-build-tools/${a} $a
2166 ln -sf ../rpm-build-tools/mirrors mirrors
2173 DONT_PRINT_REVISION="yes"
2175 # remove spec and sources
2176 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
2177 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2178 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2181 #---------------------------------------------
2189 while [ $# -gt 0 ]; do
2192 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2193 # unfortunately $GETURI is already formed
2198 COMMAND="update_md5"
2203 COMMAND="update_md5"
2212 DEBUG="yes"; shift ;;
2214 COMMAND="version"; shift ;;
2216 COMMAND="short-version"; shift ;;
2223 -b | -ba | --build )
2224 COMMAND="build"; shift ;;
2225 -bb | --build-binary )
2226 COMMAND="build-binary"; shift ;;
2228 COMMAND="build-build"; shift ;;
2230 COMMAND="build-install"; shift ;;
2232 COMMAND="build-list"; shift ;;
2233 -bp | --build-prep )
2234 COMMAND="build-prep"; shift ;;
2235 -bs | --build-source )
2236 COMMAND="build-source"; shift ;;
2238 COMMAND="branch"; shift; TAG="${1}"; shift;;
2240 CLEAN="--clean"; shift ;;
2242 CVS_FORCE="-f"; shift;;
2248 COMMAND="get"; shift ;;
2250 COMMAND="usage"; shift ;;
2252 PROTOCOL="ftp"; shift ;;
2254 PROTOCOL="http"; shift ;;
2256 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2260 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2264 PARALLEL_DOWNLOADS=$2
2268 PARALLEL_DOWNLOADS=${1#-p}
2272 shift; LOGFILE="${1}"; shift ;;
2274 shift; DEF_NICE_LEVEL=${1}; shift ;;
2275 -ske | --skip-existing-files)
2276 SKIP_EXISTING_FILES="yes"; shift ;;
2278 COMMAND="mr-proper"; shift ;;
2279 -ncs | --no-cvs-specs )
2280 NOCVSSPEC="yes"; shift ;;
2281 -nd | --no-distfiles )
2282 NODIST="yes"; shift ;;
2283 -nm | --no-mirrors )
2284 NOMIRRORS="yes"; shift ;;
2286 NOURLS="yes"; shift ;;
2288 NOSRCS="yes"; shift ;;
2289 -ns0 | --no-source0 )
2290 NOSOURCE0="yes"; shift ;;
2299 -pm | --prefer-mirrors )
2302 --noinit | --no-init )
2306 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2308 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2309 --skip-patch | -sp )
2310 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2312 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2315 --with | --without )
2316 case $GROUP_BCONDS in
2320 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2321 while ! `echo ${1}|grep -qE '(^-|spec)'`
2323 BCOND="$BCOND $COND $1"
2327 if [[ "$2" = *,* ]]; then
2328 for a in $(echo "$2" | tr , ' '); do
2329 BCOND="$BCOND $1 $a"
2332 BCOND="$BCOND $1 $2"
2338 shift; TARGET="${1}"; shift ;;
2340 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2342 QUIET="--quiet"; shift ;;
2344 CVSDATE="${2}"; shift 2
2345 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2355 -R | --fetch-build-requires)
2356 FETCH_BUILD_REQUIRES="yes"
2357 NOT_INSTALLED_PACKAGES=
2359 -RB | --remove-build-requires)
2360 REMOVE_BUILD_REQUIRES="nice"
2362 -FRB | --force-remove-build-requires)
2363 REMOVE_BUILD_REQUIRES="force"
2366 COMMAND="list-sources-cvs"
2368 -sd | --source-distfiles)
2369 COMMAND="list-sources-distfiles"
2371 -sdp | --source-distfiles-paths)
2372 COMMAND="list-sources-distfiles-paths"
2374 -sf | --source-files)
2375 COMMAND="list-sources-files"
2377 -lsp | --source-paths)
2378 COMMAND="list-sources-local-paths"
2380 -su | --source-urls)
2381 COMMAND="list-sources-urls"
2383 -Tvs | --tag-version-stable )
2388 -Ts | --tag-stable )
2393 -Tv | --tag-version )
2398 -Tp | --tag-prefix )
2410 -ir | --integer-release-only )
2411 INTEGER_RELEASE="yes"
2414 COMMAND="update_md5"
2419 -Upi | --update-poldek-indexes )
2420 UPDATE_POLDEK_INDEXES="yes"
2423 COMMAND="init_rpm_dir"
2425 -u | --try-upgrade )
2426 TRY_UPGRADE="1"; shift ;;
2428 shift; UPGRADE_VERSION="$1"; shift;;
2429 -un | --try-upgrade-with-float-version )
2430 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2432 BE_VERBOSE="1"; shift ;;
2437 if echo "${MACRO}" | grep -q '\W'; then
2438 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2442 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2447 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2451 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2454 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2455 COMMAND="show_bconds"
2459 COMMAND="show_bcond_args"
2462 --show-avail-bconds)
2463 COMMAND="show_avail_bconds"
2468 RPMOPTS="${RPMOPTS} --nodeps"
2471 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2475 GIT_SERVER=${PLD_GIT_SERVER}
2476 GIT_PUSH=${PLD_GIT_PUSH}
2477 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2478 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2479 ATTICDISTFILES_SERVER=${PLD_ATTICDISTFILES_SERVER}
2483 GIT_SERVER=${TLD_GIT_SERVER}
2484 GIT_PUSH=${TLD_GIT_PUSH}
2485 PACKAGES_DIR=${TLD_PACKAGES_DIR}
2486 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
2487 ATTICDISTFILES_SERVER=${TLD_ATTICDISTFILES_SERVER}
2490 COMMAND="set_pkgrev"
2493 Exit_error err_invalid_cmdline "$1"
2496 SPECFILE=${1%/}; shift
2497 # check if specname was passed as specname:cvstag
2498 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2499 CVSTAG="${SPECFILE##*:}"
2500 SPECFILE="${SPECFILE%%:*}"
2502 # always have SPECFILE ending with .spec extension
2503 SPECFILE=${SPECFILE%%.spec}.spec
2504 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2508 # Check if given package exists in TLD git
2509 if ! git ls-remote --heads ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME} 1>/dev/null 2>&1; then
2510 # Nope, we don't have it in TLD, switch to PLD repositories
2511 GIT_SERVER=${PLD_GIT_SERVER}
2512 GIT_PUSH=${PLD_GIT_PUSH}
2513 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2514 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2515 ATTICDISTFILES_SERVER=${PLD_ATTICDISTFILES_SERVER}
2518 if [ "$CVSTAG" ]; then
2519 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2520 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2523 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2524 echo >&2 "--all branches requires --depth <number>"
2525 Exit_error err_invalid_cmdline
2528 if [ -n "$DEBUG" ]; then
2533 if [ -n "$TARGET" ]; then
2536 TARGET_SWITCH="--target $TARGET" ;;
2538 TARGET_SWITCH="--target=$TARGET" ;;
2542 if [ "$SCHEDTOOL" != "no" ]; then
2543 NICE_COMMAND="$SCHEDTOOL"
2545 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2548 update_shell_title "$COMMAND"
2552 if [ -z "$SPECFILE" ]; then
2553 Exit_error err_no_spec_in_cmdl
2555 get_spec > /dev/null
2562 if [ -z "$SPECFILE" ]; then
2563 Exit_error err_no_spec_in_cmdl
2565 get_spec > /dev/null
2570 "show_avail_bconds")
2572 if [ -z "$SPECFILE" ]; then
2573 Exit_error err_no_spec_in_cmdl
2576 get_spec > /dev/null
2578 local bcond_avail=$(find_spec_bcond $SPECFILE)
2579 local opt bcond bconds
2580 for opt in $bcond_avail; do
2583 bcond=${opt#without_}
2584 bconds="$bconds $bcond"
2588 bconds="$bconds $bcond"
2591 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2599 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2601 if [ -z "$SPECFILE" ]; then
2602 Exit_error err_no_spec_in_cmdl
2605 # display SMP make flags if set
2606 smp_mflags=$(rpm -E %{?_smp_mflags})
2607 if [ "$smp_mflags" ]; then
2608 echo "builder: SMP make flags are set to $smp_mflags"
2616 if [ "$COMMAND" != "build-source" ]; then
2619 fetch_build_requires
2620 if [ "$INTEGER_RELEASE" = "yes" ]; then
2621 echo "Checking release $PACKAGE_RELEASE..."
2622 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2623 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2627 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2628 if [ -n "$TEST_TAG" ]; then
2631 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2632 # check also tags created in CVS
2633 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2634 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2635 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2636 || Exit_error err_tag_exists $TAGVER_CVS
2637 # - do not allow to build from HEAD when XX-branch exists
2638 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2639 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2640 TAG_BRANCH="${TREE_PREFIX}-branch"
2641 if [ -n "$DEPTH" ]; then
2642 cmd_branches="git ls-remote --heads"
2643 ref_prefix=refs/heads
2645 cmd_branches="git show-ref"
2646 ref_prefix=refs/remotes/${REMOTE_PLD}
2648 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2649 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2650 Exit_error err_branch_exists "$TAG_STATUS"
2656 if [ -n "$NOSOURCE0" ] ; then
2657 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2662 get_files $SOURCES $PATCHES
2663 check_md5 $SOURCES $PATCHES
2666 NODIST="yes" get_files $SOURCES $PATCHES
2667 update_md5 $SOURCES $PATCHES
2671 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2672 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2674 remove_build_requires
2678 if [ -z "$SPECFILE" ]; then
2679 Exit_error err_no_spec_in_cmdl
2688 if [ -z "$SPECFILE" ]; then
2689 Exit_error err_no_spec_in_cmdl
2693 if [ -n "$NEW_REPO" ]; then
2696 for file in $SOURCES $PATCHES; do
2697 if [ -z $(src_md5 "$file") ]; then
2698 git add $file || Exit_error err_no_source_in_repo $file
2700 cvsignore_df `nourl $file`
2704 echo "When you are ready commit your changes and run git push origin master"
2706 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2711 if [ -z "$SPECFILE" ]; then
2712 Exit_error err_no_spec_in_cmdl
2718 if [ -n "$NOSOURCE0" ] ; then
2719 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2721 get_files $SOURCES $PATCHES
2726 if [ -z "$SPECFILE" ]; then
2727 Exit_error err_no_spec_in_cmdl
2733 if [ -n "$NOSOURCE0" ] ; then
2734 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2736 update_md5 $SOURCES $PATCHES
2742 if [ -z "$SPECFILE" ]; then
2743 Exit_error err_no_spec_in_cmdl
2747 if [ ! -d .git ]; then
2748 echo "No git reposiotory" >&2
2756 "list-sources-files" )
2759 DONT_PRINT_REVISION="yes"
2762 for SAP in $SOURCES $PATCHES; do
2763 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2766 "list-sources-urls" )
2769 DONT_PRINT_REVISION="yes"
2772 SAPS="$SOURCES $PATCHES"
2773 for SAP in $SAPS; do
2777 "list-sources-local-paths" )
2780 DONT_PRINT_REVISION="yes"
2783 for SAP in $SOURCES $PATCHES; do
2784 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2787 "list-sources-distfiles-paths" )
2790 DONT_PRINT_REVISION="yes"
2793 for SAP in $SOURCES $PATCHES; do
2794 if [ -n "$(src_md5 "$SAP")" ]; then
2795 distfiles_path "$SAP"
2799 "list-sources-distfiles" )
2802 DONT_PRINT_REVISION="yes"
2805 for SAP in $SOURCES $PATCHES; do
2806 if [ -n "$(src_md5 "$SAP")" ]; then
2807 distfiles_url "$SAP"
2811 "list-sources-cvs" )
2814 DONT_PRINT_REVISION="yes"
2817 for SAP in $SOURCES $PATCHES; do
2818 if [ -z "$(src_md5 "$SAP")" ]; then
2819 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2833 echo "$VERSIONSTRING"
2837 if [ -z "$SPECFILE" ]; then
2838 Exit_error err_no_spec_in_cmdl
2840 get_spec > /dev/null
2847 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2848 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2852 # vi:syntax=sh:ts=4:sw=4:noet