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-2020 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_RPMGETDEPS="no"
156 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
157 if [ -x /usr/bin/rpm-getdeps ]; then
158 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
160 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
164 UPDATE_POLDEK_INDEXES_OPTS=""
166 # Here we load saved user environment used to
167 # predefine options set above, or passed to builder
169 # This one reads global system environment settings:
170 if [ -f ~/etc/builderrc ]; then
173 # And this one cascades settings using user personal
175 # Example of ~/.builderrc:
177 #UPDATE_POLDEK_INDEXES="yes"
178 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
179 #FETCH_BUILD_REQUIRES="yes"
180 #REMOVE_BUILD_REQUIRES="force"
182 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
187 if [ -n "$HOME_ETC" ]; then
188 USER_CFG="$HOME_ETC/.builderrc"
189 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
191 USER_CFG=~/.builderrc
192 BUILDER_MACROS=~/.builder-rpmmacros
195 [ -f "$USER_CFG" ] && . "$USER_CFG"
197 if [ "$SCHEDTOOL" = "auto" ]; then
198 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
199 SCHEDTOOL="schedtool -B -e"
205 if [ -n "$USE_PROZILLA" ]; then
207 elif [ -n "$USE_AXEL" ]; then
209 elif [ -n "$USE_LFTP" ]; then
215 GETLOCAL=${GETLOCAL:-cp -a}
223 if [ -d $HOME/rpm/SOURCES ]; then
224 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
225 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
229 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
230 POLDEK_CMD="$SU_SUDO /usr/bin/poldek"
233 # TODO: what this function does?
236 if [ -n "$LOGFILE" ]; then
237 LOG=`eval echo $LOGFILE`
238 if [ -n "$LASTLOG_FILE" ]; then
239 echo "LASTLOG=$LOG" > $LASTLOG_FILE
241 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
242 # FIXME $exit_pldk undefined
245 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
246 return `cat ${RES_FILE}`
251 #---------------------------------------------
254 download_prozilla() {
255 local outfile=$1 url=$2 retval
257 proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS -O "$outfile" "$url"
264 local outfile=$1 url=$2 retval
266 axel -a $AXEL_OPTS -o "$outfile" "$url"
273 local outfile=$1 url=$2 retval wget_help
274 if [ -z "${WGET_OPTS_SET+x}" ]; then
275 wget_help="$(wget --help 2>&1)"
276 echo "$wget_help" | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
277 echo "$wget_help" | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
278 echo "$wget_help" | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
279 echo "$wget_help" | grep -q -- ' --no-iri ' && WGET_OPTS="$WGET_OPTS --no-iri"
280 WGET_OPTS="-c -nd -t$WGET_RETRIES $WGET_OPTS --user-agent=$USER_AGENT $IPOPT --passive-ftp"
284 wget $WGET_OPTS -O "$outfile" "$url"
286 if [ $retval -ne 0 ]; then
287 if [ "`echo $url | grep -E 'ftp://'`" ]; then
288 ${GETURI} -O "$outfile" "$url"
296 local outfile=$1 url=$2 retval tmpfile
297 tmpfile=$(tempfile) || exit 1
299 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
300 $([ "$IPOPT" = "-4" ] && echo "set dns:order \"inet\";")
301 $([ "$IPOPT" = "-6" ] && echo "set dns:order \"inet6\";")
302 set ssl:verify-certificate no;
303 set net:max-retries $WGET_RETRIES;
304 set http:user-agent \"$USER_AGENT\";
305 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
309 if [ $retval -eq 0 ]; then
310 mv -f "$tmpfile" "$outfile"
318 if [ -n "$DEBUG" ]; then set -xv; fi
320 # to make this output parseable by bash-completion _parse_help()
321 # if the line contains short and long option, it will take only the long option
322 # but if you want both being completed, put the short option to separate line
324 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
325 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
326 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
327 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
328 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
329 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
330 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
331 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
332 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
333 <package>[.spec][:tag]
335 -4 - force IPv4 when transferring files
336 -6 - force IPv6 when transferring files
338 --update-md5 - update md5 comments in spec, implies -nd -ncs
340 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
341 --all-branches - make shallow fetch of all branches; --depth required
342 -n5, --no-md5 - ignore md5 comments in spec
343 -D, --debug - enable builder script debugging mode,
344 -debug - produce rpm debug package (same as --opts -debug)
345 -V, --version - output builder version string
346 --short-version - output builder short version
347 -a - try add new package to PLD repo.
350 - get all files from PLD repo or HTTP/FTP and build package
352 -bb - get all files from PLD repo or HTTP/FTP and build binary
353 only package from <package>.spec,
354 -bp - execute the %prep phase of <package>.spec,
355 -bc - execute the %build phase of <package>.spec,
356 -bi - execute the %install phase of <package>.spec
357 -bl - execute the %files phase of <package>.spec
358 -bs - get all files from PLD repo or HTTP/FTP and only pack
360 --short-circuit - short-circuit build
361 -B, --branch - add branch
363 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
364 may be used with building process.
365 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
366 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
367 -cf, --cvs-force - use -f when tagging
368 --define '<macro> <value>'
369 - define a macro <macro> with value <value>,
370 --depth <number> - make shallow fetch
371 --alt_kernel <kernel>
372 - same as --define 'alt_kernel <kernel>'
373 --nodeps - rpm won't check any dependences
375 --get - get <package>.spec and all related files from PLD repo
376 -h, --help - this message,
377 -j N - set %_smp_mflags to propagate concurrent jobs
378 --ftp - use FTP protocol to access distfiles server
379 --http - use HTTP protocol to access distfiles server
380 -l <logfile>, --logtofile=<logfile>
383 - don't pull from PLD repo
384 -nd, --no-distfiles - don't download from distfiles
385 -nm, --no-mirrors - don't download from mirror, if source URL is given,
386 -nu, --no-urls - don't try to download from FTP/HTTP location,
387 -ns, --no-srcs - don't download Sources/Patches
388 -ns0, --no-source0 - don't download Source0
389 -nn, --no-net - don't download anything from the net
390 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
391 -pm, --prefer-mirrors
392 - prefer mirrors (if any) over distfiles for SOURCES
393 --no-init - don't initialize builder paths (SPECS and SOURCES)
395 --skip-existing-files
396 - skip existing files in get_files
397 --opts <rpm opts> - additional options for rpm
398 -q, --quiet - be quiet,
399 --date yyyy-mm-dd - build package using resources from specified date,
400 -r <tag>, --cvstag <ref>
401 - build package using resources from specified branch/tag,
402 -A - build package using master branch as any sticky tags/branch/date being reset.
403 -R, --fetch-build-requires
404 - fetch what is BuildRequired,
405 -RB, --remove-build-requires
406 - remove all you fetched with -R or --fetch-build-requires
407 remember, this option requires confirmation,
408 -FRB, --force-remove-build-requires
409 - remove all you fetched with -R or --fetch-build-requires
410 remember, this option works without confirmation,
411 -sd, --source-distfiles
412 - list sources available from distfiles (intended for offline
413 operations; does not work when Icon field is present
414 but icon file is absent),
415 -sc, --source-cvs - list sources available from PLD repo
416 -sdp, --source-distfiles-paths
417 - list sources available from distfiles -
418 paths relative to distfiles directory (intended for offline
419 operations; does not work when Icon field is present
420 but icon file is absent),
421 -sf, --source-files - list sources - bare filenames (intended for offline
422 operations; does not work when Icon field is present
423 but icon file is absent),
425 - list sources - filenames with full local paths (intended for
426 offline operations; does not work when Icon field is present
427 but icon file is absent),
428 -su, --source-urls - list urls - urls to sources and patches
429 intended for copying urls with spec with lots of macros in urls
430 -T <tag> , --tag <tag>
431 - add git tag <tag> for files,
432 -Tvs, --tag-version-stable
433 - add git tags STABLE and NAME-VERSION-RELEASE for files,
435 - add git tag STABLE for files,
437 --tag-version - add git tag NAME-VERSION-RELEASE for files,
438 -Tp, --tag-prefix <prefix>
439 - add <prefix> to NAME-VERSION-RELEASE tags,
440 -tt, --test-tag <prefix>
441 - fail if tag is already present,
442 -ir, --integer-release-only
443 - allow only integer and snapshot releases
444 -v, --verbose - be verbose,
445 -u, --try-upgrade - check version, and try to upgrade package
446 -un, --try-upgrade-with-float-version
447 - as above, but allow float version
448 php-pear-Services_Digg/
449 --upgrade-version - upgrade to specified version in try-upgrade
450 -U, --update - refetch sources, don't use distfiles, and update md5 comments
451 -Upi, --update-poldek-indexes
452 - refresh or make poldek package index files.
454 --skip-patch <patchnumber>
455 - don't apply <patchnumber>. may be repeated.
457 --nopatch <patchnumber>
458 - abort instead of applying patch <patchnumber>
460 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
461 --show-bconds - show available conditional builds, which can be used
462 - with --with and/or --without switches.
463 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
464 In other words, the output is parseable by scripts.
465 --show-avail-bconds - show available bconds
468 - conditional build package depending on %_with_<feature>/
469 %_without_<feature> macro switch. You may now use
470 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
471 constructions. Set GROUP_BCONDS to yes to make use of it.
472 --target <platform>, --target=<platform>
473 - build for platform <platform>.
474 --init-rpm-dir, --init
475 - initialize ~/rpm directory structure
482 v=$(LC_ALL=C LANG=C rpm --version 2>&1)
483 v=${v#RPM version } # rpm 4
484 v=${v#rpm \(RPM\) } # rpm 5
494 echo "ERROR: unsupported RPM version $v" >&2
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.pld-linux.org/?p=packages/${SPECFILE%.spec}.git;a=log"
532 if [ -n "$CVSTAG" ]; then
533 giturl="$giturl;h=$CVSTAG"
535 local gitauthor="PLD Linux Team <feedback@pld-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 -a $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'
713 local safe_macrofiles
714 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
715 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
717 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --load "$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
722 if [ -n "$DEBUG" ]; then
727 if [ -x /usr/bin/rpm-specdump ]; then
728 update_shell_title "cache_rpm_dump using rpm-specdump command"
729 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
731 update_shell_title "cache_rpm_dump using rpmbuild command"
734 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
735 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
741 ARGS='--nodigest --nosignature --nobuild'
744 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
746 if [ $? -gt 0 ]; then
747 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
749 Exit_error err_build_fail
752 # make small dump cache
753 rpm_dump_cache=`echo "$rpm_dump" | awk '
754 $2 ~ /^SOURCEURL/ {print}
755 $2 ~ /^PATCHURL/ {print}
756 $2 ~ /^nosource/ {print}
757 $2 ~ /^PACKAGE_/ {print}
761 update_shell_title "cache_rpm_dump: OK!"
765 if [ -z "$rpm_dump_cache" ] ; then
766 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
768 echo "$rpm_dump_cache"
772 update_shell_title "get icons"
773 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
774 if [ -z "$ICONS" ]; then
778 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
782 update_shell_title "parsing specfile"
783 if [ -n "$DEBUG" ]; then
788 # icons are needed for successful spec parse
794 if rpm_dump | grep -qEi ":.*nosource.*1"; then
795 FAIL_IF_NO_SOURCES="no"
798 if [ "$NOSRCS" != "yes" ]; then
799 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
800 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
801 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
804 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
805 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
806 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
808 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
809 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
812 if [ -n "$BE_VERBOSE" ]; then
813 echo "- Sources : `nourl $SOURCES`"
814 if [ -n "$PATCHES" ]; then
815 echo "- Patches : `nourl $PATCHES`"
817 echo "- Patches : *no patches needed*"
819 if [ -n "$ICONS" ]; then
820 echo "- Icon : `nourl $ICONS`"
822 echo "- Icon : *no package icon*"
824 echo "- Name : $PACKAGE_NAME"
825 echo "- Version : $PACKAGE_VERSION"
826 echo "- Release : $PACKAGE_RELEASE"
829 update_shell_title "parse_spec: OK!"
832 # aborts program abnormally
835 echo >&2 "$PROGRAM: ERROR: $*"
840 if [ -n "$DEBUG" ]; then
848 "err_no_spec_in_cmdl" )
849 remove_build_requires
850 echo >&2 "ERROR: spec file name not specified."
852 "err_invalid_cmdline" )
853 echo >&2 "ERROR: invalid command line arg ($2)."
855 "err_no_spec_in_repo" )
856 remove_build_requires
857 echo >&2 "Error: spec file not stored in repository."
863 "err_no_source_in_repo" )
864 remove_build_requires
865 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
867 "err_cvs_add_failed" )
868 echo >&2 "Error: failed to add package to PLD repo."
871 remove_build_requires
872 echo >&2 "Error: package build failed. (${2:-no more info})"
874 "err_no_package_data" )
875 remove_build_requires
876 echo >&2 "Error: couldn't get out package name/version/release from spec file."
879 remove_build_requires
880 echo >&2 "Tag ${2} already exists"
883 remove_build_requires
884 echo >&2 "Release ${2} not integer and not a snapshot."
886 "err_branch_exists" )
887 remove_build_requires
888 echo >&2 "Tree branch already exists (${2})."
891 remove_build_requires
892 echo >&2 "Error: conditions reject building this spec (${2})."
894 "err_remote_problem" )
895 remove_build_requires
896 echo >&2 "Error: problem with remote (${2})"
899 echo >&2 "Error: cannot checkout $2"
901 "err_not_implemented" )
902 remove_build_requires
903 echo >&2 "Error: functionality not yet imlemented"
906 echo >&2 "Unknown error."
911 if [ -n "$DEBUG" ]; then
916 if [ "$NOINIT" != "yes" ] ; then
917 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
919 local macros_ver=$(rpm -E %?rpm_build_macros)
920 if [ -z "$macros_ver" ]; then
921 REPO_DIR=$TOP_DIR/packages
922 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
924 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
925 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
929 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
934 REPO_DIR=$PACKAGE_DIR
935 RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
937 export GIT_WORK_TREE=$PACKAGE_DIR
938 export GIT_DIR=$PACKAGE_DIR/.git
940 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
941 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
942 CVSTAG=${CVSTAG#refs/heads/}
943 if [ "$CVSTAG" != "master" ]; then
944 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
947 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
950 elif [ "$CVSTAG" = "HEAD" ]; then
951 # assume -r HEAD is same as -A
959 update_shell_title "add_package"
961 if [ -n "$DEBUG" ]; then
967 SPECFILE=$(basename $SPECFILE)
968 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
969 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
972 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
973 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
977 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
978 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
980 git config --local push.default current
981 git config --local branch.master.remote $REMOTE_PLD
982 git config --local branch.master.merge refs/heads/master
984 test $? = 0 || Exit_error err_remote_problem $REMOTE_PLD
989 update_shell_title "get_spec"
991 if [ -n "$DEBUG" ]; then
997 SPECFILE=$(basename $SPECFILE)
998 if [ "$NOCVSSPEC" != "yes" ]; then
999 if [ -z "$DEPTH" ]; then
1000 if [ -d "$PACKAGE_DIR/.git" ]; then
1001 git fetch $IPOPT $REMOTE_PLD || Exit_error err_no_spec_in_repo
1002 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
1003 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
1004 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
1007 Exit_error err_not_implemented
1011 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
1012 # softfail if new package, i.e not yet added to PLD rep
1013 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
1014 echo "Warning: package not in Git - assuming new package"
1017 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1018 git config --local --add "remote.$REMOTE_PLD.push" 'refs/notes/*:refs/notes/*'
1019 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1020 git config --local push.default current
1021 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1025 if [ ! -d "$PACKAGE_DIR/.git" ]; then
1026 if [ ! -d "$PACKAGE_DIR" ]; then
1027 install -d $PACKAGE_DIR
1030 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
1031 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1032 git config --local --add "remote.$REMOTE_PLD.push" 'refs/heads/*:refs/remotes/origin/*'
1033 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1034 git config --local push.default current
1035 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1036 CVSTAG=${CVSTAG:-"master"}
1039 if [ -z "$ALL_BRANCHES" ]; then
1040 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
1042 git fetch $IPOPT $DEPTH $REMOTE_PLD $refs || {
1043 echo >&2 "Error: branch $CVSTAG does not exist"
1047 git fetch $IPOPT $REMOTE_PLD 'refs/notes/*:refs/notes/*'
1049 cvsignore_df .gitignore
1051 # add default log format to .gitignore if it is relative to package dir
1052 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
1053 # substitute known "macros" to glob
1054 local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g')
1055 if [ "$logfile" ]; then
1056 cvsignore_df "$logfile"
1060 # create symlinks for tools
1061 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
1062 for a in dropin md5 builder {relup,compile,repackage,rsync,pearize}.sh; do
1063 # skip tools that don't exist in top dir
1064 [ -f $a ] || continue
1065 # skip tools that already exist
1066 [ -f $PACKAGE_DIR/$a ] && continue
1067 ln -s ../$a $PACKAGE_DIR
1073 if [ -n "$CVSTAG" ]; then
1074 if git rev-parse --verify -q "$CVSTAG" >/dev/null; then
1075 # checkout only if differs, so this will not trash git reflog
1076 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1077 git checkout "$CVSTAG" --
1079 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1080 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1082 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1083 Exit_error "err_no_checkut" "$CVSTAG"
1086 git merge --ff-only '@{u}'
1087 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1088 if [ -n "$CVSDATE" ]; then
1089 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1093 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1094 Exit_error err_no_spec_in_repo "$PACKAGE_DIR/$SPECFILE"
1097 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1098 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1101 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1106 # find mirrors in this order. first match wins:
1107 # - package dir (~/rpm/packages/foo)
1108 # - repository dir (~/rpm/packages)
1109 # - tools dir dir (~/rpm/packages/rpm-build-tools)
1113 update_shell_title "find_mirror[$url][$REPO_DIR]"
1115 # NOTE: as while loop runs in subshell,
1116 # we use exit 2 to indicate that the match was found
1117 # otherwise we end up outputing mirror url and origin url.
1119 local origin mirror name rest ol prefix
1121 cat "$PACKAGE_DIR/mirrors" "$REPO_DIR/mirrors" "$REPO_DIR/../rpm-build-tools/mirrors" /dev/null 2>/dev/null | \
1122 while read origin mirror name rest; do
1123 # skip comments and empty lines
1124 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1127 ol=$(echo -n "$origin" | wc -c)
1128 prefix=$(echo -n "$url" | head -c $ol)
1129 if [ "$prefix" = "$origin" ] ; then
1130 suffix=$(echo "$url" | cut -b $((ol+1))-)
1131 echo -n "$mirror$suffix"
1137 # Warning: unpredictable results if same URL used twice
1140 # escape some regexp characters if part of file name
1141 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1144 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1145 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1146 head -n 1 | tr OURCEATH ourceath | xargs
1150 [ "$NO5" = "yes" ] && return
1152 [ -z "$no" ] && return
1156 # use "sources" file from package dir, like vim
1157 if [ -f sources ]; then
1158 md5=$(grep -s -v '^#' sources | \
1159 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1160 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1161 grep -E '^[0-9a-f]{32}$')
1164 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1165 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1167 echo "$md5" | tail -n 1
1172 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1173 if [ -n "$source_md5" ]; then
1176 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1177 if [ -n "$source_md5" ]; then
1180 # we have empty SourceX-md5, but it is still possible
1181 # that we have NoSourceX-md5 AND NoSource: X
1182 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1183 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1191 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1195 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1198 distfiles_attic_url() {
1199 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(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")
1373 url_attic=$(distfiles_attic_url "$i")
1375 # is $url local file?
1376 if [[ "$url" = [./]* ]]; then
1377 update_shell_title "${GETLOCAL%% *}: $url"
1378 ${GETLOCAL} $url $target
1381 # make shorter message for distfiles urls
1382 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1383 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1384 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1387 update_shell_title "${GETURI%% *}: $uri"
1388 ${GETURI} "$target" "$url"
1392 if [ ! -s "$target" ]; then
1394 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1395 update_shell_title "${GETLOCAL%% *}: $url_attic"
1396 ${GETLOCAL} $url_attic $target
1398 update_shell_title "${GETURI%% *}: $url_attic"
1399 ${GETURI} "$target" "$url_attic"
1400 test -s "$target" || rm -f "$target"
1404 if [ -s "$target" ]; then
1405 cvsignore_df $target
1412 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1413 if [ -z "$NOMIRRORS" ]; then
1414 im=$(find_mirror "$i")
1418 update_shell_title "${GETURI%% *}: $im"
1419 ${GETURI} "$target" "$im"
1420 test -s "$target" || rm -f "$target"
1423 if [ "$cvsup" = 1 ]; then
1429 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1430 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1431 Exit_error err_no_source_in_repo $i
1434 # we check md5 here just only to refetch immediately
1435 if good_md5 "$i" && good_size "$i"; then
1437 elif [ "$FROM_DISTFILES" = 1 ]; then
1438 # wrong md5 from distfiles: remove the file and try again
1440 echo "MD5 sum mismatch. Trying full fetch."
1443 update_shell_title "${GETURI%% *}: $url"
1444 ${GETURI} "$target" "$url"
1445 if [ ! -s "$target" ]; then
1447 update_shell_title "${GETURI%% *}: $url_attic"
1448 ${GETURI} "$target" "$url_attic"
1450 test -s "$target" || rm -f "$target"
1453 SHELL_TITLE_PREFIX=""
1456 if [ "$CHMOD" = "yes" ]; then
1457 CHMOD_FILES=$(nourl "$@")
1458 if [ -n "$CHMOD_FILES" ]; then
1459 chmod $CHMOD_MODE $CHMOD_FILES
1466 # If tag exists and points to other commit exit with error
1467 # If it existsts and points to HEAD return 1
1468 # If it doesn't exist return 0
1470 local sha1=$(git rev-parse HEAD)
1471 echo "Searching for tag $_tag..."
1472 if [ -n "$DEPTH" ]; then
1473 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1475 local ref=$(git show-ref -s "refs/tags/$_tag")
1477 [ -z "$ref" ] && return 0
1478 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1483 if [ -n "$DEBUG" ]; then
1488 # Check whether first character of PACKAGE_NAME is legal for tag name
1489 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1493 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1494 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1496 # Remove @kernel.version_release from TAGVER because tagging sources
1497 # could occur with different kernel-headers than kernel-headers used at build time.
1498 # besides, %{_kernel_ver_str} is not expanded.
1500 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1501 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1508 if [ -n "$DEBUG" ]; then
1513 echo "Version: $PACKAGE_VERSION"
1514 echo "Release: $PACKAGE_RELEASE"
1517 if [ "$TAG_VERSION" = "yes" ]; then
1520 if [ -n "$TAG" ]; then
1525 local OPTIONS="tag $CVS_FORCE"
1529 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1530 update_shell_title "tag sources: $_tag"
1531 git $OPTIONS $_tag || exit
1532 git push $IPOPT $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1534 echo "Tag $_tag already exists and points to the same commit"
1540 echo "Git branch: $TAG"
1543 if [ -n "$DEBUG" ]; then
1548 local OPTIONS="branch $CVS_FORCE"
1551 git $OPTIONS $TAG || exit
1555 # this function should exit early if package can't be built for this arch
1556 # this avoids unneccessary BR filling.
1559 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1561 if [ $ret -ne 0 ]; then
1573 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1574 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1580 local ver="$2" subver=$ver
1581 local newver="$3" newsubver=$newver
1583 # try handling subver, everything that's not numeric-dotted in version
1584 if grep -Eq '%define\s+subver' $specfile; then
1585 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1587 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1588 newver=${newver%$newsubver}
1591 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1592 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1593 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1597 # try to upgrade .spec to new version
1598 # if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1600 # return 1: if .spec was updated
1601 # return 0: no changes to .spec
1602 # exit 1 in case of error
1604 if [ -z "$TRY_UPGRADE" ]; then
1608 local TNOTIFY TNEWVER TOLDVER
1609 update_shell_title "build_package: try_upgrade"
1613 if [ "$UPGRADE_VERSION" ]; then
1614 TNEWVER=$UPGRADE_VERSION
1615 echo "Updating spec file to version $TNEWVER"
1617 if [ -n "$FLOAT_VERSION" ]; then
1618 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1620 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1623 # pldnotify does not set exit codes, but it has match for ERROR
1624 # in output which means so.
1625 if [[ "$TNOTIFY" = *ERROR* ]]; then
1630 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1631 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1633 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1636 if [ -z "$TNEWVER" ]; then
1640 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1641 cp -f $SPECFILE $SPECFILE.bak
1644 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1645 set_release $SPECFILE $PACKAGE_RELEASE 1
1647 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1648 echo >&2 "Upgrading version failed, you need to update spec yourself"
1655 update_shell_title "build_package"
1656 if [ -n "$DEBUG" ]; then
1665 BUILD_SWITCH="-ba" ;;
1667 BUILD_SWITCH="-bb" ;;
1669 BUILD_SWITCH="-bs --nodeps" ;;
1671 BUILD_SWITCH="-bp --nodeps" ;;
1673 BUILD_SWITCH="-bc" ;;
1675 BUILD_SWITCH="-bi" ;;
1677 BUILD_SWITCH="-bl" ;;
1681 update_shell_title "build_package: $COMMAND"
1682 local logfile retval
1683 if [ -n "$LOGFILE" ]; then
1684 logfile=`eval echo $LOGFILE`
1685 if [ -d "$logfile" ]; then
1686 echo "Log file $logfile is a directory."
1687 echo "Parse error in the spec?"
1688 Exit_error err_build_fail
1690 if [ -n "$LASTLOG_FILE" ]; then
1691 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1695 # unset these, should not be exposed to builder shell!
1696 unset GIT_WORK_TREE GIT_DIR
1697 # these are set by jenkins
1698 unset GIT_PREVIOUS_COMMIT GIT_URL GIT_PREVIOUS_SUCCESSFUL_COMMIT GIT_BRANCH GIT_COMMIT
1699 # this may be set by user
1701 # may be set by user
1702 unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_TESTING_PORCELAIN_COMMAND_LIST
1703 # fail if something still set
1704 env | grep ^GIT_ && Exit_error err_build_fail
1706 local specdir=$(insert_gitlog $SPECFILE)
1708 # FIXME: eval here is exactly why?
1709 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
1713 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1714 if [ "$retval" -eq "0" ]; then
1715 mv $logfile $LOGDIROK
1717 mv $logfile $LOGDIRFAIL
1721 if [ "$retval" -ne "0" ]; then
1722 if [ -n "$TRY_UPGRADE" ]; then
1723 echo "\nUpgrade package to new version failed."
1724 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1725 echo "Restoring old spec file."
1726 mv -f $SPECFILE.bak $SPECFILE
1730 Exit_error err_build_fail
1736 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1739 install_required_packages() {
1744 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1747 /^%changelog/ { exit }
1749 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1750 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1751 gsub(/[ \t]+/, "_", bcond);
1753 }' $SPEC | LC_ALL=C sort -u
1757 # expand bconds from ~/.bcondrc
1758 # The file structure is like gentoo's package.use:
1761 # samba -mysql -pgsql
1762 # w32codec-installer license_agreement
1765 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1771 SN=${SPECFILE%%\.spec}
1773 local bcondrc=$HOME/.bcondrc
1774 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1776 local bcond_avail=$(find_spec_bcond $SPECFILE)
1778 while read pkg flags; do
1780 [[ "$pkg" == \#* ]] && continue
1782 # any package or current package?
1783 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1784 for flag in $flags; do
1785 local opt=${flag#[+-]}
1787 # use only flags which are in this package.
1788 if [[ $bcond_avail = *${opt}* ]]; then
1789 if [[ $flag = -* ]]; then
1790 if [[ $BCOND != *--with?${opt}* ]]; then
1791 BCOND="$BCOND --without $opt"
1794 if [[ $BCOND != *--without?${opt}* ]]; then
1795 BCOND="$BCOND --with $opt"
1802 update_shell_title "parse ~/.bcondrc: DONE!"
1805 set_bconds_values() {
1806 update_shell_title "set bcond values"
1808 AVAIL_BCONDS_WITHOUT=""
1809 AVAIL_BCONDS_WITH=""
1811 if grep -Eq '^# *_with' ${SPECFILE}; then
1812 echo >&2 "ERROR: This spec has old style bconds."
1816 if ! grep -q '^%bcond' ${SPECFILE}; then
1820 local bcond_avail=$(find_spec_bcond $SPECFILE)
1821 process_bcondrc "$SPECFILE"
1823 update_shell_title "parse bconds"
1826 for opt in $bcond_avail; do
1829 bcond=${opt#without_}
1831 *--without?${bcond}\ *|*--without?${bcond})
1832 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1835 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1842 *--with?${bcond}\ *|*--with?${bcond})
1843 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1846 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1851 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1860 update_shell_title "run_sub_builder $package_name"
1862 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1863 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
1864 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1865 # jakby nie bylo tego kawalka kodu.
1867 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1868 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
1872 # kurwa. translate that ^^^^
1876 # Istnieje taki spec? ${package}.spec
1877 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1878 parent_spec_name=${package}.spec
1879 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1880 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1882 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1887 if [ "${parent_spec_name}" != "" ]; then
1888 spawn_sub_builder $parent_spec_name
1890 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1893 # install package with poldek
1894 # @return exit code from poldek
1896 # this requires following sudo rules:
1897 # - poldek --noask --caplookup -ug
1899 LC_ALL=C LANG=C $POLDEK_CMD --noask --caplookup --uniq -ug "$@"
1904 # this requires following sudo rules:
1905 # - poldek -q --update --upa
1906 install_packages() {
1907 # sync poldek indexes once per invocation
1908 if [ -z "$package_indexes_updated" ]; then
1909 update_shell_title "poldek: update indexes"
1910 $POLDEK_CMD -q --update --upa --mo=nodesc
1911 package_indexes_updated=true
1914 update_shell_title "install packages: $*"
1915 poldek_install "$@" && return
1917 # retry install, install packages one by one
1918 # this is slower one
1920 for package in $*; do
1921 package=$(depspecname $package)
1922 update_shell_title "install package: $package"
1923 poldek_install "$package" || rc=$?
1928 uninstall_packages() {
1929 update_shell_title "uninstall packages: $*"
1930 $POLDEK_CMD --noask --nofollow -ev "$@"
1933 spawn_sub_builder() {
1935 update_shell_title "spawn_sub_builder $package_name"
1938 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1939 sub_builder_opts="${sub_builder_opts} -R"
1941 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1942 sub_builder_opts="${sub_builder_opts} -RB"
1943 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1944 sub_builder_opts="${sub_builder_opts} -FRB"
1946 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1947 sub_builder_opts="${sub_builder_opts} -Upi"
1951 ./builder ${sub_builder_opts} "$@"
1954 remove_build_requires() {
1955 if [ "$INSTALLED_PACKAGES" != "" ]; then
1956 case "$REMOVE_BUILD_REQUIRES" in
1958 run_poldek --noask -ve $INSTALLED_PACKAGES
1961 run_poldek --ask -ve $INSTALLED_PACKAGES
1964 echo You may want to manually remove following BuildRequires fetched:
1965 echo $INSTALLED_PACKAGES
1966 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1973 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1974 if [ "$BCOND" ]; then
1976 echo "Building $SPECFILE with the following conditional flags:"
1980 echo "No conditional flags passed"
1983 echo "from available:"
1984 echo "--with :\t$AVAIL_BCONDS_WITH"
1985 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1990 display_branches() {
1991 echo -n "Available branches: "
1992 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1995 # checks a given list of packages/files/provides against current rpmdb.
1996 # outputs all dependencies which current rpmdb doesn't satisfy.
1997 # input can be either STDIN or parameters
2001 if [ $# -gt 0 ]; then
2007 out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1)
2010 echo "$out" | awk '/^no package provides/ { print $NF }'
2012 # other deps (files)
2013 echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p'
2016 # checks if given package/files/provides exists in rpmdb.
2017 # input can be either stdin or parameters
2018 # returns packages which are present in the rpmdb
2022 if [ $# -gt 0 ]; then
2028 LC_ALL=C LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
2031 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
2032 install_build_requires_rpmdeps() {
2034 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
2035 # TODO: Conflicts list doesn't check versions
2036 CNFL=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
2037 DEPS=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
2039 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2040 CNFL=$(eval rpm -q --specsrpm --conflicts $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
2041 DEPS=$(eval rpm -q --specsrpm --requires $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
2044 if [ -n "$CNFL" ]; then
2045 echo "Uninstall conflicting packages: $CNFL"
2046 uninstall_packages $CNFL
2049 if [ -n "$DEPS" ]; then
2050 echo "Install dependencies: $DEPS"
2051 install_packages $DEPS
2055 fetch_build_requires()
2057 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
2061 update_shell_title "fetch build requires"
2062 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2063 install_build_requires_rpmdeps
2067 die "need rpm-getdeps tool"
2074 if [ ! -e $localrepo ]; then
2075 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
2076 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2081 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2082 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2083 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2084 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2085 local TEMPLATES=template-specs
2088 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2089 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2092 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2093 init_repository projects/$TEMPLATES ../$TEMPLATES
2094 for a in builder fetchsrc_request compile repackage; do
2095 ln -sf ../rpm-build-tools/${a}.sh $a
2098 ln -sf ../rpm-build-tools/${a} $a
2100 ln -sf ../rpm-build-tools/mirrors mirrors
2107 DONT_PRINT_REVISION="yes"
2109 # remove spec and sources
2110 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
2111 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2112 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2115 #---------------------------------------------
2123 # stuff global $BUILDER_OPTS from env as args
2124 if [ "$BUILDER_OPTS" ]; then
2125 set -- "$BUILDER_OPTS" "$@"
2128 while [ $# -gt 0 ]; do
2135 COMMAND="update_md5"
2140 COMMAND="update_md5"
2149 DEBUG="yes"; shift ;;
2151 COMMAND="version"; shift ;;
2153 COMMAND="short-version"; shift ;;
2160 -b | -ba | --build )
2161 COMMAND="build"; shift ;;
2162 -bb | --build-binary )
2163 COMMAND="build-binary"; shift ;;
2165 COMMAND="build-build"; shift ;;
2167 COMMAND="build-install"; shift ;;
2169 COMMAND="build-list"; shift ;;
2170 -bp | --build-prep )
2171 COMMAND="build-prep"; shift ;;
2172 -bs | --build-source )
2173 COMMAND="build-source"; shift ;;
2175 COMMAND="branch"; shift; TAG="${1}"; shift;;
2177 CLEAN="--clean"; shift ;;
2179 CVS_FORCE="-f"; shift;;
2185 COMMAND="get"; shift ;;
2187 COMMAND="usage"; shift ;;
2189 PROTOCOL="ftp"; shift ;;
2191 PROTOCOL="http"; shift ;;
2193 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2197 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2201 PARALLEL_DOWNLOADS=$2
2205 PARALLEL_DOWNLOADS=${1#-p}
2209 shift; LOGFILE="${1}"; shift ;;
2211 shift; DEF_NICE_LEVEL=${1}; shift ;;
2212 -ske | --skip-existing-files)
2213 SKIP_EXISTING_FILES="yes"; shift ;;
2215 COMMAND="mr-proper"; shift ;;
2216 -ncs | --no-cvs-specs )
2217 NOCVSSPEC="yes"; shift ;;
2218 -nd | --no-distfiles )
2219 NODIST="yes"; shift ;;
2220 -nm | --no-mirrors )
2221 NOMIRRORS="yes"; shift ;;
2223 NOURLS="yes"; shift ;;
2225 NOSRCS="yes"; shift ;;
2226 -ns0 | --no-source0 )
2227 NOSOURCE0="yes"; shift ;;
2236 -pm | --prefer-mirrors )
2239 --noinit | --no-init )
2243 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2245 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2246 --skip-patch | -sp )
2247 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2249 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2252 --with | --without )
2253 case $GROUP_BCONDS in
2257 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2258 while ! `echo ${1}|grep -qE '(^-|spec)'`
2260 BCOND="$BCOND $COND $1"
2264 if [[ "$2" = *,* ]]; then
2265 for a in $(echo "$2" | tr , ' '); do
2266 BCOND="$BCOND $1 $a"
2269 BCOND="$BCOND $1 $2"
2275 shift; TARGET="${1}"; shift ;;
2277 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2279 QUIET="--quiet"; shift ;;
2281 CVSDATE="${2}"; shift 2
2282 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2292 -R | --fetch-build-requires)
2293 FETCH_BUILD_REQUIRES="yes"
2294 NOT_INSTALLED_PACKAGES=
2296 -RB | --remove-build-requires)
2297 REMOVE_BUILD_REQUIRES="nice"
2299 -FRB | --force-remove-build-requires)
2300 REMOVE_BUILD_REQUIRES="force"
2303 COMMAND="list-sources-cvs"
2305 -sd | --source-distfiles)
2306 COMMAND="list-sources-distfiles"
2308 -sdp | --source-distfiles-paths)
2309 COMMAND="list-sources-distfiles-paths"
2311 -sf | --source-files)
2312 COMMAND="list-sources-files"
2314 -lsp | --source-paths)
2315 COMMAND="list-sources-local-paths"
2317 -su | --source-urls)
2318 COMMAND="list-sources-urls"
2320 -Tvs | --tag-version-stable )
2325 -Ts | --tag-stable )
2330 -Tv | --tag-version )
2335 -Tp | --tag-prefix )
2347 -ir | --integer-release-only )
2348 INTEGER_RELEASE="yes"
2351 COMMAND="update_md5"
2356 -Upi | --update-poldek-indexes )
2357 UPDATE_POLDEK_INDEXES="yes"
2359 --init-rpm-dir|--init)
2360 COMMAND="init_rpm_dir"
2362 -u | --try-upgrade )
2363 TRY_UPGRADE="1"; shift ;;
2365 shift; UPGRADE_VERSION="$1"; shift;;
2366 -un | --try-upgrade-with-float-version )
2367 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2369 BE_VERBOSE="1"; shift ;;
2374 if echo "${MACRO}" | grep -q '\W'; then
2375 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2379 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2384 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\""
2388 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2391 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2392 COMMAND="show_bconds"
2396 COMMAND="show_bcond_args"
2399 --show-avail-bconds)
2400 COMMAND="show_avail_bconds"
2405 RPMOPTS="${RPMOPTS} --nodeps"
2408 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2411 Exit_error err_invalid_cmdline "$1"
2414 SPECFILE=${1%/}; shift
2415 # check if specname was passed as specname:cvstag
2416 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2417 CVSTAG="${SPECFILE##*:}"
2418 SPECFILE="${SPECFILE%%:*}"
2420 # always have SPECFILE ending with .spec extension
2421 SPECFILE=${SPECFILE%%.spec}.spec
2422 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2426 if [ "$CVSTAG" ]; then
2427 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2428 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2431 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2432 echo >&2 "--all branches requires --depth <number>"
2433 Exit_error err_invalid_cmdline
2436 if [ -n "$DEBUG" ]; then
2441 if [ -n "$TARGET" ]; then
2444 TARGET_SWITCH="--target $TARGET" ;;
2446 TARGET_SWITCH="--target=$TARGET" ;;
2450 if [ "$SCHEDTOOL" != "no" ]; then
2451 NICE_COMMAND="$SCHEDTOOL"
2453 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2456 # see time(1) for output format that could be used
2457 TIME_COMMAND="time -p"
2459 update_shell_title "$COMMAND"
2463 if [ -z "$SPECFILE" ]; then
2464 Exit_error err_no_spec_in_cmdl
2466 get_spec > /dev/null
2473 if [ -z "$SPECFILE" ]; then
2474 Exit_error err_no_spec_in_cmdl
2476 get_spec > /dev/null
2481 "show_avail_bconds")
2483 if [ -z "$SPECFILE" ]; then
2484 Exit_error err_no_spec_in_cmdl
2487 get_spec > /dev/null
2489 local bcond_avail=$(find_spec_bcond $SPECFILE)
2490 local opt bcond bconds
2491 for opt in $bcond_avail; do
2494 bcond=${opt#without_}
2495 bconds="$bconds $bcond"
2499 bconds="$bconds $bcond"
2502 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2510 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2512 if [ -z "$SPECFILE" ]; then
2513 Exit_error err_no_spec_in_cmdl
2516 # display SMP make flags if set
2517 smp_mflags=$(rpm -E %{?_smp_mflags})
2518 if [ "$smp_mflags" ]; then
2519 echo "builder: SMP make flags are set to $smp_mflags"
2527 if [ "$COMMAND" != "build-source" ]; then
2530 fetch_build_requires
2531 if [ "$INTEGER_RELEASE" = "yes" ]; then
2532 echo "Checking release $PACKAGE_RELEASE..."
2533 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2534 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2538 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2539 if [ -n "$TEST_TAG" ]; then
2540 local TAGVER=`make_tagver`
2541 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2542 # check also tags created in CVS
2543 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2544 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2545 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2546 || Exit_error err_tag_exists $TAGVER_CVS
2547 # - do not allow to build from HEAD when XX-branch exists
2548 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2549 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2550 TAG_BRANCH="${TREE_PREFIX}-branch"
2551 if [ -n "$DEPTH" ]; then
2552 cmd_branches="git ls-remote --heads"
2553 ref_prefix=refs/heads
2555 cmd_branches="git show-ref"
2556 ref_prefix=refs/remotes/${REMOTE_PLD}
2558 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2559 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2560 Exit_error err_branch_exists "$TAG_STATUS"
2566 if [ -n "$NOSOURCE0" ] ; then
2567 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2572 get_files $SOURCES $PATCHES
2573 check_md5 $SOURCES $PATCHES
2576 NODIST="yes" get_files $SOURCES $PATCHES
2577 update_md5 $SOURCES $PATCHES
2581 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2582 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2584 remove_build_requires
2588 if [ -z "$SPECFILE" ]; then
2589 Exit_error err_no_spec_in_cmdl
2598 if [ -z "$SPECFILE" ]; then
2599 Exit_error err_no_spec_in_cmdl
2603 if [ -n "$NEW_REPO" ]; then
2606 for file in $SOURCES $PATCHES; do
2607 if [ -z $(src_md5 "$file") ]; then
2608 git add $file || Exit_error err_no_source_in_repo $file
2610 cvsignore_df `nourl $file`
2614 echo "When you are ready commit your changes and run git push origin master"
2616 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2621 if [ -z "$SPECFILE" ]; then
2622 Exit_error err_no_spec_in_cmdl
2628 if [ -n "$NOSOURCE0" ] ; then
2629 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2631 get_files $SOURCES $PATCHES
2633 fetch_build_requires
2637 if [ -z "$SPECFILE" ]; then
2638 Exit_error err_no_spec_in_cmdl
2644 if [ -n "$NOSOURCE0" ] ; then
2645 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2647 update_md5 $SOURCES $PATCHES
2653 if [ -z "$SPECFILE" ]; then
2654 Exit_error err_no_spec_in_cmdl
2658 if [ ! -d .git ]; then
2659 echo "No git reposiotory" >&2
2667 "list-sources-files" )
2670 DONT_PRINT_REVISION="yes"
2673 for SAP in $SOURCES $PATCHES; do
2674 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2677 "list-sources-urls" )
2680 DONT_PRINT_REVISION="yes"
2683 SAPS="$SOURCES $PATCHES"
2684 for SAP in $SAPS; do
2688 "list-sources-local-paths" )
2691 DONT_PRINT_REVISION="yes"
2694 for SAP in $SOURCES $PATCHES; do
2695 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2698 "list-sources-distfiles-paths" )
2701 DONT_PRINT_REVISION="yes"
2704 for SAP in $SOURCES $PATCHES; do
2705 if [ -n "$(src_md5 "$SAP")" ]; then
2706 distfiles_path "$SAP"
2710 "list-sources-distfiles" )
2713 DONT_PRINT_REVISION="yes"
2716 for SAP in $SOURCES $PATCHES; do
2717 if [ -n "$(src_md5 "$SAP")" ]; then
2718 distfiles_url "$SAP"
2722 "list-sources-cvs" )
2725 DONT_PRINT_REVISION="yes"
2728 for SAP in $SOURCES $PATCHES; do
2729 if [ -z "$(src_md5 "$SAP")" ]; then
2730 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2744 echo "$VERSIONSTRING"
2747 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2748 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2752 # vi:syntax=sh:ts=4:sw=4:noet