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}
124 # rsync repository with git refs of packages
125 PKGREVS_URL="http://pkgrevs.tld-linux.org"
129 TLD_GIT_SERVER="git://git.tld-linux.org"
130 TLD_GIT_PUSH="git@git.tld-linux.org:7272"
131 TLD_PACKAGES_DIR="packages"
132 TLD_DISTFILES_SERVER="://df.tld-linux.org"
135 PLD_GIT_SERVER="git://git.pld-linux.org"
136 PLD_GIT_PUSH="git@git.pld-linux.org"
137 PLD_PACKAGES_DIR="packages"
138 PLD_DISTFILES_SERVER="://distfiles.pld-linux.org"
143 GIT_SERVER=${TLD_GIT_SERVER}
144 GIT_PUSH=${TLD_GIT_PUSH}
145 PACKAGES_DIR=${TLD_PACKAGES_DIR}
154 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
159 FAIL_IF_NO_SOURCES="yes"
161 # let get_files skip over files which are present to get those damn files fetched
162 SKIP_EXISTING_FILES="no"
165 # should the specfile be restored if upgrade failed?
166 REVERT_BROKEN_UPGRADE="yes"
168 if rpm --specsrpm 2>/dev/null; then
169 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
170 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
172 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
173 if [ -x /usr/bin/rpm-getdeps ]; then
174 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
176 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
180 UPDATE_POLDEK_INDEXES_OPTS=""
182 # Here we load saved user environment used to
183 # predefine options set above, or passed to builder
185 # This one reads global system environment settings:
186 if [ -f ~/etc/builderrc ]; then
189 # And this one cascades settings using user personal
191 # Example of ~/.builderrc:
193 #UPDATE_POLDEK_INDEXES="yes"
194 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
195 #FETCH_BUILD_REQUIRES="yes"
196 #REMOVE_BUILD_REQUIRES="force"
198 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
203 if [ -n "$HOME_ETC" ]; then
204 USER_CFG="$HOME_ETC/.builderrc"
205 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
207 USER_CFG=~/.builderrc
208 BUILDER_MACROS=~/.builder-rpmmacros
211 [ -f "$USER_CFG" ] && . "$USER_CFG"
213 if [ "$SCHEDTOOL" = "auto" ]; then
214 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
215 SCHEDTOOL="schedtool -B -e"
221 if [ -n "$USE_PROZILLA" ]; then
223 elif [ -n "$USE_AXEL" ]; then
225 elif [ -n "$USE_LFTP" ]; then
231 GETLOCAL=${GETLOCAL:-cp -a}
239 if [ -d $HOME/rpm/SOURCES ]; then
240 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
241 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
245 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
246 POLDEK_CMD="$SU_SUDO /usr/bin/poldek"
249 # TODO: what this function does?
252 if [ -n "$LOGFILE" ]; then
253 LOG=`eval echo $LOGFILE`
254 if [ -n "$LASTLOG_FILE" ]; then
255 echo "LASTLOG=$LOG" > $LASTLOG_FILE
257 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
258 # FIXME $exit_pldk undefined
261 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
262 return `cat ${RES_FILE}`
267 #---------------------------------------------
270 download_prozilla() {
271 local outfile=$1 url=$2 retval
273 proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS -O "$outfile" "$url"
280 local outfile=$1 url=$2 retval
282 axel -a $AXEL_OPTS -o "$outfile" "$url"
289 local outfile=$1 url=$2 retval wget_help
290 if [ -z "${WGET_OPTS_SET+x}" ]; then
291 wget_help="$(wget --help 2>&1)"
292 echo "$wget_help" | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
293 echo "$wget_help" | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
294 echo "$wget_help" | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
295 echo "$wget_help" | grep -q -- ' --no-iri ' && WGET_OPTS="$WGET_OPTS --no-iri"
296 WGET_OPTS="-c -nd -t$WGET_RETRIES $WGET_OPTS --user-agent=$USER_AGENT $IPOPT --passive-ftp"
300 wget $WGET_OPTS -O "$outfile" "$url"
302 if [ $retval -ne 0 ]; then
303 if [ "`echo $url | grep -E 'ftp://'`" ]; then
304 ${GETURI} -O "$outfile" "$url"
312 local outfile=$1 url=$2 retval tmpfile
313 tmpfile=$(tempfile) || exit 1
315 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
316 $([ "$IPOPT" = "-4" ] && echo "set dns:order \"inet\";")
317 $([ "$IPOPT" = "-6" ] && echo "set dns:order \"inet6\";")
318 set ssl:verify-certificate no;
319 set net:max-retries $WGET_RETRIES;
320 set http:user-agent \"$USER_AGENT\";
321 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
325 if [ $retval -eq 0 ]; then
326 mv -f "$tmpfile" "$outfile"
334 if [ -n "$DEBUG" ]; then set -xv; fi
336 # to make this output parseable by bash-completion _parse_help()
337 # if the line contains short and long option, it will take only the long option
338 # but if you want both being completed, put the short option to separate line
340 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
341 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
342 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
343 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
344 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
345 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
346 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
347 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
348 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
349 [--git-pld|--git-tld] [--pkgrev] [-lp]
350 <package>[.spec][:tag]
352 -4 - force IPv4 when transferring files
353 -6 - force IPv6 when transferring files
355 --update-md5 - update md5 comments in spec, implies -nd -ncs
357 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
358 --all-branches - make shallow fetch of all branches; --depth required
359 -n5, --no-md5 - ignore md5 comments in spec
360 -D, --debug - enable builder script debugging mode,
361 -debug - produce rpm debug package (same as --opts -debug)
362 -V, --version - output builder version string
363 --short-version - output builder short version
364 -a - try add new package to PLD repo.
367 - get all files from PLD repo or HTTP/FTP and build package
369 -bb - get all files from PLD repo or HTTP/FTP and build binary
370 only package from <package>.spec,
371 -bp - execute the %prep phase of <package>.spec,
372 -bc - execute the %build phase of <package>.spec,
373 -bi - execute the %install phase of <package>.spec
374 -bl - execute the %files phase of <package>.spec
375 -bs - get all files from PLD repo or HTTP/FTP and only pack
377 --short-circuit - short-circuit build
378 -B, --branch - add branch
380 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
381 may be used with building process.
382 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
383 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
384 -cf, --cvs-force - use -f when tagging
385 --define '<macro> <value>'
386 - define a macro <macro> with value <value>,
387 --depth <number> - make shallow fetch
388 --alt_kernel <kernel>
389 - same as --define 'alt_kernel <kernel>'
390 --nodeps - rpm won't check any dependences
392 --get - get <package>.spec and all related files from PLD repo
393 -h, --help - this message,
394 -j N - set %_smp_mflags to propagate concurrent jobs
395 --ftp - use FTP protocol to access distfiles server
396 --http - use HTTP protocol to access distfiles server
397 -l <logfile>, --logtofile=<logfile>
400 - don't pull from PLD repo
401 -nd, --no-distfiles - don't download from distfiles
402 -nm, --no-mirrors - don't download from mirror, if source URL is given,
403 -nu, --no-urls - don't try to download from FTP/HTTP location,
404 -ns, --no-srcs - don't download Sources/Patches
405 -ns0, --no-source0 - don't download Source0
406 -nn, --no-net - don't download anything from the net
407 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
408 -pm, --prefer-mirrors
409 - prefer mirrors (if any) over distfiles for SOURCES
410 --no-init - don't initialize builder paths (SPECS and SOURCES)
412 --skip-existing-files
413 - skip existing files in get_files
414 --opts <rpm opts> - additional options for rpm
415 -q, --quiet - be quiet,
416 --date yyyy-mm-dd - build package using resources from specified date,
417 -r <tag>, --cvstag <ref>
418 - build package using resources from specified branch/tag,
419 -A - build package using master branch as any sticky tags/branch/date being reset.
420 -R, --fetch-build-requires
421 - fetch what is BuildRequired,
422 -RB, --remove-build-requires
423 - remove all you fetched with -R or --fetch-build-requires
424 remember, this option requires confirmation,
425 -FRB, --force-remove-build-requires
426 - remove all you fetched with -R or --fetch-build-requires
427 remember, this option works without confirmation,
428 -sd, --source-distfiles
429 - list sources available from distfiles (intended for offline
430 operations; does not work when Icon field is present
431 but icon file is absent),
432 -sc, --source-cvs - list sources available from PLD repo
433 -sdp, --source-distfiles-paths
434 - list sources available from distfiles -
435 paths relative to distfiles directory (intended for offline
436 operations; does not work when Icon field is present
437 but icon file is absent),
438 -sf, --source-files - list sources - bare filenames (intended for offline
439 operations; does not work when Icon field is present
440 but icon file is absent),
442 - list sources - filenames with full local paths (intended for
443 offline operations; does not work when Icon field is present
444 but icon file is absent),
445 -su, --source-urls - list urls - urls to sources and patches
446 intended for copying urls with spec with lots of macros in urls
447 -T <tag> , --tag <tag>
448 - add git tag <tag> for files,
449 -Tvs, --tag-version-stable
450 - add git tags STABLE and NAME-VERSION-RELEASE for files,
452 - add git tag STABLE for files,
454 --tag-version - add git tag NAME-VERSION-RELEASE for files,
455 -Tp, --tag-prefix <prefix>
456 - add <prefix> to NAME-VERSION-RELEASE tags,
457 -tt, --test-tag <prefix>
458 - fail if tag is already present,
459 -ir, --integer-release-only
460 - allow only integer and snapshot releases
461 -v, --verbose - be verbose,
462 -u, --try-upgrade - check version, and try to upgrade package
463 -un, --try-upgrade-with-float-version
464 - as above, but allow float version
465 php-pear-Services_Digg/
466 --upgrade-version - upgrade to specified version in try-upgrade
467 -U, --update - refetch sources, don't use distfiles, and update md5 comments
468 -Upi, --update-poldek-indexes
469 - refresh or make poldek package index files.
471 --skip-patch <patchnumber>
472 - don't apply <patchnumber>. may be repeated.
474 --nopatch <patchnumber>
475 - abort instead of applying patch <patchnumber>
477 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
478 --show-bconds - show available conditional builds, which can be used
479 - with --with and/or --without switches.
480 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
481 In other words, the output is parseable by scripts.
482 --show-avail-bconds - show available bconds
485 - conditional build package depending on %_with_<feature>/
486 %_without_<feature> macro switch. You may now use
487 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
488 constructions. Set GROUP_BCONDS to yes to make use of it.
489 --target <platform>, --target=<platform>
490 - build for platform <platform>.
491 --init-rpm-dir, --init
492 - initialize ~/rpm directory structure
493 --git-pld - force use of PLD git and distfiles
494 --git-tld - force use of TLD git and distfiles (note: it will fall
495 back to PLD git/df if package doesn't exist in TLD git)
496 --pkgrev - save git revision of package being built into pkgrevs
497 (note: only official TLD source builders are allowed to do so)
498 -lp - list pkgrevs for specified package
505 v=$(LC_ALL=C LANG=C rpm --version 2>&1)
506 v=${v#RPM version } # rpm 4
507 v=${v#rpm \(RPM\) } # rpm 5
517 echo "ERROR: unsupported RPM version $v" >&2
522 # create tempfile. as secure as possible
524 local prefix=builder.$PACKAGE_NAME${1:+.$1}
525 mktemp --tmpdir -t $prefix.XXXXXX || echo ${TMPDIR:-/tmp}/$prefix.$RANDOM.$$
529 local prefix=builder.$PACKAGE_NAME${1:+.$1}
530 mktemp --tmpdir -d $prefix.XXXXXX
533 # inserts git log instead of %changelog
534 # @output directory containing modified specfile
536 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
538 # allow this being customized
539 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
541 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
542 # otherwise i'd use --date=iso here
543 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
544 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
545 # NOTE: changelog date is always in UTC for rpmbuild
546 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
547 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
549 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
550 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
553 # add link to full git logs
554 local giturl="http://git.tld-linux.org/?p=packages/${SPECFILE%.spec}.git;a=log"
555 if [ -n "$CVSTAG" ]; then
556 giturl="$giturl;h=$CVSTAG"
558 local gitauthor="TLD Linux <feedback@tld-linux.org>"
559 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
560 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
565 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
566 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
570 " > $specdir/$SPECFILE
571 rm -f $gitlog $speclog
575 # @param string logfile
576 # @param varargs... commands to execute
579 # use teeboth from toys/cleanbuild, if available and enabled
580 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
584 local efile rc logfile=$1; shift
585 if [ "$logfile" ]; then
587 { "$@" 2>&1; echo $? > $efile; } | tee $logfile
598 # change dependency to specname
600 # - perl(Package::Name) -> perl-Package-Name
604 if [ $# -gt 0 ]; then
610 echo "$DEPS" | tr ' ' '\n' | sed -re '
613 s/perl\((.*)\)/perl-\1/
617 s/apache\(EAPI\)-devel/apache-devel/
619 s/db-devel/db5.3-devel/
620 s/libjpeg-devel/libjpeg-turbo-devel/
624 update_shell_title() {
626 local len=${COLUMNS:-80}
627 local msg="$(echo "$*" | cut -c-$len)"
629 if [ -n "$BE_VERBOSE" ]; then
630 echo >&2 "$(date +%s.%N) $*"
633 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
635 if [ -n "$PACKAGE_NAME" ]; then
636 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
641 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
642 msg=$(echo $msg | tr -d '\n\r')
645 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
648 echo >&2 -ne "\033]0;$msg\007"
654 # set TARGET from BuildArch: from SPECFILE
656 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
657 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
659 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
663 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
665 TARGET_SWITCH="--target=$TARGET" ;;
671 # runs rpm with minimal macroset
673 # TODO: move these to /usr/lib/rpm/macros
674 cat > $BUILDER_MACROS <<'EOF'
675 %x8664 x86_64 amd64 ia32e
678 %bootstrap_release() %{1}
679 %requires_releq_kernel_up(s:n:) %{nil}
680 %requires_releq_kernel_smp(s:n:) %{nil}
681 %requires_releq_kernel(s:n:) %{nil}
682 %requires_releq() %{nil}
683 %pyrequires_eq() %{nil}
684 %requires_eq() %{nil}
685 %requires_eq_to() %{nil}
686 %requires_ge() %{nil}
687 %requires_ge_to() %{nil}
688 %requires_ge() %{nil}
689 %releq_kernel_up(n:) ERROR
690 %releq_kernel_smp(n:) ERROR
691 %releq_kernel(n:) ERROR
692 %py_postclean(x:) ERROR
696 %ruby_ver_requires_eq() %{nil}
697 %ruby_mod_ver_requires_eq() %{nil}
698 %__php_api_requires() %{nil}
699 %php_major_version ERROR
700 %php_api_version ERROR
701 %requires_xorg_xserver_extension %{nil}
702 %requires_xorg_xserver_xinput %{nil}
703 %requires_xorg_xserver_font %{nil}
704 %requires_xorg_xserver_videodrv %{nil}
706 %perl_vendorarch ERROR
707 %perl_vendorlib ERROR
708 # damn. need it here! - copied from /usr/lib/rpm/macros.build
709 %tmpdir %(echo "${TMPDIR:-/tmp}")
710 %patchset_source(f:b:) %(
711 base=%{-b*}%{!-b*:10000};
712 start=$(expr $base + %1);
713 end=$(expr $base + %{?2}%{!?2:%{1}});
714 # we need to call seq twice as it doesn't allow two formats
715 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
716 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
717 paste %{tmpdir}/__ps{1,2};
718 rm -f %{tmpdir}/__ps{1,2};
721 %add_etc_shells(p) %{p:<lua>}
722 %remove_etc_shells(p) %{p:<lua>}
723 %lua_add_etc_shells() %{nil}
724 %lua_remove_etc_shells() %{nil}
726 %buildrequires_jdk %{nil}
727 %pear_package_print_optionalpackages %{nil}
729 if [ "$NOINIT" = "yes" ] ; then
730 cat >> $BUILDER_MACROS <<'EOF'
736 local safe_macrofiles
737 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
738 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMUSERDEFS $RPMBUILDOPTS $BCOND $* 2>&1
740 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --load "$BUILDER_MACROS" $QUIET $RPMOPTS $RPMUSERDEFS $RPMBUILDOPTS $BCOND $* 2>&1
746 if [ -n "$DEBUG" ]; then
751 if [ ! -z "$1" ]; then
754 SPEC_PATH="$PACKAGE_DIR/$SPECFILE"
756 if [ -x /usr/bin/rpm-specdump ]; then
757 update_shell_title "cache_rpm_dump using rpm-specdump command"
758 rpm_dump_cache=$(eval rpm-specdump $TARGET_SWITCH $BCOND $RPMUSERDEFS --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPEC_PATH)
760 update_shell_title "cache_rpm_dump using rpmbuild command"
763 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
764 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
770 ARGS='--nodigest --nosignature --nobuild'
773 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
775 if [ $? -gt 0 ]; then
776 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
778 Exit_error err_build_fail
781 # make small dump cache
782 rpm_dump_cache=`echo "$rpm_dump" | awk '
783 $2 ~ /^SOURCEURL/ {print}
784 $2 ~ /^PATCHURL/ {print}
785 $2 ~ /^nosource/ {print}
786 $2 ~ /^PACKAGE_/ {print}
790 update_shell_title "cache_rpm_dump: OK!"
794 if [ -z "$rpm_dump_cache" ] ; then
795 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
797 echo "$rpm_dump_cache"
801 update_shell_title "get icons"
802 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
803 if [ -z "$ICONS" ]; then
807 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
811 update_shell_title "parsing specfile"
812 if [ -n "$DEBUG" ]; then
817 # icons are needed for successful spec parse
823 if rpm_dump | grep -qEi ":.*nosource.*1"; then
824 FAIL_IF_NO_SOURCES="no"
827 if [ "$NOSRCS" != "yes" ]; then
828 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
829 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
830 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
833 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
834 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
835 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
837 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
838 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
841 if [ -n "$BE_VERBOSE" ]; then
842 echo "- Sources : `nourl $SOURCES`"
843 if [ -n "$PATCHES" ]; then
844 echo "- Patches : `nourl $PATCHES`"
846 echo "- Patches : *no patches needed*"
848 if [ -n "$ICONS" ]; then
849 echo "- Icon : `nourl $ICONS`"
851 echo "- Icon : *no package icon*"
853 echo "- Name : $PACKAGE_NAME"
854 echo "- Version : $PACKAGE_VERSION"
855 echo "- Release : $PACKAGE_RELEASE"
858 update_shell_title "parse_spec: OK!"
861 # aborts program abnormally
864 echo >&2 "$PROGRAM: ERROR: $*"
869 if [ -n "$DEBUG" ]; then
877 "err_no_spec_in_cmdl" )
878 remove_build_requires
879 echo >&2 "ERROR: spec file name not specified."
881 "err_invalid_cmdline" )
882 echo >&2 "ERROR: invalid command line arg ($2)."
884 "err_no_spec_in_repo" )
885 remove_build_requires
886 echo >&2 "Error: spec file not stored in repository."
892 "err_no_source_in_repo" )
893 remove_build_requires
894 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
896 "err_cvs_add_failed" )
897 echo >&2 "Error: failed to add package to PLD repo."
900 remove_build_requires
901 echo >&2 "Error: package build failed. (${2:-no more info})"
903 "err_no_package_data" )
904 remove_build_requires
905 echo >&2 "Error: couldn't get out package name/version/release from spec file."
908 remove_build_requires
909 echo >&2 "Tag ${2} already exists"
912 remove_build_requires
913 echo >&2 "Release ${2} not integer and not a snapshot."
915 "err_branch_exists" )
916 remove_build_requires
917 echo >&2 "Tree branch already exists (${2})."
920 remove_build_requires
921 echo >&2 "Error: conditions reject building this spec (${2})."
923 "err_remote_problem" )
924 remove_build_requires
925 echo >&2 "Error: problem with remote (${2})"
928 echo >&2 "Error: cannot checkout ${2}"
931 echo >&2 "Error: failed to set package revision for tag ${2}"
934 echo >&2 "Error: failed to get package revision for tag ${2}"
936 "err_not_implemented" )
937 remove_build_requires
938 echo >&2 "Error: functionality not yet imlemented"
941 echo >&2 "Unknown error."
946 if [ -n "$DEBUG" ]; then
951 if [ "$NOINIT" != "yes" ] ; then
952 TOP_DIR=$(eval $RPM $RPMOPTS $RPMUSERDEFS --eval '%{_topdir}')
954 local macros_ver=$(rpm -E %?rpm_build_macros)
955 if [ -z "$macros_ver" ]; then
956 REPO_DIR=$TOP_DIR/packages
957 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
959 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
960 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
964 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
969 REPO_DIR=$PACKAGE_DIR
970 RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
972 export GIT_WORK_TREE=$PACKAGE_DIR
973 export GIT_DIR=$PACKAGE_DIR/.git
975 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
976 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
977 CVSTAG=${CVSTAG#refs/heads/}
978 if [ "$CVSTAG" != "master" ]; then
979 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
982 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
985 elif [ "$CVSTAG" = "HEAD" ]; then
986 # assume -r HEAD is same as -A
994 update_shell_title "add_package"
996 if [ -n "$DEBUG" ]; then
1002 SPECFILE=$(basename $SPECFILE)
1003 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
1004 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
1007 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
1008 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
1012 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
1013 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1015 git config --local push.default current
1016 git config --local branch.master.remote $REMOTE_PLD
1017 git config --local branch.master.merge refs/heads/master
1019 test $? = 0 || Exit_error err_remote_problem $REMOTE_PLD
1024 update_shell_title "get_spec"
1026 if [ -n "$DEBUG" ]; then
1032 SPECFILE=$(basename $SPECFILE)
1033 if [ "$NOCVSSPEC" != "yes" ]; then
1034 if [ -z "$DEPTH" ]; then
1035 if [ -d "$PACKAGE_DIR/.git" ]; then
1036 git fetch $IPOPT $REMOTE_PLD || Exit_error err_no_spec_in_repo
1037 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
1038 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
1039 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
1042 Exit_error err_not_implemented
1046 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
1047 # softfail if new package, i.e not yet added to PLD rep
1048 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
1049 echo "Warning: package not in Git - assuming new package"
1052 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1053 git config --local --add "remote.$REMOTE_PLD.push" 'refs/notes/*:refs/notes/*'
1054 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1055 git config --local push.default current
1056 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1060 if [ ! -d "$PACKAGE_DIR/.git" ]; then
1061 if [ ! -d "$PACKAGE_DIR" ]; then
1062 install -d $PACKAGE_DIR
1065 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
1066 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1067 git config --local --add "remote.$REMOTE_PLD.push" 'refs/heads/*:refs/remotes/origin/*'
1068 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1069 git config --local push.default current
1070 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1071 CVSTAG=${CVSTAG:-"master"}
1074 if [ -z "$ALL_BRANCHES" ]; then
1075 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
1077 git fetch $IPOPT $DEPTH $REMOTE_PLD $refs || {
1078 echo >&2 "Error: branch $CVSTAG does not exist"
1082 git fetch $IPOPT $REMOTE_PLD 'refs/notes/*:refs/notes/*'
1084 cvsignore_df .gitignore
1086 # add default log format to .gitignore if it is relative to package dir
1087 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
1088 # substitute known "macros" to glob
1089 local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g')
1090 if [ "$logfile" ]; then
1091 cvsignore_df "$logfile"
1095 # create symlinks for tools
1096 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
1097 for a in dropin md5 builder {relup,compile,repackage,rsync,pearize}.sh; do
1098 # skip tools that don't exist in top dir
1099 [ -f $a ] || continue
1100 # skip tools that already exist
1101 [ -f $PACKAGE_DIR/$a ] && continue
1102 ln -s ../$a $PACKAGE_DIR
1108 if [ -n "$CVSTAG" ]; then
1109 local _rev=$(get_pkgrev "$CVSTAG")
1110 echo "$_rev" | grep -q -E "^ERROR$" || CVSTAG="$_rev"
1111 if git rev-parse --verify -q "$CVSTAG" >/dev/null; then
1112 # checkout only if differs, so this will not trash git reflog
1113 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1114 git checkout "$CVSTAG" --
1116 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1117 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1119 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1120 Exit_error "err_no_checkut" "$CVSTAG"
1123 git merge --ff-only '@{u}'
1124 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1125 if [ -n "$CVSDATE" ]; then
1126 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1130 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1131 Exit_error err_no_spec_in_repo "$PACKAGE_DIR/$SPECFILE"
1134 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1135 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1138 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1143 # find mirrors in this order. first match wins:
1144 # - package dir (~/rpm/packages/foo)
1145 # - repository dir (~/rpm/packages)
1146 # - tools dir dir (~/rpm/packages/rpm-build-tools)
1150 update_shell_title "find_mirror[$url][$REPO_DIR]"
1152 # NOTE: as while loop runs in subshell,
1153 # we use exit 2 to indicate that the match was found
1154 # otherwise we end up outputing mirror url and origin url.
1156 local origin mirror name rest ol prefix
1158 cat "$PACKAGE_DIR/mirrors" "$REPO_DIR/mirrors" "$REPO_DIR/../rpm-build-tools/mirrors" /dev/null 2>/dev/null | \
1159 while read origin mirror name rest; do
1160 # skip comments and empty lines
1161 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1164 ol=$(echo -n "$origin" | wc -c)
1165 prefix=$(echo -n "$url" | head -c $ol)
1166 if [ "$prefix" = "$origin" ] ; then
1167 suffix=$(echo "$url" | cut -b $((ol+1))-)
1168 echo -n "$mirror$suffix"
1174 # Warning: unpredictable results if same URL used twice
1177 # escape some regexp characters if part of file name
1178 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1181 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1182 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1183 head -n 1 | tr OURCEATH ourceath | xargs
1187 [ "$NO5" = "yes" ] && return
1189 [ -z "$no" ] && return
1193 # use "sources" file from package dir, like vim
1194 if [ -f sources ]; then
1195 md5=$(grep -s -v '^#' sources | \
1196 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1197 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1198 grep -E '^[0-9a-f]{32}$')
1201 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1202 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1204 echo "$md5" | tail -n 1
1209 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1210 if [ -n "$source_md5" ]; then
1213 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1214 if [ -n "$source_md5" ]; then
1217 # we have empty SourceX-md5, but it is still possible
1218 # that we have NoSourceX-md5 AND NoSource: X
1219 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1220 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1228 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1232 echo "$PROTOCOL$DISTFILES_SERVER/$(distfiles_path "$1")"
1237 [ "$md5" = "" ] || \
1238 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1242 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1243 [ -n "$size" -a "$size" -gt 0 ]
1247 if [ "$CVSIGNORE_DF" != "yes" ]; then
1250 local cvsignore=${PACKAGE_DIR}/.git/info/exclude
1252 # add only if not yet there
1253 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1254 echo "$1" >> $cvsignore
1258 # returns true if "$1" is ftp, http or https protocol url
1261 ftp://*|http://*|https://*)
1269 if [ $# -eq 0 ]; then
1273 update_shell_title "update md5"
1274 if [ -n "$DEBUG" ]; then
1281 # pass 1: check files to be fetched
1285 local fp=$(nourl "$i")
1286 local srcno=$(src_no "$i")
1287 if [ -n "$ADD5" ]; then
1288 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1289 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1290 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1292 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1294 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1295 need_files="$need_files $i"
1299 # pass 1a: get needed files
1300 if [ "$need_files" ]; then
1301 get_files $need_files
1304 # pass 2: proceed with md5 adding or updating
1306 local fp=$(nourl "$i")
1307 local srcno=$(src_no "$i")
1308 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1309 if [ -z "$md5" ]; then
1310 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1312 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1313 local tag="# $srcno-md5:\t"
1314 if [[ "$md5" == *NoSource* ]]; then
1315 tag="# No$srcno-md5:\t"
1316 elif [ -n "$USEDIGEST" ]; then
1317 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1319 md5=$(md5sum "$fp" | cut -f1 -d' ')
1320 echo "Updating $srcno ($md5: $fp)."
1322 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1323 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1325 $PACKAGE_DIR/$SPECFILE
1332 [ "$NO5" = "yes" ] && return
1334 update_shell_title "check md5"
1338 if ! good_md5 "$i"; then
1339 echo -n "MD5 sum mismatch."
1342 if ! good_size "$i"; then
1343 echo -n "0 sized file."
1347 if [ $bad -eq 1 ]; then
1348 echo " Use -U to refetch sources,"
1349 echo "or -5 to update md5 sums, if you're sure files are correct."
1350 Exit_error err_no_source_in_repo $i
1356 update_shell_title "get_files"
1358 if [ -n "$DEBUG" ]; then
1363 if [ $# -gt 0 ]; then
1367 local get_files_cvs=""
1371 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1372 update_shell_title "$i"
1373 local fp=`nourl "$i"`
1374 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1379 local srcmd5=$(src_md5 "$i")
1381 # we know if source/patch is present in cvs/distfiles
1382 # - has md5 (in distfiles)
1383 # - in cvs... ideas?
1385 # CHECK: local file didn't exist or always cvs up (first) requested.
1386 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1387 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1388 echo "Warning: no URL given for $i"
1392 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1393 if good_md5 "$i" && good_size "$i"; then
1394 echo "$fp having proper md5sum already exists"
1398 # optionally prefer mirror over distfiles if there's mirror
1399 # TODO: build url list and then try each url from the list
1400 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1403 url=$(distfiles_url "$i")
1407 # is $url local file?
1408 if [[ "$url" = [./]* ]]; then
1409 update_shell_title "${GETLOCAL%% *}: $url"
1410 ${GETLOCAL} $url $target
1413 # make shorter message for distfiles urls
1414 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]]; then
1415 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/by-md5/?/?/*/}
1418 update_shell_title "${GETURI%% *}: $uri"
1419 ${GETURI} "$target" "$url"
1423 if [ -s "$target" ]; then
1424 cvsignore_df $target
1431 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1432 if [ -z "$NOMIRRORS" ]; then
1433 im=$(find_mirror "$i")
1437 update_shell_title "${GETURI%% *}: $im"
1438 ${GETURI} "$target" "$im"
1439 test -s "$target" || rm -f "$target"
1442 if [ "$cvsup" = 1 ]; then
1448 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1449 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1450 Exit_error err_no_source_in_repo $i
1453 # we check md5 here just only to refetch immediately
1454 if good_md5 "$i" && good_size "$i"; then
1456 elif [ "$FROM_DISTFILES" = 1 ]; then
1457 # wrong md5 from distfiles: remove the file and try again
1459 echo "MD5 sum mismatch. Trying full fetch."
1462 update_shell_title "${GETURI%% *}: $url"
1463 ${GETURI} "$target" "$url"
1464 test -s "$target" || rm -f "$target"
1467 SHELL_TITLE_PREFIX=""
1470 if [ "$CHMOD" = "yes" ]; then
1471 CHMOD_FILES=$(nourl "$@")
1472 if [ -n "$CHMOD_FILES" ]; then
1473 chmod $CHMOD_MODE $CHMOD_FILES
1480 # If tag exists and points to other commit exit with error
1481 # If it existsts and points to HEAD return 1
1482 # If it doesn't exist return 0
1484 local sha1=$(git rev-parse HEAD)
1485 echo "Searching for tag $_tag..."
1486 if [ -n "$DEPTH" ]; then
1487 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1489 local ref=$(git show-ref -s "refs/tags/$_tag")
1491 [ -z "$ref" ] && return 0
1492 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1497 if [ -n "$DEBUG" ]; then
1502 # Check whether first character of PACKAGE_NAME is legal for tag name
1503 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1507 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1508 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1510 # Remove @kernel.version_release from TAGVER because tagging sources
1511 # could occur with different kernel-headers than kernel-headers used at build time.
1512 # besides, %{_kernel_ver_str} is not expanded.
1514 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1515 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1522 if [ -n "$DEBUG" ]; then
1527 echo "Version: $PACKAGE_VERSION"
1528 echo "Release: $PACKAGE_RELEASE"
1531 if [ "$TAG_VERSION" = "yes" ]; then
1534 if [ -n "$TAG" ]; then
1539 local OPTIONS="tag $CVS_FORCE"
1543 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1544 update_shell_title "tag sources: $_tag"
1545 git $OPTIONS $_tag || exit
1546 git push $IPOPT $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1548 echo "Tag $_tag already exists and points to the same commit"
1553 [ -z "$1" ] && return 1
1554 local _tmp=$(mktemp /tmp/.builder-XXXX)
1555 rm $_tmp 2>/dev/null
1556 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/get/$1 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1557 local result=$(cat $_tmp)
1558 rm $_tmp 2>/dev/null
1565 if [ "$TAG_VERSION" = "yes" ]; then
1568 if [ -n "$TAG" ]; then
1571 echo "Writing git revision for tag $_tag"
1572 local _tmp=$(mktemp /tmp/.builder-XXXX)
1573 rm $_tmp 2>/dev/null
1574 local _rev=$(git rev-parse HEAD)
1575 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/set/$_rev/$_tag 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1576 local result=$(cat $_tmp)
1577 rm $_tmp 2>/dev/null
1578 [ "$(get_pkgrev "$_tag")" = "$CVSTAG" ] && return 0
1579 echo "$result" | grep -q -E "^OK$" && return 0
1580 echo "$result" | grep -q -E "^EXISTS$" && Exit_error err_tag_exists "$_tag"
1581 Exit_error err_pkgrev_set
1585 local _tmp=$(mktemp /tmp/.builder-XXXX)
1586 rm $_tmp 2>/dev/null
1587 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/list/$PACKAGE_NAME 1>/dev/null 2>&1
1589 rm $_tmp 2>/dev/null
1594 echo "Git branch: $TAG"
1597 if [ -n "$DEBUG" ]; then
1602 local OPTIONS="branch $CVS_FORCE"
1605 git $OPTIONS $TAG || exit
1609 # this function should exit early if package can't be built for this arch
1610 # this avoids unneccessary BR filling.
1613 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1615 if [ $ret -ne 0 ]; then
1627 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1628 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1634 local ver="$2" subver=$ver
1635 local newver="$3" newsubver=$newver
1637 # try handling subver, everything that's not numeric-dotted in version
1638 if grep -Eq '%define\s+subver' $specfile; then
1639 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1641 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1642 newver=${newver%$newsubver}
1645 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1646 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1647 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1651 # try to upgrade .spec to new version
1652 # if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1654 # return 1: if .spec was updated
1655 # return 0: no changes to .spec
1656 # exit 1 in case of error
1658 if [ -z "$TRY_UPGRADE" ]; then
1662 local TNOTIFY TNEWVER TOLDVER
1663 update_shell_title "build_package: try_upgrade"
1667 if [ "$UPGRADE_VERSION" ]; then
1668 TNEWVER=$UPGRADE_VERSION
1669 echo "Updating spec file to version $TNEWVER"
1671 if [ -n "$FLOAT_VERSION" ]; then
1672 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1674 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1677 # pldnotify does not set exit codes, but it has match for ERROR
1678 # in output which means so.
1679 if [[ "$TNOTIFY" = *ERROR* ]]; then
1684 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1685 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1687 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1690 if [ -z "$TNEWVER" ]; then
1694 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1695 cp -f $SPECFILE $SPECFILE.bak
1698 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1699 set_release $SPECFILE $PACKAGE_RELEASE 1
1701 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1702 echo >&2 "Upgrading version failed, you need to update spec yourself"
1709 update_shell_title "build_package"
1710 if [ -n "$DEBUG" ]; then
1719 BUILD_SWITCH="-ba" ;;
1721 BUILD_SWITCH="-bb" ;;
1723 BUILD_SWITCH="-bs --nodeps" ;;
1725 BUILD_SWITCH="-bp --nodeps" ;;
1727 BUILD_SWITCH="-bc" ;;
1729 BUILD_SWITCH="-bi" ;;
1731 BUILD_SWITCH="-bl" ;;
1735 update_shell_title "build_package: $COMMAND"
1736 local logfile retval
1737 if [ -n "$LOGFILE" ]; then
1738 logfile=`eval echo $LOGFILE`
1739 if [ -d "$logfile" ]; then
1740 echo "Log file $logfile is a directory."
1741 echo "Parse error in the spec?"
1742 Exit_error err_build_fail
1744 if [ -n "$LASTLOG_FILE" ]; then
1745 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1749 # unset these, should not be exposed to builder shell!
1750 unset GIT_WORK_TREE GIT_DIR
1751 # these are set by jenkins
1752 unset GIT_PREVIOUS_COMMIT GIT_URL GIT_PREVIOUS_SUCCESSFUL_COMMIT GIT_BRANCH GIT_COMMIT
1753 # this may be set by user
1755 # may be set by user
1756 unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_TESTING_PORCELAIN_COMMAND_LIST
1757 # fail if something still set
1758 env | grep ^GIT_ && Exit_error err_build_fail
1760 local specdir=$(insert_gitlog $SPECFILE)
1762 # If required exclude directories with systemd related files from package contents
1763 if grep -q -E 'systemd(unitdir|userunitdir|tmpfilesdir)' $specdir/$SPECFILE; then
1764 sed -i -e '/^%exclude_systemd_files/d; /^%files/s/$/\n%exclude_systemd_files/g;' $specdir/$SPECFILE
1766 # Enable/disable distro wide bconds based on ~/.distbcond
1767 process_distbcond "$specdir/$SPECFILE"
1768 # Add %tld macro to release to allow release control
1769 sed -i -r -e '/^Release:/s/%\{\?tld\}//g; s/^Release:\s+(.*)$/Release:\t\1%{?tld}/;' $specdir/$SPECFILE
1770 # FIXME: eval here is exactly why?
1771 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
1774 # Set pkgrev if requested and build status is OK
1775 if [ ! -z "$SETPKGREV" ] && [ "$SETPKGREV" = "true" ] && [ "$retval" -eq "0" ]; then
1776 set_pkgrev "$specdir/$SPECFILE"
1781 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1782 if [ "$retval" -eq "0" ]; then
1783 mv $logfile $LOGDIROK
1785 mv $logfile $LOGDIRFAIL
1789 if [ "$retval" -ne "0" ]; then
1790 if [ -n "$TRY_UPGRADE" ]; then
1791 echo "\nUpgrade package to new version failed."
1792 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1793 echo "Restoring old spec file."
1794 mv -f $SPECFILE.bak $SPECFILE
1798 Exit_error err_build_fail
1804 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1807 install_required_packages() {
1812 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1815 /^%changelog/ { exit }
1817 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1818 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1819 gsub(/[ \t]+/, "_", bcond);
1821 }' $SPEC | LC_ALL=C sort -u
1825 # expand bconds from ~/.bcondrc
1826 # The file structure is like gentoo's package.use:
1829 # samba -mysql -pgsql
1830 # w32codec-installer license_agreement
1833 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1839 SN=${SPECFILE%%\.spec}
1841 local bcondrc=$HOME/.bcondrc
1842 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1844 local bcond_avail=$(find_spec_bcond $SPECFILE)
1846 while read pkg flags; do
1848 [[ "$pkg" == \#* ]] && continue
1850 # any package or current package?
1851 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1852 for flag in $flags; do
1853 local opt=${flag#[+-]}
1855 # use only flags which are in this package.
1856 if [[ $bcond_avail = *${opt}* ]]; then
1857 if [[ $flag = -* ]]; then
1858 if [[ $BCOND != *--with?${opt}* ]]; then
1859 BCOND="$BCOND --without $opt"
1862 if [[ $BCOND != *--without?${opt}* ]]; then
1863 BCOND="$BCOND --with $opt"
1870 update_shell_title "parse ~/.bcondrc: DONE!"
1873 process_distbcond() {
1874 # apply bconds from ~/.distbcond to spec
1875 # The file structure is like gentoo's package.use:
1878 # samba -mysql -pgsql
1879 # w32codec-installer license_agreement
1882 if [ -f $HOME/.distbcond ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.distbcond ]); then
1888 SN=${SPECFILE%%\.spec}
1890 local distbcond=$HOME/.distbcond
1891 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.distbcond ] && distbcond=$HOME_ETC/.distbcond
1893 local bcond_avail=$(find_spec_bcond $SPECFILE)
1895 while read pkg flags; do
1897 [[ "$pkg" == \#* ]] && continue
1899 # any package or current package?
1900 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1901 for flag in $flags; do
1902 local opt=${flag#[+-]}
1904 # use only flags which are in this package.
1905 if [[ $bcond_avail = *${opt}* ]]; then
1906 if [[ $flag = -* ]]; then
1907 sed -i -r -e '/^%bcond_(with|without)\s+'$opt'/s/^%bcond_(with|without)/%bcond_with/g;' "$1"
1908 elif [[ $flag = +* ]]; then
1909 sed -i -r -e '/^%bcond_(with|without)\s+'$opt'/s/^%bcond_(with|without)/%bcond_without/g;' "$1"
1915 update_shell_title "parse ~/.distbcond: DONE!"
1918 set_bconds_values() {
1919 update_shell_title "set bcond values"
1921 AVAIL_BCONDS_WITHOUT=""
1922 AVAIL_BCONDS_WITH=""
1924 if grep -Eq '^# *_with' ${SPECFILE}; then
1925 echo >&2 "ERROR: This spec has old style bconds."
1929 if ! grep -q '^%bcond' ${SPECFILE}; then
1933 local bcond_avail=$(find_spec_bcond $SPECFILE)
1934 process_bcondrc "$SPECFILE"
1936 update_shell_title "parse bconds"
1939 for opt in $bcond_avail; do
1942 bcond=${opt#without_}
1944 *--without?${bcond}\ *|*--without?${bcond})
1945 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1948 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1955 *--with?${bcond}\ *|*--with?${bcond})
1956 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1959 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1964 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1973 update_shell_title "run_sub_builder $package_name"
1975 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1976 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
1977 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1978 # jakby nie bylo tego kawalka kodu.
1980 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1981 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
1985 # kurwa. translate that ^^^^
1989 # Istnieje taki spec? ${package}.spec
1990 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1991 parent_spec_name=${package}.spec
1992 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1993 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1995 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
2000 if [ "${parent_spec_name}" != "" ]; then
2001 spawn_sub_builder $parent_spec_name
2003 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
2006 # install package with poldek
2007 # @return exit code from poldek
2009 # this requires following sudo rules:
2010 # - poldek --noask --caplookup -ug
2012 LC_ALL=C LANG=C $POLDEK_CMD --noask --caplookup --uniq -ug "$@"
2017 # this requires following sudo rules:
2018 # - poldek -q --update --upa
2019 install_packages() {
2020 # sync poldek indexes once per invocation
2021 if [ -z "$package_indexes_updated" ]; then
2022 update_shell_title "poldek: update indexes"
2023 $POLDEK_CMD -q --update --upa --mo=nodesc
2024 package_indexes_updated=true
2027 update_shell_title "install packages: $*"
2028 poldek_install "$@" && return
2030 # retry install, install packages one by one
2031 # this is slower one
2033 for package in $*; do
2034 package=$(depspecname $package)
2035 update_shell_title "install package: $package"
2036 poldek_install "$package" || rc=$?
2041 uninstall_packages() {
2042 update_shell_title "uninstall packages: $*"
2043 $POLDEK_CMD --noask --nofollow -ev "$@"
2046 spawn_sub_builder() {
2048 update_shell_title "spawn_sub_builder $package_name"
2051 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
2052 sub_builder_opts="${sub_builder_opts} -R"
2054 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
2055 sub_builder_opts="${sub_builder_opts} -RB"
2056 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
2057 sub_builder_opts="${sub_builder_opts} -FRB"
2059 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
2060 sub_builder_opts="${sub_builder_opts} -Upi"
2064 ./builder ${sub_builder_opts} "$@"
2067 remove_build_requires() {
2068 if [ "$INSTALLED_PACKAGES" != "" ]; then
2069 case "$REMOVE_BUILD_REQUIRES" in
2071 run_poldek --noask -ve $INSTALLED_PACKAGES
2074 run_poldek --ask -ve $INSTALLED_PACKAGES
2077 echo You may want to manually remove following BuildRequires fetched:
2078 echo $INSTALLED_PACKAGES
2079 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
2086 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
2087 if [ "$BCOND" ]; then
2089 echo "Building $SPECFILE with the following conditional flags:"
2093 echo "No conditional flags passed"
2096 echo "from available:"
2097 echo "--with :\t$AVAIL_BCONDS_WITH"
2098 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
2103 display_branches() {
2104 echo -n "Available branches: "
2105 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
2108 # checks a given list of packages/files/provides against current rpmdb.
2109 # outputs all dependencies which current rpmdb doesn't satisfy.
2110 # input can be either STDIN or parameters
2114 if [ $# -gt 0 ]; then
2120 out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1)
2123 echo "$out" | awk '/^no package provides/ { print $NF }'
2125 # other deps (files)
2126 echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p'
2129 # checks if given package/files/provides exists in rpmdb.
2130 # input can be either stdin or parameters
2131 # returns packages which are present in the rpmdb
2135 if [ $# -gt 0 ]; then
2141 LC_ALL=C LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
2144 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
2145 install_build_requires_rpmdeps() {
2147 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
2148 # TODO: Conflicts list doesn't check versions
2149 CNFL=$(eval rpm-getdeps $BCOND $RPMOPTS $RPMUSERDEFS $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
2150 DEPS=$(eval rpm-getdeps $BCOND $RPMOPTS $RPMUSERDEFS $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
2152 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2153 CNFL=$(eval rpm -q --specsrpm --conflicts $BCOND $RPMOPTS $RPMUSERDEFS $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
2154 DEPS=$(eval rpm -q --specsrpm --requires $BCOND $RPMOPTS $RPM_USERDEFS $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
2157 if [ -n "$CNFL" ]; then
2158 echo "Uninstall conflicting packages: $CNFL"
2159 uninstall_packages $CNFL
2162 if [ -n "$DEPS" ]; then
2163 echo "Install dependencies: $DEPS"
2164 install_packages $DEPS
2168 fetch_build_requires()
2170 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
2174 update_shell_title "fetch build requires"
2175 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2176 install_build_requires_rpmdeps
2180 die "need rpm-getdeps tool"
2187 if [ ! -e $localrepo ]; then
2188 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
2189 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2194 local TOP_DIR=$(eval $RPM $RPMOPTS $RPMUSERDEFS --eval '%{_topdir}')
2195 local rpmdir=$(eval $RPM $RPMOPTS $RPMUSERDEFS --eval '%{_rpmdir}')
2196 local buildir=$(eval $RPM $RPMOPTS $RPMUSERDEFS --eval '%{_builddir}')
2197 local srpmdir=$(eval $RPM $RPMOPTS $RPMUSERDEFS --eval '%{_srcrpmdir}')
2198 local TEMPLATES=template-specs
2201 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2202 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2205 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2206 init_repository projects/$TEMPLATES ../$TEMPLATES
2207 for a in builder fetchsrc_request compile repackage; do
2208 ln -sf ../rpm-build-tools/${a}.sh $a
2211 ln -sf ../rpm-build-tools/${a} $a
2213 ln -sf ../rpm-build-tools/mirrors mirrors
2220 DONT_PRINT_REVISION="yes"
2222 # remove spec and sources
2223 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
2224 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2225 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2228 #---------------------------------------------
2236 # stuff global $BUILDER_OPTS from env as args
2237 if [ "$BUILDER_OPTS" ]; then
2238 set -- "$BUILDER_OPTS" "$@"
2241 while [ $# -gt 0 ]; do
2248 COMMAND="update_md5"
2253 COMMAND="update_md5"
2262 DEBUG="yes"; shift ;;
2264 COMMAND="version"; shift ;;
2266 COMMAND="short-version"; shift ;;
2273 -b | -ba | --build )
2274 COMMAND="build"; shift ;;
2275 -bb | --build-binary )
2276 COMMAND="build-binary"; shift ;;
2278 COMMAND="build-build"; shift ;;
2280 COMMAND="build-install"; shift ;;
2282 COMMAND="build-list"; shift ;;
2283 -bp | --build-prep )
2284 COMMAND="build-prep"; shift ;;
2285 -bs | --build-source )
2286 COMMAND="build-source"; shift ;;
2288 COMMAND="branch"; shift; TAG="${1}"; shift;;
2290 CLEAN="--clean"; shift ;;
2292 CVS_FORCE="-f"; shift;;
2298 COMMAND="get"; shift ;;
2300 COMMAND="usage"; shift ;;
2302 PROTOCOL="ftp"; shift ;;
2304 PROTOCOL="http"; shift ;;
2306 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2310 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2314 PARALLEL_DOWNLOADS=$2
2318 PARALLEL_DOWNLOADS=${1#-p}
2322 shift; LOGFILE="${1}"; shift ;;
2324 shift; DEF_NICE_LEVEL=${1}; shift ;;
2325 -ske | --skip-existing-files)
2326 SKIP_EXISTING_FILES="yes"; shift ;;
2328 COMMAND="mr-proper"; shift ;;
2329 -ncs | --no-cvs-specs )
2330 NOCVSSPEC="yes"; shift ;;
2331 -nd | --no-distfiles )
2332 NODIST="yes"; shift ;;
2333 -nm | --no-mirrors )
2334 NOMIRRORS="yes"; shift ;;
2336 NOURLS="yes"; shift ;;
2338 NOSRCS="yes"; shift ;;
2339 -ns0 | --no-source0 )
2340 NOSOURCE0="yes"; shift ;;
2349 -pm | --prefer-mirrors )
2352 --noinit | --no-init )
2356 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2358 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2359 --skip-patch | -sp )
2360 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2362 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2365 --with | --without )
2366 case $GROUP_BCONDS in
2370 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2371 while ! `echo ${1}|grep -qE '(^-|spec)'`
2373 BCOND="$BCOND $COND $1"
2377 if [[ "$2" = *,* ]]; then
2378 for a in $(echo "$2" | tr , ' '); do
2379 BCOND="$BCOND $1 $a"
2382 BCOND="$BCOND $1 $2"
2388 shift; TARGET="${1}"; shift ;;
2390 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2392 QUIET="--quiet"; shift ;;
2394 CVSDATE="${2}"; shift 2
2395 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2405 -R | --fetch-build-requires)
2406 FETCH_BUILD_REQUIRES="yes"
2407 NOT_INSTALLED_PACKAGES=
2409 -RB | --remove-build-requires)
2410 REMOVE_BUILD_REQUIRES="nice"
2412 -FRB | --force-remove-build-requires)
2413 REMOVE_BUILD_REQUIRES="force"
2416 COMMAND="list-sources-cvs"
2418 -sd | --source-distfiles)
2419 COMMAND="list-sources-distfiles"
2421 -sdp | --source-distfiles-paths)
2422 COMMAND="list-sources-distfiles-paths"
2424 -sf | --source-files)
2425 COMMAND="list-sources-files"
2427 -lsp | --source-paths)
2428 COMMAND="list-sources-local-paths"
2430 -su | --source-urls)
2431 COMMAND="list-sources-urls"
2433 -Tvs | --tag-version-stable )
2438 -Ts | --tag-stable )
2443 -Tv | --tag-version )
2448 -Tp | --tag-prefix )
2460 -ir | --integer-release-only )
2461 INTEGER_RELEASE="yes"
2464 COMMAND="update_md5"
2469 -Upi | --update-poldek-indexes )
2470 UPDATE_POLDEK_INDEXES="yes"
2472 --init-rpm-dir|--init)
2473 COMMAND="init_rpm_dir"
2475 -u | --try-upgrade )
2476 TRY_UPGRADE="1"; shift ;;
2478 shift; UPGRADE_VERSION="$1"; shift;;
2479 -un | --try-upgrade-with-float-version )
2480 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2482 BE_VERBOSE="1"; shift ;;
2487 if echo "${MACRO}" | grep -q '\W'; then
2488 RPMUSERDEFS="${RPMUSERDEFS} --define \"${MACRO}\""
2492 RPMUSERDEFS="${RPMUSERDEFS} --define \"${MACRO} ${VALUE}\""
2497 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\""
2501 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2504 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2505 COMMAND="show_bconds"
2509 COMMAND="show_bcond_args"
2512 --show-avail-bconds)
2513 COMMAND="show_avail_bconds"
2518 RPMOPTS="${RPMOPTS} --nodeps"
2521 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2525 GIT_SERVER=${PLD_GIT_SERVER}
2526 GIT_PUSH=${PLD_GIT_PUSH}
2527 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2528 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2532 GIT_SERVER=${TLD_GIT_SERVER}
2533 GIT_PUSH=${TLD_GIT_PUSH}
2534 PACKAGES_DIR=${TLD_PACKAGES_DIR}
2535 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
2539 COMMAND="build-source"
2542 COMMAND="list_pkgrev"
2545 Exit_error err_invalid_cmdline "$1"
2548 SPECFILE=${1%/}; shift
2549 # check if specname was passed as specname:cvstag
2550 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2551 CVSTAG="${SPECFILE##*:}"
2552 SPECFILE="${SPECFILE%%:*}"
2554 # always have SPECFILE ending with .spec extension
2555 SPECFILE=${SPECFILE%%.spec}.spec
2556 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2560 # Check if given package exists in TLD git
2561 if ! git ls-remote --heads ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME} 1>/dev/null 2>&1; then
2562 # Nope, we don't have it in TLD, switch to PLD repositories
2563 GIT_SERVER=${PLD_GIT_SERVER}
2564 GIT_PUSH=${PLD_GIT_PUSH}
2565 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2566 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2569 if [ "$CVSTAG" ]; then
2570 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2571 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2574 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2575 echo >&2 "--all branches requires --depth <number>"
2576 Exit_error err_invalid_cmdline
2579 if [ -n "$DEBUG" ]; then
2584 if [ -n "$TARGET" ]; then
2587 TARGET_SWITCH="--target $TARGET" ;;
2589 TARGET_SWITCH="--target=$TARGET" ;;
2593 if [ "$SCHEDTOOL" != "no" ]; then
2594 NICE_COMMAND="$SCHEDTOOL"
2596 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2599 # see time(1) for output format that could be used
2600 TIME_COMMAND="time -p"
2602 update_shell_title "$COMMAND"
2606 if [ -z "$SPECFILE" ]; then
2607 Exit_error err_no_spec_in_cmdl
2609 get_spec > /dev/null
2616 if [ -z "$SPECFILE" ]; then
2617 Exit_error err_no_spec_in_cmdl
2619 get_spec > /dev/null
2624 "show_avail_bconds")
2626 if [ -z "$SPECFILE" ]; then
2627 Exit_error err_no_spec_in_cmdl
2630 get_spec > /dev/null
2632 local bcond_avail=$(find_spec_bcond $SPECFILE)
2633 local opt bcond bconds
2634 for opt in $bcond_avail; do
2637 bcond=${opt#without_}
2638 bconds="$bconds $bcond"
2642 bconds="$bconds $bcond"
2645 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2653 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2655 if [ -z "$SPECFILE" ]; then
2656 Exit_error err_no_spec_in_cmdl
2659 # display SMP make flags if set
2660 smp_mflags=$(rpm -E %{?_smp_mflags})
2661 if [ "$smp_mflags" ]; then
2662 echo "builder: SMP make flags are set to $smp_mflags"
2670 if [ "$COMMAND" != "build-source" ]; then
2673 fetch_build_requires
2674 if [ "$INTEGER_RELEASE" = "yes" ]; then
2675 echo "Checking release $PACKAGE_RELEASE..."
2676 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2677 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2681 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2682 if [ -n "$TEST_TAG" ]; then
2685 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2686 # check also tags created in CVS
2687 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2688 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2689 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2690 || Exit_error err_tag_exists $TAGVER_CVS
2691 # - do not allow to build from HEAD when XX-branch exists
2692 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2693 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2694 TAG_BRANCH="${TREE_PREFIX}-branch"
2695 if [ -n "$DEPTH" ]; then
2696 cmd_branches="git ls-remote --heads"
2697 ref_prefix=refs/heads
2699 cmd_branches="git show-ref"
2700 ref_prefix=refs/remotes/${REMOTE_PLD}
2702 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2703 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2704 Exit_error err_branch_exists "$TAG_STATUS"
2710 if [ -n "$NOSOURCE0" ] ; then
2711 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2716 get_files $SOURCES $PATCHES
2717 check_md5 $SOURCES $PATCHES
2720 NODIST="yes" get_files $SOURCES $PATCHES
2721 update_md5 $SOURCES $PATCHES
2725 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2726 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2728 remove_build_requires
2732 if [ -z "$SPECFILE" ]; then
2733 Exit_error err_no_spec_in_cmdl
2742 if [ -z "$SPECFILE" ]; then
2743 Exit_error err_no_spec_in_cmdl
2747 if [ -n "$NEW_REPO" ]; then
2750 for file in $SOURCES $PATCHES; do
2751 if [ -z $(src_md5 "$file") ]; then
2752 git add $file || Exit_error err_no_source_in_repo $file
2754 cvsignore_df `nourl $file`
2758 echo "When you are ready commit your changes and run git push origin master"
2760 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2765 if [ -z "$SPECFILE" ]; then
2766 Exit_error err_no_spec_in_cmdl
2772 if [ -n "$NOSOURCE0" ] ; then
2773 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2775 get_files $SOURCES $PATCHES
2777 fetch_build_requires
2781 if [ -z "$SPECFILE" ]; then
2782 Exit_error err_no_spec_in_cmdl
2788 if [ -n "$NOSOURCE0" ] ; then
2789 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2791 update_md5 $SOURCES $PATCHES
2797 if [ -z "$SPECFILE" ]; then
2798 Exit_error err_no_spec_in_cmdl
2802 if [ ! -d .git ]; then
2803 echo "No git reposiotory" >&2
2811 "list-sources-files" )
2814 DONT_PRINT_REVISION="yes"
2817 for SAP in $SOURCES $PATCHES; do
2818 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2821 "list-sources-urls" )
2824 DONT_PRINT_REVISION="yes"
2827 SAPS="$SOURCES $PATCHES"
2828 for SAP in $SAPS; do
2832 "list-sources-local-paths" )
2835 DONT_PRINT_REVISION="yes"
2838 for SAP in $SOURCES $PATCHES; do
2839 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2842 "list-sources-distfiles-paths" )
2845 DONT_PRINT_REVISION="yes"
2848 for SAP in $SOURCES $PATCHES; do
2849 if [ -n "$(src_md5 "$SAP")" ]; then
2850 distfiles_path "$SAP"
2854 "list-sources-distfiles" )
2857 DONT_PRINT_REVISION="yes"
2860 for SAP in $SOURCES $PATCHES; do
2861 if [ -n "$(src_md5 "$SAP")" ]; then
2862 distfiles_url "$SAP"
2866 "list-sources-cvs" )
2869 DONT_PRINT_REVISION="yes"
2872 for SAP in $SOURCES $PATCHES; do
2873 if [ -z "$(src_md5 "$SAP")" ]; then
2874 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2888 echo "$VERSIONSTRING"
2892 if [ -z "$SPECFILE" ]; then
2893 Exit_error err_no_spec_in_cmdl
2895 get_spec > /dev/null
2900 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2901 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2905 # vi:syntax=sh:ts=4:sw=4:noet