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-2021 Free Penguins".
43 # Clean PATH without /usr/local or user paths
44 CLEAN_PATH="/usr/sbin:/usr/bin:/sbin:/bin:/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="PLD/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 # Note the *single* quotes, this allows using shell variables expanded at build time
81 # Example: LOGFILE='../log.$PACKAGE_NAME'
82 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
83 # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
84 # Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
85 # Example: LOGFILE='.log.$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.$TARGET.$DATE'
88 # use teeboth Perl wrapper
89 # temporary option to disable if broken
104 # create symlinks for tools in PACKAGE_DIR, see get_spec()
117 # use lftp by default when available
118 test -z "${USE_LFTP+x}" && lftp --version > /dev/null 2>&1 && USE_LFTP=yes
119 PARALLEL_DOWNLOADS=10
121 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
126 GIT_SERVER="git://git.pld-linux.org"
127 GIT_PUSH="git@git.pld-linux.org"
128 PACKAGES_DIR="packages"
137 DISTFILES_SERVER="://distfiles.pld-linux.org"
138 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
143 FAIL_IF_NO_SOURCES="yes"
145 # let get_files skip over files which are present to get those damn files fetched
146 SKIP_EXISTING_FILES="no"
149 # should the specfile be restored if upgrade failed?
150 REVERT_BROKEN_UPGRADE="yes"
152 if rpm --specsrpm 2>/dev/null; then
153 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
154 FETCH_BUILD_REQUIRES_RPMSPEC_BINARY="no"
155 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
156 elif [ -x /usr/bin/rpmspec ]; then
157 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
158 FETCH_BUILD_REQUIRES_RPMSPEC_BINARY="yes"
159 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
161 if [ -x /usr/bin/rpm-getdeps ]; then
162 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
164 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
168 UPDATE_POLDEK_INDEXES_OPTS=""
170 # Here we load saved user environment used to
171 # predefine options set above, or passed to builder
173 # This one reads global system environment settings:
174 if [ -f ~/etc/builderrc ]; then
177 # And this one cascades settings using user personal
179 # Example of ~/.builderrc:
181 #UPDATE_POLDEK_INDEXES="yes"
182 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
183 #FETCH_BUILD_REQUIRES="yes"
184 #REMOVE_BUILD_REQUIRES="force"
186 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
189 if [ "$(id -u )" != "0" ]; then
193 if [ -n "$HOME_ETC" ]; then
194 USER_CFG="$HOME_ETC/.builderrc"
195 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
197 USER_CFG=~/.builderrc
198 BUILDER_MACROS=~/.builder-rpmmacros
201 [ -f "$USER_CFG" ] && . "$USER_CFG"
203 if [ "$SCHEDTOOL" = "auto" ]; then
204 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
205 SCHEDTOOL="schedtool -B -e"
211 if [ -n "$USE_PROZILLA" ]; then
213 elif [ -n "$USE_AXEL" ]; then
215 elif [ -n "$USE_LFTP" ]; then
221 GETLOCAL=${GETLOCAL:-cp -a}
229 if [ -d $HOME/rpm/SOURCES ]; then
230 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
231 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
235 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
236 POLDEK_CMD="$SU_SUDO /usr/bin/poldek"
239 # TODO: what this function does?
242 if [ -n "$LOGFILE" ]; then
243 LOG=`eval echo $LOGFILE`
244 if [ -n "$LASTLOG_FILE" ]; then
245 echo "LASTLOG=$LOG" > $LASTLOG_FILE
247 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
248 # FIXME $exit_pldk undefined
251 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
252 return `cat ${RES_FILE}`
257 #---------------------------------------------
260 download_prozilla() {
261 local outfile=$1 url=$2 retval
263 proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS -O "$outfile" "$url"
270 local outfile=$1 url=$2 retval
272 axel -a $AXEL_OPTS -o "$outfile" "$url"
279 local outfile=$1 url=$2 retval wget_help
280 if [ -z "${WGET_OPTS_SET+x}" ]; then
281 wget_help="$(wget --help 2>&1)"
282 echo "$wget_help" | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
283 echo "$wget_help" | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
284 echo "$wget_help" | grep -q -- ' --no-iri ' && WGET_OPTS="$WGET_OPTS --no-iri"
285 WGET_OPTS="-c -nd -t$WGET_RETRIES $WGET_OPTS --user-agent=$USER_AGENT $IPOPT --passive-ftp"
289 wget $WGET_OPTS -O "$outfile" "$url"
291 if [ $retval -ne 0 ]; then
292 if [ "`echo $url | grep -E 'ftp://'`" ]; then
293 ${GETURI} -O "$outfile" "$url"
301 local outfile=$1 url=$2 retval tmpfile
302 tmpfile=$(tempfile) || exit 1
304 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
305 $([ "$IPOPT" = "-4" ] && echo "set dns:order \"inet\";")
306 $([ "$IPOPT" = "-6" ] && echo "set dns:order \"inet6\";")
307 set ssl:verify-certificate no;
308 set net:max-retries $WGET_RETRIES;
309 set http:user-agent \"$USER_AGENT\";
310 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
314 if [ $retval -eq 0 ]; then
315 mv -f "$tmpfile" "$outfile"
323 if [ -n "$DEBUG" ]; then set -xv; fi
325 # to make this output parseable by bash-completion _parse_help()
326 # if the line contains short and long option, it will take only the long option
327 # but if you want both being completed, put the short option to separate line
329 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
330 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
331 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
332 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
333 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
334 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
335 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
336 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
337 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
338 <package>[.spec][:tag]
340 -4 - force IPv4 when transferring files
341 -6 - force IPv6 when transferring files
343 --update-md5 - update md5 comments in spec, implies -nd -ncs
345 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
346 --all-branches - make shallow fetch of all branches; --depth required
347 -n5, --no-md5 - ignore md5 comments in spec
348 -D, --debug - enable builder script debugging mode,
349 -debug - produce rpm debug package (same as --opts -debug)
350 -V, --version - output builder version string
351 --short-version - output builder short version
352 -a - try add new package to PLD repo.
355 - get all files from PLD repo or HTTP/FTP and build package
357 -bb - get all files from PLD repo or HTTP/FTP and build binary
358 only package from <package>.spec,
359 -bp - execute the %prep phase of <package>.spec,
360 -bc - execute the %build phase of <package>.spec,
361 -bi - execute the %install phase of <package>.spec
362 -bl - execute the %files phase of <package>.spec
363 -bs - get all files from PLD repo or HTTP/FTP and only pack
365 --short-circuit - short-circuit build
366 -B, --branch - add branch
368 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
369 may be used with building process.
370 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
371 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
372 -cf, --cvs-force - use -f when tagging
373 --define '<macro> <value>'
374 - define a macro <macro> with value <value>,
375 --depth <number> - make shallow fetch
376 --alt_kernel <kernel>
377 - same as --define 'alt_kernel <kernel>'
378 --nodeps - rpm won't check any dependences
380 --get - get <package>.spec and all related files from PLD repo
381 -h, --help - this message,
382 -j N - set %_smp_mflags to propagate concurrent jobs
383 --ftp - use FTP protocol to access distfiles server
384 --http - use HTTP protocol to access distfiles server
385 -l <logfile>, --logtofile=<logfile>
388 - don't pull from PLD repo
389 -nd, --no-distfiles - don't download from distfiles
390 -nm, --no-mirrors - don't download from mirror, if source URL is given,
391 -nu, --no-urls - don't try to download from FTP/HTTP location,
392 -ns, --no-srcs - don't download Sources/Patches
393 -ns0, --no-source0 - don't download Source0
394 -nn, --no-net - don't download anything from the net
395 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
396 -pm, --prefer-mirrors
397 - prefer mirrors (if any) over distfiles for SOURCES
398 --no-init - don't initialize builder paths (SPECS and SOURCES)
400 --skip-existing-files
401 - skip existing files in get_files
402 --opts <rpm opts> - additional options for rpm
403 -q, --quiet - be quiet,
404 --date yyyy-mm-dd - build package using resources from specified date,
405 -r <tag>, --cvstag <ref>
406 - build package using resources from specified branch/tag,
407 -A - build package using master branch as any sticky tags/branch/date being reset.
408 -R, --fetch-build-requires
409 - fetch what is BuildRequired,
410 -RB, --remove-build-requires
411 - remove all you fetched with -R or --fetch-build-requires
412 remember, this option requires confirmation,
413 -FRB, --force-remove-build-requires
414 - remove all you fetched with -R or --fetch-build-requires
415 remember, this option works without confirmation,
416 -sd, --source-distfiles
417 - list sources available from distfiles (intended for offline
418 operations; does not work when Icon field is present
419 but icon file is absent),
420 -sc, --source-cvs - list sources available from PLD repo
421 -sdp, --source-distfiles-paths
422 - list sources available from distfiles -
423 paths relative to distfiles directory (intended for offline
424 operations; does not work when Icon field is present
425 but icon file is absent),
426 -sf, --source-files - list sources - bare filenames (intended for offline
427 operations; does not work when Icon field is present
428 but icon file is absent),
430 - list sources - filenames with full local paths (intended for
431 offline operations; does not work when Icon field is present
432 but icon file is absent),
433 -su, --source-urls - list urls - urls to sources and patches
434 intended for copying urls with spec with lots of macros in urls
435 -T <tag> , --tag <tag>
436 - add git tag <tag> for files,
437 -Tvs, --tag-version-stable
438 - add git tags STABLE and NAME-VERSION-RELEASE for files,
440 - add git tag STABLE for files,
442 --tag-version - add git tag NAME-VERSION-RELEASE for files,
443 -Tp, --tag-prefix <prefix>
444 - add <prefix> to NAME-VERSION-RELEASE tags,
445 -tt, --test-tag <prefix>
446 - fail if tag is already present,
447 -ir, --integer-release-only
448 - allow only integer and snapshot releases
449 -v, --verbose - be verbose,
450 -u, --try-upgrade - check version, and try to upgrade package
451 -un, --try-upgrade-with-float-version
452 - as above, but allow float version
453 php-pear-Services_Digg/
454 --upgrade-version - upgrade to specified version in try-upgrade
455 -U, --update - refetch sources, don't use distfiles, and update md5 comments
456 -Upi, --update-poldek-indexes
457 - refresh or make poldek package index files.
459 --skip-patch <patchnumber>
460 - don't apply <patchnumber>. may be repeated.
462 --nopatch <patchnumber>
463 - abort instead of applying patch <patchnumber>
465 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
466 --show-bconds - show available conditional builds, which can be used
467 - with --with and/or --without switches.
468 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
469 In other words, the output is parseable by scripts.
470 --show-avail-bconds - show available bconds
473 - conditional build package depending on %_with_<feature>/
474 %_without_<feature> macro switch. You may now use
475 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
476 constructions. Set GROUP_BCONDS to yes to make use of it.
477 --target <platform>, --target=<platform>
478 - build for platform <platform>.
479 --init-rpm-dir, --init
480 - initialize ~/rpm directory structure
487 v=$(LC_ALL=C LANG=C rpm --version 2>&1)
488 v=${v#RPM version } # rpm 4
489 v=${v#rpm \(RPM\) } # rpm 5
499 echo "ERROR: unsupported RPM version $v" >&2
504 # create tempfile. as secure as possible
506 local prefix=builder.$PACKAGE_NAME${1:+.$1}
507 mktemp --tmpdir -t $prefix.XXXXXX || echo ${TMPDIR:-/tmp}/$prefix.$RANDOM.$$
511 local prefix=builder.$PACKAGE_NAME${1:+.$1}
512 mktemp --tmpdir -d $prefix.XXXXXX
515 # inserts git log instead of %changelog
516 # @output directory containing modified specfile
518 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
520 # allow this being customized
521 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
523 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
524 # otherwise i'd use --date=iso here
525 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
526 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
527 # NOTE: changelog date is always in UTC for rpmbuild
528 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
529 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
531 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
532 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
535 # add link to full git logs
536 local giturl="http://git.pld-linux.org/?p=packages/${SPECFILE%.spec}.git;a=log"
537 if [ -n "$CVSTAG" ]; then
538 giturl="$giturl;h=$CVSTAG"
540 local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
541 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
542 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
547 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
548 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
552 " > $specdir/$SPECFILE
553 rm -f $gitlog $speclog
557 # @param string logfile
558 # @param varargs... commands to execute
561 # use teeboth from toys/cleanbuild, if available and enabled
562 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
566 local efile rc logfile=$1; shift
567 if [ "$logfile" ]; then
569 { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile
580 # change dependency to specname
582 # - perl(Package::Name) -> perl-Package-Name
586 if [ $# -gt 0 ]; then
592 echo "$DEPS" | tr ' ' '\n' | sed -re '
595 s/perl\((.*)\)/perl-\1/
599 s/apache\(EAPI\)-devel/apache-devel/
601 s/^db-devel/db5.3-devel/
602 s/libjpeg-devel/libjpeg-turbo-devel/
606 update_shell_title() {
608 local len=${COLUMNS:-80}
609 local msg="$(echo "$*" | cut -c-$len)"
611 if [ -n "$BE_VERBOSE" ]; then
612 echo >&2 "$(date +%s.%N) $*"
615 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
617 if [ -n "$PACKAGE_NAME" ]; then
618 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
623 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
624 msg=$(echo $msg | tr -d '\n\r')
627 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
630 echo >&2 -ne "\033]0;$msg\007"
636 # set TARGET from BuildArch: from SPECFILE
638 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
639 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
641 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
645 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
647 TARGET_SWITCH="--target=$TARGET" ;;
653 # runs rpm with minimal macroset
655 # TODO: move these to /usr/lib/rpm/macros
656 cat > $BUILDER_MACROS <<'EOF'
657 %x8664 x86_64 amd64 ia32e
660 %bootstrap_release() %{1}
661 %requires_releq_kernel_up(s:n:) %{nil}
662 %requires_releq_kernel_smp(s:n:) %{nil}
663 %requires_releq_kernel(s:n:) %{nil}
664 %requires_releq() %{nil}
665 %pyrequires_eq() %{nil}
666 %requires_eq() %{nil}
667 %requires_eq_to() %{nil}
668 %requires_ge() %{nil}
669 %requires_ge_to() %{nil}
670 %requires_ge() %{nil}
671 %releq_kernel_up(n:) ERROR
672 %releq_kernel_smp(n:) ERROR
673 %releq_kernel(n:) ERROR
674 %py_postclean(x:) ERROR
678 %ruby_ver_requires_eq() %{nil}
679 %ruby_mod_ver_requires_eq() %{nil}
680 %__php_api_requires() %{nil}
681 %php_major_version ERROR
682 %php_api_version ERROR
683 %requires_xorg_xserver_extension %{nil}
684 %requires_xorg_xserver_xinput %{nil}
685 %requires_xorg_xserver_font %{nil}
686 %requires_xorg_xserver_videodrv %{nil}
688 %perl_vendorarch ERROR
689 %perl_vendorlib ERROR
690 # damn. need it here! - copied from /usr/lib/rpm/macros.build
691 %tmpdir %(echo "${TMPDIR:-/tmp}")
692 %patchset_source(f:b:) %(
693 base=%{-b*}%{!-b*:10000};
694 start=$(expr $base + %1);
695 end=$(expr $base + %{?2}%{!?2:%{1}});
696 # we need to call seq twice as it doesn't allow two formats
697 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
698 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
699 paste %{tmpdir}/__ps{1,2};
700 rm -f %{tmpdir}/__ps{1,2};
703 %add_etc_shells(p) %{p:<lua>}
704 %remove_etc_shells(p) %{p:<lua>}
705 %lua_add_etc_shells() %{nil}
706 %lua_remove_etc_shells() %{nil}
708 %buildrequires_jdk %{nil}
709 %pear_package_print_optionalpackages %{nil}
711 if [ "$NOINIT" = "yes" ] ; then
712 cat >> $BUILDER_MACROS <<'EOF'
718 local safe_macrofiles
719 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
720 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
722 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --load "$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
727 if [ -n "$DEBUG" ]; then
732 if [ -x /usr/bin/rpm-specdump ]; then
733 update_shell_title "cache_rpm_dump using rpm-specdump command"
734 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
736 update_shell_title "cache_rpm_dump using rpmbuild command"
739 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
740 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
746 ARGS='--nodigest --nosignature --nobuild'
749 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
751 if [ $? -gt 0 ]; then
752 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
754 Exit_error err_build_fail
757 # make small dump cache
758 rpm_dump_cache=`echo "$rpm_dump" | awk '
759 $2 ~ /^SOURCEURL/ {print}
760 $2 ~ /^PATCHURL/ {print}
761 $2 ~ /^nosource/ {print}
762 $2 ~ /^PACKAGE_/ {print}
766 update_shell_title "cache_rpm_dump: OK!"
770 if [ -z "$rpm_dump_cache" ] ; then
771 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
773 echo "$rpm_dump_cache"
777 update_shell_title "get icons"
778 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
779 if [ -z "$ICONS" ]; then
783 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
787 update_shell_title "parsing specfile"
788 if [ -n "$DEBUG" ]; then
793 # icons are needed for successful spec parse
799 if rpm_dump | grep -qEi ":.*nosource.*1"; then
800 FAIL_IF_NO_SOURCES="no"
803 if [ "$NOSRCS" != "yes" ]; then
804 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
805 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
806 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
809 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
810 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
811 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
813 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
814 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
817 if [ -n "$BE_VERBOSE" ]; then
818 echo "- Sources : `nourl $SOURCES`"
819 if [ -n "$PATCHES" ]; then
820 echo "- Patches : `nourl $PATCHES`"
822 echo "- Patches : *no patches needed*"
824 if [ -n "$ICONS" ]; then
825 echo "- Icon : `nourl $ICONS`"
827 echo "- Icon : *no package icon*"
829 echo "- Name : $PACKAGE_NAME"
830 echo "- Version : $PACKAGE_VERSION"
831 echo "- Release : $PACKAGE_RELEASE"
834 update_shell_title "parse_spec: OK!"
837 # aborts program abnormally
840 echo >&2 "$PROGRAM: ERROR: $*"
845 if [ -n "$DEBUG" ]; then
853 "err_no_spec_in_cmdl" )
854 remove_build_requires
855 echo >&2 "ERROR: spec file name not specified."
857 "err_invalid_cmdline" )
858 echo >&2 "ERROR: invalid command line arg ($2)."
860 "err_no_spec_in_repo" )
861 remove_build_requires
862 echo >&2 "Error: spec file not stored in repository."
868 "err_no_source_in_repo" )
869 remove_build_requires
870 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
872 "err_cvs_add_failed" )
873 echo >&2 "Error: failed to add package to PLD repo."
876 remove_build_requires
877 echo >&2 "Error: package build failed. (${2:-no more info})"
879 "err_no_package_data" )
880 remove_build_requires
881 echo >&2 "Error: couldn't get out package name/version/release from spec file."
884 remove_build_requires
885 echo >&2 "Tag ${2} already exists"
888 remove_build_requires
889 echo >&2 "Release ${2} not integer and not a snapshot."
891 "err_branch_exists" )
892 remove_build_requires
893 echo >&2 "Tree branch already exists (${2})."
896 remove_build_requires
897 echo >&2 "Error: conditions reject building this spec (${2})."
899 "err_remote_problem" )
900 remove_build_requires
901 echo >&2 "Error: problem with remote (${2})"
904 echo >&2 "Error: cannot checkout $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 if git rev-parse --verify -q "$CVSTAG" >/dev/null; then
1080 # checkout only if differs, so this will not trash git reflog
1081 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1082 git checkout "$CVSTAG" --
1084 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1085 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1087 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1088 Exit_error "err_no_checkut" "$CVSTAG"
1091 git merge --ff-only '@{u}'
1092 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1093 if [ -n "$CVSDATE" ]; then
1094 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1098 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1099 Exit_error err_no_spec_in_repo "$PACKAGE_DIR/$SPECFILE"
1102 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1103 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1106 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1111 # find mirrors in this order. first match wins:
1112 # - package dir (~/rpm/packages/foo)
1113 # - repository dir (~/rpm/packages)
1114 # - tools dir dir (~/rpm/packages/rpm-build-tools)
1118 update_shell_title "find_mirror[$url][$REPO_DIR]"
1120 # NOTE: as while loop runs in subshell,
1121 # we use exit 2 to indicate that the match was found
1122 # otherwise we end up outputing mirror url and origin url.
1124 local origin mirror name rest ol prefix
1126 cat "$PACKAGE_DIR/mirrors" "$REPO_DIR/mirrors" "$REPO_DIR/../rpm-build-tools/mirrors" /dev/null 2>/dev/null | \
1127 while read origin mirror name rest; do
1128 # skip comments and empty lines
1129 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1132 ol=$(echo -n "$origin" | wc -c)
1133 prefix=$(echo -n "$url" | head -c $ol)
1134 if [ "$prefix" = "$origin" ] ; then
1135 suffix=$(echo "$url" | cut -b $((ol+1))-)
1136 echo -n "$mirror$suffix"
1142 # Warning: unpredictable results if same URL used twice
1145 # escape some regexp characters if part of file name
1146 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1149 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1150 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1151 head -n 1 | tr OURCEATH ourceath | xargs
1155 [ "$NO5" = "yes" ] && return
1157 [ -z "$no" ] && return
1161 # use "sources" file from package dir, like vim
1162 if [ -f sources ]; then
1163 md5=$(grep -s -v '^#' sources | \
1164 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1165 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1166 grep -E '^[0-9a-f]{32}$')
1169 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1170 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1172 echo "$md5" | tail -n 1
1177 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1178 if [ -n "$source_md5" ]; then
1181 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1182 if [ -n "$source_md5" ]; then
1185 # we have empty SourceX-md5, but it is still possible
1186 # that we have NoSourceX-md5 AND NoSource: X
1187 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1188 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1196 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1200 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1203 distfiles_attic_url() {
1204 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
1209 [ "$md5" = "" ] || \
1210 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1214 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1215 [ -n "$size" -a "$size" -gt 0 ]
1219 if [ "$CVSIGNORE_DF" != "yes" ]; then
1222 local cvsignore=${PACKAGE_DIR}/.git/info/exclude
1224 # add only if not yet there
1225 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1226 echo "$1" >> $cvsignore
1230 # returns true if "$1" is ftp, http or https protocol url
1233 ftp://*|http://*|https://*)
1241 if [ $# -eq 0 ]; then
1245 update_shell_title "update md5"
1246 if [ -n "$DEBUG" ]; then
1253 # pass 1: check files to be fetched
1257 local fp=$(nourl "$i")
1258 local srcno=$(src_no "$i")
1259 if [ -n "$ADD5" ]; then
1260 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1261 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1262 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1264 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1266 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1267 need_files="$need_files $i"
1271 # pass 1a: get needed files
1272 if [ "$need_files" ]; then
1273 get_files $need_files
1276 # pass 2: proceed with md5 adding or updating
1278 local fp=$(nourl "$i")
1279 local srcno=$(src_no "$i")
1280 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1281 if [ -z "$md5" ]; then
1282 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1284 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1285 local tag="# $srcno-md5:\t"
1286 if [[ "$md5" == *NoSource* ]]; then
1287 tag="# No$srcno-md5:\t"
1288 elif [ -n "$USEDIGEST" ]; then
1289 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1291 md5=$(md5sum "$fp" | cut -f1 -d' ')
1292 echo "Updating $srcno ($md5: $fp)."
1294 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1295 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1297 $PACKAGE_DIR/$SPECFILE
1304 [ "$NO5" = "yes" ] && return
1306 update_shell_title "check md5"
1310 if ! good_md5 "$i"; then
1311 echo -n "MD5 sum mismatch."
1314 if ! good_size "$i"; then
1315 echo -n "0 sized file."
1319 if [ $bad -eq 1 ]; then
1320 echo " Use -U to refetch sources,"
1321 echo "or -5 to update md5 sums, if you're sure files are correct."
1322 Exit_error err_no_source_in_repo $i
1328 update_shell_title "get_files"
1330 if [ -n "$DEBUG" ]; then
1335 if [ $# -gt 0 ]; then
1339 local get_files_cvs=""
1343 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1344 update_shell_title "$i"
1345 local fp=`nourl "$i"`
1346 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1351 local srcmd5=$(src_md5 "$i")
1353 # we know if source/patch is present in cvs/distfiles
1354 # - has md5 (in distfiles)
1355 # - in cvs... ideas?
1357 # CHECK: local file didn't exist or always cvs up (first) requested.
1358 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1359 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1360 echo "Warning: no URL given for $i"
1364 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1365 if good_md5 "$i" && good_size "$i"; then
1366 echo "$fp having proper md5sum already exists"
1370 # optionally prefer mirror over distfiles if there's mirror
1371 # TODO: build url list and then try each url from the list
1372 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1375 url=$(distfiles_url "$i")
1378 url_attic=$(distfiles_attic_url "$i")
1380 # is $url local file?
1381 if [[ "$url" = [./]* ]]; then
1382 update_shell_title "${GETLOCAL%% *}: $url"
1383 ${GETLOCAL} $url $target
1386 # make shorter message for distfiles urls
1387 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1388 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1389 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1392 update_shell_title "${GETURI%% *}: $uri"
1393 ${GETURI} "$target" "$url"
1397 if [ ! -s "$target" ]; then
1399 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1400 update_shell_title "${GETLOCAL%% *}: $url_attic"
1401 ${GETLOCAL} $url_attic $target
1403 update_shell_title "${GETURI%% *}: $url_attic"
1404 ${GETURI} "$target" "$url_attic"
1405 test -s "$target" || rm -f "$target"
1409 if [ -s "$target" ]; then
1410 cvsignore_df $target
1417 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1418 if [ -z "$NOMIRRORS" ]; then
1419 im=$(find_mirror "$i")
1423 update_shell_title "${GETURI%% *}: $im"
1424 ${GETURI} "$target" "$im"
1425 test -s "$target" || rm -f "$target"
1428 if [ "$cvsup" = 1 ]; then
1434 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1435 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1436 Exit_error err_no_source_in_repo $i
1439 # we check md5 here just only to refetch immediately
1440 if good_md5 "$i" && good_size "$i"; then
1442 elif [ "$FROM_DISTFILES" = 1 ]; then
1443 # wrong md5 from distfiles: remove the file and try again
1445 echo "MD5 sum mismatch. Trying full fetch."
1448 update_shell_title "${GETURI%% *}: $url"
1449 ${GETURI} "$target" "$url"
1450 if [ ! -s "$target" ]; then
1452 update_shell_title "${GETURI%% *}: $url_attic"
1453 ${GETURI} "$target" "$url_attic"
1455 test -s "$target" || rm -f "$target"
1458 SHELL_TITLE_PREFIX=""
1461 if [ "$CHMOD" = "yes" ]; then
1462 CHMOD_FILES=$(nourl "$@")
1463 if [ -n "$CHMOD_FILES" ]; then
1464 chmod $CHMOD_MODE $CHMOD_FILES
1471 # If tag exists and points to other commit exit with error
1472 # If it existsts and points to HEAD return 1
1473 # If it doesn't exist return 0
1475 local sha1=$(git rev-parse HEAD)
1476 echo "Searching for tag $_tag..."
1477 if [ -n "$DEPTH" ]; then
1478 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1480 local ref=$(git show-ref -s "refs/tags/$_tag")
1482 [ -z "$ref" ] && return 0
1483 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1488 if [ -n "$DEBUG" ]; then
1493 # Check whether first character of PACKAGE_NAME is legal for tag name
1494 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1498 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1499 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1501 # Remove @kernel.version_release from TAGVER because tagging sources
1502 # could occur with different kernel-headers than kernel-headers used at build time.
1503 # besides, %{_kernel_ver_str} is not expanded.
1505 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1506 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1513 if [ -n "$DEBUG" ]; then
1518 echo "Version: $PACKAGE_VERSION"
1519 echo "Release: $PACKAGE_RELEASE"
1522 if [ "$TAG_VERSION" = "yes" ]; then
1525 if [ -n "$TAG" ]; then
1530 local OPTIONS="tag $CVS_FORCE"
1534 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1535 update_shell_title "tag sources: $_tag"
1536 git $OPTIONS $_tag || exit
1537 git push $IPOPT $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1539 echo "Tag $_tag already exists and points to the same commit"
1545 echo "Git branch: $TAG"
1548 if [ -n "$DEBUG" ]; then
1553 local OPTIONS="branch $CVS_FORCE"
1556 git $OPTIONS $TAG || exit
1560 # this function should exit early if package can't be built for this arch
1561 # this avoids unneccessary BR filling.
1564 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1566 if [ $ret -ne 0 ]; then
1578 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1579 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1585 local ver="$2" subver=$ver
1586 local newver="$3" newsubver=$newver
1588 # try handling subver, everything that's not numeric-dotted in version
1589 if grep -Eq '%define\s+subver' $specfile; then
1590 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1592 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1593 newver=${newver%$newsubver}
1596 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1597 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1598 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1602 # try to upgrade .spec to new version
1603 # if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1605 # return 1: if .spec was updated
1606 # return 0: no changes to .spec
1607 # exit 1 in case of error
1609 if [ -z "$TRY_UPGRADE" ]; then
1613 local TNOTIFY TNEWVER TOLDVER
1614 update_shell_title "build_package: try_upgrade"
1618 if [ "$UPGRADE_VERSION" ]; then
1619 TNEWVER=$UPGRADE_VERSION
1620 echo "Updating spec file to version $TNEWVER"
1622 if [ -n "$FLOAT_VERSION" ]; then
1623 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1625 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1628 # pldnotify does not set exit codes, but it has match for ERROR
1629 # in output which means so.
1630 if [[ "$TNOTIFY" = *ERROR* ]]; then
1635 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1636 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1638 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1641 if [ -z "$TNEWVER" ]; then
1645 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1646 cp -f $SPECFILE $SPECFILE.bak
1649 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1650 set_release $SPECFILE $PACKAGE_RELEASE 1
1652 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1653 echo >&2 "Upgrading version failed, you need to update spec yourself"
1660 update_shell_title "build_package"
1661 if [ -n "$DEBUG" ]; then
1670 BUILD_SWITCH="-ba" ;;
1672 BUILD_SWITCH="-bb" ;;
1674 BUILD_SWITCH="-bs --nodeps" ;;
1676 BUILD_SWITCH="-bp --nodeps" ;;
1678 BUILD_SWITCH="-bc" ;;
1680 BUILD_SWITCH="-bi" ;;
1682 BUILD_SWITCH="-bl" ;;
1686 update_shell_title "build_package: $COMMAND"
1687 local logfile retval
1688 if [ -n "$LOGFILE" ]; then
1689 logfile=`eval echo $LOGFILE`
1690 if [ -d "$logfile" ]; then
1691 echo "Log file $logfile is a directory."
1692 echo "Parse error in the spec?"
1693 Exit_error err_build_fail
1695 if [ -n "$LASTLOG_FILE" ]; then
1696 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1700 # unset these, should not be exposed to builder shell!
1701 unset GIT_WORK_TREE GIT_DIR
1702 # these are set by jenkins
1703 unset GIT_PREVIOUS_COMMIT GIT_URL GIT_PREVIOUS_SUCCESSFUL_COMMIT GIT_BRANCH GIT_COMMIT
1704 # this may be set by user
1706 # may be set by user
1707 unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_TESTING_PORCELAIN_COMMAND_LIST GIT_EDITOR
1708 # fail if something still set
1709 env | grep ^GIT_ && Exit_error err_build_fail "One of GIT_* env variables is still set. The builder script needs to be updated to unset that variable. In the meantime, unset it manually."
1711 local specdir=$(insert_gitlog $SPECFILE)
1713 # FIXME: eval here is exactly why?
1714 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
1718 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1719 if [ "$retval" -eq "0" ]; then
1720 mv $logfile $LOGDIROK
1722 mv $logfile $LOGDIRFAIL
1726 if [ "$retval" -ne "0" ]; then
1727 if [ -n "$TRY_UPGRADE" ]; then
1728 echo "\nUpgrade package to new version failed."
1729 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1730 echo "Restoring old spec file."
1731 mv -f $SPECFILE.bak $SPECFILE
1735 Exit_error err_build_fail
1741 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1744 install_required_packages() {
1749 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1752 /^%changelog/ { exit }
1754 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1755 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1756 gsub(/[ \t]+/, "_", bcond);
1758 }' $SPEC | LC_ALL=C sort -u
1762 # expand bconds from ~/.bcondrc
1763 # The file structure is like gentoo's package.use:
1766 # samba -mysql -pgsql
1767 # w32codec-installer license_agreement
1770 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1776 SN=${SPECFILE%%\.spec}
1778 local bcondrc=$HOME/.bcondrc
1779 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1781 local bcond_avail=$(find_spec_bcond $SPECFILE)
1783 while read pkg flags; do
1785 [[ "$pkg" == \#* ]] && continue
1787 # any package or current package?
1788 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1789 for flag in $flags; do
1790 local opt=${flag#[+-]}
1792 # use only flags which are in this package.
1793 if [[ $bcond_avail = *${opt}* ]]; then
1794 if [[ $flag = -* ]]; then
1795 if [[ $BCOND != *--with?${opt}* ]]; then
1796 BCOND="$BCOND --without $opt"
1799 if [[ $BCOND != *--without?${opt}* ]]; then
1800 BCOND="$BCOND --with $opt"
1807 update_shell_title "parse ~/.bcondrc: DONE!"
1810 set_bconds_values() {
1811 update_shell_title "set bcond values"
1813 AVAIL_BCONDS_WITHOUT=""
1814 AVAIL_BCONDS_WITH=""
1816 if grep -Eq '^# *_with' ${SPECFILE}; then
1817 echo >&2 "ERROR: This spec has old style bconds."
1821 if ! grep -q '^%bcond' ${SPECFILE}; then
1825 local bcond_avail=$(find_spec_bcond $SPECFILE)
1826 process_bcondrc "$SPECFILE"
1828 update_shell_title "parse bconds"
1831 for opt in $bcond_avail; do
1834 bcond=${opt#without_}
1836 *--without?${bcond}\ *|*--without?${bcond})
1837 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1840 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1847 *--with?${bcond}\ *|*--with?${bcond})
1848 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1851 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1856 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1865 update_shell_title "run_sub_builder $package_name"
1867 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1868 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
1869 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1870 # jakby nie bylo tego kawalka kodu.
1872 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1873 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
1877 # kurwa. translate that ^^^^
1881 # Istnieje taki spec? ${package}.spec
1882 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1883 parent_spec_name=${package}.spec
1884 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1885 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1887 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1892 if [ "${parent_spec_name}" != "" ]; then
1893 spawn_sub_builder $parent_spec_name
1895 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1898 # install package with poldek
1899 # @return exit code from poldek
1901 # this requires following sudo rules:
1902 # - poldek --noask --caplookup -ug
1904 LC_ALL=C LANG=C $POLDEK_CMD --noask --caplookup --uniq -ug "$@"
1909 # this requires following sudo rules:
1910 # - poldek -q --update --upa
1911 install_packages() {
1912 # sync poldek indexes once per invocation
1913 if [ -z "$package_indexes_updated" ]; then
1914 update_shell_title "poldek: update indexes"
1915 $POLDEK_CMD -q --update --upa --mo=nodesc
1916 package_indexes_updated=true
1919 update_shell_title "install packages: $*"
1920 poldek_install "$@" && return
1922 # retry install, install packages one by one
1923 # this is slower one
1925 for package in $*; do
1926 package=$(depspecname $package)
1927 update_shell_title "install package: $package"
1928 poldek_install "$package" || rc=$?
1933 uninstall_packages() {
1934 update_shell_title "uninstall packages: $*"
1935 $POLDEK_CMD --noask --nofollow -ev "$@"
1938 spawn_sub_builder() {
1940 update_shell_title "spawn_sub_builder $package_name"
1943 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1944 sub_builder_opts="${sub_builder_opts} -R"
1946 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1947 sub_builder_opts="${sub_builder_opts} -RB"
1948 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1949 sub_builder_opts="${sub_builder_opts} -FRB"
1951 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1952 sub_builder_opts="${sub_builder_opts} -Upi"
1956 ./builder ${sub_builder_opts} "$@"
1959 remove_build_requires() {
1960 if [ "$INSTALLED_PACKAGES" != "" ]; then
1961 case "$REMOVE_BUILD_REQUIRES" in
1963 run_poldek --noask -ve $INSTALLED_PACKAGES
1966 run_poldek --ask -ve $INSTALLED_PACKAGES
1969 echo You may want to manually remove following BuildRequires fetched:
1970 echo $INSTALLED_PACKAGES
1971 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1978 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1979 if [ "$BCOND" ]; then
1981 echo "Building $SPECFILE with the following conditional flags:"
1985 echo "No conditional flags passed"
1988 echo "from available:"
1989 echo "--with :\t$AVAIL_BCONDS_WITH"
1990 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1995 display_branches() {
1996 echo -n "Available branches: "
1997 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
2000 # checks a given list of packages/files/provides against current rpmdb.
2001 # outputs all dependencies which current rpmdb doesn't satisfy.
2002 # input can be either STDIN or parameters
2006 if [ $# -gt 0 ]; then
2012 out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1)
2015 echo "$out" | awk '/^no package provides/ { print $NF }'
2017 # other deps (files)
2018 echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p'
2021 # checks if given package/files/provides exists in rpmdb.
2022 # input can be either stdin or parameters
2023 # returns packages which are present in the rpmdb
2027 if [ $# -gt 0 ]; then
2033 LC_ALL=C LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
2036 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
2037 install_build_requires_rpmdeps() {
2039 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
2040 # TODO: Conflicts list doesn't check versions
2041 CNFL=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
2042 DEPS=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
2044 if [ "$FETCH_BUILD_REQUIRES_RPMSPEC_BINARY" = "yes" ]; then
2045 CNFL=$(eval rpmspec --query --buildconflicts $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '{print $1}' | _rpm_cnfl_check | xargs);
2046 DEPS=$(eval rpmspec --query --buildrequires $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '{print $1}' | _rpm_prov_check | xargs);
2048 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2049 CNFL=$(eval rpm -q --specsrpm --conflicts $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
2050 DEPS=$(eval rpm -q --specsrpm --requires $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
2053 if [ -n "$CNFL" ]; then
2054 echo "Uninstall conflicting packages: $CNFL"
2055 uninstall_packages $CNFL
2058 if [ -n "$DEPS" ]; then
2059 echo "Install dependencies: $DEPS"
2060 install_packages $DEPS
2064 fetch_build_requires()
2066 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
2070 update_shell_title "fetch build requires"
2071 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPEC_BINARY" = "yes" ]; then
2072 install_build_requires_rpmdeps
2076 die "need rpm-getdeps tool"
2083 if [ ! -e $localrepo ]; then
2084 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
2085 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2090 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2091 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2092 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2093 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2094 local TEMPLATES=template-specs
2097 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2098 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2101 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2102 init_repository projects/$TEMPLATES ../$TEMPLATES
2103 for a in builder fetchsrc_request compile repackage; do
2104 ln -sf ../rpm-build-tools/${a}.sh $a
2107 ln -sf ../rpm-build-tools/${a} $a
2109 ln -sf ../rpm-build-tools/mirrors mirrors
2116 DONT_PRINT_REVISION="yes"
2118 # remove spec and sources
2119 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
2120 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2121 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2124 #---------------------------------------------
2132 # stuff global $BUILDER_OPTS from env as args
2133 if [ "$BUILDER_OPTS" ]; then
2134 set -- "$BUILDER_OPTS" "$@"
2137 while [ $# -gt 0 ]; do
2144 COMMAND="update_md5"
2149 COMMAND="update_md5"
2158 DEBUG="yes"; shift ;;
2160 COMMAND="version"; shift ;;
2162 COMMAND="short-version"; shift ;;
2169 -b | -ba | --build )
2170 COMMAND="build"; shift ;;
2171 -bb | --build-binary )
2172 COMMAND="build-binary"; shift ;;
2174 COMMAND="build-build"; shift ;;
2176 COMMAND="build-install"; shift ;;
2178 COMMAND="build-list"; shift ;;
2179 -bp | --build-prep )
2180 COMMAND="build-prep"; shift ;;
2181 -bs | --build-source )
2182 COMMAND="build-source"; shift ;;
2184 COMMAND="branch"; shift; TAG="${1}"; shift;;
2186 CLEAN="--clean"; shift ;;
2188 CVS_FORCE="-f"; shift;;
2194 COMMAND="get"; shift ;;
2196 COMMAND="usage"; shift ;;
2198 PROTOCOL="ftp"; shift ;;
2200 PROTOCOL="http"; shift ;;
2202 RPMOPTS="${RPMOPTS} --define \"__jobs $2\""
2206 RPMOPTS="${RPMOPTS} --define \"__jobs ${1#-j}\""
2210 PARALLEL_DOWNLOADS=$2
2214 PARALLEL_DOWNLOADS=${1#-p}
2218 shift; LOGFILE="${1}"; shift ;;
2220 shift; DEF_NICE_LEVEL=${1}; shift ;;
2221 -ske | --skip-existing-files)
2222 SKIP_EXISTING_FILES="yes"; shift ;;
2224 COMMAND="mr-proper"; shift ;;
2225 -ncs | --no-cvs-specs )
2226 NOCVSSPEC="yes"; shift ;;
2227 -nd | --no-distfiles )
2228 NODIST="yes"; shift ;;
2229 -nm | --no-mirrors )
2230 NOMIRRORS="yes"; shift ;;
2232 NOURLS="yes"; shift ;;
2234 NOSRCS="yes"; shift ;;
2235 -ns0 | --no-source0 )
2236 NOSOURCE0="yes"; shift ;;
2245 -pm | --prefer-mirrors )
2248 --noinit | --no-init )
2252 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2254 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2255 --skip-patch | -sp )
2256 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2258 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2261 --with | --without )
2262 case $GROUP_BCONDS in
2266 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2267 while ! `echo ${1}|grep -qE '(^-|spec)'`
2269 BCOND="$BCOND $COND $1"
2273 if [[ "$2" = *,* ]]; then
2274 for a in $(echo "$2" | tr , ' '); do
2275 BCOND="$BCOND $1 $a"
2278 BCOND="$BCOND $1 $2"
2284 shift; TARGET="${1}"; shift ;;
2286 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2288 QUIET="--quiet"; shift ;;
2290 CVSDATE="${2}"; shift 2
2291 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2301 -R | --fetch-build-requires)
2302 FETCH_BUILD_REQUIRES="yes"
2303 NOT_INSTALLED_PACKAGES=
2305 -RB | --remove-build-requires)
2306 REMOVE_BUILD_REQUIRES="nice"
2308 -FRB | --force-remove-build-requires)
2309 REMOVE_BUILD_REQUIRES="force"
2312 COMMAND="list-sources-cvs"
2314 -sd | --source-distfiles)
2315 COMMAND="list-sources-distfiles"
2317 -sdp | --source-distfiles-paths)
2318 COMMAND="list-sources-distfiles-paths"
2320 -sf | --source-files)
2321 COMMAND="list-sources-files"
2323 -lsp | --source-paths)
2324 COMMAND="list-sources-local-paths"
2326 -su | --source-urls)
2327 COMMAND="list-sources-urls"
2329 -Tvs | --tag-version-stable )
2334 -Ts | --tag-stable )
2339 -Tv | --tag-version )
2344 -Tp | --tag-prefix )
2356 -ir | --integer-release-only )
2357 INTEGER_RELEASE="yes"
2360 COMMAND="update_md5"
2365 -Upi | --update-poldek-indexes )
2366 UPDATE_POLDEK_INDEXES="yes"
2368 --init-rpm-dir|--init)
2369 COMMAND="init_rpm_dir"
2371 -u | --try-upgrade )
2372 TRY_UPGRADE="1"; shift ;;
2374 shift; UPGRADE_VERSION="$1"; shift;;
2375 -un | --try-upgrade-with-float-version )
2376 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2378 BE_VERBOSE="1"; shift ;;
2383 if echo "${MACRO}" | grep -q '\W'; then
2384 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2388 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2393 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\""
2397 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2400 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2401 COMMAND="show_bconds"
2405 COMMAND="show_bcond_args"
2408 --show-avail-bconds)
2409 COMMAND="show_avail_bconds"
2414 RPMOPTS="${RPMOPTS} --nodeps"
2417 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2420 Exit_error err_invalid_cmdline "$1"
2423 SPECFILE=${1%/}; shift
2424 # check if specname was passed as specname:cvstag
2425 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2426 CVSTAG="${SPECFILE##*:}"
2427 SPECFILE="${SPECFILE%%:*}"
2429 # always have SPECFILE ending with .spec extension
2430 SPECFILE=${SPECFILE%%.spec}.spec
2431 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2435 if [ "$CVSTAG" ]; then
2436 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2437 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2440 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2441 echo >&2 "--all branches requires --depth <number>"
2442 Exit_error err_invalid_cmdline
2445 if [ -n "$DEBUG" ]; then
2450 if [ -n "$TARGET" ]; then
2453 TARGET_SWITCH="--target $TARGET" ;;
2455 TARGET_SWITCH="--target=$TARGET" ;;
2459 if [ "$SCHEDTOOL" != "no" ]; then
2460 NICE_COMMAND="$SCHEDTOOL"
2462 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2465 # see time(1) for output format that could be used
2466 TIME_COMMAND="time -p"
2468 update_shell_title "$COMMAND"
2472 if [ -z "$SPECFILE" ]; then
2473 Exit_error err_no_spec_in_cmdl
2475 get_spec > /dev/null
2482 if [ -z "$SPECFILE" ]; then
2483 Exit_error err_no_spec_in_cmdl
2485 get_spec > /dev/null
2490 "show_avail_bconds")
2492 if [ -z "$SPECFILE" ]; then
2493 Exit_error err_no_spec_in_cmdl
2496 get_spec > /dev/null
2498 local bcond_avail=$(find_spec_bcond $SPECFILE)
2499 local opt bcond bconds
2500 for opt in $bcond_avail; do
2503 bcond=${opt#without_}
2504 bconds="$bconds $bcond"
2508 bconds="$bconds $bcond"
2511 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2519 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2521 if [ -z "$SPECFILE" ]; then
2522 Exit_error err_no_spec_in_cmdl
2525 # display SMP make flags if set
2526 smp_mflags=$(rpm -E %{?_smp_mflags})
2527 if [ "$smp_mflags" ]; then
2528 echo "builder: SMP make flags are set to $smp_mflags"
2536 if [ "$COMMAND" != "build-source" ]; then
2539 fetch_build_requires
2540 if [ "$INTEGER_RELEASE" = "yes" ]; then
2541 echo "Checking release $PACKAGE_RELEASE..."
2542 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2543 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2547 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2548 if [ -n "$TEST_TAG" ]; then
2549 local TAGVER=`make_tagver`
2550 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2551 # check also tags created in CVS
2552 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2553 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2554 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2555 || Exit_error err_tag_exists $TAGVER_CVS
2556 # - do not allow to build from HEAD when XX-branch exists
2557 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2558 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2559 TAG_BRANCH="${TREE_PREFIX}-branch"
2560 if [ -n "$DEPTH" ]; then
2561 cmd_branches="git ls-remote --heads"
2562 ref_prefix=refs/heads
2564 cmd_branches="git show-ref"
2565 ref_prefix=refs/remotes/${REMOTE_PLD}
2567 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2568 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2569 Exit_error err_branch_exists "$TAG_STATUS"
2575 if [ -n "$NOSOURCE0" ] ; then
2576 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2581 get_files $SOURCES $PATCHES
2582 check_md5 $SOURCES $PATCHES
2585 NODIST="yes" get_files $SOURCES $PATCHES
2586 update_md5 $SOURCES $PATCHES
2590 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2591 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2593 remove_build_requires
2597 if [ -z "$SPECFILE" ]; then
2598 Exit_error err_no_spec_in_cmdl
2607 if [ -z "$SPECFILE" ]; then
2608 Exit_error err_no_spec_in_cmdl
2612 if [ -n "$NEW_REPO" ]; then
2615 for file in $SOURCES $PATCHES; do
2616 if [ -z $(src_md5 "$file") ]; then
2617 git add $file || Exit_error err_no_source_in_repo $file
2619 cvsignore_df `nourl $file`
2623 echo "When you are ready commit your changes and run git push origin master"
2625 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2630 if [ -z "$SPECFILE" ]; then
2631 Exit_error err_no_spec_in_cmdl
2637 if [ -n "$NOSOURCE0" ] ; then
2638 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2640 get_files $SOURCES $PATCHES
2642 fetch_build_requires
2646 if [ -z "$SPECFILE" ]; then
2647 Exit_error err_no_spec_in_cmdl
2653 if [ -n "$NOSOURCE0" ] ; then
2654 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2656 update_md5 $SOURCES $PATCHES
2662 if [ -z "$SPECFILE" ]; then
2663 Exit_error err_no_spec_in_cmdl
2667 if [ ! -d .git ]; then
2668 echo "No git reposiotory" >&2
2676 "list-sources-files" )
2679 DONT_PRINT_REVISION="yes"
2682 for SAP in $SOURCES $PATCHES; do
2683 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2686 "list-sources-urls" )
2689 DONT_PRINT_REVISION="yes"
2692 SAPS="$SOURCES $PATCHES"
2693 for SAP in $SAPS; do
2697 "list-sources-local-paths" )
2700 DONT_PRINT_REVISION="yes"
2703 for SAP in $SOURCES $PATCHES; do
2704 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2707 "list-sources-distfiles-paths" )
2710 DONT_PRINT_REVISION="yes"
2713 for SAP in $SOURCES $PATCHES; do
2714 if [ -n "$(src_md5 "$SAP")" ]; then
2715 distfiles_path "$SAP"
2719 "list-sources-distfiles" )
2722 DONT_PRINT_REVISION="yes"
2725 for SAP in $SOURCES $PATCHES; do
2726 if [ -n "$(src_md5 "$SAP")" ]; then
2727 distfiles_url "$SAP"
2731 "list-sources-cvs" )
2734 DONT_PRINT_REVISION="yes"
2737 for SAP in $SOURCES $PATCHES; do
2738 if [ -z "$(src_md5 "$SAP")" ]; then
2739 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2753 echo "$VERSIONSTRING"
2756 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2757 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2761 # vi:syntax=sh:ts=4:sw=4:noet