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-2015 Free Penguins".
43 CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
45 # required rpm-build-macros
64 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
66 # use rpm 4.4.6+ digest format instead of comments if non-zero
69 # user agent when fetching files
70 USER_AGENT="PLD/Builder($VERSION)"
72 # It can be used i.e. in log file naming.
73 # See LOGFILE example.
74 DATE=`date +%Y-%m-%d_%H-%M-%S`
76 # target arch, can also be used for log file naming
77 TARGET=$(rpm -E %{_target})
79 # Note the *single* quotes, this allows using shell variables expanded at build time
80 # Example: LOGFILE='../log.$PACKAGE_NAME'
81 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
82 # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
83 # Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
84 # Example: LOGFILE='.log.$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.$TARGET.$DATE'
87 # use teeboth Perl wrapper
88 # temporary option to disable if broken
103 # create symlinks for tools in PACKAGE_DIR, see get_spec()
115 # use lftp by default when available
117 lftp --version > /dev/null 2>&1 && USE_LFTP=yes
118 PARALLEL_DOWNLOADS=10
120 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
125 GIT_SERVER="git://git.pld-linux.org"
126 GIT_PUSH="git@git.pld-linux.org"
127 PACKAGES_DIR="packages"
136 DISTFILES_SERVER="://distfiles.pld-linux.org"
137 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
142 FAIL_IF_NO_SOURCES="yes"
144 # let get_files skip over files which are present to get those damn files fetched
145 SKIP_EXISTING_FILES="no"
148 # should the specfile be restored if upgrade failed?
149 REVERT_BROKEN_UPGRADE="yes"
151 if rpm --specsrpm 2>/dev/null; then
152 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
153 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
155 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
156 if [ -x /usr/bin/rpm-getdeps ]; then
157 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
159 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
163 UPDATE_POLDEK_INDEXES_OPTS=""
165 # Here we load saved user environment used to
166 # predefine options set above, or passed to builder
168 # This one reads global system environment settings:
169 if [ -f ~/etc/builderrc ]; then
172 # And this one cascades settings using user personal
174 # Example of ~/.builderrc:
176 #UPDATE_POLDEK_INDEXES="yes"
177 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
178 #FETCH_BUILD_REQUIRES="yes"
179 #REMOVE_BUILD_REQUIRES="force"
181 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
186 if [ -n "$HOME_ETC" ]; then
187 USER_CFG="$HOME_ETC/.builderrc"
188 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
190 USER_CFG=~/.builderrc
191 BUILDER_MACROS=~/.builder-rpmmacros
194 [ -f "$USER_CFG" ] && . "$USER_CFG"
196 if [ "$SCHEDTOOL" = "auto" ]; then
197 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
198 SCHEDTOOL="schedtool -B -e"
204 if [ -n "$USE_PROZILLA" ]; then
205 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
208 elif [ -n "$USE_AXEL" ]; then
209 GETURI="axel -a $AXEL_OPTS"
212 elif [ -n "$USE_LFTP" ]; then
217 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
218 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
219 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
220 wget --help 2>&1 | grep -q -- ' --no-iri ' && WGET_OPTS="$WGET_OPTS --no-iri"
221 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
223 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
224 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
230 if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
241 if [ -d $HOME/rpm/SOURCES ]; then
242 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
243 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
247 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
248 POLDEK_CMD="$SU_SUDO /usr/bin/poldek"
251 # TODO: what this function does?
254 if [ -n "$LOGFILE" ]; then
255 LOG=`eval echo $LOGFILE`
256 if [ -n "$LASTLOG_FILE" ]; then
257 echo "LASTLOG=$LOG" > $LASTLOG_FILE
259 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
260 # FIXME $exit_pldk undefined
263 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
264 return `cat ${RES_FILE}`
269 #---------------------------------------------
273 local outfile=$1 url=$2 retval tmpfile
277 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
278 set ssl:verify-certificate no;
279 set net:max-retries $WGET_RETRIES;
280 set http:user-agent \"$USER_AGENT\";
281 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
285 if [ $retval -eq 0 ]; then
286 mv -f "$tmpfile" "$outfile"
294 if [ -n "$DEBUG" ]; then set -xv; fi
296 # to make this output parseable by bash-completion _parse_help()
297 # if the line contains short and long option, it will take only the long option
298 # but if you want both being completed, put the short option to separate line
300 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
301 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
302 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
303 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
304 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
305 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
306 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
307 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
308 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
309 <package>[.spec][:tag]
311 -4 - force IPv4 when transferring files
312 -6 - force IPv6 when transferring files
314 --update-md5 - update md5 comments in spec, implies -nd -ncs
316 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
317 --all-branches - make shallow fetch of all branches; --depth required
318 -n5, --no-md5 - ignore md5 comments in spec
319 -D, --debug - enable builder script debugging mode,
320 -debug - produce rpm debug package (same as --opts -debug)
321 -V, --version - output builder version string
322 --short-version - output builder short version
323 -a - try add new package to PLD repo.
326 - get all files from PLD repo or HTTP/FTP and build package
328 -bb - get all files from PLD repo or HTTP/FTP and build binary
329 only package from <package>.spec,
330 -bp - execute the %prep phase of <package>.spec,
331 -bc - execute the %build phase of <package>.spec,
332 -bi - execute the %install phase of <package>.spec
333 -bl - execute the %files phase of <package>.spec
334 -bs - get all files from PLD repo or HTTP/FTP and only pack
336 --short-circuit - short-circuit build
337 -B, --branch - add branch
339 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
340 may be used with building process.
341 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
342 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
343 -cf, --cvs-force - use -f when tagging
344 --define '<macro> <value>'
345 - define a macro <macro> with value <value>,
346 --depth <number> - make shallow fetch
347 --alt_kernel <kernel>
348 - same as --define 'alt_kernel <kernel>'
349 --nodeps - rpm won't check any dependences
351 --get - get <package>.spec and all related files from PLD repo
352 -h, --help - this message,
353 -j N - set %_smp_mflags to propagate concurrent jobs
354 --ftp - use FTP protocol to access distfiles server
355 --http - use HTTP protocol to access distfiles server
356 -l <logfile>, --logtofile=<logfile>
359 - don't pull from PLD repo
360 -nd, --no-distfiles - don't download from distfiles
361 -nm, --no-mirrors - don't download from mirror, if source URL is given,
362 -nu, --no-urls - don't try to download from FTP/HTTP location,
363 -ns, --no-srcs - don't download Sources/Patches
364 -ns0, --no-source0 - don't download Source0
365 -nn, --no-net - don't download anything from the net
366 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
367 -pm, --prefer-mirrors
368 - prefer mirrors (if any) over distfiles for SOURCES
369 --no-init - don't initialize builder paths (SPECS and SOURCES)
371 --skip-existing-files
372 - skip existing files in get_files
373 --opts <rpm opts> - additional options for rpm
374 -q, --quiet - be quiet,
375 --date yyyy-mm-dd - build package using resources from specified date,
376 -r <tag>, --cvstag <ref>
377 - build package using resources from specified branch/tag,
378 -A - build package using master branch as any sticky tags/branch/date being reset.
379 -R, --fetch-build-requires
380 - fetch what is BuildRequired,
381 -RB, --remove-build-requires
382 - remove all you fetched with -R or --fetch-build-requires
383 remember, this option requires confirmation,
384 -FRB, --force-remove-build-requires
385 - remove all you fetched with -R or --fetch-build-requires
386 remember, this option works without confirmation,
387 -sd, --source-distfiles
388 - list sources available from distfiles (intended for offline
389 operations; does not work when Icon field is present
390 but icon file is absent),
391 -sc, --source-cvs - list sources available from PLD repo
392 -sdp, --source-distfiles-paths
393 - list sources available from distfiles -
394 paths relative to distfiles directory (intended for offline
395 operations; does not work when Icon field is present
396 but icon file is absent),
397 -sf, --source-files - list sources - bare filenames (intended for offline
398 operations; does not work when Icon field is present
399 but icon file is absent),
401 - list sources - filenames with full local paths (intended for
402 offline operations; does not work when Icon field is present
403 but icon file is absent),
404 -su, --source-urls - list urls - urls to sources and patches
405 intended for copying urls with spec with lots of macros in urls
406 -T <tag> , --tag <tag>
407 - add git tag <tag> for files,
408 -Tvs, --tag-version-stable
409 - add git tags STABLE and NAME-VERSION-RELEASE for files,
411 - add git tag STABLE for files,
413 --tag-version - add git tag NAME-VERSION-RELEASE for files,
414 -Tp, --tag-prefix <prefix>
415 - add <prefix> to NAME-VERSION-RELEASE tags,
416 -tt, --test-tag <prefix>
417 - fail if tag is already present,
418 -ir, --integer-release-only
419 - allow only integer and snapshot releases
420 -v, --verbose - be verbose,
421 -u, --try-upgrade - check version, and try to upgrade package
422 -un, --try-upgrade-with-float-version
423 - as above, but allow float version
424 php-pear-Services_Digg/
425 --upgrade-version - upgrade to specified version in try-upgrade
426 -U, --update - refetch sources, don't use distfiles, and update md5 comments
427 -Upi, --update-poldek-indexes
428 - refresh or make poldek package index files.
430 --skip-patch <patchnumber>
431 - don't apply <patchnumber>. may be repeated.
433 --nopatch <patchnumber>
434 - abort instead of applying patch <patchnumber>
436 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
437 --show-bconds - show available conditional builds, which can be used
438 - with --with and/or --without switches.
439 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
440 In other words, the output is parseable by scripts.
441 --show-avail-bconds - show available bconds
444 - conditional build package depending on %_with_<feature>/
445 %_without_<feature> macro switch. You may now use
446 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
447 constructions. Set GROUP_BCONDS to yes to make use of it.
448 --target <platform>, --target=<platform>
449 - build for platform <platform>.
450 --init-rpm-dir - initialize ~/rpm directory structure
454 # create tempfile. as secure as possible
456 local prefix=builder.$PACKAGE_NAME${1:+.$1}
457 mktemp --tmpdir -t $prefix.XXXXXX || echo ${TMPDIR:-/tmp}/$prefix.$RANDOM.$$
461 local prefix=builder.$PACKAGE_NAME${1:+.$1}
462 mktemp --tmpdir -d $prefix.XXXXXX
465 # inserts git log instead of %changelog
466 # @output directory containing modified specfile
468 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
470 # allow this being customized
471 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
473 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
474 # otherwise i'd use --date=iso here
475 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
476 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
477 # NOTE: changelog date is always in UTC for rpmbuild
478 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
479 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
481 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
482 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
485 # add link to full git logs
486 local giturl="http://git.pld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
487 if [ -n "$CVSTAG" ]; then
488 giturl="$giturl;h=$CVSTAG"
490 local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
491 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
492 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
497 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
498 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
502 " > $specdir/$SPECFILE
503 rm -f $gitlog $speclog
507 # @param string logfile
508 # @param varargs... commands to execute
511 # use teeboth from toys/cleanbuild, if available and enabled
512 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
516 local efile rc logfile=$1; shift
517 if [ "$logfile" ]; then
519 { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile
530 # change dependency to specname
532 # - perl(Package::Name) -> perl-Package-Name
536 if [ $# -gt 0 ]; then
542 echo "$DEPS" | tr ' ' '\n' | sed -re '
545 s/perl\((.*)\)/perl-\1/
549 s/apache\(EAPI\)-devel/apache-devel/
551 s/db-devel/db5.3-devel/
552 s/libjpeg-devel/libjpeg-turbo-devel/
556 update_shell_title() {
558 local len=${COLUMNS:-80}
559 local msg="$(echo "$*" | cut -c-$len)"
561 if [ -n "$BE_VERBOSE" ]; then
562 echo >&2 "$(date +%s.%N) $*"
565 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
567 if [ -n "$PACKAGE_NAME" ]; then
568 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
573 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
574 msg=$(echo $msg | tr -d '\n\r')
577 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
580 echo >&2 -ne "\033]0;$msg\007"
586 # set TARGET from BuildArch: from SPECFILE
588 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
589 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
591 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
595 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
597 TARGET_SWITCH="--target=$TARGET" ;;
603 # runs rpm with minimal macroset
605 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
607 # TODO: move these to /usr/lib/rpm/macros
608 cat > $BUILDER_MACROS <<'EOF'
609 %x8664 x86_64 amd64 ia32e
612 %bootstrap_release() %{1}
613 %requires_releq_kernel_up(s:n:) %{nil}
614 %requires_releq_kernel_smp(s:n:) %{nil}
615 %requires_releq_kernel(s:n:) %{nil}
616 %requires_releq() %{nil}
617 %pyrequires_eq() %{nil}
618 %requires_eq() %{nil}
619 %requires_eq_to() %{nil}
620 %requires_ge() %{nil}
621 %requires_ge_to() %{nil}
622 %requires_ge() %{nil}
623 %releq_kernel_up(n:) ERROR
624 %releq_kernel_smp(n:) ERROR
625 %releq_kernel(n:) ERROR
626 %py_postclean(x:) ERROR
630 %ruby_ver_requires_eq() %{nil}
631 %ruby_mod_ver_requires_eq() %{nil}
632 %__php_api_requires() %{nil}
633 %php_major_version ERROR
634 %php_api_version ERROR
635 %requires_xorg_xserver_extension %{nil}
636 %requires_xorg_xserver_xinput %{nil}
637 %requires_xorg_xserver_font %{nil}
638 %requires_xorg_xserver_videodrv %{nil}
640 %perl_vendorarch ERROR
641 %perl_vendorlib ERROR
642 # damn. need it here! - copied from /usr/lib/rpm/macros.build
643 %tmpdir %(echo "${TMPDIR:-/tmp}")
644 %patchset_source(f:b:) %(
645 base=%{-b*}%{!-b*:10000};
646 start=$(expr $base + %1);
647 end=$(expr $base + %{?2}%{!?2:%{1}});
648 # we need to call seq twice as it doesn't allow two formats
649 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
650 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
651 paste %{tmpdir}/__ps{1,2};
652 rm -f %{tmpdir}/__ps{1,2};
655 %add_etc_shells(p) %{p:<lua>}
656 %remove_etc_shells(p) %{p:<lua>}
657 %lua_add_etc_shells() %{nil}
658 %lua_remove_etc_shells() %{nil}
660 %buildrequires_jdk %{nil}
661 %pear_package_print_optionalpackages %{nil}
663 if [ "$NOINIT" = "yes" ] ; then
664 cat >> $BUILDER_MACROS <<'EOF'
669 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
673 if [ -n "$DEBUG" ]; then
678 if [ -x /usr/bin/rpm-specdump ]; then
679 update_shell_title "cache_rpm_dump using rpm-specdump command"
680 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
682 update_shell_title "cache_rpm_dump using rpmbuild command"
685 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
686 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
692 ARGS='--nodigest --nosignature --nobuild'
695 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
697 if [ $? -gt 0 ]; then
698 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
700 Exit_error err_build_fail
703 # make small dump cache
704 rpm_dump_cache=`echo "$rpm_dump" | awk '
705 $2 ~ /^SOURCEURL/ {print}
706 $2 ~ /^PATCHURL/ {print}
707 $2 ~ /^nosource/ {print}
708 $2 ~ /^PACKAGE_/ {print}
712 update_shell_title "cache_rpm_dump: OK!"
716 if [ -z "$rpm_dump_cache" ] ; then
717 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
719 echo "$rpm_dump_cache"
723 update_shell_title "get icons"
724 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
725 if [ -z "$ICONS" ]; then
729 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
733 update_shell_title "parsing specfile"
734 if [ -n "$DEBUG" ]; then
739 # icons are needed for successful spec parse
745 if rpm_dump | grep -qEi ":.*nosource.*1"; then
746 FAIL_IF_NO_SOURCES="no"
749 if [ "$NOSRCS" != "yes" ]; then
750 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
751 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
752 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
755 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
756 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
757 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
759 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
760 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
763 if [ -n "$BE_VERBOSE" ]; then
764 echo "- Sources : `nourl $SOURCES`"
765 if [ -n "$PATCHES" ]; then
766 echo "- Patches : `nourl $PATCHES`"
768 echo "- Patches : *no patches needed*"
770 if [ -n "$ICONS" ]; then
771 echo "- Icon : `nourl $ICONS`"
773 echo "- Icon : *no package icon*"
775 echo "- Name : $PACKAGE_NAME"
776 echo "- Version : $PACKAGE_VERSION"
777 echo "- Release : $PACKAGE_RELEASE"
780 update_shell_title "parse_spec: OK!"
783 # aborts program abnormally
786 echo >&2 "$PROGRAM: ERROR: $*"
791 if [ -n "$DEBUG" ]; then
799 "err_no_spec_in_cmdl" )
800 remove_build_requires
801 echo >&2 "ERROR: spec file name not specified."
803 "err_invalid_cmdline" )
804 echo >&2 "ERROR: invalid command line arg ($2)."
806 "err_no_spec_in_repo" )
807 remove_build_requires
808 echo >&2 "Error: spec file not stored in PLD repo."
810 "err_no_source_in_repo" )
811 remove_build_requires
812 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
814 "err_cvs_add_failed" )
815 echo >&2 "Error: failed to add package to PLD repo."
818 remove_build_requires
819 echo >&2 "Error: package build failed. (${2:-no more info})"
821 "err_no_package_data" )
822 remove_build_requires
823 echo >&2 "Error: couldn't get out package name/version/release from spec file."
826 remove_build_requires
827 echo >&2 "Tag ${2} already exists"
830 remove_build_requires
831 echo >&2 "Release ${2} not integer and not a snapshot."
833 "err_branch_exists" )
834 remove_build_requires
835 echo >&2 "Tree branch already exists (${2})."
838 remove_build_requires
839 echo >&2 "Error: conditions reject building this spec (${2})."
841 "err_remote_problem" )
842 remove_build_requires
843 echo >&2 "Error: problem with remote (${2})"
846 echo >&2 "Error: cannot checkout $2"
848 "err_not_implemented" )
849 remove_build_requires
850 echo >&2 "Error: functionality not yet imlemented"
853 echo >&2 "Unknown error."
858 if [ -n "$DEBUG" ]; then
863 if [ "$NOINIT" != "yes" ] ; then
864 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
866 local macros_ver=$(rpm -E %?rpm_build_macros)
867 if [ -z "$macros_ver" ]; then
868 REPO_DIR=$TOP_DIR/packages
869 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
871 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
872 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
876 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
881 REPO_DIR=$PACKAGE_DIR
882 RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
884 export GIT_WORK_TREE=$PACKAGE_DIR
885 export GIT_DIR=$PACKAGE_DIR/.git
887 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
888 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
889 CVSTAG=${CVSTAG#refs/heads/}
890 if [ "$CVSTAG" != "master" ]; then
891 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
894 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
897 elif [ "$CVSTAG" = "HEAD" ]; then
898 # assume -r HEAD is same as -A
906 update_shell_title "add_package"
908 if [ -n "$DEBUG" ]; then
914 SPECFILE=$(basename $SPECFILE)
915 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
916 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
919 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
920 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
924 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
925 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
927 git config --local push.default current
928 git config --local branch.master.remote $REMOTE_PLD
929 git config --local branch.master.merge refs/heads/master
931 test $? = 0 || Exit_error err_remote_problem $REMOTE_PLD
936 update_shell_title "get_spec"
938 if [ -n "$DEBUG" ]; then
944 SPECFILE=$(basename $SPECFILE)
945 if [ "$NOCVSSPEC" != "yes" ]; then
946 if [ -z "$DEPTH" ]; then
947 if [ -d "$PACKAGE_DIR/.git" ]; then
948 git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
949 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
950 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
951 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
954 Exit_error err_not_implemented
958 git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
959 # softfail if new package, i.e not yet added to PLD rep
960 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
961 echo "Warning: package not in CVS - assuming new package"
964 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
965 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
969 if [ ! -d "$PACKAGE_DIR/.git" ]; then
970 if [ ! -d "$PACKAGE_DIR" ]; then
971 install -d $PACKAGE_DIR
974 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
975 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
976 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
977 CVSTAG=${CVSTAG:-"master"}
980 if [ -z "$ALL_BRANCHES" ]; then
981 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
983 git fetch $DEPTH $REMOTE_PLD $refs || {
984 echo >&2 "Error: branch $CVSTAG does not exist"
988 git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*'
990 cvsignore_df .gitignore
992 # add default log format to .gitignore if it is relative to package dir
993 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
994 # substitute known "macros" to glob
995 local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g')
996 if [ "$logfile" ]; then
997 cvsignore_df "$logfile"
1001 # create symlinks for tools
1002 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
1003 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh; do
1004 # skip tools that don't exist in top dir
1005 [ -f $a ] || continue
1006 # skip tools that already exist
1007 [ -f $PACKAGE_DIR/$a ] && continue
1008 ln -s ../$a $PACKAGE_DIR
1014 if [ -n "$CVSTAG" ]; then
1015 if git rev-parse --verify -q "$CVSTAG"; then
1016 git checkout "$CVSTAG" --
1017 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1018 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1020 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1021 Exit_error "err_no_checkut" "$CVSTAG"
1023 git merge --ff-only '@{u}'
1024 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1025 if [ -n "$CVSDATE" ]; then
1026 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1030 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1031 Exit_error err_no_spec_in_repo
1034 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1035 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1038 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1043 # find mirrors in this order. first match wins:
1044 # - package dir (~/rpm/packages/foo)
1045 # - repository dir (~/rpm/packages)
1046 # - tools dir dir (~/rpm/packages/rpm-build-tools)
1050 update_shell_title "find_mirror[$url][$REPO_DIR]"
1052 # NOTE: as while loop runs in subshell,
1053 # we use exit 2 to indicate that the match was found
1054 # otherwise we end up outputing mirror url and origin url.
1056 local origin mirror name rest ol prefix
1058 cat "$PACKAGE_DIR/mirrors" "$REPO_DIR/mirrors" "$REPO_DIR/../rpm-build-tools/mirrors" /dev/null 2>/dev/null | \
1059 while read origin mirror name rest; do
1060 # skip comments and empty lines
1061 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1064 ol=$(echo -n "$origin" | wc -c)
1065 prefix=$(echo -n "$url" | head -c $ol)
1066 if [ "$prefix" = "$origin" ] ; then
1067 suffix=$(echo "$url" | cut -b $((ol+1))-)
1068 echo -n "$mirror$suffix"
1074 # Warning: unpredictable results if same URL used twice
1077 # escape some regexp characters if part of file name
1078 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1081 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1082 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1083 head -n 1 | tr OURCEATH ourceath | xargs
1087 [ "$NO5" = "yes" ] && return
1089 [ -z "$no" ] && return
1093 # use "sources" file from package dir, like vim
1094 if [ -f sources ]; then
1095 md5=$(grep -s -v '^#' sources | \
1096 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1097 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1098 grep -E '^[0-9a-f]{32}$')
1101 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1102 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1104 echo "$md5" | tail -n 1
1109 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1110 if [ -n "$source_md5" ]; then
1113 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1114 if [ -n "$source_md5" ]; then
1117 # we have empty SourceX-md5, but it is still possible
1118 # that we have NoSourceX-md5 AND NoSource: X
1119 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1120 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1128 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1132 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1135 distfiles_attic_url() {
1136 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
1141 [ "$md5" = "" ] || \
1142 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1146 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1147 [ -n "$size" -a "$size" -gt 0 ]
1151 if [ "$CVSIGNORE_DF" != "yes" ]; then
1154 cvsignore=${PACKAGE_DIR}/.gitignore
1156 # add only if not yet there
1157 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1158 echo "$1" >> $cvsignore
1162 # returns true if "$1" is ftp, http or https protocol url
1165 ftp://*|http://*|https://*)
1173 if [ $# -eq 0 ]; then
1177 update_shell_title "update md5"
1178 if [ -n "$DEBUG" ]; then
1185 # pass 1: check files to be fetched
1189 local fp=$(nourl "$i")
1190 local srcno=$(src_no "$i")
1191 if [ -n "$ADD5" ]; then
1192 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1193 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1194 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1196 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1198 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1199 need_files="$need_files $i"
1203 # pass 1a: get needed files
1204 if [ "$need_files" ]; then
1205 get_files $need_files
1208 # pass 2: proceed with md5 adding or updating
1210 local fp=$(nourl "$i")
1211 local srcno=$(src_no "$i")
1212 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1213 if [ -z "$md5" ]; then
1214 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1216 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1217 local tag="# $srcno-md5:\t"
1218 if [[ "$md5" == *NoSource* ]]; then
1219 tag="# No$srcno-md5:\t"
1220 elif [ -n "$USEDIGEST" ]; then
1221 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1223 md5=$(md5sum "$fp" | cut -f1 -d' ')
1224 echo "Updating $srcno ($md5: $fp)."
1226 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1227 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1229 $PACKAGE_DIR/$SPECFILE
1236 [ "$NO5" = "yes" ] && return
1238 update_shell_title "check md5"
1242 if ! good_md5 "$i"; then
1243 echo -n "MD5 sum mismatch."
1246 if ! good_size "$i"; then
1247 echo -n "0 sized file."
1251 if [ $bad -eq 1 ]; then
1252 echo " Use -U to refetch sources,"
1253 echo "or -5 to update md5 sums, if you're sure files are correct."
1254 Exit_error err_no_source_in_repo $i
1260 update_shell_title "get_files"
1262 if [ -n "$DEBUG" ]; then
1267 if [ $# -gt 0 ]; then
1271 local get_files_cvs=""
1275 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1276 update_shell_title "$i"
1277 local fp=`nourl "$i"`
1278 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1283 local srcmd5=$(src_md5 "$i")
1285 # we know if source/patch is present in cvs/distfiles
1286 # - has md5 (in distfiles)
1287 # - in cvs... ideas?
1289 # CHECK: local file didn't exist or always cvs up (first) requested.
1290 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1291 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1292 echo "Warning: no URL given for $i"
1296 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1297 if good_md5 "$i" && good_size "$i"; then
1298 echo "$fp having proper md5sum already exists"
1302 # optionally prefer mirror over distfiles if there's mirror
1303 # TODO: build url list and then try each url from the list
1304 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1307 url=$(distfiles_url "$i")
1310 url_attic=$(distfiles_attic_url "$i")
1312 # is $url local file?
1313 if [[ "$url" = [./]* ]]; then
1314 update_shell_title "${GETLOCAL%% *}: $url"
1315 ${GETLOCAL} $url $target
1318 # make shorter message for distfiles urls
1319 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1320 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1321 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1324 update_shell_title "${GETURI%% *}: $uri"
1325 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1326 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1327 update_shell_title "${GETURI2%% *}: $url"
1328 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1333 if [ ! -s "$target" ]; then
1335 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1336 update_shell_title "${GETLOCAL%% *}: $url_attic"
1337 ${GETLOCAL} $url_attic $target
1339 update_shell_title "${GETURI%% *}: $url_attic"
1340 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1341 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1342 update_shell_title "${GETURI2%% *}: $url_attic"
1343 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1345 test -s "$target" || rm -f "$target"
1349 if [ -s "$target" ]; then
1350 cvsignore_df $target
1357 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1358 if [ -z "$NOMIRRORS" ]; then
1359 im=$(find_mirror "$i")
1363 update_shell_title "${GETURI%% *}: $im"
1364 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1365 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1366 update_shell_title "${GETURI2%% *}: $im"
1367 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1369 test -s "$target" || rm -f "$target"
1372 if [ "$cvsup" = 1 ]; then
1378 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1379 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1380 Exit_error err_no_source_in_repo $i
1383 # we check md5 here just only to refetch immediately
1384 if good_md5 "$i" && good_size "$i"; then
1386 elif [ "$FROM_DISTFILES" = 1 ]; then
1387 # wrong md5 from distfiles: remove the file and try again
1389 echo "MD5 sum mismatch. Trying full fetch."
1392 update_shell_title "${GETURI%% *}: $url"
1393 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1394 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1395 update_shell_title "${GETURI2%% *}: $url"
1396 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1398 if [ ! -s "$target" ]; then
1400 update_shell_title "${GETURI%% *}: $url_attic"
1401 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1402 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1403 update_shell_title "${GETURI2%% *}: $url_attic"
1404 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1407 test -s "$target" || rm -f "$target"
1410 SHELL_TITLE_PREFIX=""
1413 if [ "$CHMOD" = "yes" ]; then
1414 CHMOD_FILES=$(nourl "$@")
1415 if [ -n "$CHMOD_FILES" ]; then
1416 chmod $CHMOD_MODE $CHMOD_FILES
1423 # If tag exists and points to other commit exit with error
1424 # If it existsts and points to HEAD return 1
1425 # If it doesn't exist return 0
1427 local sha1=$(git rev-parse HEAD)
1428 echo "Searching for tag $_tag..."
1429 if [ -n "$DEPTH" ]; then
1430 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1432 local ref=$(git show-ref -s "refs/tags/$_tag")
1434 [ -z "$ref" ] && return 0
1435 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1440 if [ -n "$DEBUG" ]; then
1445 # Check whether first character of PACKAGE_NAME is legal for tag name
1446 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1450 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1451 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1453 # Remove @kernel.version_release from TAGVER because tagging sources
1454 # could occur with different kernel-headers than kernel-headers used at build time.
1455 # besides, %{_kernel_ver_str} is not expanded.
1457 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1458 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1465 if [ -n "$DEBUG" ]; then
1470 echo "Version: $PACKAGE_VERSION"
1471 echo "Release: $PACKAGE_RELEASE"
1474 if [ "$TAG_VERSION" = "yes" ]; then
1477 if [ -n "$TAG" ]; then
1482 local OPTIONS="tag $CVS_FORCE"
1486 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1487 update_shell_title "tag sources: $_tag"
1488 git $OPTIONS $_tag || exit
1489 git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1491 echo "Tag $_tag already exists and points to the same commit"
1497 echo "Git branch: $TAG"
1500 if [ -n "$DEBUG" ]; then
1505 local OPTIONS="branch $CVS_FORCE"
1508 git $OPTIONS $TAG || exit
1512 # this function should exit early if package can't be built for this arch
1513 # this avoids unneccessary BR filling.
1516 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1518 if [ $ret -ne 0 ]; then
1530 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1531 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1537 local ver="$2" subver=$ver
1538 local newver="$3" newsubver=$newver
1540 # try handling subver, everything that's not numeric-dotted in version
1541 if grep -Eq '%define\s+subver' $specfile; then
1542 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1544 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1545 newver=${newver%$newsubver}
1548 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1549 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1550 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1554 # try to upgrade .spec to new version
1555 # if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1557 # return 1: if .spec was updated
1558 # return 0: no changes to .spec
1559 # exit 1 in case of error
1561 if [ -z "$TRY_UPGRADE" ]; then
1565 local TNOTIFY TNEWVER TOLDVER
1566 update_shell_title "build_package: try_upgrade"
1570 if [ "$UPGRADE_VERSION" ]; then
1571 TNEWVER=$UPGRADE_VERSION
1572 echo "Updating spec file to version $TNEWVER"
1574 if [ -n "$FLOAT_VERSION" ]; then
1575 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1577 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1580 # pldnotify does not set exit codes, but it has match for ERROR
1581 # in output which means so.
1582 if [[ "$TNOTIFY" = *ERROR* ]]; then
1587 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1588 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1590 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1593 if [ -z "$TNEWVER" ]; then
1597 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1598 cp -f $SPECFILE $SPECFILE.bak
1601 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1602 set_release $SPECFILE $PACKAGE_RELEASE 1
1604 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1605 echo >&2 "Upgrading version failed, you need to update spec yourself"
1612 update_shell_title "build_package"
1613 if [ -n "$DEBUG" ]; then
1622 BUILD_SWITCH="-ba" ;;
1624 BUILD_SWITCH="-bb" ;;
1626 BUILD_SWITCH="-bs --nodeps" ;;
1628 BUILD_SWITCH="-bp --nodeps" ;;
1630 BUILD_SWITCH="-bc" ;;
1632 BUILD_SWITCH="-bi" ;;
1634 BUILD_SWITCH="-bl" ;;
1638 update_shell_title "build_package: $COMMAND"
1639 local logfile retval
1640 if [ -n "$LOGFILE" ]; then
1641 logfile=`eval echo $LOGFILE`
1642 if [ -d "$logfile" ]; then
1643 echo "Log file $logfile is a directory."
1644 echo "Parse error in the spec?"
1645 Exit_error err_build_fail
1647 if [ -n "$LASTLOG_FILE" ]; then
1648 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1652 local specdir=$(insert_gitlog $SPECFILE)
1653 # FIXME: eval here is exactly why?
1654 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
1658 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1659 if [ "$retval" -eq "0" ]; then
1660 mv $logfile $LOGDIROK
1662 mv $logfile $LOGDIRFAIL
1666 if [ "$retval" -ne "0" ]; then
1667 if [ -n "$TRY_UPGRADE" ]; then
1668 echo "\nUpgrade package to new version failed."
1669 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1670 echo "Restoring old spec file."
1671 mv -f $SPECFILE.bak $SPECFILE
1675 Exit_error err_build_fail
1681 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1684 install_required_packages() {
1689 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1692 /^%changelog/ { exit }
1694 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1695 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1696 gsub(/[ \t]+/, "_", bcond);
1698 }' $SPEC | LC_ALL=C sort -u
1702 # expand bconds from ~/.bcondrc
1703 # The file structure is like gentoo's package.use:
1706 # samba -mysql -pgsql
1707 # w32codec-installer license_agreement
1710 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1716 SN=${SPECFILE%%\.spec}
1718 local bcondrc=$HOME/.bcondrc
1719 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1721 local bcond_avail=$(find_spec_bcond $SPECFILE)
1723 while read pkg flags; do
1725 [[ "$pkg" == \#* ]] && continue
1727 # any package or current package?
1728 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1729 for flag in $flags; do
1730 local opt=${flag#[+-]}
1732 # use only flags which are in this package.
1733 if [[ $bcond_avail = *${opt}* ]]; then
1734 if [[ $flag = -* ]]; then
1735 if [[ $BCOND != *--with?${opt}* ]]; then
1736 BCOND="$BCOND --without $opt"
1739 if [[ $BCOND != *--without?${opt}* ]]; then
1740 BCOND="$BCOND --with $opt"
1747 update_shell_title "parse ~/.bcondrc: DONE!"
1750 set_bconds_values() {
1751 update_shell_title "set bcond values"
1753 AVAIL_BCONDS_WITHOUT=""
1754 AVAIL_BCONDS_WITH=""
1756 if grep -Eq '^# *_with' ${SPECFILE}; then
1757 echo >&2 "ERROR: This spec has old style bconds."
1761 if ! grep -q '^%bcond' ${SPECFILE}; then
1765 local bcond_avail=$(find_spec_bcond $SPECFILE)
1766 process_bcondrc "$SPECFILE"
1768 update_shell_title "parse bconds"
1771 for opt in $bcond_avail; do
1774 bcond=${opt#without_}
1776 *--without?${bcond}*)
1777 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1780 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1788 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1791 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1796 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1805 update_shell_title "run_sub_builder $package_name"
1807 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1808 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
1809 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1810 # jakby nie bylo tego kawalka kodu.
1812 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1813 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
1817 # kurwa. translate that ^^^^
1821 # Istnieje taki spec? ${package}.spec
1822 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1823 parent_spec_name=${package}.spec
1824 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1825 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1827 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1832 if [ "${parent_spec_name}" != "" ]; then
1833 spawn_sub_builder $parent_spec_name
1835 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1838 # install package with poldek
1839 # @return exit code from poldek
1841 # this requires following sudo rules:
1842 # - poldek --noask --caplookup -uG
1844 LANG=C $POLDEK_CMD --noask --caplookup --uniq -uG "$@"
1849 # this requires following sudo rules:
1850 # - poldek -q --update --upa
1851 install_packages() {
1852 # sync poldek indexes once per invocation
1853 if [ -z "$package_indexes_updated" ]; then
1854 update_shell_title "poldek: update indexes"
1855 $POLDEK_CMD -q --update --upa
1856 package_indexes_updated=true
1859 update_shell_title "install packages: $*"
1860 poldek_install "$@" && return
1862 # retry install, install packages one by one
1863 # this is slower one
1865 for package in $*; do
1866 package=$(depspecname $package)
1867 update_shell_title "install package: $package"
1868 poldek_install "$package" || rc=$?
1873 uninstall_packages() {
1874 update_shell_title "uninstall packages: $*"
1875 $POLDEK_CMD --noask --nofollow -ev "$@"
1878 spawn_sub_builder() {
1880 update_shell_title "spawn_sub_builder $package_name"
1883 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1884 sub_builder_opts="${sub_builder_opts} -R"
1886 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1887 sub_builder_opts="${sub_builder_opts} -RB"
1888 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1889 sub_builder_opts="${sub_builder_opts} -FRB"
1891 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1892 sub_builder_opts="${sub_builder_opts} -Upi"
1896 ./builder ${sub_builder_opts} "$@"
1899 remove_build_requires() {
1900 if [ "$INSTALLED_PACKAGES" != "" ]; then
1901 case "$REMOVE_BUILD_REQUIRES" in
1903 run_poldek --noask -ve $INSTALLED_PACKAGES
1906 run_poldek --ask -ve $INSTALLED_PACKAGES
1909 echo You may want to manually remove following BuildRequires fetched:
1910 echo $INSTALLED_PACKAGES
1911 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1918 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1919 if [ "$BCOND" ]; then
1921 echo "Building $SPECFILE with the following conditional flags:"
1925 echo "No conditional flags passed"
1928 echo "from available:"
1929 echo "--with :\t$AVAIL_BCONDS_WITH"
1930 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1935 display_branches() {
1936 echo -n "Available branches: "
1937 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1940 # checks a given list of packages/files/provides against current rpmdb.
1941 # outputs all dependencies which current rpmdb doesn't satisfy.
1942 # input can be either STDIN or parameters
1946 if [ $# -gt 0 ]; then
1952 out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1)
1955 echo "$out" | awk '/^no package provides/ { print $NF }'
1957 # other deps (files)
1958 echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p'
1961 # checks if given package/files/provides exists in rpmdb.
1962 # input can be either stdin or parameters
1963 # returns packages which are present in the rpmdb
1967 if [ $# -gt 0 ]; then
1973 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1976 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1977 install_build_requires_rpmdeps() {
1979 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1980 # TODO: Conflicts list doesn't check versions
1981 CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1982 DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1984 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1985 CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1986 DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1989 if [ -n "$CNFL" ]; then
1990 echo "Uninstall conflicting packages: $CNFL"
1991 uninstall_packages $CNFL
1994 if [ -n "$DEPS" ]; then
1995 echo "Install dependencies: $DEPS"
1996 install_packages $DEPS
2000 fetch_build_requires()
2002 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
2006 update_shell_title "fetch build requires"
2007 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2008 install_build_requires_rpmdeps
2012 die "need rpm-getdeps tool"
2019 if [ ! -e $localrepo ]; then
2020 git clone -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
2021 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2026 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2027 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2028 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2029 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2030 local TEMPLATES=template-specs
2033 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2034 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2037 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2038 init_repository projects/$TEMPLATES ../$TEMPLATES
2039 for a in adapter builder fetchsrc_request compile repackage; do
2040 ln -sf ../rpm-build-tools/${a}.sh $a
2043 ln -sf ../rpm-build-tools/${a} $a
2045 ln -sf ../rpm-build-tools/mirrors mirrors
2052 DONT_PRINT_REVISION="yes"
2054 # remove spec and sources
2055 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
2056 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2057 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2060 #---------------------------------------------
2068 # stuff global $BUILDER_OPTS from env as args
2069 if [ "$BUILDER_OPTS" ]; then
2070 set -- "$BUILDER_OPTS" "$@"
2073 while [ $# -gt 0 ]; do
2076 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2077 # unfortunately $GETURI is already formed
2082 COMMAND="update_md5"
2087 COMMAND="update_md5"
2096 DEBUG="yes"; shift ;;
2098 COMMAND="version"; shift ;;
2100 COMMAND="short-version"; shift ;;
2107 -b | -ba | --build )
2108 COMMAND="build"; shift ;;
2109 -bb | --build-binary )
2110 COMMAND="build-binary"; shift ;;
2112 COMMAND="build-build"; shift ;;
2114 COMMAND="build-install"; shift ;;
2116 COMMAND="build-list"; shift ;;
2117 -bp | --build-prep )
2118 COMMAND="build-prep"; shift ;;
2119 -bs | --build-source )
2120 COMMAND="build-source"; shift ;;
2122 COMMAND="branch"; shift; TAG="${1}"; shift;;
2124 CLEAN="--clean"; shift ;;
2126 CVS_FORCE="-f"; shift;;
2132 COMMAND="get"; shift ;;
2134 COMMAND="usage"; shift ;;
2136 PROTOCOL="ftp"; shift ;;
2138 PROTOCOL="http"; shift ;;
2140 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2144 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2148 PARALLEL_DOWNLOADS=$2
2152 PARALLEL_DOWNLOADS=${1#-p}
2156 shift; LOGFILE="${1}"; shift ;;
2158 shift; DEF_NICE_LEVEL=${1}; shift ;;
2159 -ske | --skip-existing-files)
2160 SKIP_EXISTING_FILES="yes"; shift ;;
2162 COMMAND="mr-proper"; shift ;;
2163 -ncs | --no-cvs-specs )
2164 NOCVSSPEC="yes"; shift ;;
2165 -nd | --no-distfiles )
2166 NODIST="yes"; shift ;;
2167 -nm | --no-mirrors )
2168 NOMIRRORS="yes"; shift ;;
2170 NOURLS="yes"; shift ;;
2172 NOSRCS="yes"; shift ;;
2173 -ns0 | --no-source0 )
2174 NOSOURCE0="yes"; shift ;;
2183 -pm | --prefer-mirrors )
2186 --noinit | --no-init )
2190 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2192 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2193 --skip-patch | -sp )
2194 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2196 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2199 --with | --without )
2200 case $GROUP_BCONDS in
2204 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2205 while ! `echo ${1}|grep -qE '(^-|spec)'`
2207 BCOND="$BCOND $COND $1"
2211 if [[ "$2" = *,* ]]; then
2212 for a in $(echo "$2" | tr , ' '); do
2213 BCOND="$BCOND $1 $a"
2216 BCOND="$BCOND $1 $2"
2222 shift; TARGET="${1}"; shift ;;
2224 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2226 QUIET="--quiet"; shift ;;
2228 CVSDATE="${2}"; shift 2
2229 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2239 -R | --fetch-build-requires)
2240 FETCH_BUILD_REQUIRES="yes"
2241 NOT_INSTALLED_PACKAGES=
2243 -RB | --remove-build-requires)
2244 REMOVE_BUILD_REQUIRES="nice"
2246 -FRB | --force-remove-build-requires)
2247 REMOVE_BUILD_REQUIRES="force"
2250 COMMAND="list-sources-cvs"
2252 -sd | --source-distfiles)
2253 COMMAND="list-sources-distfiles"
2255 -sdp | --source-distfiles-paths)
2256 COMMAND="list-sources-distfiles-paths"
2258 -sf | --source-files)
2259 COMMAND="list-sources-files"
2261 -lsp | --source-paths)
2262 COMMAND="list-sources-local-paths"
2264 -su | --source-urls)
2265 COMMAND="list-sources-urls"
2267 -Tvs | --tag-version-stable )
2272 -Ts | --tag-stable )
2277 -Tv | --tag-version )
2282 -Tp | --tag-prefix )
2294 -ir | --integer-release-only )
2295 INTEGER_RELEASE="yes"
2298 COMMAND="update_md5"
2303 -Upi | --update-poldek-indexes )
2304 UPDATE_POLDEK_INDEXES="yes"
2307 COMMAND="init_rpm_dir"
2309 -u | --try-upgrade )
2310 TRY_UPGRADE="1"; shift ;;
2312 shift; UPGRADE_VERSION="$1"; shift;;
2313 -un | --try-upgrade-with-float-version )
2314 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2316 BE_VERBOSE="1"; shift ;;
2321 if echo "${MACRO}" | grep -q '\W'; then
2322 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2326 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2331 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\""
2335 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2338 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2339 COMMAND="show_bconds"
2343 COMMAND="show_bcond_args"
2346 --show-avail-bconds)
2347 COMMAND="show_avail_bconds"
2352 RPMOPTS="${RPMOPTS} --nodeps"
2355 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2358 Exit_error err_invalid_cmdline "$1"
2361 SPECFILE=${1%/}; shift
2362 # check if specname was passed as specname:cvstag
2363 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2364 CVSTAG="${SPECFILE##*:}"
2365 SPECFILE="${SPECFILE%%:*}"
2367 # always have SPECFILE ending with .spec extension
2368 SPECFILE=${SPECFILE%%.spec}.spec
2369 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2373 if [ "$CVSTAG" ]; then
2374 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2375 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2378 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2379 echo >&2 "--all branches requires --depth <number>"
2380 Exit_error err_invalid_cmdline
2383 if [ -n "$DEBUG" ]; then
2388 if [ -n "$TARGET" ]; then
2391 TARGET_SWITCH="--target $TARGET" ;;
2393 TARGET_SWITCH="--target=$TARGET" ;;
2397 if [ "$SCHEDTOOL" != "no" ]; then
2398 NICE_COMMAND="$SCHEDTOOL"
2400 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2403 # see time(1) for output format that could be used
2404 TIME_COMMAND="time -p"
2406 update_shell_title "$COMMAND"
2410 if [ -z "$SPECFILE" ]; then
2411 Exit_error err_no_spec_in_cmdl
2413 get_spec > /dev/null
2420 if [ -z "$SPECFILE" ]; then
2421 Exit_error err_no_spec_in_cmdl
2423 get_spec > /dev/null
2428 "show_avail_bconds")
2430 if [ -z "$SPECFILE" ]; then
2431 Exit_error err_no_spec_in_cmdl
2434 get_spec > /dev/null
2436 local bcond_avail=$(find_spec_bcond $SPECFILE)
2437 local opt bcond bconds
2438 for opt in $bcond_avail; do
2441 bcond=${opt#without_}
2442 bconds="$bconds $bcond"
2446 bconds="$bconds $bcond"
2449 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2457 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2459 if [ -z "$SPECFILE" ]; then
2460 Exit_error err_no_spec_in_cmdl
2463 # display SMP make flags if set
2464 smp_mflags=$(rpm -E %{?_smp_mflags})
2465 if [ "$smp_mflags" ]; then
2466 echo "builder: SMP make flags are set to $smp_mflags"
2474 if [ "$COMMAND" != "build-source" ]; then
2477 fetch_build_requires
2478 if [ "$INTEGER_RELEASE" = "yes" ]; then
2479 echo "Checking release $PACKAGE_RELEASE..."
2480 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2481 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2485 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2486 if [ -n "$TEST_TAG" ]; then
2487 local TAGVER=`make_tagver`
2488 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2489 # check also tags created in CVS
2490 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2491 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2492 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2493 || Exit_error err_tag_exists $TAGVER_CVS
2494 # - do not allow to build from HEAD when XX-branch exists
2495 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2496 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2497 TAG_BRANCH="${TREE_PREFIX}-branch"
2498 if [ -n "$DEPTH" ]; then
2499 cmd_branches="git ls-remote --heads"
2500 ref_prefix=refs/heads
2502 cmd_branches="git show-ref"
2503 ref_prefix=refs/remotes/${REMOTE_PLD}
2505 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2506 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2507 Exit_error err_branch_exists "$TAG_STATUS"
2513 if [ -n "$NOSOURCE0" ] ; then
2514 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2519 get_files $SOURCES $PATCHES
2520 check_md5 $SOURCES $PATCHES
2523 NODIST="yes" get_files $SOURCES $PATCHES
2524 update_md5 $SOURCES $PATCHES
2528 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2529 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2531 remove_build_requires
2535 if [ -z "$SPECFILE" ]; then
2536 Exit_error err_no_spec_in_cmdl
2545 if [ -z "$SPECFILE" ]; then
2546 Exit_error err_no_spec_in_cmdl
2550 if [ -n "$NEW_REPO" ]; then
2553 for file in $SOURCES $PATCHES; do
2554 if [ -z $(src_md5 "$file") ]; then
2555 git add $file || Exit_error err_no_source_in_repo $file
2557 cvsignore_df `nourl $file`
2561 echo "When you are ready commit your changes and run git push origin master"
2563 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2568 if [ -z "$SPECFILE" ]; then
2569 Exit_error err_no_spec_in_cmdl
2575 if [ -n "$NOSOURCE0" ] ; then
2576 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2578 get_files $SOURCES $PATCHES
2583 if [ -z "$SPECFILE" ]; then
2584 Exit_error err_no_spec_in_cmdl
2590 if [ -n "$NOSOURCE0" ] ; then
2591 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2593 update_md5 $SOURCES $PATCHES
2599 if [ -z "$SPECFILE" ]; then
2600 Exit_error err_no_spec_in_cmdl
2604 if [ ! -d .git ]; then
2605 echo "No git reposiotory" >&2
2613 "list-sources-files" )
2616 DONT_PRINT_REVISION="yes"
2619 for SAP in $SOURCES $PATCHES; do
2620 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2623 "list-sources-urls" )
2626 DONT_PRINT_REVISION="yes"
2629 SAPS="$SOURCES $PATCHES"
2630 for SAP in $SAPS; do
2634 "list-sources-local-paths" )
2637 DONT_PRINT_REVISION="yes"
2640 for SAP in $SOURCES $PATCHES; do
2641 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2644 "list-sources-distfiles-paths" )
2647 DONT_PRINT_REVISION="yes"
2650 for SAP in $SOURCES $PATCHES; do
2651 if [ -n "$(src_md5 "$SAP")" ]; then
2652 distfiles_path "$SAP"
2656 "list-sources-distfiles" )
2659 DONT_PRINT_REVISION="yes"
2662 for SAP in $SOURCES $PATCHES; do
2663 if [ -n "$(src_md5 "$SAP")" ]; then
2664 distfiles_url "$SAP"
2668 "list-sources-cvs" )
2671 DONT_PRINT_REVISION="yes"
2674 for SAP in $SOURCES $PATCHES; do
2675 if [ -z "$(src_md5 "$SAP")" ]; then
2676 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2690 echo "$VERSIONSTRING"
2693 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2694 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2698 # vi:syntax=sh:ts=4:sw=4:noet