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="TLD/Builder($VERSION)"
73 # It can be used i.e. in log file naming.
74 # See LOGFILE example.
75 DATE=`date +%Y-%m-%d_%H-%M-%S`
77 # target arch, can also be used for log file naming
78 TARGET=$(rpm -E %{_target})
80 # 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
105 # create symlinks for tools in PACKAGE_DIR, see get_spec()
118 # use lftp by default when available
119 test -z "${USE_LFTP+x}" && lftp --version > /dev/null 2>&1 && USE_LFTP=yes
120 PARALLEL_DOWNLOADS=10
122 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
125 DISTBCOND_URL="https://src.tld-linux.org/.distbcond"
127 # rsync repository with git refs of packages
128 PKGREVS_URL="https://pkgrevs.tld-linux.org"
129 PKGREVS_PREFIX="tld/"
133 TLD_GIT_SERVER="git://git.tld-linux.org"
134 TLD_GIT_PUSH="git@git.tld-linux.org:7272"
135 TLD_PACKAGES_DIR="packages"
136 TLD_DISTFILES_SERVER="://df.tld-linux.org"
139 PLD_GIT_SERVER="git://git.pld-linux.org"
140 PLD_GIT_PUSH="git@git.pld-linux.org"
141 PLD_PACKAGES_DIR="packages"
142 PLD_DISTFILES_SERVER="://distfiles.pld-linux.org"
147 GIT_SERVER=${TLD_GIT_SERVER}
148 GIT_PUSH=${TLD_GIT_PUSH}
149 PACKAGES_DIR=${TLD_PACKAGES_DIR}
158 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
163 FAIL_IF_NO_SOURCES="yes"
165 # let get_files skip over files which are present to get those damn files fetched
166 SKIP_EXISTING_FILES="no"
169 # should the specfile be restored if upgrade failed?
170 REVERT_BROKEN_UPGRADE="yes"
172 if rpm --specsrpm 2>/dev/null; then
173 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
174 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
176 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
177 if [ -x /usr/bin/rpm-getdeps ]; then
178 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
180 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
184 UPDATE_POLDEK_INDEXES_OPTS=""
186 # Here we load saved user environment used to
187 # predefine options set above, or passed to builder
189 # This one reads global system environment settings:
190 if [ -f ~/etc/builderrc ]; then
193 # And this one cascades settings using user personal
195 # Example of ~/.builderrc:
197 #UPDATE_POLDEK_INDEXES="yes"
198 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
199 #FETCH_BUILD_REQUIRES="yes"
200 #REMOVE_BUILD_REQUIRES="force"
202 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
207 if [ -n "$HOME_ETC" ]; then
208 USER_CFG="$HOME_ETC/.builderrc"
209 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
211 USER_CFG=~/.builderrc
212 BUILDER_MACROS=~/.builder-rpmmacros
215 [ -f "$USER_CFG" ] && . "$USER_CFG"
217 if [ "$SCHEDTOOL" = "auto" ]; then
218 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
219 SCHEDTOOL="schedtool -B -e"
225 if [ -n "$USE_PROZILLA" ]; then
227 elif [ -n "$USE_AXEL" ]; then
229 elif [ -n "$USE_LFTP" ]; then
235 GETLOCAL=${GETLOCAL:-cp -a}
243 if [ -d $HOME/rpm/SOURCES ]; then
244 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
245 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
249 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
250 POLDEK_CMD="$SU_SUDO /usr/bin/poldek"
253 # TODO: what this function does?
256 if [ -n "$LOGFILE" ]; then
257 LOG=`eval echo $LOGFILE`
258 if [ -n "$LASTLOG_FILE" ]; then
259 echo "LASTLOG=$LOG" > $LASTLOG_FILE
261 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
262 # FIXME $exit_pldk undefined
265 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
266 return `cat ${RES_FILE}`
271 #---------------------------------------------
274 download_prozilla() {
275 local outfile=$1 url=$2 retval
277 proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS -O "$outfile" "$url"
284 local outfile=$1 url=$2 retval
286 axel -a $AXEL_OPTS -o "$outfile" "$url"
293 local outfile=$1 url=$2 retval wget_help
294 if [ -z "${WGET_OPTS_SET+x}" ]; then
295 wget_help="$(wget --help 2>&1)"
296 echo "$wget_help" | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
297 echo "$wget_help" | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
298 echo "$wget_help" | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
299 echo "$wget_help" | grep -q -- ' --no-iri ' && WGET_OPTS="$WGET_OPTS --no-iri"
300 WGET_OPTS="-c -nd -t$WGET_RETRIES $WGET_OPTS --user-agent=$USER_AGENT $IPOPT --passive-ftp"
304 wget $WGET_OPTS -O "$outfile" "$url"
306 if [ $retval -ne 0 ]; then
307 if [ "`echo $url | grep -E 'ftp://'`" ]; then
308 ${GETURI} -O "$outfile" "$url"
316 local outfile=$1 url=$2 retval tmpfile
317 tmpfile=$(tempfile) || exit 1
319 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
320 $([ "$IPOPT" = "-4" ] && echo "set dns:order \"inet\";")
321 $([ "$IPOPT" = "-6" ] && echo "set dns:order \"inet6\";")
322 set ssl:verify-certificate no;
323 set net:max-retries $WGET_RETRIES;
324 set http:user-agent \"$USER_AGENT\";
325 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
329 if [ $retval -eq 0 ]; then
330 mv -f "$tmpfile" "$outfile"
338 if [ -n "$DEBUG" ]; then set -xv; fi
340 # to make this output parseable by bash-completion _parse_help()
341 # if the line contains short and long option, it will take only the long option
342 # but if you want both being completed, put the short option to separate line
344 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version]
345 [-a|--add_cvs] [-b|-ba|--build] [-bb|--build-binary] [-bs|--build-source]
346 [-bc] [-bi] [-bl] [-u|--try-upgrade] [{-cf|--cvs-force}] [{-B|--branch} <branch>]
347 [--depth <number>] [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>]
348 [-m|--mr-proper] [-q|--quiet] [--date <yyyy-mm-dd>] [-r <tag>]
349 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
350 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
351 [--git-pld|--git-tld] [--pkgrev] [-lp]
352 <package>[.spec][:tag]
354 -4 - force IPv4 when transferring files
355 -6 - force IPv6 when transferring files
357 --update-md5 - update md5 comments in spec, implies -nd -ncs
359 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
360 --all-branches - make shallow fetch of all branches; --depth required
361 -n5, --no-md5 - ignore md5 comments in spec
362 -D, --debug - enable builder script debugging mode,
363 -debug - produce rpm debug package (same as --opts -debug)
364 -V, --version - output builder version string
365 --short-version - output builder short version
366 -a - try add new package to PLD repo.
369 - get all files from PLD repo or HTTP/FTP and build package
371 -bb - get all files from PLD repo or HTTP/FTP and build binary
372 only package from <package>.spec,
373 -bp - execute the %prep phase of <package>.spec,
374 -bc - execute the %build phase of <package>.spec,
375 -bi - execute the %install phase of <package>.spec
376 -bl - execute the %files phase of <package>.spec
377 -bs - get all files from PLD repo or HTTP/FTP and only pack
379 --short-circuit - short-circuit build
380 -B, --branch - add branch
382 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
383 may be used with building process.
384 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
385 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
386 -cf, --cvs-force - use -f when tagging
387 --define '<macro> <value>'
388 - define a macro <macro> with value <value>,
389 --depth <number> - make shallow fetch
390 --alt_kernel <kernel>
391 - same as --define 'alt_kernel <kernel>'
392 --nodeps - rpm won't check any dependences
394 --get - get <package>.spec and all related files from PLD repo
395 -h, --help - this message,
396 -j N - set %_smp_mflags to propagate concurrent jobs
397 --ftp - use FTP protocol to access distfiles server
398 --http - use HTTP protocol to access distfiles server
399 -l <logfile>, --logtofile=<logfile>
402 - don't pull from PLD repo
403 -nd, --no-distfiles - don't download from distfiles
404 -nm, --no-mirrors - don't download from mirror, if source URL is given,
405 -nu, --no-urls - don't try to download from FTP/HTTP location,
406 -ns, --no-srcs - don't download Sources/Patches
407 -ns0, --no-source0 - don't download Source0
408 -nn, --no-net - don't download anything from the net
409 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
410 -pm, --prefer-mirrors
411 - prefer mirrors (if any) over distfiles for SOURCES
412 --no-init - don't initialize builder paths (SPECS and SOURCES)
414 --skip-existing-files
415 - skip existing files in get_files
416 --opts <rpm opts> - additional options for rpm
417 -q, --quiet - be quiet,
418 --date yyyy-mm-dd - build package using resources from specified date,
419 -r <tag>, --cvstag <ref>
420 - build package using resources from specified branch/tag,
421 -A - build package using master branch as any sticky tags/branch/date being reset.
422 -R, --fetch-build-requires
423 - fetch what is BuildRequired,
424 -RB, --remove-build-requires
425 - remove all you fetched with -R or --fetch-build-requires
426 remember, this option requires confirmation,
427 -FRB, --force-remove-build-requires
428 - remove all you fetched with -R or --fetch-build-requires
429 remember, this option works without confirmation,
430 -sd, --source-distfiles
431 - list sources available from distfiles (intended for offline
432 operations; does not work when Icon field is present
433 but icon file is absent),
434 -sc, --source-cvs - list sources available from PLD repo
435 -sdp, --source-distfiles-paths
436 - list sources available from distfiles -
437 paths relative to distfiles directory (intended for offline
438 operations; does not work when Icon field is present
439 but icon file is absent),
440 -sf, --source-files - list sources - bare filenames (intended for offline
441 operations; does not work when Icon field is present
442 but icon file is absent),
444 - list sources - filenames with full local paths (intended for
445 offline operations; does not work when Icon field is present
446 but icon file is absent),
447 -su, --source-urls - list urls - urls to sources and patches
448 intended for copying urls with spec with lots of macros in urls
449 -ir, --integer-release-only
450 - allow only integer and snapshot releases
451 -v, --verbose - be verbose,
452 -u, --try-upgrade - check version, and try to upgrade package
453 -un, --try-upgrade-with-float-version
454 - as above, but allow float version
455 php-pear-Services_Digg/
456 --upgrade-version - upgrade to specified version in try-upgrade
457 -U, --update - refetch sources, don't use distfiles, and update md5 comments
458 -Upi, --update-poldek-indexes
459 - refresh or make poldek package index files.
461 --skip-patch <patchnumber>
462 - don't apply <patchnumber>. may be repeated.
464 --nopatch <patchnumber>
465 - abort instead of applying patch <patchnumber>
467 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
468 --show-bconds - show available conditional builds, which can be used
469 - with --with and/or --without switches.
470 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
471 In other words, the output is parseable by scripts.
472 --show-avail-bconds - show available bconds
475 - conditional build package depending on %_with_<feature>/
476 %_without_<feature> macro switch. You may now use
477 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
478 constructions. Set GROUP_BCONDS to yes to make use of it.
479 --target <platform>, --target=<platform>
480 - build for platform <platform>.
481 --init-rpm-dir, --init
482 - initialize ~/rpm directory structure
483 --git-pld - force use of PLD git and distfiles
484 --git-tld - force use of TLD git and distfiles (note: it will fall
485 back to PLD git/df if package doesn't exist in TLD git)
486 --pkgrev - save git revision of package being built into pkgrevs
487 (note: only official TLD source builders are allowed to do so)
488 -lp - list pkgrevs for specified package
495 v=$(LC_ALL=C LANG=C rpm --version 2>&1)
496 v=${v#RPM version } # rpm 4
497 v=${v#rpm \(RPM\) } # rpm 5
507 echo "ERROR: unsupported RPM version $v" >&2
512 # create tempfile. as secure as possible
514 local prefix=builder.$PACKAGE_NAME${1:+.$1}
515 mktemp --tmpdir -t $prefix.XXXXXX || echo ${TMPDIR:-/tmp}/$prefix.$RANDOM.$$
519 local prefix=builder.$PACKAGE_NAME${1:+.$1}
520 mktemp --tmpdir -d $prefix.XXXXXX
523 # inserts git log instead of %changelog
524 # @output directory containing modified specfile
526 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
528 # allow this being customized
529 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
531 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
532 # otherwise i'd use --date=iso here
533 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
534 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
535 # NOTE: changelog date is always in UTC for rpmbuild
536 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
537 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
539 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
540 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
543 # add link to full git logs
544 local giturl="http://git.tld-linux.org/?p=packages/${SPECFILE%.spec}.git;a=log"
545 if [ -n "$CVSTAG" ]; then
546 giturl="$giturl;h=$CVSTAG"
548 local gitauthor="TLD Linux <feedback@tld-linux.org>"
549 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
550 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
555 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
556 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
560 " > $specdir/$SPECFILE
561 rm -f $gitlog $speclog
565 # @param string logfile
566 # @param varargs... commands to execute
569 # use teeboth from toys/cleanbuild, if available and enabled
570 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
574 local efile rc logfile=$1; shift
575 if [ "$logfile" ]; then
577 { "$@" 2>&1; echo $? > $efile; } | tee $logfile
588 # change dependency to specname
590 # - perl(Package::Name) -> perl-Package-Name
594 if [ $# -gt 0 ]; then
600 echo "$DEPS" | tr ' ' '\n' | sed -re '
603 s/perl\((.*)\)/perl-\1/
607 s/apache\(EAPI\)-devel/apache-devel/
609 s/db-devel/db5.3-devel/
610 s/libjpeg-devel/libjpeg-turbo-devel/
614 update_shell_title() {
616 local len=${COLUMNS:-80}
617 local msg="$(echo "$*" | cut -c-$len)"
619 if [ -n "$BE_VERBOSE" ]; then
620 echo >&2 "$(date +%s.%N) $*"
623 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
625 if [ -n "$PACKAGE_NAME" ]; then
626 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
631 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
632 msg=$(echo $msg | tr -d '\n\r')
635 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
638 echo >&2 -ne "\033]0;$msg\007"
644 # set TARGET from BuildArch: from SPECFILE
646 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
647 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
649 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
653 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
655 TARGET_SWITCH="--target=$TARGET" ;;
661 # runs rpm with minimal macroset
663 # TODO: move these to /usr/lib/rpm/macros
664 cat > $BUILDER_MACROS <<'EOF'
665 %x8664 x86_64 amd64 ia32e
668 %bootstrap_release() %{1}
669 %requires_releq_kernel_up(s:n:) %{nil}
670 %requires_releq_kernel_smp(s:n:) %{nil}
671 %requires_releq_kernel(s:n:) %{nil}
672 %requires_releq() %{nil}
673 %pyrequires_eq() %{nil}
674 %requires_eq() %{nil}
675 %requires_eq_to() %{nil}
676 %requires_ge() %{nil}
677 %requires_ge_to() %{nil}
678 %requires_ge() %{nil}
679 %releq_kernel_up(n:) ERROR
680 %releq_kernel_smp(n:) ERROR
681 %releq_kernel(n:) ERROR
682 %py_postclean(x:) ERROR
686 %ruby_ver_requires_eq() %{nil}
687 %ruby_mod_ver_requires_eq() %{nil}
688 %__php_api_requires() %{nil}
689 %php_major_version ERROR
690 %php_api_version ERROR
691 %requires_xorg_xserver_extension %{nil}
692 %requires_xorg_xserver_xinput %{nil}
693 %requires_xorg_xserver_font %{nil}
694 %requires_xorg_xserver_videodrv %{nil}
696 %perl_vendorarch ERROR
697 %perl_vendorlib ERROR
698 # damn. need it here! - copied from /usr/lib/rpm/macros.build
699 %tmpdir %(echo "${TMPDIR:-/tmp}")
700 %patchset_source(f:b:) %(
701 base=%{-b*}%{!-b*:10000};
702 start=$(expr $base + %1);
703 end=$(expr $base + %{?2}%{!?2:%{1}});
704 # we need to call seq twice as it doesn't allow two formats
705 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
706 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
707 paste %{tmpdir}/__ps{1,2};
708 rm -f %{tmpdir}/__ps{1,2};
711 %add_etc_shells(p) %{p:<lua>}
712 %remove_etc_shells(p) %{p:<lua>}
713 %lua_add_etc_shells() %{nil}
714 %lua_remove_etc_shells() %{nil}
716 %buildrequires_jdk %{nil}
717 %pear_package_print_optionalpackages %{nil}
719 if [ "$NOINIT" = "yes" ] ; then
720 cat >> $BUILDER_MACROS <<'EOF'
726 local safe_macrofiles
727 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
728 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMUSERDEFS $RPMBUILDOPTS $BCOND $* 2>&1
730 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --load "$BUILDER_MACROS" $QUIET $RPMOPTS $RPMUSERDEFS $RPMBUILDOPTS $BCOND $* 2>&1
736 if [ -n "$DEBUG" ]; then
741 if [ ! -z "$1" ]; then
744 SPEC_PATH="$PACKAGE_DIR/$SPECFILE"
746 if [ -x /usr/bin/rpm-specdump ]; then
747 update_shell_title "cache_rpm_dump using rpm-specdump command"
748 rpm_dump_cache=$(eval rpm-specdump $TARGET_SWITCH $BCOND $RPMUSERDEFS --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPEC_PATH)
750 update_shell_title "cache_rpm_dump using rpmbuild command"
753 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
754 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
760 ARGS='--nodigest --nosignature --nobuild'
763 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
765 if [ $? -gt 0 ]; then
766 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
768 Exit_error err_build_fail
771 # make small dump cache
772 rpm_dump_cache=`echo "$rpm_dump" | awk '
773 $2 ~ /^SOURCEURL/ {print}
774 $2 ~ /^PATCHURL/ {print}
775 $2 ~ /^nosource/ {print}
776 $2 ~ /^PACKAGE_/ {print}
780 update_shell_title "cache_rpm_dump: OK!"
784 if [ -z "$rpm_dump_cache" ] ; then
785 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
787 echo "$rpm_dump_cache"
791 update_shell_title "get icons"
792 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
793 if [ -z "$ICONS" ]; then
797 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
801 update_shell_title "parsing specfile"
802 if [ -n "$DEBUG" ]; then
807 # icons are needed for successful spec parse
813 if rpm_dump | grep -qEi ":.*nosource.*1"; then
814 FAIL_IF_NO_SOURCES="no"
817 if [ "$NOSRCS" != "yes" ]; then
818 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
819 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
820 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
823 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
824 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
825 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
827 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
828 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
831 if [ -n "$BE_VERBOSE" ]; then
832 echo "- Sources : `nourl $SOURCES`"
833 if [ -n "$PATCHES" ]; then
834 echo "- Patches : `nourl $PATCHES`"
836 echo "- Patches : *no patches needed*"
838 if [ -n "$ICONS" ]; then
839 echo "- Icon : `nourl $ICONS`"
841 echo "- Icon : *no package icon*"
843 echo "- Name : $PACKAGE_NAME"
844 echo "- Version : $PACKAGE_VERSION"
845 echo "- Release : $PACKAGE_RELEASE"
848 update_shell_title "parse_spec: OK!"
851 # aborts program abnormally
854 echo >&2 "$PROGRAM: ERROR: $*"
859 if [ -n "$DEBUG" ]; then
867 "err_no_spec_in_cmdl" )
868 remove_build_requires
869 echo >&2 "ERROR: spec file name not specified."
871 "err_invalid_cmdline" )
872 echo >&2 "ERROR: invalid command line arg ($2)."
874 "err_no_spec_in_repo" )
875 remove_build_requires
876 echo >&2 "Error: spec file not stored in repository."
882 "err_no_source_in_repo" )
883 remove_build_requires
884 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
886 "err_cvs_add_failed" )
887 echo >&2 "Error: failed to add package to PLD repo."
890 remove_build_requires
891 echo >&2 "Error: package build failed. (${2:-no more info})"
893 "err_no_package_data" )
894 remove_build_requires
895 echo >&2 "Error: couldn't get out package name/version/release from spec file."
897 "err_pkgrev_exists" )
898 remove_build_requires
899 echo >&2 "Error: package revision ${2} already exists"
902 remove_build_requires
903 echo >&2 "Release ${2} not integer and not a snapshot."
905 "err_branch_exists" )
906 remove_build_requires
907 echo >&2 "Tree branch already exists (${2})."
910 remove_build_requires
911 echo >&2 "Error: conditions reject building this spec (${2})."
913 "err_remote_problem" )
914 remove_build_requires
915 echo >&2 "Error: problem with remote (${2})"
918 echo >&2 "Error: cannot checkout ${2}"
921 echo >&2 "Error: failed to set package revision for tag ${2}"
924 echo >&2 "Error: failed to get package revision for tag ${2}"
926 "err_distbcond_update" )
927 echo >&2 "Error: failed to update .distbcond"
929 "err_not_implemented" )
930 remove_build_requires
931 echo >&2 "Error: functionality not yet imlemented"
934 echo >&2 "Unknown error."
939 if [ -n "$DEBUG" ]; then
944 if [ "$NOINIT" != "yes" ] ; then
945 TOP_DIR=$(eval $RPM $RPMOPTS $RPMUSERDEFS --eval '%{_topdir}')
947 local macros_ver=$(rpm -E %?rpm_build_macros)
948 if [ -z "$macros_ver" ]; then
949 REPO_DIR=$TOP_DIR/packages
950 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
952 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
953 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
957 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
962 REPO_DIR=$PACKAGE_DIR
963 RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
965 export GIT_WORK_TREE=$PACKAGE_DIR
966 export GIT_DIR=$PACKAGE_DIR/.git
968 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
969 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
970 CVSTAG=${CVSTAG#refs/heads/}
971 if [ "$CVSTAG" != "master" ]; then
972 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
975 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
978 elif [ "$CVSTAG" = "HEAD" ]; then
979 # assume -r HEAD is same as -A
987 update_shell_title "add_package"
989 if [ -n "$DEBUG" ]; then
995 SPECFILE=$(basename $SPECFILE)
996 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
997 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
1000 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
1001 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
1005 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
1006 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1008 git config --local push.default current
1009 git config --local branch.master.remote $REMOTE_PLD
1010 git config --local branch.master.merge refs/heads/master
1012 test $? = 0 || Exit_error err_remote_problem $REMOTE_PLD
1017 update_shell_title "get_spec"
1019 if [ -n "$DEBUG" ]; then
1025 SPECFILE=$(basename $SPECFILE)
1026 if [ "$NOCVSSPEC" != "yes" ]; then
1027 if [ -z "$DEPTH" ]; then
1028 if [ -d "$PACKAGE_DIR/.git" ]; then
1029 git fetch $IPOPT $REMOTE_PLD || Exit_error err_no_spec_in_repo
1030 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
1031 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
1032 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
1035 Exit_error err_not_implemented
1039 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
1040 # softfail if new package, i.e not yet added to PLD rep
1041 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
1042 echo "Warning: package not in Git - assuming new package"
1045 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1046 git config --local --add "remote.$REMOTE_PLD.push" 'refs/notes/*:refs/notes/*'
1047 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1048 git config --local push.default current
1049 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1053 if [ ! -d "$PACKAGE_DIR/.git" ]; then
1054 if [ ! -d "$PACKAGE_DIR" ]; then
1055 install -d $PACKAGE_DIR
1058 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
1059 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1060 git config --local --add "remote.$REMOTE_PLD.push" 'refs/heads/*:refs/remotes/origin/*'
1061 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1062 git config --local push.default current
1063 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1064 CVSTAG=${CVSTAG:-"master"}
1067 if [ -z "$ALL_BRANCHES" ]; then
1068 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
1070 git fetch $IPOPT $DEPTH $REMOTE_PLD $refs || {
1071 echo >&2 "Error: branch $CVSTAG does not exist"
1075 git fetch $IPOPT $REMOTE_PLD 'refs/notes/*:refs/notes/*'
1077 cvsignore_df .gitignore
1079 # add default log format to .gitignore if it is relative to package dir
1080 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
1081 # substitute known "macros" to glob
1082 local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g')
1083 if [ "$logfile" ]; then
1084 cvsignore_df "$logfile"
1088 # create symlinks for tools
1089 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
1090 for a in dropin md5 builder {relup,compile,repackage,rsync,pearize}.sh; do
1091 # skip tools that don't exist in top dir
1092 [ -f $a ] || continue
1093 # skip tools that already exist
1094 [ -f $PACKAGE_DIR/$a ] && continue
1095 ln -s ../$a $PACKAGE_DIR
1101 if [ -n "$CVSTAG" ]; then
1102 local _rev=$(get_pkgrev "$CVSTAG")
1103 echo "$_rev" | grep -q -E "^ERROR$" || CVSTAG="$_rev"
1104 if git rev-parse --verify -q "$CVSTAG" >/dev/null; then
1105 # checkout only if differs, so this will not trash git reflog
1106 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1107 git checkout "$CVSTAG" --
1109 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1110 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1112 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1113 Exit_error "err_no_checkut" "$CVSTAG"
1116 git merge --ff-only '@{u}'
1117 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1118 if [ -n "$CVSDATE" ]; then
1119 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1123 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1124 Exit_error err_no_spec_in_repo "$PACKAGE_DIR/$SPECFILE"
1127 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1128 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1131 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1136 # find mirrors in this order. first match wins:
1137 # - package dir (~/rpm/packages/foo)
1138 # - repository dir (~/rpm/packages)
1139 # - tools dir dir (~/rpm/packages/rpm-build-tools)
1143 update_shell_title "find_mirror[$url][$REPO_DIR]"
1145 # NOTE: as while loop runs in subshell,
1146 # we use exit 2 to indicate that the match was found
1147 # otherwise we end up outputing mirror url and origin url.
1149 local origin mirror name rest ol prefix
1151 cat "$PACKAGE_DIR/mirrors" "$REPO_DIR/mirrors" "$REPO_DIR/../rpm-build-tools/mirrors" /dev/null 2>/dev/null | \
1152 while read origin mirror name rest; do
1153 # skip comments and empty lines
1154 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1157 ol=$(echo -n "$origin" | wc -c)
1158 prefix=$(echo -n "$url" | head -c $ol)
1159 if [ "$prefix" = "$origin" ] ; then
1160 suffix=$(echo "$url" | cut -b $((ol+1))-)
1161 echo -n "$mirror$suffix"
1167 # Warning: unpredictable results if same URL used twice
1170 # escape some regexp characters if part of file name
1171 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1174 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1175 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1176 head -n 1 | tr OURCEATH ourceath | xargs
1180 [ "$NO5" = "yes" ] && return
1182 [ -z "$no" ] && return
1186 # use "sources" file from package dir, like vim
1187 if [ -f sources ]; then
1188 md5=$(grep -s -v '^#' sources | \
1189 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1190 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1191 grep -E '^[0-9a-f]{32}$')
1194 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1195 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1197 echo "$md5" | tail -n 1
1202 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1203 if [ -n "$source_md5" ]; then
1206 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1207 if [ -n "$source_md5" ]; then
1210 # we have empty SourceX-md5, but it is still possible
1211 # that we have NoSourceX-md5 AND NoSource: X
1212 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1213 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1221 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1225 echo "$PROTOCOL$DISTFILES_SERVER/$(distfiles_path "$1")"
1230 [ "$md5" = "" ] || \
1231 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1235 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1236 [ -n "$size" -a "$size" -gt 0 ]
1240 if [ "$CVSIGNORE_DF" != "yes" ]; then
1243 local cvsignore=${PACKAGE_DIR}/.git/info/exclude
1245 # add only if not yet there
1246 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1247 echo "$1" >> $cvsignore
1251 # returns true if "$1" is ftp, http or https protocol url
1254 ftp://*|http://*|https://*)
1262 if [ $# -eq 0 ]; then
1266 update_shell_title "update md5"
1267 if [ -n "$DEBUG" ]; then
1274 # pass 1: check files to be fetched
1278 local fp=$(nourl "$i")
1279 local srcno=$(src_no "$i")
1280 if [ -n "$ADD5" ]; then
1281 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1282 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1283 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1285 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1287 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1288 need_files="$need_files $i"
1292 # pass 1a: get needed files
1293 if [ "$need_files" ]; then
1294 get_files $need_files
1297 # pass 2: proceed with md5 adding or updating
1299 local fp=$(nourl "$i")
1300 local srcno=$(src_no "$i")
1301 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1302 if [ -z "$md5" ]; then
1303 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1305 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1306 local tag="# $srcno-md5:\t"
1307 if [[ "$md5" == *NoSource* ]]; then
1308 tag="# No$srcno-md5:\t"
1309 elif [ -n "$USEDIGEST" ]; then
1310 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1312 md5=$(md5sum "$fp" | cut -f1 -d' ')
1313 echo "Updating $srcno ($md5: $fp)."
1315 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1316 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1318 $PACKAGE_DIR/$SPECFILE
1325 [ "$NO5" = "yes" ] && return
1327 update_shell_title "check md5"
1331 if ! good_md5 "$i"; then
1332 echo -n "MD5 sum mismatch."
1335 if ! good_size "$i"; then
1336 echo -n "0 sized file."
1340 if [ $bad -eq 1 ]; then
1341 echo " Use -U to refetch sources,"
1342 echo "or -5 to update md5 sums, if you're sure files are correct."
1343 Exit_error err_no_source_in_repo $i
1349 update_shell_title "get_files"
1351 if [ -n "$DEBUG" ]; then
1356 if [ $# -gt 0 ]; then
1360 local get_files_cvs=""
1364 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1365 update_shell_title "$i"
1366 local fp=`nourl "$i"`
1367 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1372 local srcmd5=$(src_md5 "$i")
1374 # we know if source/patch is present in cvs/distfiles
1375 # - has md5 (in distfiles)
1376 # - in cvs... ideas?
1378 # CHECK: local file didn't exist or always cvs up (first) requested.
1379 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1380 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1381 echo "Warning: no URL given for $i"
1385 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1386 if good_md5 "$i" && good_size "$i"; then
1387 echo "$fp having proper md5sum already exists"
1391 # optionally prefer mirror over distfiles if there's mirror
1392 # TODO: build url list and then try each url from the list
1393 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1396 url=$(distfiles_url "$i")
1400 # is $url local file?
1401 if [[ "$url" = [./]* ]]; then
1402 update_shell_title "${GETLOCAL%% *}: $url"
1403 ${GETLOCAL} $url $target
1406 # make shorter message for distfiles urls
1407 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]]; then
1408 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/by-md5/?/?/*/}
1411 update_shell_title "${GETURI%% *}: $uri"
1412 ${GETURI} "$target" "$url"
1416 if [ -s "$target" ]; then
1417 cvsignore_df $target
1424 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1425 if [ -z "$NOMIRRORS" ]; then
1426 im=$(find_mirror "$i")
1430 update_shell_title "${GETURI%% *}: $im"
1431 ${GETURI} "$target" "$im"
1432 test -s "$target" || rm -f "$target"
1435 if [ "$cvsup" = 1 ]; then
1441 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1442 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1443 Exit_error err_no_source_in_repo $i
1446 # we check md5 here just only to refetch immediately
1447 if good_md5 "$i" && good_size "$i"; then
1449 elif [ "$FROM_DISTFILES" = 1 ]; then
1450 # wrong md5 from distfiles: remove the file and try again
1452 echo "MD5 sum mismatch. Trying full fetch."
1455 update_shell_title "${GETURI%% *}: $url"
1456 ${GETURI} "$target" "$url"
1457 test -s "$target" || rm -f "$target"
1460 SHELL_TITLE_PREFIX=""
1463 if [ "$CHMOD" = "yes" ]; then
1464 CHMOD_FILES=$(nourl "$@")
1465 if [ -n "$CHMOD_FILES" ]; then
1466 chmod $CHMOD_MODE $CHMOD_FILES
1473 if [ -n "$DEBUG" ]; then
1478 TAGVER=$(echo $PKGREVS_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1480 # Remove @kernel.version_release from TAGVER because tagging sources
1481 # could occur with different kernel-headers than kernel-headers used at build time.
1482 # besides, %{_kernel_ver_str} is not expanded.
1484 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1485 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1492 [ -z "$1" ] && return 1
1493 local _tmp=$(mktemp /tmp/.builder-XXXX)
1494 rm $_tmp 2>/dev/null
1495 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/get/$1 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1496 local result=$(cat $_tmp)
1497 rm $_tmp 2>/dev/null
1505 echo "Writing git revision for tag $_tag"
1506 local _tmp=$(mktemp /tmp/.builder-XXXX)
1507 rm $_tmp 2>/dev/null
1508 local _rev=$(git rev-parse HEAD)
1509 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/set/$_rev/$_tag 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1510 local result=$(cat $_tmp)
1511 rm $_tmp 2>/dev/null
1512 [ "$(get_pkgrev "$_tag")" = "$CVSTAG" ] && return 0
1513 echo "$result" | grep -q -E "^OK$" && return 0
1514 echo "$result" | grep -q -E "^EXISTS$" && Exit_error err_pkgrev_exists "$_tag"
1515 Exit_error err_pkgrev_set
1519 local _tmp=$(mktemp /tmp/.builder-XXXX)
1520 rm $_tmp 2>/dev/null
1521 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/list/$PACKAGE_NAME 1>/dev/null 2>&1
1523 rm $_tmp 2>/dev/null
1528 echo "Git branch: $TAG"
1531 if [ -n "$DEBUG" ]; then
1536 local OPTIONS="branch $CVS_FORCE"
1539 git $OPTIONS $TAG || exit
1543 # this function should exit early if package can't be built for this arch
1544 # this avoids unneccessary BR filling.
1547 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1549 if [ $ret -ne 0 ]; then
1561 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1562 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1568 local ver="$2" subver=$ver
1569 local newver="$3" newsubver=$newver
1571 # try handling subver, everything that's not numeric-dotted in version
1572 if grep -Eq '%define\s+subver' $specfile; then
1573 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1575 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1576 newver=${newver%$newsubver}
1579 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1580 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1581 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1585 # try to upgrade .spec to new version
1586 # if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1588 # return 1: if .spec was updated
1589 # return 0: no changes to .spec
1590 # exit 1 in case of error
1592 if [ -z "$TRY_UPGRADE" ]; then
1596 local TNOTIFY TNEWVER TOLDVER
1597 update_shell_title "build_package: try_upgrade"
1601 if [ "$UPGRADE_VERSION" ]; then
1602 TNEWVER=$UPGRADE_VERSION
1603 echo "Updating spec file to version $TNEWVER"
1605 if [ -n "$FLOAT_VERSION" ]; then
1606 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1608 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1611 # pldnotify does not set exit codes, but it has match for ERROR
1612 # in output which means so.
1613 if [[ "$TNOTIFY" = *ERROR* ]]; then
1618 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1619 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1621 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1624 if [ -z "$TNEWVER" ]; then
1628 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1629 cp -f $SPECFILE $SPECFILE.bak
1632 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1633 set_release $SPECFILE $PACKAGE_RELEASE 1
1635 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1636 echo >&2 "Upgrading version failed, you need to update spec yourself"
1643 update_shell_title "build_package"
1644 if [ -n "$DEBUG" ]; then
1653 BUILD_SWITCH="-ba" ;;
1655 BUILD_SWITCH="-bb" ;;
1657 BUILD_SWITCH="-bs --nodeps" ;;
1659 BUILD_SWITCH="-bp --nodeps" ;;
1661 BUILD_SWITCH="-bc" ;;
1663 BUILD_SWITCH="-bi" ;;
1665 BUILD_SWITCH="-bl" ;;
1669 update_shell_title "build_package: $COMMAND"
1670 local logfile retval
1671 if [ -n "$LOGFILE" ]; then
1672 logfile=`eval echo $LOGFILE`
1673 if [ -d "$logfile" ]; then
1674 echo "Log file $logfile is a directory."
1675 echo "Parse error in the spec?"
1676 Exit_error err_build_fail
1678 if [ -n "$LASTLOG_FILE" ]; then
1679 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1683 # unset these, should not be exposed to builder shell!
1684 unset GIT_WORK_TREE GIT_DIR
1685 # these are set by jenkins
1686 unset GIT_PREVIOUS_COMMIT GIT_URL GIT_PREVIOUS_SUCCESSFUL_COMMIT GIT_BRANCH GIT_COMMIT
1687 # this may be set by user
1689 # may be set by user
1690 unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_TESTING_PORCELAIN_COMMAND_LIST
1691 # fail if something still set
1692 env | grep ^GIT_ && Exit_error err_build_fail
1694 local specdir=$(insert_gitlog $SPECFILE)
1696 # If required exclude directories with systemd related files from package contents
1697 if grep -q -E '(lib/(systemd|binfmt.d|sysctl.d|sysusers.d|tmpfiles.d)|systemd(unitdir|userunitdir|tmpfilesdir))' $specdir/$SPECFILE; then
1698 sed -i -e '/^%exclude_systemd_files/d; /^%files/s/$/\n%exclude_systemd_files/g;' $specdir/$SPECFILE
1700 # Enable/disable distro wide bconds based on ~/.distbcond
1701 process_distbcond "$specdir/$SPECFILE"
1702 # Add %tld macro to release to allow release control
1703 sed -i -r -e '/^Release:/s/%\{\?tld\}//g; s/^Release:\s+(.*)$/Release:\t\1%{?tld}/;' $specdir/$SPECFILE
1704 # FIXME: eval here is exactly why?
1705 PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${TIME_COMMAND} ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMUSERDEFS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE
1708 # Set pkgrev if requested and build status is OK
1709 if [ ! -z "$SETPKGREV" ] && [ "$SETPKGREV" = "true" ] && [ "$retval" -eq "0" ]; then
1710 set_pkgrev "$specdir/$SPECFILE"
1715 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1716 if [ "$retval" -eq "0" ]; then
1717 mv $logfile $LOGDIROK
1719 mv $logfile $LOGDIRFAIL
1723 if [ "$retval" -ne "0" ]; then
1724 if [ -n "$TRY_UPGRADE" ]; then
1725 echo "\nUpgrade package to new version failed."
1726 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1727 echo "Restoring old spec file."
1728 mv -f $SPECFILE.bak $SPECFILE
1732 Exit_error err_build_fail
1738 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1741 install_required_packages() {
1746 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1749 /^%changelog/ { exit }
1751 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1752 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1753 gsub(/[ \t]+/, "_", bcond);
1755 }' $SPEC | LC_ALL=C sort -u
1759 # expand bconds from ~/.bcondrc
1760 # The file structure is like gentoo's package.use:
1763 # samba -mysql -pgsql
1764 # w32codec-installer license_agreement
1767 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1773 SN=${SPECFILE%%\.spec}
1775 local bcondrc=$HOME/.bcondrc
1776 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1778 local bcond_avail=$(find_spec_bcond $SPECFILE)
1780 while read pkg flags; do
1782 [[ "$pkg" == \#* ]] && continue
1784 # any package or current package?
1785 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1786 for flag in $flags; do
1787 local opt=${flag#[+-]}
1789 # use only flags which are in this package.
1790 if [[ $bcond_avail = *${opt}* ]]; then
1791 if [[ $flag = -* ]]; then
1792 if [[ $BCOND != *--with?${opt}* ]]; then
1793 BCOND="$BCOND --without $opt"
1796 if [[ $BCOND != *--without?${opt}* ]]; then
1797 BCOND="$BCOND --with $opt"
1804 update_shell_title "parse ~/.bcondrc: DONE!"
1807 process_distbcond() {
1808 # apply bconds from ~/.distbcond to spec
1809 # The file structure is like gentoo's package.use:
1812 # samba -mysql -pgsql
1813 # w32codec-installer license_agreement
1817 local distbcond=$HOME/.distbcond
1819 echo "Updating .distbcond"
1820 wget -q --no-check-certificate $DISTBCOND_URL -O "$distbcond"
1821 if [ $? -ne 0 ]; then
1822 Exit_error err_distbcond_update
1824 DISTBCOND_MD5=$(grep -E "^# MD5 " "$distbcond" | cut -d ' ' -f 3)
1825 DISTBCOND_MD5_LOCAL=$(grep -v -E "^#" "$distbcond" | md5sum | cut -d ' ' -f 1)
1826 if [ "$DISTBCOND_MD5" != "$DISTBCOND_MD5_LOCAL" ]; then
1828 Exit_error err_distbcond_update
1831 SN=${SPECFILE%%\.spec}
1833 local bcond_avail=$(find_spec_bcond $SPECFILE)
1835 while read pkg flags; do
1837 [[ "$pkg" == \#* ]] && continue
1839 # any package or current package?
1840 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1841 for flag in $flags; do
1842 local opt=${flag#[+-]}
1844 # use only flags which are in this package.
1845 if [[ $bcond_avail = *${opt}* ]]; then
1846 if [[ $flag = -* ]]; then
1847 sed -i -r -e '/^%bcond_(with|without)\s+'$opt'/s/^%bcond_(with|without)/%bcond_with/g;' "$1"
1848 elif [[ $flag = +* ]]; then
1849 sed -i -r -e '/^%bcond_(with|without)\s+'$opt'/s/^%bcond_(with|without)/%bcond_without/g;' "$1"
1855 update_shell_title "parse ~/.distbcond: DONE!"
1858 set_bconds_values() {
1859 update_shell_title "set bcond values"
1861 AVAIL_BCONDS_WITHOUT=""
1862 AVAIL_BCONDS_WITH=""
1864 if grep -Eq '^# *_with' ${SPECFILE}; then
1865 echo >&2 "ERROR: This spec has old style bconds."
1869 if ! grep -q '^%bcond' ${SPECFILE}; then
1873 local bcond_avail=$(find_spec_bcond $SPECFILE)
1874 process_bcondrc "$SPECFILE"
1876 update_shell_title "parse bconds"
1879 for opt in $bcond_avail; do
1882 bcond=${opt#without_}
1884 *--without?${bcond}\ *|*--without?${bcond})
1885 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1888 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1895 *--with?${bcond}\ *|*--with?${bcond})
1896 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1899 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1904 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1913 update_shell_title "run_sub_builder $package_name"
1915 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1916 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
1917 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1918 # jakby nie bylo tego kawalka kodu.
1920 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1921 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
1925 # kurwa. translate that ^^^^
1929 # Istnieje taki spec? ${package}.spec
1930 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1931 parent_spec_name=${package}.spec
1932 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1933 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1935 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1940 if [ "${parent_spec_name}" != "" ]; then
1941 spawn_sub_builder $parent_spec_name
1943 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1946 # install package with poldek
1947 # @return exit code from poldek
1949 # this requires following sudo rules:
1950 # - poldek --noask --caplookup -ug
1952 LC_ALL=C LANG=C $POLDEK_CMD --noask --caplookup --uniq -ug "$@"
1957 # this requires following sudo rules:
1958 # - poldek -q --update --upa
1959 install_packages() {
1960 # sync poldek indexes once per invocation
1961 if [ -z "$package_indexes_updated" ]; then
1962 update_shell_title "poldek: update indexes"
1963 $POLDEK_CMD -q --update --upa --mo=nodesc
1964 package_indexes_updated=true
1967 update_shell_title "install packages: $*"
1968 poldek_install "$@" && return
1970 # retry install, install packages one by one
1971 # this is slower one
1973 for package in $*; do
1974 package=$(depspecname $package)
1975 update_shell_title "install package: $package"
1976 poldek_install "$package" || rc=$?
1981 uninstall_packages() {
1982 update_shell_title "uninstall packages: $*"
1983 $POLDEK_CMD --noask --nofollow -ev "$@"
1986 spawn_sub_builder() {
1988 update_shell_title "spawn_sub_builder $package_name"
1991 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1992 sub_builder_opts="${sub_builder_opts} -R"
1994 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1995 sub_builder_opts="${sub_builder_opts} -RB"
1996 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1997 sub_builder_opts="${sub_builder_opts} -FRB"
1999 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
2000 sub_builder_opts="${sub_builder_opts} -Upi"
2004 ./builder ${sub_builder_opts} "$@"
2007 remove_build_requires() {
2008 if [ "$INSTALLED_PACKAGES" != "" ]; then
2009 case "$REMOVE_BUILD_REQUIRES" in
2011 run_poldek --noask -ve $INSTALLED_PACKAGES
2014 run_poldek --ask -ve $INSTALLED_PACKAGES
2017 echo You may want to manually remove following BuildRequires fetched:
2018 echo $INSTALLED_PACKAGES
2019 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
2026 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
2027 if [ "$BCOND" ]; then
2029 echo "Building $SPECFILE with the following conditional flags:"
2033 echo "No conditional flags passed"
2036 echo "from available:"
2037 echo "--with :\t$AVAIL_BCONDS_WITH"
2038 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
2043 display_branches() {
2044 echo -n "Available branches: "
2045 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
2048 # checks a given list of packages/files/provides against current rpmdb.
2049 # outputs all dependencies which current rpmdb doesn't satisfy.
2050 # input can be either STDIN or parameters
2054 if [ $# -gt 0 ]; then
2060 out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1)
2063 echo "$out" | awk '/^no package provides/ { print $NF }'
2065 # other deps (files)
2066 echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p'
2069 # checks if given package/files/provides exists in rpmdb.
2070 # input can be either stdin or parameters
2071 # returns packages which are present in the rpmdb
2075 if [ $# -gt 0 ]; then
2081 LC_ALL=C LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
2084 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
2085 install_build_requires_rpmdeps() {
2087 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
2088 # TODO: Conflicts list doesn't check versions
2089 CNFL=$(eval rpm-getdeps $BCOND $RPMOPTS $RPMUSERDEFS $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
2090 DEPS=$(eval rpm-getdeps $BCOND $RPMOPTS $RPMUSERDEFS $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
2092 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2093 CNFL=$(eval rpm -q --specsrpm --conflicts $BCOND $RPMOPTS $RPMUSERDEFS $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
2094 DEPS=$(eval rpm -q --specsrpm --requires $BCOND $RPMOPTS $RPM_USERDEFS $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
2097 if [ -n "$CNFL" ]; then
2098 echo "Uninstall conflicting packages: $CNFL"
2099 uninstall_packages $CNFL
2102 if [ -n "$DEPS" ]; then
2103 echo "Install dependencies: $DEPS"
2104 install_packages $DEPS
2108 fetch_build_requires()
2110 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
2114 update_shell_title "fetch build requires"
2115 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2116 install_build_requires_rpmdeps
2120 die "need rpm-getdeps tool"
2127 if [ ! -e $localrepo ]; then
2128 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
2129 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2134 local TOP_DIR=$(eval $RPM $RPMOPTS $RPMUSERDEFS --eval '%{_topdir}')
2135 local rpmdir=$(eval $RPM $RPMOPTS $RPMUSERDEFS --eval '%{_rpmdir}')
2136 local buildir=$(eval $RPM $RPMOPTS $RPMUSERDEFS --eval '%{_builddir}')
2137 local srpmdir=$(eval $RPM $RPMOPTS $RPMUSERDEFS --eval '%{_srcrpmdir}')
2138 local TEMPLATES=template-specs
2141 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2142 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2145 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2146 init_repository projects/$TEMPLATES ../$TEMPLATES
2147 for a in builder fetchsrc_request compile repackage; do
2148 ln -sf ../rpm-build-tools/${a}.sh $a
2151 ln -sf ../rpm-build-tools/${a} $a
2153 ln -sf ../rpm-build-tools/mirrors mirrors
2160 DONT_PRINT_REVISION="yes"
2162 # remove spec and sources
2163 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
2164 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2165 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2168 #---------------------------------------------
2176 # stuff global $BUILDER_OPTS from env as args
2177 if [ "$BUILDER_OPTS" ]; then
2178 set -- "$BUILDER_OPTS" "$@"
2181 while [ $# -gt 0 ]; do
2188 COMMAND="update_md5"
2193 COMMAND="update_md5"
2202 DEBUG="yes"; shift ;;
2204 COMMAND="version"; shift ;;
2206 COMMAND="short-version"; shift ;;
2213 -b | -ba | --build )
2214 COMMAND="build"; shift ;;
2215 -bb | --build-binary )
2216 COMMAND="build-binary"; shift ;;
2218 COMMAND="build-build"; shift ;;
2220 COMMAND="build-install"; shift ;;
2222 COMMAND="build-list"; shift ;;
2223 -bp | --build-prep )
2224 COMMAND="build-prep"; shift ;;
2225 -bs | --build-source )
2226 COMMAND="build-source"; shift ;;
2228 COMMAND="branch"; shift; TAG="${1}"; shift;;
2230 CLEAN="--clean"; shift ;;
2232 CVS_FORCE="-f"; shift;;
2238 COMMAND="get"; shift ;;
2240 COMMAND="usage"; shift ;;
2242 PROTOCOL="ftp"; shift ;;
2244 PROTOCOL="http"; shift ;;
2246 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2250 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2254 PARALLEL_DOWNLOADS=$2
2258 PARALLEL_DOWNLOADS=${1#-p}
2262 shift; LOGFILE="${1}"; shift ;;
2264 shift; DEF_NICE_LEVEL=${1}; shift ;;
2265 -ske | --skip-existing-files)
2266 SKIP_EXISTING_FILES="yes"; shift ;;
2268 COMMAND="mr-proper"; shift ;;
2269 -ncs | --no-cvs-specs )
2270 NOCVSSPEC="yes"; shift ;;
2271 -nd | --no-distfiles )
2272 NODIST="yes"; shift ;;
2273 -nm | --no-mirrors )
2274 NOMIRRORS="yes"; shift ;;
2276 NOURLS="yes"; shift ;;
2278 NOSRCS="yes"; shift ;;
2279 -ns0 | --no-source0 )
2280 NOSOURCE0="yes"; shift ;;
2289 -pm | --prefer-mirrors )
2292 --noinit | --no-init )
2296 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2298 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2299 --skip-patch | -sp )
2300 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2302 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2305 --with | --without )
2306 case $GROUP_BCONDS in
2310 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2311 while ! `echo ${1}|grep -qE '(^-|spec)'`
2313 BCOND="$BCOND $COND $1"
2317 if [[ "$2" = *,* ]]; then
2318 for a in $(echo "$2" | tr , ' '); do
2319 BCOND="$BCOND $1 $a"
2322 BCOND="$BCOND $1 $2"
2328 shift; TARGET="${1}"; shift ;;
2330 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2332 QUIET="--quiet"; shift ;;
2334 CVSDATE="${2}"; shift 2
2335 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2345 -R | --fetch-build-requires)
2346 FETCH_BUILD_REQUIRES="yes"
2347 NOT_INSTALLED_PACKAGES=
2349 -RB | --remove-build-requires)
2350 REMOVE_BUILD_REQUIRES="nice"
2352 -FRB | --force-remove-build-requires)
2353 REMOVE_BUILD_REQUIRES="force"
2356 COMMAND="list-sources-cvs"
2358 -sd | --source-distfiles)
2359 COMMAND="list-sources-distfiles"
2361 -sdp | --source-distfiles-paths)
2362 COMMAND="list-sources-distfiles-paths"
2364 -sf | --source-files)
2365 COMMAND="list-sources-files"
2367 -lsp | --source-paths)
2368 COMMAND="list-sources-local-paths"
2370 -su | --source-urls)
2371 COMMAND="list-sources-urls"
2373 -ir | --integer-release-only )
2374 INTEGER_RELEASE="yes"
2377 COMMAND="update_md5"
2382 -Upi | --update-poldek-indexes )
2383 UPDATE_POLDEK_INDEXES="yes"
2385 --init-rpm-dir|--init)
2386 COMMAND="init_rpm_dir"
2388 -u | --try-upgrade )
2389 TRY_UPGRADE="1"; shift ;;
2391 shift; UPGRADE_VERSION="$1"; shift;;
2392 -un | --try-upgrade-with-float-version )
2393 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2395 BE_VERBOSE="1"; shift ;;
2400 if echo "${MACRO}" | grep -q '\W'; then
2401 RPMUSERDEFS="${RPMUSERDEFS} --define \"${MACRO}\""
2405 RPMUSERDEFS="${RPMUSERDEFS} --define \"${MACRO} ${VALUE}\""
2410 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\""
2414 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2417 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2418 COMMAND="show_bconds"
2422 COMMAND="show_bcond_args"
2425 --show-avail-bconds)
2426 COMMAND="show_avail_bconds"
2431 RPMOPTS="${RPMOPTS} --nodeps"
2434 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2438 GIT_SERVER=${PLD_GIT_SERVER}
2439 GIT_PUSH=${PLD_GIT_PUSH}
2440 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2441 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2445 GIT_SERVER=${TLD_GIT_SERVER}
2446 GIT_PUSH=${TLD_GIT_PUSH}
2447 PACKAGES_DIR=${TLD_PACKAGES_DIR}
2448 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
2452 COMMAND="build-source"
2455 COMMAND="list_pkgrev"
2458 Exit_error err_invalid_cmdline "$1"
2461 SPECFILE=${1%/}; shift
2462 # check if specname was passed as specname:cvstag
2463 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2464 CVSTAG="${SPECFILE##*:}"
2465 SPECFILE="${SPECFILE%%:*}"
2467 # always have SPECFILE ending with .spec extension
2468 SPECFILE=${SPECFILE%%.spec}.spec
2469 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2473 # Check if given package exists in TLD git
2474 if ! git ls-remote --heads ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME} 1>/dev/null 2>&1; then
2475 # Nope, we don't have it in TLD, switch to PLD repositories
2476 GIT_SERVER=${PLD_GIT_SERVER}
2477 GIT_PUSH=${PLD_GIT_PUSH}
2478 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2479 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2482 if [ "$CVSTAG" ]; then
2483 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2484 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2487 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2488 echo >&2 "--all branches requires --depth <number>"
2489 Exit_error err_invalid_cmdline
2492 if [ -n "$DEBUG" ]; then
2497 if [ -n "$TARGET" ]; then
2500 TARGET_SWITCH="--target $TARGET" ;;
2502 TARGET_SWITCH="--target=$TARGET" ;;
2506 if [ "$SCHEDTOOL" != "no" ]; then
2507 NICE_COMMAND="$SCHEDTOOL"
2509 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2512 # see time(1) for output format that could be used
2513 TIME_COMMAND="time -p"
2515 update_shell_title "$COMMAND"
2519 if [ -z "$SPECFILE" ]; then
2520 Exit_error err_no_spec_in_cmdl
2522 get_spec > /dev/null
2529 if [ -z "$SPECFILE" ]; then
2530 Exit_error err_no_spec_in_cmdl
2532 get_spec > /dev/null
2537 "show_avail_bconds")
2539 if [ -z "$SPECFILE" ]; then
2540 Exit_error err_no_spec_in_cmdl
2543 get_spec > /dev/null
2545 local bcond_avail=$(find_spec_bcond $SPECFILE)
2546 local opt bcond bconds
2547 for opt in $bcond_avail; do
2550 bcond=${opt#without_}
2551 bconds="$bconds $bcond"
2555 bconds="$bconds $bcond"
2558 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2566 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2568 if [ -z "$SPECFILE" ]; then
2569 Exit_error err_no_spec_in_cmdl
2572 # display SMP make flags if set
2573 smp_mflags=$(rpm -E %{?_smp_mflags})
2574 if [ "$smp_mflags" ]; then
2575 echo "builder: SMP make flags are set to $smp_mflags"
2583 if [ "$COMMAND" != "build-source" ]; then
2586 fetch_build_requires
2587 if [ "$INTEGER_RELEASE" = "yes" ]; then
2588 echo "Checking release $PACKAGE_RELEASE..."
2589 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2590 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2594 if [ -n "$NOSOURCE0" ] ; then
2595 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2600 get_files $SOURCES $PATCHES
2601 check_md5 $SOURCES $PATCHES
2604 NODIST="yes" get_files $SOURCES $PATCHES
2605 update_md5 $SOURCES $PATCHES
2609 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2610 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2612 remove_build_requires
2616 if [ -z "$SPECFILE" ]; then
2617 Exit_error err_no_spec_in_cmdl
2626 if [ -z "$SPECFILE" ]; then
2627 Exit_error err_no_spec_in_cmdl
2631 if [ -n "$NEW_REPO" ]; then
2634 for file in $SOURCES $PATCHES; do
2635 if [ -z $(src_md5 "$file") ]; then
2636 git add $file || Exit_error err_no_source_in_repo $file
2638 cvsignore_df `nourl $file`
2642 echo "When you are ready commit your changes and run git push origin master"
2644 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2649 if [ -z "$SPECFILE" ]; then
2650 Exit_error err_no_spec_in_cmdl
2656 if [ -n "$NOSOURCE0" ] ; then
2657 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2659 get_files $SOURCES $PATCHES
2661 fetch_build_requires
2665 if [ -z "$SPECFILE" ]; then
2666 Exit_error err_no_spec_in_cmdl
2672 if [ -n "$NOSOURCE0" ] ; then
2673 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2675 update_md5 $SOURCES $PATCHES
2680 "list-sources-files" )
2683 DONT_PRINT_REVISION="yes"
2686 for SAP in $SOURCES $PATCHES; do
2687 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2690 "list-sources-urls" )
2693 DONT_PRINT_REVISION="yes"
2696 SAPS="$SOURCES $PATCHES"
2697 for SAP in $SAPS; do
2701 "list-sources-local-paths" )
2704 DONT_PRINT_REVISION="yes"
2707 for SAP in $SOURCES $PATCHES; do
2708 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2711 "list-sources-distfiles-paths" )
2714 DONT_PRINT_REVISION="yes"
2717 for SAP in $SOURCES $PATCHES; do
2718 if [ -n "$(src_md5 "$SAP")" ]; then
2719 distfiles_path "$SAP"
2723 "list-sources-distfiles" )
2726 DONT_PRINT_REVISION="yes"
2729 for SAP in $SOURCES $PATCHES; do
2730 if [ -n "$(src_md5 "$SAP")" ]; then
2731 distfiles_url "$SAP"
2735 "list-sources-cvs" )
2738 DONT_PRINT_REVISION="yes"
2741 for SAP in $SOURCES $PATCHES; do
2742 if [ -z "$(src_md5 "$SAP")" ]; then
2743 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2757 echo "$VERSIONSTRING"
2761 if [ -z "$SPECFILE" ]; then
2762 Exit_error err_no_spec_in_cmdl
2764 get_spec > /dev/null
2769 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2770 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2774 # vi:syntax=sh:ts=4:sw=4:noet