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="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
45 # required rpm-build-macros
64 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
66 # use rpm 4.4.6+ digest format instead of comments if non-zero
69 # user agent when fetching files
70 USER_AGENT="PLD/Builder($VERSION)"
72 # It can be used i.e. in log file naming.
73 # See LOGFILE example.
74 DATE=`date +%Y-%m-%d_%H-%M-%S`
76 # target arch, can also be used for log file naming
77 TARGET=$(rpm -E %{_target})
79 # Note the *single* quotes, this allows using shell variables expanded at build time
80 # Example: LOGFILE='../log.$PACKAGE_NAME'
81 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
82 # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
83 # Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
84 # Example: LOGFILE='.log.$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.$TARGET.$DATE'
87 # use teeboth Perl wrapper
88 # temporary option to disable if broken
103 # create symlinks for tools in PACKAGE_DIR, see get_spec()
116 # use lftp by default when available
117 test -z "${USE_LFTP+x}" && lftp --version > /dev/null 2>&1 && USE_LFTP=yes
118 PARALLEL_DOWNLOADS=10
120 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
125 GIT_SERVER="git://git.pld-linux.org"
126 GIT_PUSH="git@git.pld-linux.org"
127 PACKAGES_DIR="packages"
136 DISTFILES_SERVER="://distfiles.pld-linux.org"
137 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
142 FAIL_IF_NO_SOURCES="yes"
144 # let get_files skip over files which are present to get those damn files fetched
145 SKIP_EXISTING_FILES="no"
148 # should the specfile be restored if upgrade failed?
149 REVERT_BROKEN_UPGRADE="yes"
151 if rpm --specsrpm 2>/dev/null; then
152 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
153 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
155 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
156 if [ -x /usr/bin/rpm-getdeps ]; then
157 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
159 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
163 UPDATE_POLDEK_INDEXES_OPTS=""
165 # Here we load saved user environment used to
166 # predefine options set above, or passed to builder
168 # This one reads global system environment settings:
169 if [ -f ~/etc/builderrc ]; then
172 # And this one cascades settings using user personal
174 # Example of ~/.builderrc:
176 #UPDATE_POLDEK_INDEXES="yes"
177 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
178 #FETCH_BUILD_REQUIRES="yes"
179 #REMOVE_BUILD_REQUIRES="force"
181 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
186 if [ -n "$HOME_ETC" ]; then
187 USER_CFG="$HOME_ETC/.builderrc"
188 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
190 USER_CFG=~/.builderrc
191 BUILDER_MACROS=~/.builder-rpmmacros
194 [ -f "$USER_CFG" ] && . "$USER_CFG"
196 if [ "$SCHEDTOOL" = "auto" ]; then
197 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
198 SCHEDTOOL="schedtool -B -e"
204 if [ -n "$USE_PROZILLA" ]; then
206 elif [ -n "$USE_AXEL" ]; then
208 elif [ -n "$USE_LFTP" ]; then
214 GETLOCAL=${GETLOCAL:-cp -a}
222 if [ -d $HOME/rpm/SOURCES ]; then
223 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
224 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
228 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
229 POLDEK_CMD="$SU_SUDO /usr/bin/poldek"
232 # TODO: what this function does?
235 if [ -n "$LOGFILE" ]; then
236 LOG=`eval echo $LOGFILE`
237 if [ -n "$LASTLOG_FILE" ]; then
238 echo "LASTLOG=$LOG" > $LASTLOG_FILE
240 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
241 # FIXME $exit_pldk undefined
244 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
245 return `cat ${RES_FILE}`
250 #---------------------------------------------
253 download_prozilla() {
254 local outfile=$1 url=$2 retval
256 proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS -O "$outfile" "$url"
263 local outfile=$1 url=$2 retval
265 axel -a $AXEL_OPTS -o "$outfile" "$url"
272 local outfile=$1 url=$2 retval wget_help
273 if [ -z "${WGET_OPTS_SET+x}" ]; then
274 wget_help="$(wget --help 2>&1)"
275 echo "$wget_help" | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
276 echo "$wget_help" | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
277 echo "$wget_help" | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
278 echo "$wget_help" | grep -q -- ' --no-iri ' && WGET_OPTS="$WGET_OPTS --no-iri"
279 WGET_OPTS="-c -nd -t$WGET_RETRIES $WGET_OPTS --user-agent=$USER_AGENT $IPOPT --passive-ftp"
283 wget $WGET_OPTS -O "$outfile" "$url"
285 if [ $retval -ne 0 ]; then
286 if [ "`echo $url | grep -E 'ftp://'`" ]; then
287 ${GETURI} -O "$outfile" "$url"
295 local outfile=$1 url=$2 retval tmpfile
296 tmpfile=$(tempfile) || exit 1
298 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
299 $([ "$IPOPT" = "-4" ] && echo "set dns:order \"inet\";")
300 $([ "$IPOPT" = "-6" ] && echo "set dns:order \"inet6\";")
301 set ssl:verify-certificate no;
302 set net:max-retries $WGET_RETRIES;
303 set http:user-agent \"$USER_AGENT\";
304 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
308 if [ $retval -eq 0 ]; then
309 mv -f "$tmpfile" "$outfile"
317 if [ -n "$DEBUG" ]; then set -xv; fi
319 # to make this output parseable by bash-completion _parse_help()
320 # if the line contains short and long option, it will take only the long option
321 # but if you want both being completed, put the short option to separate line
323 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
324 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
325 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
326 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
327 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
328 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
329 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
330 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
331 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
332 <package>[.spec][:tag]
334 -4 - force IPv4 when transferring files
335 -6 - force IPv6 when transferring files
337 --update-md5 - update md5 comments in spec, implies -nd -ncs
339 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
340 --all-branches - make shallow fetch of all branches; --depth required
341 -n5, --no-md5 - ignore md5 comments in spec
342 -D, --debug - enable builder script debugging mode,
343 -debug - produce rpm debug package (same as --opts -debug)
344 -V, --version - output builder version string
345 --short-version - output builder short version
346 -a - try add new package to PLD repo.
349 - get all files from PLD repo or HTTP/FTP and build package
351 -bb - get all files from PLD repo or HTTP/FTP and build binary
352 only package from <package>.spec,
353 -bp - execute the %prep phase of <package>.spec,
354 -bc - execute the %build phase of <package>.spec,
355 -bi - execute the %install phase of <package>.spec
356 -bl - execute the %files phase of <package>.spec
357 -bs - get all files from PLD repo or HTTP/FTP and only pack
359 --short-circuit - short-circuit build
360 -B, --branch - add branch
362 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
363 may be used with building process.
364 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
365 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
366 -cf, --cvs-force - use -f when tagging
367 --define '<macro> <value>'
368 - define a macro <macro> with value <value>,
369 --depth <number> - make shallow fetch
370 --alt_kernel <kernel>
371 - same as --define 'alt_kernel <kernel>'
372 --nodeps - rpm won't check any dependences
374 --get - get <package>.spec and all related files from PLD repo
375 -h, --help - this message,
376 -j N - set %_smp_mflags to propagate concurrent jobs
377 --ftp - use FTP protocol to access distfiles server
378 --http - use HTTP protocol to access distfiles server
379 -l <logfile>, --logtofile=<logfile>
382 - don't pull from PLD repo
383 -nd, --no-distfiles - don't download from distfiles
384 -nm, --no-mirrors - don't download from mirror, if source URL is given,
385 -nu, --no-urls - don't try to download from FTP/HTTP location,
386 -ns, --no-srcs - don't download Sources/Patches
387 -ns0, --no-source0 - don't download Source0
388 -nn, --no-net - don't download anything from the net
389 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
390 -pm, --prefer-mirrors
391 - prefer mirrors (if any) over distfiles for SOURCES
392 --no-init - don't initialize builder paths (SPECS and SOURCES)
394 --skip-existing-files
395 - skip existing files in get_files
396 --opts <rpm opts> - additional options for rpm
397 -q, --quiet - be quiet,
398 --date yyyy-mm-dd - build package using resources from specified date,
399 -r <tag>, --cvstag <ref>
400 - build package using resources from specified branch/tag,
401 -A - build package using master branch as any sticky tags/branch/date being reset.
402 -R, --fetch-build-requires
403 - fetch what is BuildRequired,
404 -RB, --remove-build-requires
405 - remove all you fetched with -R or --fetch-build-requires
406 remember, this option requires confirmation,
407 -FRB, --force-remove-build-requires
408 - remove all you fetched with -R or --fetch-build-requires
409 remember, this option works without confirmation,
410 -sd, --source-distfiles
411 - list sources available from distfiles (intended for offline
412 operations; does not work when Icon field is present
413 but icon file is absent),
414 -sc, --source-cvs - list sources available from PLD repo
415 -sdp, --source-distfiles-paths
416 - list sources available from distfiles -
417 paths relative to distfiles directory (intended for offline
418 operations; does not work when Icon field is present
419 but icon file is absent),
420 -sf, --source-files - list sources - bare filenames (intended for offline
421 operations; does not work when Icon field is present
422 but icon file is absent),
424 - list sources - filenames with full local paths (intended for
425 offline operations; does not work when Icon field is present
426 but icon file is absent),
427 -su, --source-urls - list urls - urls to sources and patches
428 intended for copying urls with spec with lots of macros in urls
429 -T <tag> , --tag <tag>
430 - add git tag <tag> for files,
431 -Tvs, --tag-version-stable
432 - add git tags STABLE and NAME-VERSION-RELEASE for files,
434 - add git tag STABLE for files,
436 --tag-version - add git tag NAME-VERSION-RELEASE for files,
437 -Tp, --tag-prefix <prefix>
438 - add <prefix> to NAME-VERSION-RELEASE tags,
439 -tt, --test-tag <prefix>
440 - fail if tag is already present,
441 -ir, --integer-release-only
442 - allow only integer and snapshot releases
443 -v, --verbose - be verbose,
444 -u, --try-upgrade - check version, and try to upgrade package
445 -un, --try-upgrade-with-float-version
446 - as above, but allow float version
447 php-pear-Services_Digg/
448 --upgrade-version - upgrade to specified version in try-upgrade
449 -U, --update - refetch sources, don't use distfiles, and update md5 comments
450 -Upi, --update-poldek-indexes
451 - refresh or make poldek package index files.
453 --skip-patch <patchnumber>
454 - don't apply <patchnumber>. may be repeated.
456 --nopatch <patchnumber>
457 - abort instead of applying patch <patchnumber>
459 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
460 --show-bconds - show available conditional builds, which can be used
461 - with --with and/or --without switches.
462 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
463 In other words, the output is parseable by scripts.
464 --show-avail-bconds - show available bconds
467 - conditional build package depending on %_with_<feature>/
468 %_without_<feature> macro switch. You may now use
469 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
470 constructions. Set GROUP_BCONDS to yes to make use of it.
471 --target <platform>, --target=<platform>
472 - build for platform <platform>.
473 --init-rpm-dir, --init
474 - initialize ~/rpm directory structure
481 v=$(rpm --version 2>&1)
482 v=${v#RPM version } # rpm 4
483 v=${v#rpm (RPM) } # rpm 5
495 # create tempfile. as secure as possible
497 local prefix=builder.$PACKAGE_NAME${1:+.$1}
498 mktemp --tmpdir -t $prefix.XXXXXX || echo ${TMPDIR:-/tmp}/$prefix.$RANDOM.$$
502 local prefix=builder.$PACKAGE_NAME${1:+.$1}
503 mktemp --tmpdir -d $prefix.XXXXXX
506 # inserts git log instead of %changelog
507 # @output directory containing modified specfile
509 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
511 # allow this being customized
512 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
514 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
515 # otherwise i'd use --date=iso here
516 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
517 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
518 # NOTE: changelog date is always in UTC for rpmbuild
519 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
520 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
522 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
523 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
526 # add link to full git logs
527 local giturl="http://git.pld-linux.org/?p=packages/${SPECFILE%.spec}.git;a=log"
528 if [ -n "$CVSTAG" ]; then
529 giturl="$giturl;h=$CVSTAG"
531 local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
532 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
533 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
538 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
539 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
543 " > $specdir/$SPECFILE
544 rm -f $gitlog $speclog
548 # @param string logfile
549 # @param varargs... commands to execute
552 # use teeboth from toys/cleanbuild, if available and enabled
553 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
557 local efile rc logfile=$1; shift
558 if [ "$logfile" ]; then
560 { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile
571 # change dependency to specname
573 # - perl(Package::Name) -> perl-Package-Name
577 if [ $# -gt 0 ]; then
583 echo "$DEPS" | tr ' ' '\n' | sed -re '
586 s/perl\((.*)\)/perl-\1/
590 s/apache\(EAPI\)-devel/apache-devel/
592 s/db-devel/db5.3-devel/
593 s/libjpeg-devel/libjpeg-turbo-devel/
597 update_shell_title() {
599 local len=${COLUMNS:-80}
600 local msg="$(echo "$*" | cut -c-$len)"
602 if [ -n "$BE_VERBOSE" ]; then
603 echo >&2 "$(date +%s.%N) $*"
606 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
608 if [ -n "$PACKAGE_NAME" ]; then
609 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
614 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
615 msg=$(echo $msg | tr -d '\n\r')
618 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
621 echo >&2 -ne "\033]0;$msg\007"
627 # set TARGET from BuildArch: from SPECFILE
629 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
630 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
632 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
636 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
638 TARGET_SWITCH="--target=$TARGET" ;;
644 # runs rpm with minimal macroset
646 # TODO: move these to /usr/lib/rpm/macros
647 cat > $BUILDER_MACROS <<'EOF'
648 %x8664 x86_64 amd64 ia32e
651 %bootstrap_release() %{1}
652 %requires_releq_kernel_up(s:n:) %{nil}
653 %requires_releq_kernel_smp(s:n:) %{nil}
654 %requires_releq_kernel(s:n:) %{nil}
655 %requires_releq() %{nil}
656 %pyrequires_eq() %{nil}
657 %requires_eq() %{nil}
658 %requires_eq_to() %{nil}
659 %requires_ge() %{nil}
660 %requires_ge_to() %{nil}
661 %requires_ge() %{nil}
662 %releq_kernel_up(n:) ERROR
663 %releq_kernel_smp(n:) ERROR
664 %releq_kernel(n:) ERROR
665 %py_postclean(x:) ERROR
669 %ruby_ver_requires_eq() %{nil}
670 %ruby_mod_ver_requires_eq() %{nil}
671 %__php_api_requires() %{nil}
672 %php_major_version ERROR
673 %php_api_version ERROR
674 %requires_xorg_xserver_extension %{nil}
675 %requires_xorg_xserver_xinput %{nil}
676 %requires_xorg_xserver_font %{nil}
677 %requires_xorg_xserver_videodrv %{nil}
679 %perl_vendorarch ERROR
680 %perl_vendorlib ERROR
681 # damn. need it here! - copied from /usr/lib/rpm/macros.build
682 %tmpdir %(echo "${TMPDIR:-/tmp}")
683 %patchset_source(f:b:) %(
684 base=%{-b*}%{!-b*:10000};
685 start=$(expr $base + %1);
686 end=$(expr $base + %{?2}%{!?2:%{1}});
687 # we need to call seq twice as it doesn't allow two formats
688 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
689 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
690 paste %{tmpdir}/__ps{1,2};
691 rm -f %{tmpdir}/__ps{1,2};
694 %add_etc_shells(p) %{p:<lua>}
695 %remove_etc_shells(p) %{p:<lua>}
696 %lua_add_etc_shells() %{nil}
697 %lua_remove_etc_shells() %{nil}
699 %buildrequires_jdk %{nil}
700 %pear_package_print_optionalpackages %{nil}
702 if [ "$NOINIT" = "yes" ] ; then
703 cat >> $BUILDER_MACROS <<'EOF'
709 local safe_macrofiles
710 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
711 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
713 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --load "$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
718 if [ -n "$DEBUG" ]; then
723 if [ -x /usr/bin/rpm-specdump ]; then
724 update_shell_title "cache_rpm_dump using rpm-specdump command"
725 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
727 update_shell_title "cache_rpm_dump using rpmbuild command"
730 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
731 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
737 ARGS='--nodigest --nosignature --nobuild'
740 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
742 if [ $? -gt 0 ]; then
743 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
745 Exit_error err_build_fail
748 # make small dump cache
749 rpm_dump_cache=`echo "$rpm_dump" | awk '
750 $2 ~ /^SOURCEURL/ {print}
751 $2 ~ /^PATCHURL/ {print}
752 $2 ~ /^nosource/ {print}
753 $2 ~ /^PACKAGE_/ {print}
757 update_shell_title "cache_rpm_dump: OK!"
761 if [ -z "$rpm_dump_cache" ] ; then
762 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
764 echo "$rpm_dump_cache"
768 update_shell_title "get icons"
769 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
770 if [ -z "$ICONS" ]; then
774 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
778 update_shell_title "parsing specfile"
779 if [ -n "$DEBUG" ]; then
784 # icons are needed for successful spec parse
790 if rpm_dump | grep -qEi ":.*nosource.*1"; then
791 FAIL_IF_NO_SOURCES="no"
794 if [ "$NOSRCS" != "yes" ]; then
795 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
796 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
797 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
800 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
801 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
802 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
804 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
805 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
808 if [ -n "$BE_VERBOSE" ]; then
809 echo "- Sources : `nourl $SOURCES`"
810 if [ -n "$PATCHES" ]; then
811 echo "- Patches : `nourl $PATCHES`"
813 echo "- Patches : *no patches needed*"
815 if [ -n "$ICONS" ]; then
816 echo "- Icon : `nourl $ICONS`"
818 echo "- Icon : *no package icon*"
820 echo "- Name : $PACKAGE_NAME"
821 echo "- Version : $PACKAGE_VERSION"
822 echo "- Release : $PACKAGE_RELEASE"
825 update_shell_title "parse_spec: OK!"
828 # aborts program abnormally
831 echo >&2 "$PROGRAM: ERROR: $*"
836 if [ -n "$DEBUG" ]; then
844 "err_no_spec_in_cmdl" )
845 remove_build_requires
846 echo >&2 "ERROR: spec file name not specified."
848 "err_invalid_cmdline" )
849 echo >&2 "ERROR: invalid command line arg ($2)."
851 "err_no_spec_in_repo" )
852 remove_build_requires
853 echo >&2 "Error: spec file not stored in repository."
859 "err_no_source_in_repo" )
860 remove_build_requires
861 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
863 "err_cvs_add_failed" )
864 echo >&2 "Error: failed to add package to PLD repo."
867 remove_build_requires
868 echo >&2 "Error: package build failed. (${2:-no more info})"
870 "err_no_package_data" )
871 remove_build_requires
872 echo >&2 "Error: couldn't get out package name/version/release from spec file."
875 remove_build_requires
876 echo >&2 "Tag ${2} already exists"
879 remove_build_requires
880 echo >&2 "Release ${2} not integer and not a snapshot."
882 "err_branch_exists" )
883 remove_build_requires
884 echo >&2 "Tree branch already exists (${2})."
887 remove_build_requires
888 echo >&2 "Error: conditions reject building this spec (${2})."
890 "err_remote_problem" )
891 remove_build_requires
892 echo >&2 "Error: problem with remote (${2})"
895 echo >&2 "Error: cannot checkout $2"
897 "err_not_implemented" )
898 remove_build_requires
899 echo >&2 "Error: functionality not yet imlemented"
902 echo >&2 "Unknown error."
907 if [ -n "$DEBUG" ]; then
912 if [ "$NOINIT" != "yes" ] ; then
913 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
915 local macros_ver=$(rpm -E %?rpm_build_macros)
916 if [ -z "$macros_ver" ]; then
917 REPO_DIR=$TOP_DIR/packages
918 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
920 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
921 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
925 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
930 REPO_DIR=$PACKAGE_DIR
931 RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
933 export GIT_WORK_TREE=$PACKAGE_DIR
934 export GIT_DIR=$PACKAGE_DIR/.git
936 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
937 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
938 CVSTAG=${CVSTAG#refs/heads/}
939 if [ "$CVSTAG" != "master" ]; then
940 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
943 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
946 elif [ "$CVSTAG" = "HEAD" ]; then
947 # assume -r HEAD is same as -A
955 update_shell_title "add_package"
957 if [ -n "$DEBUG" ]; then
963 SPECFILE=$(basename $SPECFILE)
964 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
965 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
968 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
969 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
973 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
974 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
976 git config --local push.default current
977 git config --local branch.master.remote $REMOTE_PLD
978 git config --local branch.master.merge refs/heads/master
980 test $? = 0 || Exit_error err_remote_problem $REMOTE_PLD
985 update_shell_title "get_spec"
987 if [ -n "$DEBUG" ]; then
993 SPECFILE=$(basename $SPECFILE)
994 if [ "$NOCVSSPEC" != "yes" ]; then
995 if [ -z "$DEPTH" ]; then
996 if [ -d "$PACKAGE_DIR/.git" ]; then
997 git fetch $IPOPT $REMOTE_PLD || Exit_error err_no_spec_in_repo
998 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
999 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
1000 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
1003 Exit_error err_not_implemented
1007 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
1008 # softfail if new package, i.e not yet added to PLD rep
1009 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
1010 echo "Warning: package not in Git - assuming new package"
1013 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1014 git config --local --add "remote.$REMOTE_PLD.push" 'refs/notes/*:refs/notes/*'
1015 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1016 git config --local push.default current
1017 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1021 if [ ! -d "$PACKAGE_DIR/.git" ]; then
1022 if [ ! -d "$PACKAGE_DIR" ]; then
1023 install -d $PACKAGE_DIR
1026 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
1027 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1028 git config --local --add "remote.$REMOTE_PLD.push" 'refs/heads/*:refs/remotes/origin/*'
1029 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1030 git config --local push.default current
1031 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
1032 CVSTAG=${CVSTAG:-"master"}
1035 if [ -z "$ALL_BRANCHES" ]; then
1036 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
1038 git fetch $IPOPT $DEPTH $REMOTE_PLD $refs || {
1039 echo >&2 "Error: branch $CVSTAG does not exist"
1043 git fetch $IPOPT $REMOTE_PLD 'refs/notes/*:refs/notes/*'
1045 cvsignore_df .gitignore
1047 # add default log format to .gitignore if it is relative to package dir
1048 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
1049 # substitute known "macros" to glob
1050 local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g')
1051 if [ "$logfile" ]; then
1052 cvsignore_df "$logfile"
1056 # create symlinks for tools
1057 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
1058 for a in dropin md5 builder {relup,compile,repackage,rsync,pearize}.sh; do
1059 # skip tools that don't exist in top dir
1060 [ -f $a ] || continue
1061 # skip tools that already exist
1062 [ -f $PACKAGE_DIR/$a ] && continue
1063 ln -s ../$a $PACKAGE_DIR
1069 if [ -n "$CVSTAG" ]; then
1070 if git rev-parse --verify -q "$CVSTAG" >/dev/null; then
1071 # checkout only if differs, so this will not trash git reflog
1072 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1073 git checkout "$CVSTAG" --
1075 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1076 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1078 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1079 Exit_error "err_no_checkut" "$CVSTAG"
1082 git merge --ff-only '@{u}'
1083 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1084 if [ -n "$CVSDATE" ]; then
1085 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1089 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1090 Exit_error err_no_spec_in_repo "$PACKAGE_DIR/$SPECFILE"
1093 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1094 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1097 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1102 # find mirrors in this order. first match wins:
1103 # - package dir (~/rpm/packages/foo)
1104 # - repository dir (~/rpm/packages)
1105 # - tools dir dir (~/rpm/packages/rpm-build-tools)
1109 update_shell_title "find_mirror[$url][$REPO_DIR]"
1111 # NOTE: as while loop runs in subshell,
1112 # we use exit 2 to indicate that the match was found
1113 # otherwise we end up outputing mirror url and origin url.
1115 local origin mirror name rest ol prefix
1117 cat "$PACKAGE_DIR/mirrors" "$REPO_DIR/mirrors" "$REPO_DIR/../rpm-build-tools/mirrors" /dev/null 2>/dev/null | \
1118 while read origin mirror name rest; do
1119 # skip comments and empty lines
1120 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1123 ol=$(echo -n "$origin" | wc -c)
1124 prefix=$(echo -n "$url" | head -c $ol)
1125 if [ "$prefix" = "$origin" ] ; then
1126 suffix=$(echo "$url" | cut -b $((ol+1))-)
1127 echo -n "$mirror$suffix"
1133 # Warning: unpredictable results if same URL used twice
1136 # escape some regexp characters if part of file name
1137 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1140 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1141 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1142 head -n 1 | tr OURCEATH ourceath | xargs
1146 [ "$NO5" = "yes" ] && return
1148 [ -z "$no" ] && return
1152 # use "sources" file from package dir, like vim
1153 if [ -f sources ]; then
1154 md5=$(grep -s -v '^#' sources | \
1155 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1156 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1157 grep -E '^[0-9a-f]{32}$')
1160 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1161 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1163 echo "$md5" | tail -n 1
1168 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1169 if [ -n "$source_md5" ]; then
1172 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1173 if [ -n "$source_md5" ]; then
1176 # we have empty SourceX-md5, but it is still possible
1177 # that we have NoSourceX-md5 AND NoSource: X
1178 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1179 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1187 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1191 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1194 distfiles_attic_url() {
1195 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
1200 [ "$md5" = "" ] || \
1201 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1205 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1206 [ -n "$size" -a "$size" -gt 0 ]
1210 if [ "$CVSIGNORE_DF" != "yes" ]; then
1213 local cvsignore=${PACKAGE_DIR}/.git/info/exclude
1215 # add only if not yet there
1216 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1217 echo "$1" >> $cvsignore
1221 # returns true if "$1" is ftp, http or https protocol url
1224 ftp://*|http://*|https://*)
1232 if [ $# -eq 0 ]; then
1236 update_shell_title "update md5"
1237 if [ -n "$DEBUG" ]; then
1244 # pass 1: check files to be fetched
1248 local fp=$(nourl "$i")
1249 local srcno=$(src_no "$i")
1250 if [ -n "$ADD5" ]; then
1251 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1252 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1253 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1255 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1257 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1258 need_files="$need_files $i"
1262 # pass 1a: get needed files
1263 if [ "$need_files" ]; then
1264 get_files $need_files
1267 # pass 2: proceed with md5 adding or updating
1269 local fp=$(nourl "$i")
1270 local srcno=$(src_no "$i")
1271 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1272 if [ -z "$md5" ]; then
1273 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1275 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1276 local tag="# $srcno-md5:\t"
1277 if [[ "$md5" == *NoSource* ]]; then
1278 tag="# No$srcno-md5:\t"
1279 elif [ -n "$USEDIGEST" ]; then
1280 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1282 md5=$(md5sum "$fp" | cut -f1 -d' ')
1283 echo "Updating $srcno ($md5: $fp)."
1285 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1286 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1288 $PACKAGE_DIR/$SPECFILE
1295 [ "$NO5" = "yes" ] && return
1297 update_shell_title "check md5"
1301 if ! good_md5 "$i"; then
1302 echo -n "MD5 sum mismatch."
1305 if ! good_size "$i"; then
1306 echo -n "0 sized file."
1310 if [ $bad -eq 1 ]; then
1311 echo " Use -U to refetch sources,"
1312 echo "or -5 to update md5 sums, if you're sure files are correct."
1313 Exit_error err_no_source_in_repo $i
1319 update_shell_title "get_files"
1321 if [ -n "$DEBUG" ]; then
1326 if [ $# -gt 0 ]; then
1330 local get_files_cvs=""
1334 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1335 update_shell_title "$i"
1336 local fp=`nourl "$i"`
1337 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1342 local srcmd5=$(src_md5 "$i")
1344 # we know if source/patch is present in cvs/distfiles
1345 # - has md5 (in distfiles)
1346 # - in cvs... ideas?
1348 # CHECK: local file didn't exist or always cvs up (first) requested.
1349 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1350 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1351 echo "Warning: no URL given for $i"
1355 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1356 if good_md5 "$i" && good_size "$i"; then
1357 echo "$fp having proper md5sum already exists"
1361 # optionally prefer mirror over distfiles if there's mirror
1362 # TODO: build url list and then try each url from the list
1363 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1366 url=$(distfiles_url "$i")
1369 url_attic=$(distfiles_attic_url "$i")
1371 # is $url local file?
1372 if [[ "$url" = [./]* ]]; then
1373 update_shell_title "${GETLOCAL%% *}: $url"
1374 ${GETLOCAL} $url $target
1377 # make shorter message for distfiles urls
1378 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1379 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1380 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1383 update_shell_title "${GETURI%% *}: $uri"
1384 ${GETURI} "$target" "$url"
1388 if [ ! -s "$target" ]; then
1390 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1391 update_shell_title "${GETLOCAL%% *}: $url_attic"
1392 ${GETLOCAL} $url_attic $target
1394 update_shell_title "${GETURI%% *}: $url_attic"
1395 ${GETURI} "$target" "$url_attic"
1396 test -s "$target" || rm -f "$target"
1400 if [ -s "$target" ]; then
1401 cvsignore_df $target
1408 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1409 if [ -z "$NOMIRRORS" ]; then
1410 im=$(find_mirror "$i")
1414 update_shell_title "${GETURI%% *}: $im"
1415 ${GETURI} "$target" "$im"
1416 test -s "$target" || rm -f "$target"
1419 if [ "$cvsup" = 1 ]; then
1425 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1426 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1427 Exit_error err_no_source_in_repo $i
1430 # we check md5 here just only to refetch immediately
1431 if good_md5 "$i" && good_size "$i"; then
1433 elif [ "$FROM_DISTFILES" = 1 ]; then
1434 # wrong md5 from distfiles: remove the file and try again
1436 echo "MD5 sum mismatch. Trying full fetch."
1439 update_shell_title "${GETURI%% *}: $url"
1440 ${GETURI} "$target" "$url"
1441 if [ ! -s "$target" ]; then
1443 update_shell_title "${GETURI%% *}: $url_attic"
1444 ${GETURI} "$target" "$url_attic"
1446 test -s "$target" || rm -f "$target"
1449 SHELL_TITLE_PREFIX=""
1452 if [ "$CHMOD" = "yes" ]; then
1453 CHMOD_FILES=$(nourl "$@")
1454 if [ -n "$CHMOD_FILES" ]; then
1455 chmod $CHMOD_MODE $CHMOD_FILES
1462 # If tag exists and points to other commit exit with error
1463 # If it existsts and points to HEAD return 1
1464 # If it doesn't exist return 0
1466 local sha1=$(git rev-parse HEAD)
1467 echo "Searching for tag $_tag..."
1468 if [ -n "$DEPTH" ]; then
1469 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1471 local ref=$(git show-ref -s "refs/tags/$_tag")
1473 [ -z "$ref" ] && return 0
1474 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1479 if [ -n "$DEBUG" ]; then
1484 # Check whether first character of PACKAGE_NAME is legal for tag name
1485 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1489 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1490 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1492 # Remove @kernel.version_release from TAGVER because tagging sources
1493 # could occur with different kernel-headers than kernel-headers used at build time.
1494 # besides, %{_kernel_ver_str} is not expanded.
1496 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1497 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1504 if [ -n "$DEBUG" ]; then
1509 echo "Version: $PACKAGE_VERSION"
1510 echo "Release: $PACKAGE_RELEASE"
1513 if [ "$TAG_VERSION" = "yes" ]; then
1516 if [ -n "$TAG" ]; then
1521 local OPTIONS="tag $CVS_FORCE"
1525 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1526 update_shell_title "tag sources: $_tag"
1527 git $OPTIONS $_tag || exit
1528 git push $IPOPT $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1530 echo "Tag $_tag already exists and points to the same commit"
1536 echo "Git branch: $TAG"
1539 if [ -n "$DEBUG" ]; then
1544 local OPTIONS="branch $CVS_FORCE"
1547 git $OPTIONS $TAG || exit
1551 # this function should exit early if package can't be built for this arch
1552 # this avoids unneccessary BR filling.
1555 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1557 if [ $ret -ne 0 ]; then
1569 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1570 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1576 local ver="$2" subver=$ver
1577 local newver="$3" newsubver=$newver
1579 # try handling subver, everything that's not numeric-dotted in version
1580 if grep -Eq '%define\s+subver' $specfile; then
1581 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1583 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1584 newver=${newver%$newsubver}
1587 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1588 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1589 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1593 # try to upgrade .spec to new version
1594 # if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1596 # return 1: if .spec was updated
1597 # return 0: no changes to .spec
1598 # exit 1 in case of error
1600 if [ -z "$TRY_UPGRADE" ]; then
1604 local TNOTIFY TNEWVER TOLDVER
1605 update_shell_title "build_package: try_upgrade"
1609 if [ "$UPGRADE_VERSION" ]; then
1610 TNEWVER=$UPGRADE_VERSION
1611 echo "Updating spec file to version $TNEWVER"
1613 if [ -n "$FLOAT_VERSION" ]; then
1614 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1616 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1619 # pldnotify does not set exit codes, but it has match for ERROR
1620 # in output which means so.
1621 if [[ "$TNOTIFY" = *ERROR* ]]; then
1626 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1627 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1629 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1632 if [ -z "$TNEWVER" ]; then
1636 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1637 cp -f $SPECFILE $SPECFILE.bak
1640 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1641 set_release $SPECFILE $PACKAGE_RELEASE 1
1643 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1644 echo >&2 "Upgrading version failed, you need to update spec yourself"
1651 update_shell_title "build_package"
1652 if [ -n "$DEBUG" ]; then
1661 BUILD_SWITCH="-ba" ;;
1663 BUILD_SWITCH="-bb" ;;
1665 BUILD_SWITCH="-bs --nodeps" ;;
1667 BUILD_SWITCH="-bp --nodeps" ;;
1669 BUILD_SWITCH="-bc" ;;
1671 BUILD_SWITCH="-bi" ;;
1673 BUILD_SWITCH="-bl" ;;
1677 update_shell_title "build_package: $COMMAND"
1678 local logfile retval
1679 if [ -n "$LOGFILE" ]; then
1680 logfile=`eval echo $LOGFILE`
1681 if [ -d "$logfile" ]; then
1682 echo "Log file $logfile is a directory."
1683 echo "Parse error in the spec?"
1684 Exit_error err_build_fail
1686 if [ -n "$LASTLOG_FILE" ]; then
1687 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1691 # unset these, should not be exposed to builder shell!
1692 unset GIT_WORK_TREE GIT_DIR
1693 # these are set by jenkins
1694 unset GIT_PREVIOUS_COMMIT GIT_URL GIT_PREVIOUS_SUCCESSFUL_COMMIT GIT_BRANCH GIT_COMMIT
1695 # this may be set by user
1697 # may be set by user
1698 unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_TESTING_PORCELAIN_COMMAND_LIST
1699 # fail if something still set
1700 env | grep ^GIT_ && Exit_error err_build_fail
1702 local specdir=$(insert_gitlog $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 $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE
1709 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1710 if [ "$retval" -eq "0" ]; then
1711 mv $logfile $LOGDIROK
1713 mv $logfile $LOGDIRFAIL
1717 if [ "$retval" -ne "0" ]; then
1718 if [ -n "$TRY_UPGRADE" ]; then
1719 echo "\nUpgrade package to new version failed."
1720 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1721 echo "Restoring old spec file."
1722 mv -f $SPECFILE.bak $SPECFILE
1726 Exit_error err_build_fail
1732 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1735 install_required_packages() {
1740 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1743 /^%changelog/ { exit }
1745 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1746 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1747 gsub(/[ \t]+/, "_", bcond);
1749 }' $SPEC | LC_ALL=C sort -u
1753 # expand bconds from ~/.bcondrc
1754 # The file structure is like gentoo's package.use:
1757 # samba -mysql -pgsql
1758 # w32codec-installer license_agreement
1761 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1767 SN=${SPECFILE%%\.spec}
1769 local bcondrc=$HOME/.bcondrc
1770 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1772 local bcond_avail=$(find_spec_bcond $SPECFILE)
1774 while read pkg flags; do
1776 [[ "$pkg" == \#* ]] && continue
1778 # any package or current package?
1779 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1780 for flag in $flags; do
1781 local opt=${flag#[+-]}
1783 # use only flags which are in this package.
1784 if [[ $bcond_avail = *${opt}* ]]; then
1785 if [[ $flag = -* ]]; then
1786 if [[ $BCOND != *--with?${opt}* ]]; then
1787 BCOND="$BCOND --without $opt"
1790 if [[ $BCOND != *--without?${opt}* ]]; then
1791 BCOND="$BCOND --with $opt"
1798 update_shell_title "parse ~/.bcondrc: DONE!"
1801 set_bconds_values() {
1802 update_shell_title "set bcond values"
1804 AVAIL_BCONDS_WITHOUT=""
1805 AVAIL_BCONDS_WITH=""
1807 if grep -Eq '^# *_with' ${SPECFILE}; then
1808 echo >&2 "ERROR: This spec has old style bconds."
1812 if ! grep -q '^%bcond' ${SPECFILE}; then
1816 local bcond_avail=$(find_spec_bcond $SPECFILE)
1817 process_bcondrc "$SPECFILE"
1819 update_shell_title "parse bconds"
1822 for opt in $bcond_avail; do
1825 bcond=${opt#without_}
1827 *--without?${bcond}*)
1828 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1831 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1839 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1842 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1847 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1856 update_shell_title "run_sub_builder $package_name"
1858 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1859 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
1860 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1861 # jakby nie bylo tego kawalka kodu.
1863 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1864 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
1868 # kurwa. translate that ^^^^
1872 # Istnieje taki spec? ${package}.spec
1873 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1874 parent_spec_name=${package}.spec
1875 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1876 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1878 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1883 if [ "${parent_spec_name}" != "" ]; then
1884 spawn_sub_builder $parent_spec_name
1886 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1889 # install package with poldek
1890 # @return exit code from poldek
1892 # this requires following sudo rules:
1893 # - poldek --noask --caplookup -ug
1895 LANG=C $POLDEK_CMD --noask --caplookup --uniq -ug "$@"
1900 # this requires following sudo rules:
1901 # - poldek -q --update --upa
1902 install_packages() {
1903 # sync poldek indexes once per invocation
1904 if [ -z "$package_indexes_updated" ]; then
1905 update_shell_title "poldek: update indexes"
1906 $POLDEK_CMD -q --update --upa --mo=nodesc
1907 package_indexes_updated=true
1910 update_shell_title "install packages: $*"
1911 poldek_install "$@" && return
1913 # retry install, install packages one by one
1914 # this is slower one
1916 for package in $*; do
1917 package=$(depspecname $package)
1918 update_shell_title "install package: $package"
1919 poldek_install "$package" || rc=$?
1924 uninstall_packages() {
1925 update_shell_title "uninstall packages: $*"
1926 $POLDEK_CMD --noask --nofollow -ev "$@"
1929 spawn_sub_builder() {
1931 update_shell_title "spawn_sub_builder $package_name"
1934 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1935 sub_builder_opts="${sub_builder_opts} -R"
1937 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1938 sub_builder_opts="${sub_builder_opts} -RB"
1939 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1940 sub_builder_opts="${sub_builder_opts} -FRB"
1942 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1943 sub_builder_opts="${sub_builder_opts} -Upi"
1947 ./builder ${sub_builder_opts} "$@"
1950 remove_build_requires() {
1951 if [ "$INSTALLED_PACKAGES" != "" ]; then
1952 case "$REMOVE_BUILD_REQUIRES" in
1954 run_poldek --noask -ve $INSTALLED_PACKAGES
1957 run_poldek --ask -ve $INSTALLED_PACKAGES
1960 echo You may want to manually remove following BuildRequires fetched:
1961 echo $INSTALLED_PACKAGES
1962 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1969 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1970 if [ "$BCOND" ]; then
1972 echo "Building $SPECFILE with the following conditional flags:"
1976 echo "No conditional flags passed"
1979 echo "from available:"
1980 echo "--with :\t$AVAIL_BCONDS_WITH"
1981 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1986 display_branches() {
1987 echo -n "Available branches: "
1988 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1991 # checks a given list of packages/files/provides against current rpmdb.
1992 # outputs all dependencies which current rpmdb doesn't satisfy.
1993 # input can be either STDIN or parameters
1997 if [ $# -gt 0 ]; then
2003 out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1)
2006 echo "$out" | awk '/^no package provides/ { print $NF }'
2008 # other deps (files)
2009 echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p'
2012 # checks if given package/files/provides exists in rpmdb.
2013 # input can be either stdin or parameters
2014 # returns packages which are present in the rpmdb
2018 if [ $# -gt 0 ]; then
2024 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
2027 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
2028 install_build_requires_rpmdeps() {
2030 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
2031 # TODO: Conflicts list doesn't check versions
2032 CNFL=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
2033 DEPS=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
2035 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2036 CNFL=$(eval rpm -q --specsrpm --conflicts $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
2037 DEPS=$(eval rpm -q --specsrpm --requires $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
2040 if [ -n "$CNFL" ]; then
2041 echo "Uninstall conflicting packages: $CNFL"
2042 uninstall_packages $CNFL
2045 if [ -n "$DEPS" ]; then
2046 echo "Install dependencies: $DEPS"
2047 install_packages $DEPS
2051 fetch_build_requires()
2053 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
2057 update_shell_title "fetch build requires"
2058 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2059 install_build_requires_rpmdeps
2063 die "need rpm-getdeps tool"
2070 if [ ! -e $localrepo ]; then
2071 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
2072 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2077 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2078 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2079 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2080 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2081 local TEMPLATES=template-specs
2084 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2085 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2088 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2089 init_repository projects/$TEMPLATES ../$TEMPLATES
2090 for a in builder fetchsrc_request compile repackage; do
2091 ln -sf ../rpm-build-tools/${a}.sh $a
2094 ln -sf ../rpm-build-tools/${a} $a
2096 ln -sf ../rpm-build-tools/mirrors mirrors
2103 DONT_PRINT_REVISION="yes"
2105 # remove spec and sources
2106 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
2107 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2108 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2111 #---------------------------------------------
2119 # stuff global $BUILDER_OPTS from env as args
2120 if [ "$BUILDER_OPTS" ]; then
2121 set -- "$BUILDER_OPTS" "$@"
2124 while [ $# -gt 0 ]; do
2131 COMMAND="update_md5"
2136 COMMAND="update_md5"
2145 DEBUG="yes"; shift ;;
2147 COMMAND="version"; shift ;;
2149 COMMAND="short-version"; shift ;;
2156 -b | -ba | --build )
2157 COMMAND="build"; shift ;;
2158 -bb | --build-binary )
2159 COMMAND="build-binary"; shift ;;
2161 COMMAND="build-build"; shift ;;
2163 COMMAND="build-install"; shift ;;
2165 COMMAND="build-list"; shift ;;
2166 -bp | --build-prep )
2167 COMMAND="build-prep"; shift ;;
2168 -bs | --build-source )
2169 COMMAND="build-source"; shift ;;
2171 COMMAND="branch"; shift; TAG="${1}"; shift;;
2173 CLEAN="--clean"; shift ;;
2175 CVS_FORCE="-f"; shift;;
2181 COMMAND="get"; shift ;;
2183 COMMAND="usage"; shift ;;
2185 PROTOCOL="ftp"; shift ;;
2187 PROTOCOL="http"; shift ;;
2189 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2193 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2197 PARALLEL_DOWNLOADS=$2
2201 PARALLEL_DOWNLOADS=${1#-p}
2205 shift; LOGFILE="${1}"; shift ;;
2207 shift; DEF_NICE_LEVEL=${1}; shift ;;
2208 -ske | --skip-existing-files)
2209 SKIP_EXISTING_FILES="yes"; shift ;;
2211 COMMAND="mr-proper"; shift ;;
2212 -ncs | --no-cvs-specs )
2213 NOCVSSPEC="yes"; shift ;;
2214 -nd | --no-distfiles )
2215 NODIST="yes"; shift ;;
2216 -nm | --no-mirrors )
2217 NOMIRRORS="yes"; shift ;;
2219 NOURLS="yes"; shift ;;
2221 NOSRCS="yes"; shift ;;
2222 -ns0 | --no-source0 )
2223 NOSOURCE0="yes"; shift ;;
2232 -pm | --prefer-mirrors )
2235 --noinit | --no-init )
2239 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2241 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2242 --skip-patch | -sp )
2243 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2245 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2248 --with | --without )
2249 case $GROUP_BCONDS in
2253 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2254 while ! `echo ${1}|grep -qE '(^-|spec)'`
2256 BCOND="$BCOND $COND $1"
2260 if [[ "$2" = *,* ]]; then
2261 for a in $(echo "$2" | tr , ' '); do
2262 BCOND="$BCOND $1 $a"
2265 BCOND="$BCOND $1 $2"
2271 shift; TARGET="${1}"; shift ;;
2273 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2275 QUIET="--quiet"; shift ;;
2277 CVSDATE="${2}"; shift 2
2278 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2288 -R | --fetch-build-requires)
2289 FETCH_BUILD_REQUIRES="yes"
2290 NOT_INSTALLED_PACKAGES=
2292 -RB | --remove-build-requires)
2293 REMOVE_BUILD_REQUIRES="nice"
2295 -FRB | --force-remove-build-requires)
2296 REMOVE_BUILD_REQUIRES="force"
2299 COMMAND="list-sources-cvs"
2301 -sd | --source-distfiles)
2302 COMMAND="list-sources-distfiles"
2304 -sdp | --source-distfiles-paths)
2305 COMMAND="list-sources-distfiles-paths"
2307 -sf | --source-files)
2308 COMMAND="list-sources-files"
2310 -lsp | --source-paths)
2311 COMMAND="list-sources-local-paths"
2313 -su | --source-urls)
2314 COMMAND="list-sources-urls"
2316 -Tvs | --tag-version-stable )
2321 -Ts | --tag-stable )
2326 -Tv | --tag-version )
2331 -Tp | --tag-prefix )
2343 -ir | --integer-release-only )
2344 INTEGER_RELEASE="yes"
2347 COMMAND="update_md5"
2352 -Upi | --update-poldek-indexes )
2353 UPDATE_POLDEK_INDEXES="yes"
2355 --init-rpm-dir|--init)
2356 COMMAND="init_rpm_dir"
2358 -u | --try-upgrade )
2359 TRY_UPGRADE="1"; shift ;;
2361 shift; UPGRADE_VERSION="$1"; shift;;
2362 -un | --try-upgrade-with-float-version )
2363 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2365 BE_VERBOSE="1"; shift ;;
2370 if echo "${MACRO}" | grep -q '\W'; then
2371 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2375 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2380 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\""
2384 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2387 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2388 COMMAND="show_bconds"
2392 COMMAND="show_bcond_args"
2395 --show-avail-bconds)
2396 COMMAND="show_avail_bconds"
2401 RPMOPTS="${RPMOPTS} --nodeps"
2404 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2407 Exit_error err_invalid_cmdline "$1"
2410 SPECFILE=${1%/}; shift
2411 # check if specname was passed as specname:cvstag
2412 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2413 CVSTAG="${SPECFILE##*:}"
2414 SPECFILE="${SPECFILE%%:*}"
2416 # always have SPECFILE ending with .spec extension
2417 SPECFILE=${SPECFILE%%.spec}.spec
2418 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2422 if [ "$CVSTAG" ]; then
2423 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2424 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2427 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2428 echo >&2 "--all branches requires --depth <number>"
2429 Exit_error err_invalid_cmdline
2432 if [ -n "$DEBUG" ]; then
2437 if [ -n "$TARGET" ]; then
2440 TARGET_SWITCH="--target $TARGET" ;;
2442 TARGET_SWITCH="--target=$TARGET" ;;
2446 if [ "$SCHEDTOOL" != "no" ]; then
2447 NICE_COMMAND="$SCHEDTOOL"
2449 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2452 # see time(1) for output format that could be used
2453 TIME_COMMAND="time -p"
2455 update_shell_title "$COMMAND"
2459 if [ -z "$SPECFILE" ]; then
2460 Exit_error err_no_spec_in_cmdl
2462 get_spec > /dev/null
2469 if [ -z "$SPECFILE" ]; then
2470 Exit_error err_no_spec_in_cmdl
2472 get_spec > /dev/null
2477 "show_avail_bconds")
2479 if [ -z "$SPECFILE" ]; then
2480 Exit_error err_no_spec_in_cmdl
2483 get_spec > /dev/null
2485 local bcond_avail=$(find_spec_bcond $SPECFILE)
2486 local opt bcond bconds
2487 for opt in $bcond_avail; do
2490 bcond=${opt#without_}
2491 bconds="$bconds $bcond"
2495 bconds="$bconds $bcond"
2498 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2506 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2508 if [ -z "$SPECFILE" ]; then
2509 Exit_error err_no_spec_in_cmdl
2512 # display SMP make flags if set
2513 smp_mflags=$(rpm -E %{?_smp_mflags})
2514 if [ "$smp_mflags" ]; then
2515 echo "builder: SMP make flags are set to $smp_mflags"
2523 if [ "$COMMAND" != "build-source" ]; then
2526 fetch_build_requires
2527 if [ "$INTEGER_RELEASE" = "yes" ]; then
2528 echo "Checking release $PACKAGE_RELEASE..."
2529 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2530 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2534 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2535 if [ -n "$TEST_TAG" ]; then
2536 local TAGVER=`make_tagver`
2537 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2538 # check also tags created in CVS
2539 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2540 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2541 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2542 || Exit_error err_tag_exists $TAGVER_CVS
2543 # - do not allow to build from HEAD when XX-branch exists
2544 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2545 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2546 TAG_BRANCH="${TREE_PREFIX}-branch"
2547 if [ -n "$DEPTH" ]; then
2548 cmd_branches="git ls-remote --heads"
2549 ref_prefix=refs/heads
2551 cmd_branches="git show-ref"
2552 ref_prefix=refs/remotes/${REMOTE_PLD}
2554 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2555 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2556 Exit_error err_branch_exists "$TAG_STATUS"
2562 if [ -n "$NOSOURCE0" ] ; then
2563 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2568 get_files $SOURCES $PATCHES
2569 check_md5 $SOURCES $PATCHES
2572 NODIST="yes" get_files $SOURCES $PATCHES
2573 update_md5 $SOURCES $PATCHES
2577 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2578 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2580 remove_build_requires
2584 if [ -z "$SPECFILE" ]; then
2585 Exit_error err_no_spec_in_cmdl
2594 if [ -z "$SPECFILE" ]; then
2595 Exit_error err_no_spec_in_cmdl
2599 if [ -n "$NEW_REPO" ]; then
2602 for file in $SOURCES $PATCHES; do
2603 if [ -z $(src_md5 "$file") ]; then
2604 git add $file || Exit_error err_no_source_in_repo $file
2606 cvsignore_df `nourl $file`
2610 echo "When you are ready commit your changes and run git push origin master"
2612 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2617 if [ -z "$SPECFILE" ]; then
2618 Exit_error err_no_spec_in_cmdl
2624 if [ -n "$NOSOURCE0" ] ; then
2625 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2627 get_files $SOURCES $PATCHES
2629 fetch_build_requires
2633 if [ -z "$SPECFILE" ]; then
2634 Exit_error err_no_spec_in_cmdl
2640 if [ -n "$NOSOURCE0" ] ; then
2641 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2643 update_md5 $SOURCES $PATCHES
2649 if [ -z "$SPECFILE" ]; then
2650 Exit_error err_no_spec_in_cmdl
2654 if [ ! -d .git ]; then
2655 echo "No git reposiotory" >&2
2663 "list-sources-files" )
2666 DONT_PRINT_REVISION="yes"
2669 for SAP in $SOURCES $PATCHES; do
2670 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2673 "list-sources-urls" )
2676 DONT_PRINT_REVISION="yes"
2679 SAPS="$SOURCES $PATCHES"
2680 for SAP in $SAPS; do
2684 "list-sources-local-paths" )
2687 DONT_PRINT_REVISION="yes"
2690 for SAP in $SOURCES $PATCHES; do
2691 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2694 "list-sources-distfiles-paths" )
2697 DONT_PRINT_REVISION="yes"
2700 for SAP in $SOURCES $PATCHES; do
2701 if [ -n "$(src_md5 "$SAP")" ]; then
2702 distfiles_path "$SAP"
2706 "list-sources-distfiles" )
2709 DONT_PRINT_REVISION="yes"
2712 for SAP in $SOURCES $PATCHES; do
2713 if [ -n "$(src_md5 "$SAP")" ]; then
2714 distfiles_url "$SAP"
2718 "list-sources-cvs" )
2721 DONT_PRINT_REVISION="yes"
2724 for SAP in $SOURCES $PATCHES; do
2725 if [ -z "$(src_md5 "$SAP")" ]; then
2726 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2740 echo "$VERSIONSTRING"
2743 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2744 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2748 # vi:syntax=sh:ts=4:sw=4:noet