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")
40 Build package utility from PLD Linux Packages repository
41 $VERSION (C) 1999-2016 Free Penguins".
43 CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
45 # required rpm-build-macros
64 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
66 # use rpm 4.4.6+ digest format instead of comments if non-zero
69 # user agent when fetching files
70 USER_AGENT="TLD/Builder($VERSION)"
72 # It can be used i.e. in log file naming.
73 # See LOGFILE example.
74 DATE=`date +%Y-%m-%d_%H-%M-%S`
76 # target arch, can also be used for log file naming
77 TARGET=$(rpm -E %{_target})
79 # Note the *single* quotes, this allows using shell variables expanded at build time
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 # Example: LOGFILE='.log.$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.$TARGET.$DATE'
87 # use teeboth Perl wrapper
88 # temporary option to disable if broken
103 # create symlinks for tools in PACKAGE_DIR, see get_spec()
116 # use lftp by default when available
117 test -z "${USE_LFTP+x}" && 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:7272"
128 TLD_PACKAGES_DIR="packages"
129 TLD_DISTFILES_SERVER="://df.tld-linux.org"
132 PLD_GIT_SERVER="git://git.pld-linux.org"
133 PLD_GIT_PUSH="git@git.pld-linux.org"
134 PLD_PACKAGES_DIR="packages"
135 PLD_DISTFILES_SERVER="://distfiles.pld-linux.org"
140 GIT_SERVER=${TLD_GIT_SERVER}
141 GIT_PUSH=${TLD_GIT_PUSH}
142 PACKAGES_DIR=${TLD_PACKAGES_DIR}
151 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
156 FAIL_IF_NO_SOURCES="yes"
158 # let get_files skip over files which are present to get those damn files fetched
159 SKIP_EXISTING_FILES="no"
162 # should the specfile be restored if upgrade failed?
163 REVERT_BROKEN_UPGRADE="yes"
165 if rpm --specsrpm 2>/dev/null; then
166 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
167 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
169 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
170 if [ -x /usr/bin/rpm-getdeps ]; then
171 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
173 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
177 UPDATE_POLDEK_INDEXES_OPTS=""
179 # Here we load saved user environment used to
180 # predefine options set above, or passed to builder
182 # This one reads global system environment settings:
183 if [ -f ~/etc/builderrc ]; then
186 # And this one cascades settings using user personal
188 # Example of ~/.builderrc:
190 #UPDATE_POLDEK_INDEXES="yes"
191 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
192 #FETCH_BUILD_REQUIRES="yes"
193 #REMOVE_BUILD_REQUIRES="force"
195 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
200 if [ -n "$HOME_ETC" ]; then
201 USER_CFG="$HOME_ETC/.builderrc"
202 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
204 USER_CFG=~/.builderrc
205 BUILDER_MACROS=~/.builder-rpmmacros
208 [ -f "$USER_CFG" ] && . "$USER_CFG"
210 if [ "$SCHEDTOOL" = "auto" ]; then
211 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
212 SCHEDTOOL="schedtool -B -e"
218 if [ -n "$USE_PROZILLA" ]; then
220 elif [ -n "$USE_AXEL" ]; then
222 elif [ -n "$USE_LFTP" ]; then
228 GETLOCAL=${GETLOCAL:-cp -a}
236 if [ -d $HOME/rpm/SOURCES ]; then
237 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
238 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
242 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
243 POLDEK_CMD="$SU_SUDO /usr/bin/poldek"
246 # TODO: what this function does?
249 if [ -n "$LOGFILE" ]; then
250 LOG=`eval echo $LOGFILE`
251 if [ -n "$LASTLOG_FILE" ]; then
252 echo "LASTLOG=$LOG" > $LASTLOG_FILE
254 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
255 # FIXME $exit_pldk undefined
258 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
259 return `cat ${RES_FILE}`
264 #---------------------------------------------
267 download_prozilla() {
268 local outfile=$1 url=$2 retval
270 proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS -O "$outfile" "$url"
277 local outfile=$1 url=$2 retval
279 axel -a $AXEL_OPTS -o "$outfile" "$url"
286 local outfile=$1 url=$2 retval wget_help
287 if [ -z "${WGET_OPTS_SET+x}" ]; then
288 wget_help="$(wget --help 2>&1)"
289 echo "$wget_help" | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
290 echo "$wget_help" | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
291 echo "$wget_help" | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
292 echo "$wget_help" | grep -q -- ' --no-iri ' && WGET_OPTS="$WGET_OPTS --no-iri"
293 WGET_OPTS="-c -nd -t$WGET_RETRIES $WGET_OPTS --user-agent=$USER_AGENT $IPOPT --passive-ftp"
297 wget $WGET_OPTS -O "$outfile" "$url"
299 if [ $retval -ne 0 ]; then
300 if [ "`echo $url | grep -E 'ftp://'`" ]; then
301 ${GETURI} -O "$outfile" "$url"
309 local outfile=$1 url=$2 retval tmpfile
310 tmpfile=$(tempfile) || exit 1
312 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
313 $([ "$IPOPT" = "-4" ] && echo "set dns:order \"inet\";")
314 $([ "$IPOPT" = "-6" ] && echo "set dns:order \"inet6\";")
315 set ssl:verify-certificate no;
316 set net:max-retries $WGET_RETRIES;
317 set http:user-agent \"$USER_AGENT\";
318 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
322 if [ $retval -eq 0 ]; then
323 mv -f "$tmpfile" "$outfile"
331 if [ -n "$DEBUG" ]; then set -xv; fi
333 # to make this output parseable by bash-completion _parse_help()
334 # if the line contains short and long option, it will take only the long option
335 # but if you want both being completed, put the short option to separate line
337 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
338 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
339 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
340 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
341 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
342 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
343 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
344 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
345 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
346 [--git-pld|--git-tld] [--pkgrev] [-lp]
347 <package>[.spec][:tag]
349 -4 - force IPv4 when transferring files
350 -6 - force IPv6 when transferring files
352 --update-md5 - update md5 comments in spec, implies -nd -ncs
354 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
355 --all-branches - make shallow fetch of all branches; --depth required
356 -n5, --no-md5 - ignore md5 comments in spec
357 -D, --debug - enable builder script debugging mode,
358 -debug - produce rpm debug package (same as --opts -debug)
359 -V, --version - output builder version string
360 --short-version - output builder short version
361 -a - try add new package to PLD repo.
364 - get all files from PLD repo or HTTP/FTP and build package
366 -bb - get all files from PLD repo or HTTP/FTP and build binary
367 only package from <package>.spec,
368 -bp - execute the %prep phase of <package>.spec,
369 -bc - execute the %build phase of <package>.spec,
370 -bi - execute the %install phase of <package>.spec
371 -bl - execute the %files phase of <package>.spec
372 -bs - get all files from PLD repo or HTTP/FTP and only pack
374 --short-circuit - short-circuit build
375 -B, --branch - add branch
377 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
378 may be used with building process.
379 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
380 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
381 -cf, --cvs-force - use -f when tagging
382 --define '<macro> <value>'
383 - define a macro <macro> with value <value>,
384 --depth <number> - make shallow fetch
385 --alt_kernel <kernel>
386 - same as --define 'alt_kernel <kernel>'
387 --nodeps - rpm won't check any dependences
389 --get - get <package>.spec and all related files from PLD repo
390 -h, --help - this message,
391 -j N - set %_smp_mflags to propagate concurrent jobs
392 --ftp - use FTP protocol to access distfiles server
393 --http - use HTTP protocol to access distfiles server
394 -l <logfile>, --logtofile=<logfile>
397 - don't pull from PLD repo
398 -nd, --no-distfiles - don't download from distfiles
399 -nm, --no-mirrors - don't download from mirror, if source URL is given,
400 -nu, --no-urls - don't try to download from FTP/HTTP location,
401 -ns, --no-srcs - don't download Sources/Patches
402 -ns0, --no-source0 - don't download Source0
403 -nn, --no-net - don't download anything from the net
404 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
405 -pm, --prefer-mirrors
406 - prefer mirrors (if any) over distfiles for SOURCES
407 --no-init - don't initialize builder paths (SPECS and SOURCES)
409 --skip-existing-files
410 - skip existing files in get_files
411 --opts <rpm opts> - additional options for rpm
412 -q, --quiet - be quiet,
413 --date yyyy-mm-dd - build package using resources from specified date,
414 -r <tag>, --cvstag <ref>
415 - build package using resources from specified branch/tag,
416 -A - build package using master branch as any sticky tags/branch/date being reset.
417 -R, --fetch-build-requires
418 - fetch what is BuildRequired,
419 -RB, --remove-build-requires
420 - remove all you fetched with -R or --fetch-build-requires
421 remember, this option requires confirmation,
422 -FRB, --force-remove-build-requires
423 - remove all you fetched with -R or --fetch-build-requires
424 remember, this option works without confirmation,
425 -sd, --source-distfiles
426 - list sources available from distfiles (intended for offline
427 operations; does not work when Icon field is present
428 but icon file is absent),
429 -sc, --source-cvs - list sources available from PLD repo
430 -sdp, --source-distfiles-paths
431 - list sources available from distfiles -
432 paths relative to distfiles directory (intended for offline
433 operations; does not work when Icon field is present
434 but icon file is absent),
435 -sf, --source-files - list sources - bare filenames (intended for offline
436 operations; does not work when Icon field is present
437 but icon file is absent),
439 - list sources - filenames with full local paths (intended for
440 offline operations; does not work when Icon field is present
441 but icon file is absent),
442 -su, --source-urls - list urls - urls to sources and patches
443 intended for copying urls with spec with lots of macros in urls
444 -T <tag> , --tag <tag>
445 - add git tag <tag> for files,
446 -Tvs, --tag-version-stable
447 - add git tags STABLE and NAME-VERSION-RELEASE for files,
449 - add git tag STABLE for files,
451 --tag-version - add git tag NAME-VERSION-RELEASE for files,
452 -Tp, --tag-prefix <prefix>
453 - add <prefix> to NAME-VERSION-RELEASE tags,
454 -tt, --test-tag <prefix>
455 - fail if tag is already present,
456 -ir, --integer-release-only
457 - allow only integer and snapshot releases
458 -v, --verbose - be verbose,
459 -u, --try-upgrade - check version, and try to upgrade package
460 -un, --try-upgrade-with-float-version
461 - as above, but allow float version
462 php-pear-Services_Digg/
463 --upgrade-version - upgrade to specified version in try-upgrade
464 -U, --update - refetch sources, don't use distfiles, and update md5 comments
465 -Upi, --update-poldek-indexes
466 - refresh or make poldek package index files.
468 --skip-patch <patchnumber>
469 - don't apply <patchnumber>. may be repeated.
471 --nopatch <patchnumber>
472 - abort instead of applying patch <patchnumber>
474 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
475 --show-bconds - show available conditional builds, which can be used
476 - with --with and/or --without switches.
477 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
478 In other words, the output is parseable by scripts.
479 --show-avail-bconds - show available bconds
482 - conditional build package depending on %_with_<feature>/
483 %_without_<feature> macro switch. You may now use
484 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
485 constructions. Set GROUP_BCONDS to yes to make use of it.
486 --target <platform>, --target=<platform>
487 - build for platform <platform>.
488 --init-rpm-dir, --init
489 - initialize ~/rpm directory structure
490 --git-pld - force use of PLD git and distfiles
491 --git-tld - force use of TLD git and distfiles (note: it will fall
492 back to PLD git/df if package doesn't exist in TLD git)
493 --pkgrev - save git revision of package being built into pkgrevs
494 (note: only official TLD source builders are allowed to do so)
495 -lp - list pkgrevs for specified package
499 # create tempfile. as secure as possible
501 local prefix=builder.$PACKAGE_NAME${1:+.$1}
502 mktemp --tmpdir -t $prefix.XXXXXX || echo ${TMPDIR:-/tmp}/$prefix.$RANDOM.$$
506 local prefix=builder.$PACKAGE_NAME${1:+.$1}
507 mktemp --tmpdir -d $prefix.XXXXXX
510 # inserts git log instead of %changelog
511 # @output directory containing modified specfile
513 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
515 # allow this being customized
516 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
518 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
519 # otherwise i'd use --date=iso here
520 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
521 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
522 # NOTE: changelog date is always in UTC for rpmbuild
523 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
524 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
526 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
527 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
530 # add link to full git logs
531 local giturl="http://git.tld-linux.org/?p=packages/${SPECFILE%.spec}.git;a=log"
532 if [ -n "$CVSTAG" ]; then
533 giturl="$giturl;h=$CVSTAG"
535 local gitauthor="TLD Linux <feedback@tld-linux.org>"
536 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
537 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
542 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
543 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
547 " > $specdir/$SPECFILE
548 rm -f $gitlog $speclog
552 # @param string logfile
553 # @param varargs... commands to execute
556 # use teeboth from toys/cleanbuild, if available and enabled
557 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
561 local efile rc logfile=$1; shift
562 if [ "$logfile" ]; then
564 { "$@" 2>&1; echo $? > $efile; } | tee $logfile
575 # change dependency to specname
577 # - perl(Package::Name) -> perl-Package-Name
581 if [ $# -gt 0 ]; then
587 echo "$DEPS" | tr ' ' '\n' | sed -re '
590 s/perl\((.*)\)/perl-\1/
594 s/apache\(EAPI\)-devel/apache-devel/
596 s/db-devel/db5.3-devel/
597 s/libjpeg-devel/libjpeg-turbo-devel/
601 update_shell_title() {
603 local len=${COLUMNS:-80}
604 local msg="$(echo "$*" | cut -c-$len)"
606 if [ -n "$BE_VERBOSE" ]; then
607 echo >&2 "$(date +%s.%N) $*"
610 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
612 if [ -n "$PACKAGE_NAME" ]; then
613 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
618 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
619 msg=$(echo $msg | tr -d '\n\r')
622 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
625 echo >&2 -ne "\033]0;$msg\007"
631 # set TARGET from BuildArch: from SPECFILE
633 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
634 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
636 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
640 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
642 TARGET_SWITCH="--target=$TARGET" ;;
648 # runs rpm with minimal macroset
650 # TODO: move these to /usr/lib/rpm/macros
651 cat > $BUILDER_MACROS <<'EOF'
652 %x8664 x86_64 amd64 ia32e
655 %bootstrap_release() %{1}
656 %requires_releq_kernel_up(s:n:) %{nil}
657 %requires_releq_kernel_smp(s:n:) %{nil}
658 %requires_releq_kernel(s:n:) %{nil}
659 %requires_releq() %{nil}
660 %pyrequires_eq() %{nil}
661 %requires_eq() %{nil}
662 %requires_eq_to() %{nil}
663 %requires_ge() %{nil}
664 %requires_ge_to() %{nil}
665 %requires_ge() %{nil}
666 %releq_kernel_up(n:) ERROR
667 %releq_kernel_smp(n:) ERROR
668 %releq_kernel(n:) ERROR
669 %py_postclean(x:) ERROR
673 %ruby_ver_requires_eq() %{nil}
674 %ruby_mod_ver_requires_eq() %{nil}
675 %__php_api_requires() %{nil}
676 %php_major_version ERROR
677 %php_api_version ERROR
678 %requires_xorg_xserver_extension %{nil}
679 %requires_xorg_xserver_xinput %{nil}
680 %requires_xorg_xserver_font %{nil}
681 %requires_xorg_xserver_videodrv %{nil}
683 %perl_vendorarch ERROR
684 %perl_vendorlib ERROR
685 # damn. need it here! - copied from /usr/lib/rpm/macros.build
686 %tmpdir %(echo "${TMPDIR:-/tmp}")
687 %patchset_source(f:b:) %(
688 base=%{-b*}%{!-b*:10000};
689 start=$(expr $base + %1);
690 end=$(expr $base + %{?2}%{!?2:%{1}});
691 # we need to call seq twice as it doesn't allow two formats
692 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
693 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
694 paste %{tmpdir}/__ps{1,2};
695 rm -f %{tmpdir}/__ps{1,2};
698 %add_etc_shells(p) %{p:<lua>}
699 %remove_etc_shells(p) %{p:<lua>}
700 %lua_add_etc_shells() %{nil}
701 %lua_remove_etc_shells() %{nil}
703 %buildrequires_jdk %{nil}
704 %pear_package_print_optionalpackages %{nil}
706 if [ "$NOINIT" = "yes" ] ; then
707 cat >> $BUILDER_MACROS <<'EOF'
712 if rpm --version 2>&1 | grep -qE '5\.[0-9]+\.[0-9]+'; then
713 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
714 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
716 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --load "$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
721 if [ -n "$DEBUG" ]; then
726 if [ -x /usr/bin/rpm-specdump ]; then
727 update_shell_title "cache_rpm_dump using rpm-specdump command"
728 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
730 update_shell_title "cache_rpm_dump using rpmbuild command"
733 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
734 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
740 ARGS='--nodigest --nosignature --nobuild'
743 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
745 if [ $? -gt 0 ]; then
746 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
748 Exit_error err_build_fail
751 # make small dump cache
752 rpm_dump_cache=`echo "$rpm_dump" | awk '
753 $2 ~ /^SOURCEURL/ {print}
754 $2 ~ /^PATCHURL/ {print}
755 $2 ~ /^nosource/ {print}
756 $2 ~ /^PACKAGE_/ {print}
760 update_shell_title "cache_rpm_dump: OK!"
764 if [ -z "$rpm_dump_cache" ] ; then
765 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
767 echo "$rpm_dump_cache"
771 update_shell_title "get icons"
772 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
773 if [ -z "$ICONS" ]; then
777 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
781 update_shell_title "parsing specfile"
782 if [ -n "$DEBUG" ]; then
787 # icons are needed for successful spec parse
793 if rpm_dump | grep -qEi ":.*nosource.*1"; then
794 FAIL_IF_NO_SOURCES="no"
797 if [ "$NOSRCS" != "yes" ]; then
798 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
799 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
800 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
803 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
804 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
805 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
807 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
808 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
811 if [ -n "$BE_VERBOSE" ]; then
812 echo "- Sources : `nourl $SOURCES`"
813 if [ -n "$PATCHES" ]; then
814 echo "- Patches : `nourl $PATCHES`"
816 echo "- Patches : *no patches needed*"
818 if [ -n "$ICONS" ]; then
819 echo "- Icon : `nourl $ICONS`"
821 echo "- Icon : *no package icon*"
823 echo "- Name : $PACKAGE_NAME"
824 echo "- Version : $PACKAGE_VERSION"
825 echo "- Release : $PACKAGE_RELEASE"
828 update_shell_title "parse_spec: OK!"
831 # aborts program abnormally
834 echo >&2 "$PROGRAM: ERROR: $*"
839 if [ -n "$DEBUG" ]; then
847 "err_no_spec_in_cmdl" )
848 remove_build_requires
849 echo >&2 "ERROR: spec file name not specified."
851 "err_invalid_cmdline" )
852 echo >&2 "ERROR: invalid command line arg ($2)."
854 "err_no_spec_in_repo" )
855 remove_build_requires
856 echo >&2 "Error: spec file not stored in repository."
862 "err_no_source_in_repo" )
863 remove_build_requires
864 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
866 "err_cvs_add_failed" )
867 echo >&2 "Error: failed to add package to PLD repo."
870 remove_build_requires
871 echo >&2 "Error: package build failed. (${2:-no more info})"
873 "err_no_package_data" )
874 remove_build_requires
875 echo >&2 "Error: couldn't get out package name/version/release from spec file."
878 remove_build_requires
879 echo >&2 "Tag ${2} already exists"
882 remove_build_requires
883 echo >&2 "Release ${2} not integer and not a snapshot."
885 "err_branch_exists" )
886 remove_build_requires
887 echo >&2 "Tree branch already exists (${2})."
890 remove_build_requires
891 echo >&2 "Error: conditions reject building this spec (${2})."
893 "err_remote_problem" )
894 remove_build_requires
895 echo >&2 "Error: problem with remote (${2})"
898 echo >&2 "Error: cannot checkout ${2}"
901 echo >&2 "Error: failed to set package revision for tag ${2}"
904 echo >&2 "Error: failed to get package revision for tag ${2}"
906 "err_not_implemented" )
907 remove_build_requires
908 echo >&2 "Error: functionality not yet imlemented"
911 echo >&2 "Unknown error."
916 if [ -n "$DEBUG" ]; then
921 if [ "$NOINIT" != "yes" ] ; then
922 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
924 local macros_ver=$(rpm -E %?rpm_build_macros)
925 if [ -z "$macros_ver" ]; then
926 REPO_DIR=$TOP_DIR/packages
927 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
929 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
930 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
934 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
939 REPO_DIR=$PACKAGE_DIR
940 RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
942 export GIT_WORK_TREE=$PACKAGE_DIR
943 export GIT_DIR=$PACKAGE_DIR/.git
945 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
946 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
947 CVSTAG=${CVSTAG#refs/heads/}
948 if [ "$CVSTAG" != "master" ]; then
949 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
952 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
955 elif [ "$CVSTAG" = "HEAD" ]; then
956 # assume -r HEAD is same as -A
964 update_shell_title "add_package"
966 if [ -n "$DEBUG" ]; then
972 SPECFILE=$(basename $SPECFILE)
973 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
974 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
977 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
978 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
982 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
983 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
985 git config --local push.default current
986 git config --local branch.master.remote $REMOTE_PLD
987 git config --local branch.master.merge refs/heads/master
989 test $? = 0 || Exit_error err_remote_problem $REMOTE_PLD
994 update_shell_title "get_spec"
996 if [ -n "$DEBUG" ]; then
1002 SPECFILE=$(basename $SPECFILE)
1003 if [ "$NOCVSSPEC" != "yes" ]; then
1004 if [ -z "$DEPTH" ]; then
1005 if [ -d "$PACKAGE_DIR/.git" ]; then
1006 git fetch $IPOPT $REMOTE_PLD || Exit_error err_no_spec_in_repo
1007 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
1008 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
1009 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
1012 Exit_error err_not_implemented
1016 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
1017 # softfail if new package, i.e not yet added to PLD rep
1018 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
1019 echo "Warning: package not in Git - assuming new package"
1022 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1023 git config --local --add "remote.$REMOTE_PLD.push" 'refs/notes/*:refs/notes/*'
1024 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1025 git config --local push.default current
1026 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1030 if [ ! -d "$PACKAGE_DIR/.git" ]; then
1031 if [ ! -d "$PACKAGE_DIR" ]; then
1032 install -d $PACKAGE_DIR
1035 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
1036 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1037 git config --local --add "remote.$REMOTE_PLD.push" 'refs/heads/*:refs/remotes/origin/*'
1038 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1039 git config --local push.default current
1040 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1041 CVSTAG=${CVSTAG:-"master"}
1044 if [ -z "$ALL_BRANCHES" ]; then
1045 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
1047 git fetch $IPOPT $DEPTH $REMOTE_PLD $refs || {
1048 echo >&2 "Error: branch $CVSTAG does not exist"
1052 git fetch $IPOPT $REMOTE_PLD 'refs/notes/*:refs/notes/*'
1054 cvsignore_df .gitignore
1056 # add default log format to .gitignore if it is relative to package dir
1057 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
1058 # substitute known "macros" to glob
1059 local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g')
1060 if [ "$logfile" ]; then
1061 cvsignore_df "$logfile"
1065 # create symlinks for tools
1066 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
1067 for a in dropin md5 builder {relup,compile,repackage,rsync,pearize}.sh; do
1068 # skip tools that don't exist in top dir
1069 [ -f $a ] || continue
1070 # skip tools that already exist
1071 [ -f $PACKAGE_DIR/$a ] && continue
1072 ln -s ../$a $PACKAGE_DIR
1078 if [ -n "$CVSTAG" ]; then
1079 local _rev=$(get_pkgrev "$CVSTAG")
1080 echo "$_rev" | grep -q -E "^ERROR$" || CVSTAG="$_rev"
1081 if git rev-parse --verify -q "$CVSTAG" >/dev/null; then
1082 git checkout "$CVSTAG" --
1083 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1084 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1086 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1087 Exit_error "err_no_checkut" "$CVSTAG"
1090 git merge --ff-only '@{u}'
1091 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1092 if [ -n "$CVSDATE" ]; then
1093 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1097 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1098 Exit_error err_no_spec_in_repo "$PACKAGE_DIR/$SPECFILE"
1101 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1102 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1105 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1110 # find mirrors in this order. first match wins:
1111 # - package dir (~/rpm/packages/foo)
1112 # - repository dir (~/rpm/packages)
1113 # - tools dir dir (~/rpm/packages/rpm-build-tools)
1117 update_shell_title "find_mirror[$url][$REPO_DIR]"
1119 # NOTE: as while loop runs in subshell,
1120 # we use exit 2 to indicate that the match was found
1121 # otherwise we end up outputing mirror url and origin url.
1123 local origin mirror name rest ol prefix
1125 cat "$PACKAGE_DIR/mirrors" "$REPO_DIR/mirrors" "$REPO_DIR/../rpm-build-tools/mirrors" /dev/null 2>/dev/null | \
1126 while read origin mirror name rest; do
1127 # skip comments and empty lines
1128 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1131 ol=$(echo -n "$origin" | wc -c)
1132 prefix=$(echo -n "$url" | head -c $ol)
1133 if [ "$prefix" = "$origin" ] ; then
1134 suffix=$(echo "$url" | cut -b $((ol+1))-)
1135 echo -n "$mirror$suffix"
1141 # Warning: unpredictable results if same URL used twice
1144 # escape some regexp characters if part of file name
1145 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1148 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1149 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1150 head -n 1 | tr OURCEATH ourceath | xargs
1154 [ "$NO5" = "yes" ] && return
1156 [ -z "$no" ] && return
1160 # use "sources" file from package dir, like vim
1161 if [ -f sources ]; then
1162 md5=$(grep -s -v '^#' sources | \
1163 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1164 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1165 grep -E '^[0-9a-f]{32}$')
1168 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1169 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1171 echo "$md5" | tail -n 1
1176 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1177 if [ -n "$source_md5" ]; then
1180 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1181 if [ -n "$source_md5" ]; then
1184 # we have empty SourceX-md5, but it is still possible
1185 # that we have NoSourceX-md5 AND NoSource: X
1186 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1187 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1195 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1199 echo "$PROTOCOL$DISTFILES_SERVER/$(distfiles_path "$1")"
1204 [ "$md5" = "" ] || \
1205 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1209 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1210 [ -n "$size" -a "$size" -gt 0 ]
1214 if [ "$CVSIGNORE_DF" != "yes" ]; then
1217 local cvsignore=${PACKAGE_DIR}/.git/info/exclude
1219 # add only if not yet there
1220 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1221 echo "$1" >> $cvsignore
1225 # returns true if "$1" is ftp, http or https protocol url
1228 ftp://*|http://*|https://*)
1236 if [ $# -eq 0 ]; then
1240 update_shell_title "update md5"
1241 if [ -n "$DEBUG" ]; then
1248 # pass 1: check files to be fetched
1252 local fp=$(nourl "$i")
1253 local srcno=$(src_no "$i")
1254 if [ -n "$ADD5" ]; then
1255 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1256 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1257 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1259 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1261 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1262 need_files="$need_files $i"
1266 # pass 1a: get needed files
1267 if [ "$need_files" ]; then
1268 get_files $need_files
1271 # pass 2: proceed with md5 adding or updating
1273 local fp=$(nourl "$i")
1274 local srcno=$(src_no "$i")
1275 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1276 if [ -z "$md5" ]; then
1277 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1279 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1280 local tag="# $srcno-md5:\t"
1281 if [[ "$md5" == *NoSource* ]]; then
1282 tag="# No$srcno-md5:\t"
1283 elif [ -n "$USEDIGEST" ]; then
1284 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1286 md5=$(md5sum "$fp" | cut -f1 -d' ')
1287 echo "Updating $srcno ($md5: $fp)."
1289 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1290 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1292 $PACKAGE_DIR/$SPECFILE
1299 [ "$NO5" = "yes" ] && return
1301 update_shell_title "check md5"
1305 if ! good_md5 "$i"; then
1306 echo -n "MD5 sum mismatch."
1309 if ! good_size "$i"; then
1310 echo -n "0 sized file."
1314 if [ $bad -eq 1 ]; then
1315 echo " Use -U to refetch sources,"
1316 echo "or -5 to update md5 sums, if you're sure files are correct."
1317 Exit_error err_no_source_in_repo $i
1323 update_shell_title "get_files"
1325 if [ -n "$DEBUG" ]; then
1330 if [ $# -gt 0 ]; then
1334 local get_files_cvs=""
1338 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1339 update_shell_title "$i"
1340 local fp=`nourl "$i"`
1341 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1346 local srcmd5=$(src_md5 "$i")
1348 # we know if source/patch is present in cvs/distfiles
1349 # - has md5 (in distfiles)
1350 # - in cvs... ideas?
1352 # CHECK: local file didn't exist or always cvs up (first) requested.
1353 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1354 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1355 echo "Warning: no URL given for $i"
1359 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1360 if good_md5 "$i" && good_size "$i"; then
1361 echo "$fp having proper md5sum already exists"
1365 # optionally prefer mirror over distfiles if there's mirror
1366 # TODO: build url list and then try each url from the list
1367 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1370 url=$(distfiles_url "$i")
1374 # is $url local file?
1375 if [[ "$url" = [./]* ]]; then
1376 update_shell_title "${GETLOCAL%% *}: $url"
1377 ${GETLOCAL} $url $target
1380 # make shorter message for distfiles urls
1381 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]]; then
1382 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/by-md5/?/?/*/}
1385 update_shell_title "${GETURI%% *}: $uri"
1386 ${GETURI} "$target" "$url"
1389 if [ -s "$target" ]; then
1390 cvsignore_df $target
1397 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1398 if [ -z "$NOMIRRORS" ]; then
1399 im=$(find_mirror "$i")
1403 update_shell_title "${GETURI%% *}: $im"
1404 ${GETURI} "$target" "$im"
1405 test -s "$target" || rm -f "$target"
1408 if [ "$cvsup" = 1 ]; then
1414 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1415 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1416 Exit_error err_no_source_in_repo $i
1419 # we check md5 here just only to refetch immediately
1420 if good_md5 "$i" && good_size "$i"; then
1422 elif [ "$FROM_DISTFILES" = 1 ]; then
1423 # wrong md5 from distfiles: remove the file and try again
1425 echo "MD5 sum mismatch. Trying full fetch."
1428 update_shell_title "${GETURI%% *}: $url"
1429 ${GETURI} "$target" "$url"
1430 test -s "$target" || rm -f "$target"
1433 SHELL_TITLE_PREFIX=""
1436 if [ "$CHMOD" = "yes" ]; then
1437 CHMOD_FILES=$(nourl "$@")
1438 if [ -n "$CHMOD_FILES" ]; then
1439 chmod $CHMOD_MODE $CHMOD_FILES
1446 # If tag exists and points to other commit exit with error
1447 # If it existsts and points to HEAD return 1
1448 # If it doesn't exist return 0
1450 local sha1=$(git rev-parse HEAD)
1451 echo "Searching for tag $_tag..."
1452 if [ -n "$DEPTH" ]; then
1453 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1455 local ref=$(git show-ref -s "refs/tags/$_tag")
1457 [ -z "$ref" ] && return 0
1458 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1463 if [ -n "$DEBUG" ]; then
1468 # Check whether first character of PACKAGE_NAME is legal for tag name
1469 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1473 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1474 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1476 # Remove @kernel.version_release from TAGVER because tagging sources
1477 # could occur with different kernel-headers than kernel-headers used at build time.
1478 # besides, %{_kernel_ver_str} is not expanded.
1480 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1481 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1488 if [ -n "$DEBUG" ]; then
1493 echo "Version: $PACKAGE_VERSION"
1494 echo "Release: $PACKAGE_RELEASE"
1497 if [ "$TAG_VERSION" = "yes" ]; then
1500 if [ -n "$TAG" ]; then
1505 local OPTIONS="tag $CVS_FORCE"
1509 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1510 update_shell_title "tag sources: $_tag"
1511 git $OPTIONS $_tag || exit
1512 git push $IPOPT $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1514 echo "Tag $_tag already exists and points to the same commit"
1519 [ -z "$1" ] && return 1
1520 local _tmp=$(mktemp /tmp/.builder-XXXX)
1521 rm $_tmp 2>/dev/null
1522 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/get/$1 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1523 local result=$(cat $_tmp)
1524 rm $_tmp 2>/dev/null
1530 if [ "$TAG_VERSION" = "yes" ]; then
1533 if [ -n "$TAG" ]; then
1536 echo "Writing git revision for tag $_tag"
1537 local _tmp=$(mktemp /tmp/.builder-XXXX)
1538 rm $_tmp 2>/dev/null
1539 local _rev=$(git rev-parse HEAD)
1540 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/set/$_rev/$_tag 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1541 local result=$(cat $_tmp)
1542 rm $_tmp 2>/dev/null
1543 [ "$(get_pkgrev "$_tag")" = "$CVSTAG" ] && return 0
1544 echo "$result" | grep -q -E "^OK$" && return 0
1545 echo "$result" | grep -q -E "^EXISTS$" && Exit_error err_tag_exists "$_tag"
1546 Exit_error err_pkgrev_set
1550 local _tmp=$(mktemp /tmp/.builder-XXXX)
1551 rm $_tmp 2>/dev/null
1552 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/list/$PACKAGE_NAME 1>/dev/null 2>&1
1554 rm $_tmp 2>/dev/null
1559 echo "Git branch: $TAG"
1562 if [ -n "$DEBUG" ]; then
1567 local OPTIONS="branch $CVS_FORCE"
1570 git $OPTIONS $TAG || exit
1574 # this function should exit early if package can't be built for this arch
1575 # this avoids unneccessary BR filling.
1578 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1580 if [ $ret -ne 0 ]; then
1592 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1593 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1599 local ver="$2" subver=$ver
1600 local newver="$3" newsubver=$newver
1602 # try handling subver, everything that's not numeric-dotted in version
1603 if grep -Eq '%define\s+subver' $specfile; then
1604 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1606 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1607 newver=${newver%$newsubver}
1610 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1611 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1612 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1616 # try to upgrade .spec to new version
1617 # if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1619 # return 1: if .spec was updated
1620 # return 0: no changes to .spec
1621 # exit 1 in case of error
1623 if [ -z "$TRY_UPGRADE" ]; then
1627 local TNOTIFY TNEWVER TOLDVER
1628 update_shell_title "build_package: try_upgrade"
1632 if [ "$UPGRADE_VERSION" ]; then
1633 TNEWVER=$UPGRADE_VERSION
1634 echo "Updating spec file to version $TNEWVER"
1636 if [ -n "$FLOAT_VERSION" ]; then
1637 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1639 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1642 # pldnotify does not set exit codes, but it has match for ERROR
1643 # in output which means so.
1644 if [[ "$TNOTIFY" = *ERROR* ]]; then
1649 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1650 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1652 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1655 if [ -z "$TNEWVER" ]; then
1659 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1660 cp -f $SPECFILE $SPECFILE.bak
1663 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1664 set_release $SPECFILE $PACKAGE_RELEASE 1
1666 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1667 echo >&2 "Upgrading version failed, you need to update spec yourself"
1674 update_shell_title "build_package"
1675 if [ -n "$DEBUG" ]; then
1684 BUILD_SWITCH="-ba" ;;
1686 BUILD_SWITCH="-bb" ;;
1688 BUILD_SWITCH="-bs --nodeps" ;;
1690 BUILD_SWITCH="-bp --nodeps" ;;
1692 BUILD_SWITCH="-bc" ;;
1694 BUILD_SWITCH="-bi" ;;
1696 BUILD_SWITCH="-bl" ;;
1700 update_shell_title "build_package: $COMMAND"
1701 local logfile retval
1702 if [ -n "$LOGFILE" ]; then
1703 logfile=`eval echo $LOGFILE`
1704 if [ -d "$logfile" ]; then
1705 echo "Log file $logfile is a directory."
1706 echo "Parse error in the spec?"
1707 Exit_error err_build_fail
1709 if [ -n "$LASTLOG_FILE" ]; then
1710 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1714 # unset these, should not be exposed to builder shell!
1715 unset GIT_WORK_TREE GIT_DIR
1716 # these are set by jenkins
1717 unset GIT_PREVIOUS_COMMIT GIT_URL GIT_PREVIOUS_SUCCESSFUL_COMMIT GIT_BRANCH GIT_COMMIT
1718 # this may be set by user
1720 # may be set by user
1721 unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_TESTING_PORCELAIN_COMMAND_LIST
1722 # fail if something still set
1723 env | grep ^GIT_ && Exit_error err_build_fail
1725 local specdir=$(insert_gitlog $SPECFILE)
1727 # FIXME: eval here is exactly why?
1728 PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${TIME_COMMAND} ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE
1732 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1733 if [ "$retval" -eq "0" ]; then
1734 mv $logfile $LOGDIROK
1736 mv $logfile $LOGDIRFAIL
1740 if [ "$retval" -ne "0" ]; then
1741 if [ -n "$TRY_UPGRADE" ]; then
1742 echo "\nUpgrade package to new version failed."
1743 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1744 echo "Restoring old spec file."
1745 mv -f $SPECFILE.bak $SPECFILE
1749 Exit_error err_build_fail
1755 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1758 install_required_packages() {
1763 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1766 /^%changelog/ { exit }
1768 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1769 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1770 gsub(/[ \t]+/, "_", bcond);
1772 }' $SPEC | LC_ALL=C sort -u
1776 # expand bconds from ~/.bcondrc
1777 # The file structure is like gentoo's package.use:
1780 # samba -mysql -pgsql
1781 # w32codec-installer license_agreement
1784 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1790 SN=${SPECFILE%%\.spec}
1792 local bcondrc=$HOME/.bcondrc
1793 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1795 local bcond_avail=$(find_spec_bcond $SPECFILE)
1797 while read pkg flags; do
1799 [[ "$pkg" == \#* ]] && continue
1801 # any package or current package?
1802 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1803 for flag in $flags; do
1804 local opt=${flag#[+-]}
1806 # use only flags which are in this package.
1807 if [[ $bcond_avail = *${opt}* ]]; then
1808 if [[ $flag = -* ]]; then
1809 if [[ $BCOND != *--with?${opt}* ]]; then
1810 BCOND="$BCOND --without $opt"
1813 if [[ $BCOND != *--without?${opt}* ]]; then
1814 BCOND="$BCOND --with $opt"
1821 update_shell_title "parse ~/.bcondrc: DONE!"
1824 set_bconds_values() {
1825 update_shell_title "set bcond values"
1827 AVAIL_BCONDS_WITHOUT=""
1828 AVAIL_BCONDS_WITH=""
1830 if grep -Eq '^# *_with' ${SPECFILE}; then
1831 echo >&2 "ERROR: This spec has old style bconds."
1835 if ! grep -q '^%bcond' ${SPECFILE}; then
1839 local bcond_avail=$(find_spec_bcond $SPECFILE)
1840 process_bcondrc "$SPECFILE"
1842 update_shell_title "parse bconds"
1845 for opt in $bcond_avail; do
1848 bcond=${opt#without_}
1850 *--without?${bcond}*)
1851 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1854 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1862 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1865 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1870 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1879 update_shell_title "run_sub_builder $package_name"
1881 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1882 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
1883 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1884 # jakby nie bylo tego kawalka kodu.
1886 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1887 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
1891 # kurwa. translate that ^^^^
1895 # Istnieje taki spec? ${package}.spec
1896 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1897 parent_spec_name=${package}.spec
1898 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1899 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1901 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1906 if [ "${parent_spec_name}" != "" ]; then
1907 spawn_sub_builder $parent_spec_name
1909 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1912 # install package with poldek
1913 # @return exit code from poldek
1915 # this requires following sudo rules:
1916 # - poldek --noask --caplookup -ug
1918 LANG=C $POLDEK_CMD --noask --caplookup --uniq -ug "$@"
1923 # this requires following sudo rules:
1924 # - poldek -q --update --upa
1925 install_packages() {
1926 # sync poldek indexes once per invocation
1927 if [ -z "$package_indexes_updated" ]; then
1928 update_shell_title "poldek: update indexes"
1929 $POLDEK_CMD -q --update --upa --mo=nodesc
1930 package_indexes_updated=true
1933 update_shell_title "install packages: $*"
1934 poldek_install "$@" && return
1936 # retry install, install packages one by one
1937 # this is slower one
1939 for package in $*; do
1940 package=$(depspecname $package)
1941 update_shell_title "install package: $package"
1942 poldek_install "$package" || rc=$?
1947 uninstall_packages() {
1948 update_shell_title "uninstall packages: $*"
1949 $POLDEK_CMD --noask --nofollow -ev "$@"
1952 spawn_sub_builder() {
1954 update_shell_title "spawn_sub_builder $package_name"
1957 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1958 sub_builder_opts="${sub_builder_opts} -R"
1960 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1961 sub_builder_opts="${sub_builder_opts} -RB"
1962 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1963 sub_builder_opts="${sub_builder_opts} -FRB"
1965 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1966 sub_builder_opts="${sub_builder_opts} -Upi"
1970 ./builder ${sub_builder_opts} "$@"
1973 remove_build_requires() {
1974 if [ "$INSTALLED_PACKAGES" != "" ]; then
1975 case "$REMOVE_BUILD_REQUIRES" in
1977 run_poldek --noask -ve $INSTALLED_PACKAGES
1980 run_poldek --ask -ve $INSTALLED_PACKAGES
1983 echo You may want to manually remove following BuildRequires fetched:
1984 echo $INSTALLED_PACKAGES
1985 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1992 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1993 if [ "$BCOND" ]; then
1995 echo "Building $SPECFILE with the following conditional flags:"
1999 echo "No conditional flags passed"
2002 echo "from available:"
2003 echo "--with :\t$AVAIL_BCONDS_WITH"
2004 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
2009 display_branches() {
2010 echo -n "Available branches: "
2011 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
2014 # checks a given list of packages/files/provides against current rpmdb.
2015 # outputs all dependencies which current rpmdb doesn't satisfy.
2016 # input can be either STDIN or parameters
2020 if [ $# -gt 0 ]; then
2026 out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1)
2029 echo "$out" | awk '/^no package provides/ { print $NF }'
2031 # other deps (files)
2032 echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p'
2035 # checks if given package/files/provides exists in rpmdb.
2036 # input can be either stdin or parameters
2037 # returns packages which are present in the rpmdb
2041 if [ $# -gt 0 ]; then
2047 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
2050 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
2051 install_build_requires_rpmdeps() {
2053 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
2054 # TODO: Conflicts list doesn't check versions
2055 CNFL=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
2056 DEPS=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
2058 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2059 CNFL=$(eval rpm -q --specsrpm --conflicts $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
2060 DEPS=$(eval rpm -q --specsrpm --requires $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
2063 if [ -n "$CNFL" ]; then
2064 echo "Uninstall conflicting packages: $CNFL"
2065 uninstall_packages $CNFL
2068 if [ -n "$DEPS" ]; then
2069 echo "Install dependencies: $DEPS"
2070 install_packages $DEPS
2074 fetch_build_requires()
2076 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
2080 update_shell_title "fetch build requires"
2081 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2082 install_build_requires_rpmdeps
2086 die "need rpm-getdeps tool"
2093 if [ ! -e $localrepo ]; then
2094 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
2095 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2100 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2101 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2102 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2103 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2104 local TEMPLATES=template-specs
2107 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2108 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2111 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2112 init_repository projects/$TEMPLATES ../$TEMPLATES
2113 for a in builder fetchsrc_request compile repackage; do
2114 ln -sf ../rpm-build-tools/${a}.sh $a
2117 ln -sf ../rpm-build-tools/${a} $a
2119 ln -sf ../rpm-build-tools/mirrors mirrors
2126 DONT_PRINT_REVISION="yes"
2128 # remove spec and sources
2129 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
2130 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2131 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2134 #---------------------------------------------
2142 # stuff global $BUILDER_OPTS from env as args
2143 if [ "$BUILDER_OPTS" ]; then
2144 set -- "$BUILDER_OPTS" "$@"
2147 while [ $# -gt 0 ]; do
2154 COMMAND="update_md5"
2159 COMMAND="update_md5"
2168 DEBUG="yes"; shift ;;
2170 COMMAND="version"; shift ;;
2172 COMMAND="short-version"; shift ;;
2179 -b | -ba | --build )
2180 COMMAND="build"; shift ;;
2181 -bb | --build-binary )
2182 COMMAND="build-binary"; shift ;;
2184 COMMAND="build-build"; shift ;;
2186 COMMAND="build-install"; shift ;;
2188 COMMAND="build-list"; shift ;;
2189 -bp | --build-prep )
2190 COMMAND="build-prep"; shift ;;
2191 -bs | --build-source )
2192 COMMAND="build-source"; shift ;;
2194 COMMAND="branch"; shift; TAG="${1}"; shift;;
2196 CLEAN="--clean"; shift ;;
2198 CVS_FORCE="-f"; shift;;
2204 COMMAND="get"; shift ;;
2206 COMMAND="usage"; shift ;;
2208 PROTOCOL="ftp"; shift ;;
2210 PROTOCOL="http"; shift ;;
2212 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2216 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2220 PARALLEL_DOWNLOADS=$2
2224 PARALLEL_DOWNLOADS=${1#-p}
2228 shift; LOGFILE="${1}"; shift ;;
2230 shift; DEF_NICE_LEVEL=${1}; shift ;;
2231 -ske | --skip-existing-files)
2232 SKIP_EXISTING_FILES="yes"; shift ;;
2234 COMMAND="mr-proper"; shift ;;
2235 -ncs | --no-cvs-specs )
2236 NOCVSSPEC="yes"; shift ;;
2237 -nd | --no-distfiles )
2238 NODIST="yes"; shift ;;
2239 -nm | --no-mirrors )
2240 NOMIRRORS="yes"; shift ;;
2242 NOURLS="yes"; shift ;;
2244 NOSRCS="yes"; shift ;;
2245 -ns0 | --no-source0 )
2246 NOSOURCE0="yes"; shift ;;
2255 -pm | --prefer-mirrors )
2258 --noinit | --no-init )
2262 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2264 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2265 --skip-patch | -sp )
2266 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2268 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2271 --with | --without )
2272 case $GROUP_BCONDS in
2276 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2277 while ! `echo ${1}|grep -qE '(^-|spec)'`
2279 BCOND="$BCOND $COND $1"
2283 if [[ "$2" = *,* ]]; then
2284 for a in $(echo "$2" | tr , ' '); do
2285 BCOND="$BCOND $1 $a"
2288 BCOND="$BCOND $1 $2"
2294 shift; TARGET="${1}"; shift ;;
2296 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2298 QUIET="--quiet"; shift ;;
2300 CVSDATE="${2}"; shift 2
2301 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2311 -R | --fetch-build-requires)
2312 FETCH_BUILD_REQUIRES="yes"
2313 NOT_INSTALLED_PACKAGES=
2315 -RB | --remove-build-requires)
2316 REMOVE_BUILD_REQUIRES="nice"
2318 -FRB | --force-remove-build-requires)
2319 REMOVE_BUILD_REQUIRES="force"
2322 COMMAND="list-sources-cvs"
2324 -sd | --source-distfiles)
2325 COMMAND="list-sources-distfiles"
2327 -sdp | --source-distfiles-paths)
2328 COMMAND="list-sources-distfiles-paths"
2330 -sf | --source-files)
2331 COMMAND="list-sources-files"
2333 -lsp | --source-paths)
2334 COMMAND="list-sources-local-paths"
2336 -su | --source-urls)
2337 COMMAND="list-sources-urls"
2339 -Tvs | --tag-version-stable )
2344 -Ts | --tag-stable )
2349 -Tv | --tag-version )
2354 -Tp | --tag-prefix )
2366 -ir | --integer-release-only )
2367 INTEGER_RELEASE="yes"
2370 COMMAND="update_md5"
2375 -Upi | --update-poldek-indexes )
2376 UPDATE_POLDEK_INDEXES="yes"
2378 --init-rpm-dir|--init)
2379 COMMAND="init_rpm_dir"
2381 -u | --try-upgrade )
2382 TRY_UPGRADE="1"; shift ;;
2384 shift; UPGRADE_VERSION="$1"; shift;;
2385 -un | --try-upgrade-with-float-version )
2386 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2388 BE_VERBOSE="1"; shift ;;
2393 if echo "${MACRO}" | grep -q '\W'; then
2394 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2398 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2403 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\""
2407 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2410 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2411 COMMAND="show_bconds"
2415 COMMAND="show_bcond_args"
2418 --show-avail-bconds)
2419 COMMAND="show_avail_bconds"
2424 RPMOPTS="${RPMOPTS} --nodeps"
2427 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2431 GIT_SERVER=${PLD_GIT_SERVER}
2432 GIT_PUSH=${PLD_GIT_PUSH}
2433 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2434 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2438 GIT_SERVER=${TLD_GIT_SERVER}
2439 GIT_PUSH=${TLD_GIT_PUSH}
2440 PACKAGES_DIR=${TLD_PACKAGES_DIR}
2441 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
2444 COMMAND="set_pkgrev"
2447 COMMAND="list_pkgrev"
2450 Exit_error err_invalid_cmdline "$1"
2453 SPECFILE=${1%/}; shift
2454 # check if specname was passed as specname:cvstag
2455 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2456 CVSTAG="${SPECFILE##*:}"
2457 SPECFILE="${SPECFILE%%:*}"
2459 # always have SPECFILE ending with .spec extension
2460 SPECFILE=${SPECFILE%%.spec}.spec
2461 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2465 # Check if given package exists in TLD git
2466 if ! git ls-remote --heads ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME} 1>/dev/null 2>&1; then
2467 # Nope, we don't have it in TLD, switch to PLD repositories
2468 GIT_SERVER=${PLD_GIT_SERVER}
2469 GIT_PUSH=${PLD_GIT_PUSH}
2470 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2471 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2474 if [ "$CVSTAG" ]; then
2475 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2476 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2479 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2480 echo >&2 "--all branches requires --depth <number>"
2481 Exit_error err_invalid_cmdline
2484 if [ -n "$DEBUG" ]; then
2489 if [ -n "$TARGET" ]; then
2492 TARGET_SWITCH="--target $TARGET" ;;
2494 TARGET_SWITCH="--target=$TARGET" ;;
2498 if [ "$SCHEDTOOL" != "no" ]; then
2499 NICE_COMMAND="$SCHEDTOOL"
2501 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2504 # see time(1) for output format that could be used
2505 TIME_COMMAND="time -p"
2507 update_shell_title "$COMMAND"
2511 if [ -z "$SPECFILE" ]; then
2512 Exit_error err_no_spec_in_cmdl
2514 get_spec > /dev/null
2521 if [ -z "$SPECFILE" ]; then
2522 Exit_error err_no_spec_in_cmdl
2524 get_spec > /dev/null
2529 "show_avail_bconds")
2531 if [ -z "$SPECFILE" ]; then
2532 Exit_error err_no_spec_in_cmdl
2535 get_spec > /dev/null
2537 local bcond_avail=$(find_spec_bcond $SPECFILE)
2538 local opt bcond bconds
2539 for opt in $bcond_avail; do
2542 bcond=${opt#without_}
2543 bconds="$bconds $bcond"
2547 bconds="$bconds $bcond"
2550 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2558 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2560 if [ -z "$SPECFILE" ]; then
2561 Exit_error err_no_spec_in_cmdl
2564 # display SMP make flags if set
2565 smp_mflags=$(rpm -E %{?_smp_mflags})
2566 if [ "$smp_mflags" ]; then
2567 echo "builder: SMP make flags are set to $smp_mflags"
2575 if [ "$COMMAND" != "build-source" ]; then
2578 fetch_build_requires
2579 if [ "$INTEGER_RELEASE" = "yes" ]; then
2580 echo "Checking release $PACKAGE_RELEASE..."
2581 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2582 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2586 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2587 if [ -n "$TEST_TAG" ]; then
2590 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2591 # check also tags created in CVS
2592 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2593 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2594 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2595 || Exit_error err_tag_exists $TAGVER_CVS
2596 # - do not allow to build from HEAD when XX-branch exists
2597 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2598 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2599 TAG_BRANCH="${TREE_PREFIX}-branch"
2600 if [ -n "$DEPTH" ]; then
2601 cmd_branches="git ls-remote --heads"
2602 ref_prefix=refs/heads
2604 cmd_branches="git show-ref"
2605 ref_prefix=refs/remotes/${REMOTE_PLD}
2607 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2608 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2609 Exit_error err_branch_exists "$TAG_STATUS"
2615 if [ -n "$NOSOURCE0" ] ; then
2616 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2621 get_files $SOURCES $PATCHES
2622 check_md5 $SOURCES $PATCHES
2625 NODIST="yes" get_files $SOURCES $PATCHES
2626 update_md5 $SOURCES $PATCHES
2630 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2631 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2633 remove_build_requires
2637 if [ -z "$SPECFILE" ]; then
2638 Exit_error err_no_spec_in_cmdl
2647 if [ -z "$SPECFILE" ]; then
2648 Exit_error err_no_spec_in_cmdl
2652 if [ -n "$NEW_REPO" ]; then
2655 for file in $SOURCES $PATCHES; do
2656 if [ -z $(src_md5 "$file") ]; then
2657 git add $file || Exit_error err_no_source_in_repo $file
2659 cvsignore_df `nourl $file`
2663 echo "When you are ready commit your changes and run git push origin master"
2665 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2670 if [ -z "$SPECFILE" ]; then
2671 Exit_error err_no_spec_in_cmdl
2677 if [ -n "$NOSOURCE0" ] ; then
2678 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2680 get_files $SOURCES $PATCHES
2682 fetch_build_requires
2686 if [ -z "$SPECFILE" ]; then
2687 Exit_error err_no_spec_in_cmdl
2693 if [ -n "$NOSOURCE0" ] ; then
2694 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2696 update_md5 $SOURCES $PATCHES
2702 if [ -z "$SPECFILE" ]; then
2703 Exit_error err_no_spec_in_cmdl
2707 if [ ! -d .git ]; then
2708 echo "No git reposiotory" >&2
2716 "list-sources-files" )
2719 DONT_PRINT_REVISION="yes"
2722 for SAP in $SOURCES $PATCHES; do
2723 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2726 "list-sources-urls" )
2729 DONT_PRINT_REVISION="yes"
2732 SAPS="$SOURCES $PATCHES"
2733 for SAP in $SAPS; do
2737 "list-sources-local-paths" )
2740 DONT_PRINT_REVISION="yes"
2743 for SAP in $SOURCES $PATCHES; do
2744 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2747 "list-sources-distfiles-paths" )
2750 DONT_PRINT_REVISION="yes"
2753 for SAP in $SOURCES $PATCHES; do
2754 if [ -n "$(src_md5 "$SAP")" ]; then
2755 distfiles_path "$SAP"
2759 "list-sources-distfiles" )
2762 DONT_PRINT_REVISION="yes"
2765 for SAP in $SOURCES $PATCHES; do
2766 if [ -n "$(src_md5 "$SAP")" ]; then
2767 distfiles_url "$SAP"
2771 "list-sources-cvs" )
2774 DONT_PRINT_REVISION="yes"
2777 for SAP in $SOURCES $PATCHES; do
2778 if [ -z "$(src_md5 "$SAP")" ]; then
2779 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2793 echo "$VERSIONSTRING"
2797 if [ -z "$SPECFILE" ]; then
2798 Exit_error err_no_spec_in_cmdl
2800 get_spec > /dev/null
2808 if [ -z "$SPECFILE" ]; then
2809 Exit_error err_no_spec_in_cmdl
2811 get_spec > /dev/null
2816 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2817 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2821 # vi:syntax=sh:ts=4:sw=4:noet