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")
38 RCSID='$Id: builder,v 1.645 2011/02/13 17:54:10 glen Exp $' r=${RCSID#* * } rev=${r%% *}
41 Build package utility from PLD Linux Packages repository
42 $VERSION (C) 1999-2013 Free Penguins".
44 CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
46 # required rpm-build-macros
65 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
67 # use rpm 4.4.6+ digest format instead of comments if non-zero
70 # user agent when fetching files
71 USER_AGENT="PLD/Builder($VERSION)"
73 # It can be used i.e. in log file naming.
74 # See LOGFILE example.
75 DATE=`date +%Y-%m-%d_%H-%M-%S`
77 # target arch, can also be used for log file naming
78 TARGET=$(rpm -E %{_target})
80 # 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 # Yes, you can use variable name! Note _single_ quotes!
87 # use teeboth Perl wrapper
88 # temporary option to disable if broken
103 # create symlinks for tools in PACKAGE_DIR, see get_spec()
115 # use lftp by default when available
117 lftp --version > /dev/null 2>&1 && USE_LFTP=yes
118 PARALLEL_DOWNLOADS=10
120 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
125 GIT_SERVER="git://git.pld-linux.org"
126 GIT_PUSH="git@git.pld-linux.org"
127 PACKAGES_DIR="packages"
136 DISTFILES_SERVER="://distfiles.pld-linux.org"
137 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
142 FAIL_IF_NO_SOURCES="yes"
144 # let get_files skip over files which are present to get those damn files fetched
145 SKIP_EXISTING_FILES="no"
148 # should the specfile be restored if upgrade failed?
149 REVERT_BROKEN_UPGRADE="yes"
151 if rpm --specsrpm 2>/dev/null; then
152 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
153 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
155 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
156 if [ -x /usr/bin/rpm-getdeps ]; then
157 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
159 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
163 UPDATE_POLDEK_INDEXES_OPTS=""
165 # Here we load saved user environment used to
166 # predefine options set above, or passed to builder
168 # This one reads global system environment settings:
169 if [ -f ~/etc/builderrc ]; then
172 # And this one cascades settings using user personal
174 # Example of ~/.builderrc:
176 #UPDATE_POLDEK_INDEXES="yes"
177 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
178 #FETCH_BUILD_REQUIRES="yes"
179 #REMOVE_BUILD_REQUIRES="force"
181 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
185 if [ -n "$HOME_ETC" ]; then
186 USER_CFG="$HOME_ETC/.builderrc"
187 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
189 USER_CFG=~/.builderrc
190 BUILDER_MACROS=~/.builder-rpmmacros
193 [ -f "$USER_CFG" ] && . "$USER_CFG"
195 if [ "$SCHEDTOOL" = "auto" ]; then
196 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
197 SCHEDTOOL="schedtool -B -e"
203 if [ -n "$USE_PROZILLA" ]; then
204 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
207 elif [ -n "$USE_AXEL" ]; then
208 GETURI="axel -a $AXEL_OPTS"
211 elif [ -n "$USE_LFTP" ]; then
216 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
217 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
218 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
219 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
221 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
222 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
228 if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
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 --noask"
251 if [ -n "$LOGFILE" ]; then
252 LOG=`eval echo $LOGFILE`
253 if [ -n "$LASTLOG_FILE" ]; then
254 echo "LASTLOG=$LOG" > $LASTLOG_FILE
256 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
257 # FIXME $exit_pldk undefined
260 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
261 return `cat ${RES_FILE}`
266 #---------------------------------------------
270 local outfile=$1 url=$2 retval tmpfile
274 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
275 set ssl:verify-certificate no;
276 set net:max-retries $WGET_RETRIES;
277 set http:user-agent \"$USER_AGENT\";
278 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
282 if [ $retval -eq 0 ]; then
283 mv -f "$tmpfile" "$outfile"
291 if [ -n "$DEBUG" ]; then set -xv; fi
293 # to make this output parseable by bash-completion _parse_help()
294 # if the line contains short and long option, it will take only the long option
295 # but if you want both being completed, put the short option to separate line
297 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
298 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
299 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
300 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
301 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
302 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
303 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
304 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
305 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
306 <package>[.spec][:tag]
308 -4 - force IPv4 when transferring files
309 -6 - force IPv6 when transferring files
311 --update-md5 - update md5 comments in spec, implies -nd -ncs
313 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
314 --all-branches - make shallow fetch of all branches; --depth required
315 -n5, --no-md5 - ignore md5 comments in spec
316 -D, --debug - enable builder script debugging mode,
317 -debug - produce rpm debug package (same as --opts -debug)
318 -V, --version - output builder version string
319 --short-version - output builder short version
320 -a - try add new package to PLD repo.
323 - get all files from PLD repo or HTTP/FTP and build package
325 -bb - get all files from PLD repo or HTTP/FTP and build binary
326 only package from <package>.spec,
327 -bp - execute the %prep phase of <package>.spec,
328 -bc - execute the %build phase of <package>.spec,
329 -bi - execute the %install phase of <package>.spec
330 -bl - execute the %files phase of <package>.spec
331 -bs - get all files from PLD repo or HTTP/FTP and only pack
333 --short-circuit - short-circuit build
334 -B, --branch - add branch
336 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
337 may be used with building process.
338 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
339 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
340 -cf, --cvs-force - use -f when tagging
341 --define '<macro> <value>'
342 - define a macro <macro> with value <value>,
343 --depth <number> - make shallow fetch
344 --alt_kernel <kernel>
345 - same as --define 'alt_kernel <kernel>'
346 --nodeps - rpm won't check any dependences
348 --get - get <package>.spec and all related files from PLD repo
349 -h, --help - this message,
350 -j N - set %_smp_mflags to propagate concurrent jobs
351 --ftp - use FTP protocol to access distfiles server
352 --http - use HTTP protocol to access distfiles server
353 -l <logfile>, --logtofile=<logfile>
356 - don't pull from PLD repo
357 -nd, --no-distfiles - don't download from distfiles
358 -nm, --no-mirrors - don't download from mirror, if source URL is given,
359 -nu, --no-urls - don't try to download from FTP/HTTP location,
360 -ns, --no-srcs - don't download Sources/Patches
361 -ns0, --no-source0 - don't download Source0
362 -nn, --no-net - don't download anything from the net
363 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
364 -pm, --prefer-mirrors
365 - prefer mirrors (if any) over distfiles for SOURCES
366 --no-init - don't initialize builder paths (SPECS and SOURCES)
368 --skip-existing-files
369 - skip existing files in get_files
370 --opts <rpm opts> - additional options for rpm
371 -q, --quiet - be quiet,
372 --date yyyy-mm-dd - build package using resources from specified date,
373 -r <tag>, --cvstag <ref>
374 - build package using resources from specified branch/tag,
375 -A - build package using master branch as any sticky tags/branch/date being reset.
376 -R, --fetch-build-requires
377 - fetch what is BuildRequired,
378 -RB, --remove-build-requires
379 - remove all you fetched with -R or --fetch-build-requires
380 remember, this option requires confirmation,
381 -FRB, --force-remove-build-requires
382 - remove all you fetched with -R or --fetch-build-requires
383 remember, this option works without confirmation,
384 -sd, --source-distfiles
385 - list sources available from distfiles (intended for offline
386 operations; does not work when Icon field is present
387 but icon file is absent),
388 -sc, --source-cvs - list sources available from PLD repo
389 -sdp, --source-distfiles-paths
390 - list sources available from distfiles -
391 paths relative to distfiles directory (intended for offline
392 operations; does not work when Icon field is present
393 but icon file is absent),
394 -sf, --source-files - list sources - bare filenames (intended for offline
395 operations; does not work when Icon field is present
396 but icon file is absent),
398 - list sources - filenames with full local paths (intended for
399 offline operations; does not work when Icon field is present
400 but icon file is absent),
401 -su, --source-urls - list urls - urls to sources and patches
402 intended for copying urls with spec with lots of macros in urls
403 -T <tag> , --tag <tag>
404 - add git tag <tag> for files,
405 -Tvs, --tag-version-stable
406 - add git tags STABLE and NAME-VERSION-RELEASE for files,
408 - add git tag STABLE for files,
410 --tag-version - add git tag NAME-VERSION-RELEASE for files,
411 -Tp, --tag-prefix <prefix>
412 - add <prefix> to NAME-VERSION-RELEASE tags,
413 -tt, --test-tag <prefix>
414 - fail if tag is already present,
415 -ir, --integer-release-only
416 - allow only integer and snapshot releases
417 -v, --verbose - be verbose,
418 -u, --try-upgrade - check version, and try to upgrade package
419 -un, --try-upgrade-with-float-version
420 - as above, but allow float version
421 php-pear-Services_Digg/
422 --upgrade-version - upgrade to specified version in try-upgrade
423 -U, --update - refetch sources, don't use distfiles, and update md5 comments
424 -Upi, --update-poldek-indexes
425 - refresh or make poldek package index files.
427 --skip-patch <patchnumber>
428 - don't apply <patchnumber>. may be repeated.
430 --nopatch <patchnumber>
431 - abort instead of applying patch <patchnumber>
433 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
434 --show-bconds - show available conditional builds, which can be used
435 - with --with and/or --without switches.
436 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
437 In other words, the output is parseable by scripts.
438 --show-avail-bconds - show available bconds
441 - conditional build package depending on %_with_<feature>/
442 %_without_<feature> macro switch. You may now use
443 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
444 constructions. Set GROUP_BCONDS to yes to make use of it.
445 --target <platform>, --target=<platform>
446 - build for platform <platform>.
447 --init-rpm-dir - initialize ~/rpm directory structure
451 # create tempfile. as secure as possible
453 mktemp --tmpdir -t builder.$PACKAGE_NAME.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
457 mktemp --tmpdir -d builder.$PACKAGE_NAME.XXXXXX
460 # inserts git log instead of %changelog
461 # outputs name of modified file created by tempfile
463 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
465 # allow this being customized
466 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
468 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
469 # otherwise i'd use --date=iso here
470 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
471 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
472 # NOTE: changelog date is always in UTC for rpmbuild
473 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
474 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
476 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
477 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
480 # add link to full git logs
481 local giturl="http://git.pld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
482 if [ -n "$CVSTAG" ]; then
483 giturl="$giturl;h=$CVSTAG"
485 local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
486 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
487 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
492 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
493 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
497 " > $specdir/$SPECFILE
498 rm -f $gitlog $speclog
502 # @param string logfile
503 # @param varargs... commands to execute
506 # use teeboth from toys/cleanbuild, if available and enabled
507 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
511 local efile rc logfile=$1; shift
512 if [ "$logfile" ]; then
514 { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile
525 # change dependency to specname
527 # - perl(Package::Name) -> perl-Package-Name
531 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
535 update_shell_title() {
537 local len=${COLUMNS:-80}
538 local msg="$(echo "$*" | cut -c-$len)"
540 if [ -n "$BE_VERBOSE" ]; then
541 echo >&2 "$(date +%s.%N) $*"
544 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
546 if [ -n "$PACKAGE_NAME" ]; then
547 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
552 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
553 msg=$(echo $msg | tr -d '\n\r')
556 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
559 echo >&2 -ne "\033]0;$msg\007"
565 # set TARGET from BuildArch: from SPECFILE
567 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
568 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
570 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
574 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
576 TARGET_SWITCH="--target=$TARGET" ;;
582 # runs rpm with minimal macroset
584 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
586 # TODO: move these to /usr/lib/rpm/macros
587 cat > $BUILDER_MACROS <<'EOF'
588 %x8664 x86_64 amd64 ia32e
591 %bootstrap_release() %{1}
592 %requires_releq_kernel_up(s:n:) %{nil}
593 %requires_releq_kernel_smp(s:n:) %{nil}
594 %requires_releq_kernel(s:n:) %{nil}
595 %requires_releq() %{nil}
596 %pyrequires_eq() %{nil}
597 %requires_eq() %{nil}
598 %requires_eq_to() %{nil}
599 %requires_ge() %{nil}
600 %requires_ge_to() %{nil}
601 %requires_ge() %{nil}
602 %releq_kernel_up(n:) ERROR
603 %releq_kernel_smp(n:) ERROR
604 %releq_kernel(n:) ERROR
605 %py_postclean(x:) ERROR
609 %ruby_ver_requires_eq() %{nil}
610 %ruby_mod_ver_requires_eq() %{nil}
611 %__php_api_requires() %{nil}
612 %php_major_version ERROR
613 %php_api_version ERROR
614 %requires_xorg_xserver_extension %{nil}
615 %requires_xorg_xserver_xinput %{nil}
616 %requires_xorg_xserver_font %{nil}
617 %requires_xorg_xserver_videodrv %{nil}
619 %perl_vendorarch ERROR
620 %perl_vendorlib ERROR
621 # damn. need it here! - copied from /usr/lib/rpm/macros.build
622 %tmpdir %(echo "${TMPDIR:-/tmp}")
623 %patchset_source(f:b:) %(
624 base=%{-b*}%{!-b*:10000};
625 start=$(expr $base + %1);
626 end=$(expr $base + %{?2}%{!?2:%{1}});
627 # we need to call seq twice as it doesn't allow two formats
628 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
629 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
630 paste %{tmpdir}/__ps{1,2};
631 rm -f %{tmpdir}/__ps{1,2};
634 %add_etc_shells(p) %{p:<lua>}
635 %remove_etc_shells(p) %{p:<lua>}
636 %lua_add_etc_shells() %{nil}
637 %lua_remove_etc_shells() %{nil}
639 %buildrequires_jdk %{nil}
640 %pear_package_print_optionalpackages %{nil}
642 if [ "$NOINIT" = "yes" ] ; then
643 cat >> $BUILDER_MACROS <<'EOF'
648 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
652 if [ -n "$DEBUG" ]; then
657 if [ -x /usr/bin/rpm-specdump ]; then
658 update_shell_title "cache_rpm_dump using rpm-specdump command"
659 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
661 update_shell_title "cache_rpm_dump using rpmbuild command"
664 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
665 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
671 ARGS='--nodigest --nosignature --nobuild'
674 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
676 if [ $? -gt 0 ]; then
677 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
679 Exit_error err_build_fail
682 # make small dump cache
683 rpm_dump_cache=`echo "$rpm_dump" | awk '
684 $2 ~ /^SOURCEURL/ {print}
685 $2 ~ /^PATCHURL/ {print}
686 $2 ~ /^nosource/ {print}
687 $2 ~ /^PACKAGE_/ {print}
691 update_shell_title "cache_rpm_dump: OK!"
695 if [ -z "$rpm_dump_cache" ] ; then
696 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
698 echo "$rpm_dump_cache"
702 update_shell_title "get icons"
703 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
704 if [ -z "$ICONS" ]; then
708 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
712 update_shell_title "parsing specfile"
713 if [ -n "$DEBUG" ]; then
718 # icons are needed for successful spec parse
724 if rpm_dump | grep -qEi ":.*nosource.*1"; then
725 FAIL_IF_NO_SOURCES="no"
728 if [ "$NOSRCS" != "yes" ]; then
729 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
730 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
731 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
734 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
735 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
736 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
738 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
739 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
742 if [ -n "$BE_VERBOSE" ]; then
743 echo "- Sources : `nourl $SOURCES`"
744 if [ -n "$PATCHES" ]; then
745 echo "- Patches : `nourl $PATCHES`"
747 echo "- Patches : *no patches needed*"
749 if [ -n "$ICONS" ]; then
750 echo "- Icon : `nourl $ICONS`"
752 echo "- Icon : *no package icon*"
754 echo "- Name : $PACKAGE_NAME"
755 echo "- Version : $PACKAGE_VERSION"
756 echo "- Release : $PACKAGE_RELEASE"
759 update_shell_title "parse_spec: OK!"
763 if [ -n "$DEBUG" ]; then
771 "err_no_spec_in_cmdl" )
772 remove_build_requires
773 echo >&2 "ERROR: spec file name not specified."
775 "err_invalid_cmdline" )
776 echo >&2 "ERROR: invalid command line arg ($2)."
778 "err_no_spec_in_repo" )
779 remove_build_requires
780 echo >&2 "Error: spec file not stored in PLD repo."
782 "err_no_source_in_repo" )
783 remove_build_requires
784 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
786 "err_cvs_add_failed" )
787 echo >&2 "Error: failed to add package to PLD repo."
790 remove_build_requires
791 echo >&2 "Error: package build failed. (${2:-no more info})"
793 "err_no_package_data" )
794 remove_build_requires
795 echo >&2 "Error: couldn't get out package name/version/release from spec file."
798 remove_build_requires
799 echo >&2 "Tag ${2} already exists"
802 remove_build_requires
803 echo >&2 "Release ${2} not integer and not a snapshot."
805 "err_branch_exists" )
806 remove_build_requires
807 echo >&2 "Tree branch already exists (${2})."
810 remove_build_requires
811 echo >&2 "Error: conditions reject building this spec (${2})."
813 "err_remote_problem" )
814 remove_build_requires
815 echo >&2 "Error: problem with remote (${2})"
818 echo >&2 "Error: cannot checkout $2"
820 "err_not_implemented" )
821 remove_build_requires
822 echo >&2 "Error: functionality not yet imlemented"
825 echo >&2 "Unknown error."
830 if [ -n "$DEBUG" ]; then
835 if [ "$NOINIT" != "yes" ] ; then
836 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
838 local macros_ver=$(rpm -E %?rpm_build_macros)
839 if [ -z "$macros_ver" ]; then
840 REPO_DIR=$TOP_DIR/packages
841 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
843 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
844 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
848 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
853 REPO_DIR=$PACKAGE_DIR
854 RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
856 export GIT_WORK_TREE=$PACKAGE_DIR
857 export GIT_DIR=$PACKAGE_DIR/.git
859 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
860 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
861 CVSTAG=${CVSTAG#refs/heads/}
862 if [ "$CVSTAG" != "master" ]; then
863 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
866 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
869 elif [ "$CVSTAG" = "HEAD" ]; then
870 # assume -r HEAD is same as -A
878 update_shell_title "add_package"
880 if [ -n "$DEBUG" ]; then
886 SPECFILE=$(basename $SPECFILE)
887 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
888 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
891 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
892 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
894 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git && \
895 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} \
896 || Exit_error err_remote_problem $REMOTE_PLD
901 update_shell_title "get_spec"
903 if [ -n "$DEBUG" ]; then
909 SPECFILE=$(basename $SPECFILE)
910 if [ "$NOCVSSPEC" != "yes" ]; then
911 if [ -z "$DEPTH" ]; then
912 if [ -d "$PACKAGE_DIR/.git" ]; then
913 git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
914 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
915 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
916 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
919 Exit_error err_not_implemented
923 git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
924 # softfail if new package, i.e not yet added to PLD rep
925 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
926 echo "Warning: package not in CVS - assuming new package"
929 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
930 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
934 if [ ! -d "$PACKAGE_DIR/.git" ]; then
935 if [ ! -d "$PACKAGE_DIR" ]; then
936 install -d $PACKAGE_DIR
939 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
940 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
941 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
942 CVSTAG=${CVSTAG:-"master"}
945 if [ -z "$ALL_BRANCHES" ]; then
946 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
948 git fetch $DEPTH $REMOTE_PLD $refs || {
949 echo >&2 "Error: branch $CVSTAG does not exist"
953 git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*'
955 cvsignore_df .gitignore
957 # add default log format to .gitignore if it is relative to package dir
958 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
959 # substitute known "macros" to glob
960 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\|TARGET\),*,g')
961 if [ "$logfile" ]; then
962 cvsignore_df "$logfile"
966 # create symlinks for tools
967 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
968 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
969 # skip tools that don't exist in top dir
970 [ -f $a ] || continue
971 # skip tools that already exist
972 [ -f $PACKAGE_DIR/$a ] && continue
973 ln -s ../$a $PACKAGE_DIR
979 if [ -n "$CVSTAG" ]; then
980 if git rev-parse --verify -q "$CVSTAG"; then
981 git checkout "$CVSTAG" --
982 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
983 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
985 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
986 Exit_error "err_no_checkut" "$CVSTAG"
988 git merge --ff-only '@{u}'
989 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
990 if [ -n "$CVSDATE" ]; then
991 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
995 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
996 Exit_error err_no_spec_in_repo
999 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1000 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1003 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1011 if [ ! -f "mirrors" ] ; then
1012 ln -s ../rpm-build-tools/mirrors .
1016 local origin mirror name rest ol prefix
1017 while read origin mirror name rest; do
1018 # skip comments and empty lines
1019 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1022 ol=$(echo -n "$origin" | wc -c)
1023 prefix=$(echo -n "$url" | head -c $ol)
1024 if [ "$prefix" = "$origin" ] ; then
1025 suffix=$(echo "$url" | cut -b $((ol+1))-)
1026 echo -n "$mirror$suffix"
1033 # Warning: unpredictable results if same URL used twice
1036 # escape some regexp characters if part of file name
1037 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1040 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1041 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1042 head -n 1 | tr OURCEATH ourceath | xargs
1046 [ "$NO5" = "yes" ] && return
1048 [ -z "$no" ] && return
1052 # use "sources" file from package dir, like vim
1053 if [ -f sources ]; then
1054 md5=$(grep -s -v '^#' sources | \
1055 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1056 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1057 grep -E '^[0-9a-f]{32}$')
1060 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1061 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1063 echo "$md5" | tail -n 1
1068 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1069 if [ -n "$source_md5" ]; then
1072 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1073 if [ -n "$source_md5" ]; then
1076 # we have empty SourceX-md5, but it is still possible
1077 # that we have NoSourceX-md5 AND NoSource: X
1078 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1079 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1087 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1091 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1094 distfiles_attic_url() {
1095 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
1100 [ "$md5" = "" ] || \
1101 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1105 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1106 [ -n "$size" -a "$size" -gt 0 ]
1110 if [ "$CVSIGNORE_DF" != "yes" ]; then
1113 cvsignore=${PACKAGE_DIR}/.gitignore
1115 # add only if not yet there
1116 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1117 echo "$1" >> $cvsignore
1121 # returns true if "$1" is ftp, http or https protocol url
1124 ftp://*|http://*|https://*)
1132 if [ $# -eq 0 ]; then
1136 update_shell_title "update md5"
1137 if [ -n "$DEBUG" ]; then
1144 # pass 1: check files to be fetched
1148 local fp=$(nourl "$i")
1149 local srcno=$(src_no "$i")
1150 if [ -n "$ADD5" ]; then
1151 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1152 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1153 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1155 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1157 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1158 need_files="$need_files $i"
1162 # pass 1a: get needed files
1163 if [ "$need_files" ]; then
1164 get_files $need_files
1167 # pass 2: proceed with md5 adding or updating
1169 local fp=$(nourl "$i")
1170 local srcno=$(src_no "$i")
1171 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1172 if [ -z "$md5" ]; then
1173 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1175 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1176 local tag="# $srcno-md5:\t"
1177 if [[ "$md5" == *NoSource* ]]; then
1178 tag="# No$srcno-md5:\t"
1179 elif [ -n "$USEDIGEST" ]; then
1180 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1182 md5=$(md5sum "$fp" | cut -f1 -d' ')
1183 echo "Updating $srcno ($md5: $fp)."
1185 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1186 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1188 $PACKAGE_DIR/$SPECFILE
1195 [ "$NO5" = "yes" ] && return
1197 update_shell_title "check md5"
1201 if ! good_md5 "$i"; then
1202 echo -n "MD5 sum mismatch."
1205 if ! good_size "$i"; then
1206 echo -n "0 sized file."
1210 if [ $bad -eq 1 ]; then
1211 echo " Use -U to refetch sources,"
1212 echo "or -5 to update md5 sums, if you're sure files are correct."
1213 Exit_error err_no_source_in_repo $i
1219 update_shell_title "get_files"
1221 if [ -n "$DEBUG" ]; then
1226 if [ $# -gt 0 ]; then
1230 local get_files_cvs=""
1234 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1235 update_shell_title "$i"
1236 local fp=`nourl "$i"`
1237 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1242 local srcmd5=$(src_md5 "$i")
1244 # we know if source/patch is present in cvs/distfiles
1245 # - has md5 (in distfiles)
1246 # - in cvs... ideas?
1248 # CHECK: local file didn't exist or always cvs up (first) requested.
1249 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1250 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1251 echo "Warning: no URL given for $i"
1255 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1256 if good_md5 "$i" && good_size "$i"; then
1257 echo "$fp having proper md5sum already exists"
1261 # optionally prefer mirror over distfiles if there's mirror
1262 # TODO: build url list and then try each url from the list
1263 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1266 url=$(distfiles_url "$i")
1269 url_attic=$(distfiles_attic_url "$i")
1271 # is $url local file?
1272 if [[ "$url" = [./]* ]]; then
1273 update_shell_title "${GETLOCAL%% *}: $url"
1274 ${GETLOCAL} $url $target
1277 # make shorter message for distfiles urls
1278 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1279 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1280 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1283 update_shell_title "${GETURI%% *}: $uri"
1284 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1285 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1286 update_shell_title "${GETURI2%% *}: $url"
1287 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1292 if [ ! -s "$target" ]; then
1294 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1295 update_shell_title "${GETLOCAL%% *}: $url_attic"
1296 ${GETLOCAL} $url_attic $target
1298 update_shell_title "${GETURI%% *}: $url_attic"
1299 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1300 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1301 update_shell_title "${GETURI2%% *}: $url_attic"
1302 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1304 test -s "$target" || rm -f "$target"
1308 if [ -s "$target" ]; then
1309 cvsignore_df $target
1316 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1317 if [ -z "$NOMIRRORS" ]; then
1318 im=$(find_mirror "$i")
1322 update_shell_title "${GETURI%% *}: $im"
1323 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1324 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1325 update_shell_title "${GETURI2%% *}: $im"
1326 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1328 test -s "$target" || rm -f "$target"
1331 if [ "$cvsup" = 1 ]; then
1337 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1338 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1339 Exit_error err_no_source_in_repo $i
1342 # we check md5 here just only to refetch immediately
1343 if good_md5 "$i" && good_size "$i"; then
1345 elif [ "$FROM_DISTFILES" = 1 ]; then
1346 # wrong md5 from distfiles: remove the file and try again
1348 echo "MD5 sum mismatch. Trying full fetch."
1351 update_shell_title "${GETURI%% *}: $url"
1352 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1353 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1354 update_shell_title "${GETURI2%% *}: $url"
1355 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1357 if [ ! -s "$target" ]; then
1359 update_shell_title "${GETURI%% *}: $url_attic"
1360 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1361 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1362 update_shell_title "${GETURI2%% *}: $url_attic"
1363 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1366 test -s "$target" || rm -f "$target"
1369 SHELL_TITLE_PREFIX=""
1372 if [ "$CHMOD" = "yes" ]; then
1373 CHMOD_FILES=$(nourl "$@")
1374 if [ -n "$CHMOD_FILES" ]; then
1375 chmod $CHMOD_MODE $CHMOD_FILES
1382 # If tag exists and points to other commit exit with error
1383 # If it existsts and points to HEAD return 1
1384 # If it doesn't exist return 0
1386 local sha1=$(git rev-parse HEAD)
1387 echo "Searching for tag $_tag..."
1388 if [ -n "$DEPTH" ]; then
1389 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1391 local ref=$(git show-ref -s "refs/tags/$_tag")
1393 [ -z "$ref" ] && return 0
1394 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1399 if [ -n "$DEBUG" ]; then
1404 # Check whether first character of PACKAGE_NAME is legal for tag name
1405 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1409 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1410 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1412 # Remove @kernel.version_release from TAGVER because tagging sources
1413 # could occur with different kernel-headers than kernel-headers used at build time.
1414 # besides, %{_kernel_ver_str} is not expanded.
1416 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1417 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1424 if [ -n "$DEBUG" ]; then
1429 echo "Version: $PACKAGE_VERSION"
1430 echo "Release: $PACKAGE_RELEASE"
1433 if [ "$TAG_VERSION" = "yes" ]; then
1436 if [ -n "$TAG" ]; then
1441 local OPTIONS="tag $CVS_FORCE"
1445 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1446 update_shell_title "tag sources: $_tag"
1447 git $OPTIONS $_tag || exit
1448 git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1450 echo "Tag $_tag already exists and points to the same commit"
1456 echo "Git branch: $TAG"
1459 if [ -n "$DEBUG" ]; then
1464 local OPTIONS="branch $CVS_FORCE"
1467 git $OPTIONS $TAG || exit
1471 # this function should exit early if package can't be built for this arch
1472 # this avoids unneccessary BR filling.
1475 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1477 if [ $ret -ne 0 ]; then
1489 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1490 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1496 local ver="$2" subver=$ver
1497 local newver="$3" newsubver=$newver
1499 # try handling subver, everything that's not numeric-dotted in version
1500 if grep -Eq '%define\s+subver' $specfile; then
1501 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1503 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1504 newver=${newver%$newsubver}
1507 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1508 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1509 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1513 # try to upgrade .spec to new version
1514 # if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1516 # return 1: if .spec was updated
1517 # return 0: no changes to .spec
1518 # exit 1 in case of error
1520 if [ -z "$TRY_UPGRADE" ]; then
1524 local TNOTIFY TNEWVER TOLDVER
1525 update_shell_title "build_package: try_upgrade"
1529 if [ "$UPGRADE_VERSION" ]; then
1530 TNEWVER=$UPGRADE_VERSION
1531 echo "Updating spec file to version $TNEWVER"
1533 if [ -n "$FLOAT_VERSION" ]; then
1534 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1536 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1539 # pldnotify.awk does not set exit codes, but it has match for ERROR
1540 # in output which means so.
1541 if [[ "$TNOTIFY" = *ERROR* ]]; then
1546 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1547 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1549 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1552 if [ -z "$TNEWVER" ]; then
1556 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1557 cp -f $SPECFILE $SPECFILE.bak
1560 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1561 set_release $SPECFILE $PACKAGE_RELEASE 1
1563 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1564 echo >&2 "Upgrading version failed, you need to update spec yourself"
1571 update_shell_title "build_package"
1572 if [ -n "$DEBUG" ]; then
1581 BUILD_SWITCH="-ba" ;;
1583 BUILD_SWITCH="-bb" ;;
1585 BUILD_SWITCH="-bs --nodeps" ;;
1587 BUILD_SWITCH="-bp --nodeps" ;;
1589 BUILD_SWITCH="-bc" ;;
1591 BUILD_SWITCH="-bi" ;;
1593 BUILD_SWITCH="-bl" ;;
1597 update_shell_title "build_package: $COMMAND"
1598 local logfile retval
1599 if [ -n "$LOGFILE" ]; then
1600 logfile=`eval echo $LOGFILE`
1601 if [ -d "$logfile" ]; then
1602 echo "Log file $logfile is a directory."
1603 echo "Parse error in the spec?"
1604 Exit_error err_build_fail
1606 if [ -n "$LASTLOG_FILE" ]; then
1607 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1611 local specdir=$(insert_gitlog $SPECFILE)
1612 # FIXME: eval here is exactly why?
1613 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
1617 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1618 if [ "$retval" -eq "0" ]; then
1619 mv $logfile $LOGDIROK
1621 mv $logfile $LOGDIRFAIL
1625 if [ "$retval" -ne "0" ]; then
1626 if [ -n "$TRY_UPGRADE" ]; then
1627 echo "\nUpgrade package to new version failed."
1628 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1629 echo "Restoring old spec file."
1630 mv -f $SPECFILE.bak $SPECFILE
1634 Exit_error err_build_fail
1640 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1643 install_required_packages() {
1648 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1651 /^%changelog/ { exit }
1653 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1654 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1655 gsub(/[ \t]+/, "_", bcond);
1657 }' $SPEC | LC_ALL=C sort -u
1661 # expand bconds from ~/.bcondrc
1662 # The file structure is like gentoo's package.use:
1665 # samba -mysql -pgsql
1666 # w32codec-installer license_agreement
1669 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1675 SN=${SPECFILE%%\.spec}
1677 local bcondrc=$HOME/.bcondrc
1678 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1680 local bcond_avail=$(find_spec_bcond $SPECFILE)
1682 while read pkg flags; do
1684 [[ "$pkg" == \#* ]] && continue
1686 # any package or current package?
1687 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1688 for flag in $flags; do
1689 local opt=${flag#[+-]}
1691 # use only flags which are in this package.
1692 if [[ $bcond_avail = *${opt}* ]]; then
1693 if [[ $flag = -* ]]; then
1694 if [[ $BCOND != *--with?${opt}* ]]; then
1695 BCOND="$BCOND --without $opt"
1698 if [[ $BCOND != *--without?${opt}* ]]; then
1699 BCOND="$BCOND --with $opt"
1706 update_shell_title "parse ~/.bcondrc: DONE!"
1709 set_bconds_values() {
1710 update_shell_title "set bcond values"
1712 AVAIL_BCONDS_WITHOUT=""
1713 AVAIL_BCONDS_WITH=""
1715 if grep -Eq '^# *_with' ${SPECFILE}; then
1716 echo >&2 "ERROR: This spec has old style bconds."
1720 if ! grep -q '^%bcond' ${SPECFILE}; then
1724 local bcond_avail=$(find_spec_bcond $SPECFILE)
1725 process_bcondrc "$SPECFILE"
1727 update_shell_title "parse bconds"
1730 for opt in $bcond_avail; do
1733 bcond=${opt#without_}
1735 *--without?${bcond}*)
1736 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1739 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1747 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1750 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1755 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1764 update_shell_title "run_sub_builder $package_name"
1766 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1767 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
1768 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1769 # jakby nie bylo tego kawalka kodu.
1771 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1772 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
1776 # kurwa. translate that ^^^^
1780 # Istnieje taki spec? ${package}.spec
1781 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1782 parent_spec_name=${package}.spec
1783 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1784 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1786 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1791 if [ "${parent_spec_name}" != "" ]; then
1792 spawn_sub_builder $parent_spec_name
1794 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1797 spawn_sub_builder() {
1799 update_shell_title "spawn_sub_builder $package_name"
1802 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1803 sub_builder_opts="${sub_builder_opts} -R"
1805 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1806 sub_builder_opts="${sub_builder_opts} -RB"
1807 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1808 sub_builder_opts="${sub_builder_opts} -FRB"
1810 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1811 sub_builder_opts="${sub_builder_opts} -Upi"
1815 ./builder ${sub_builder_opts} "$@"
1818 remove_build_requires() {
1819 if [ "$INSTALLED_PACKAGES" != "" ]; then
1820 case "$REMOVE_BUILD_REQUIRES" in
1822 run_poldek --noask -ve $INSTALLED_PACKAGES
1825 run_poldek --ask -ve $INSTALLED_PACKAGES
1828 echo You may want to manually remove following BuildRequires fetched:
1829 echo $INSTALLED_PACKAGES
1830 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1837 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1838 if [ "$BCOND" ]; then
1840 echo "Building $SPECFILE with the following conditional flags:"
1844 echo "No conditional flags passed"
1847 echo "from available:"
1848 echo "--with :\t$AVAIL_BCONDS_WITH"
1849 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1854 display_branches() {
1855 echo -n "Available branches: "
1856 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1859 # checks a given list of packages/files/provides agains current rpmdb.
1860 # outputs all dependencies which current rpmdb doesn't satisfy.
1861 # input can be either STDIN or parameters
1865 if [ $# -gt 0 ]; then
1871 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1874 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1876 # other deps (files)
1877 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1880 # checks if given package/files/provides exists in rpmdb.
1881 # input can be either stdin or parameters
1882 # returns packages which are present in the rpmdb
1886 if [ $# -gt 0 ]; then
1892 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1895 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1896 install_build_requires_rpmdeps() {
1897 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1898 # TODO: Conflicts list doesn't check versions
1899 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1900 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1902 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1903 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1904 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1907 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1908 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1909 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1910 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1912 if [ -n "$CNFL" ]; then
1913 update_shell_title "uninstall conflicting packages: $CNFL"
1914 echo "Trying to uninstall conflicting packages ($CNFL):"
1915 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1918 while [ "$DEPS" ]; do
1919 update_shell_title "install deps: $DEPS"
1920 echo "Trying to install dependencies ($DEPS):"
1921 local log=.${SPECFILE}_poldek.log
1922 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1923 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1926 if [ -n "$failed" ]; then
1927 for package in $failed; do
1928 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1937 fetch_build_requires()
1939 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1943 update_shell_title "fetch build requires"
1944 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1945 install_build_requires_rpmdeps
1949 # XXX is this ugliest code written in human history still needed?
1950 echo "All packages installed by fetch_build_requires() are written to:"
1951 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1953 echo "If anything fails, you may get rid of them by executing:"
1954 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
1956 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1957 for package_item in $(cat $SPECFILE | grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'|sed -e s,perl\(,perl-,g -e s,::,-,g -e s,\(.*\),,g -e s,%{,,g -e s,},,g|grep -v OpenGL-devel|sed -e s,sh-utils,coreutils,g -e s,fileutils,coreutils,g -e s,textutils,coreutils,g -e s,kgcc_package,gcc,g -e s,\),,g)
1959 package_item=$(echo $package_item|sed -e s,rpmbuild,rpm-build,g |sed -e s,__perl,perl,g |sed -e s,gasp,binutils-gasp,g -e s,binutils-binutils,binutils,g -e s,apxs,apache,g|sed -e s,apache\(EAPI\)-devel,apache-devel,g -e s,kernel-headers\(netfilter\),kernel-headers,g -e s,awk,mawk,g -e s,mmawk,mawk,g -e s,motif,openmotif,g -e s,openopenmotif,openmotif,g)
1961 package=$(basename "$package_item"|sed -e "s/}$//g")
1962 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
1965 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1966 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1967 if [ "$COND_ARCH_TST" != "" ] && [ "`echo $COND_ARCH_TST|sed -e "s/i.86/ix86/g"`" != "`echo $mach|sed -e "s/i.86/ix86/g"`" ]; then
1972 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1975 if `echo $COND_TST|grep -q 'without_'`; then
1976 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1977 if `echo $COND_TST|grep -q !`; then
1982 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1983 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1984 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1990 elif `echo $COND_TST|grep -q 'with_'`; then
1991 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1992 if `echo $COND_TST|grep -q !`; then
1997 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1998 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1999 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
2005 RESULT="${COND_STATE}-${COND_ARGV}"
2007 "with-wout" | "wout-with" )
2010 "wout-wout" | "with-with" )
2014 echo "Action '$RESULT' was not defined for package '$package_item'"
2020 if [ "$GO" = "yes" ]; then
2021 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
2022 echo "Testing if $package has subrequirements..."
2023 run_poldek -t -i $package --dumpn=".$package-req.txt"
2024 if [ -f ".$package-req.txt" ]; then
2025 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2027 if [ "$package_name" = "$package" ]; then
2028 echo "Installing BuildRequired package:\t$package_name"
2029 update_shell_title "Installing BuildRequired package: ${package_name}"
2030 install_required_packages $package
2032 echo "Installing (sub)Required package:\t$package_name"
2033 update_shell_title "Installing (sub)Required package: ${package_name}"
2034 install_required_packages $package_name
2038 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2039 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2042 echo "Attempting to run spawn sub - builder..."
2043 echo "Package installation failed:\t$package_name"
2044 run_sub_builder $package_name
2045 if [ $? -eq 0 ]; then
2046 install_required_packages $package_name
2049 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2050 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2053 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2060 rm -f ".$package-req.txt"
2062 echo "Attempting to run spawn sub - builder..."
2063 echo "Package installation failed:\t$package"
2064 run_sub_builder $package
2065 if [ $? -eq 0 ]; then
2066 install_required_packages $package
2069 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2070 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2073 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2079 echo "Package $package is already installed. BuildRequirement satisfied."
2083 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2084 echo >&2 "Unable to install following packages and their dependencies:"
2085 for pkg in "$NOT_INSTALLED_PACKAGES"
2089 remove_build_requires
2098 if [ ! -e $localrepo ]; then
2099 git clone -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
2100 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2105 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2106 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2107 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2108 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2109 local TEMPLATES=template-specs
2112 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2113 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2116 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2117 init_repository projects/$TEMPLATES ../$TEMPLATES
2118 for a in adapter builder fetchsrc_request compile repackage; do
2119 ln -sf ../rpm-build-tools/${a}.sh $a
2122 ln -sf ../rpm-build-tools/${a} $a
2124 ln -sf ../rpm-build-tools/mirrors mirrors
2131 DONT_PRINT_REVISION="yes"
2133 # remove spec and sources
2134 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
2135 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2136 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2139 #---------------------------------------------
2147 while [ $# -gt 0 ]; do
2150 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2151 # unfortunately $GETURI is already formed
2156 COMMAND="update_md5"
2161 COMMAND="update_md5"
2170 DEBUG="yes"; shift ;;
2172 COMMAND="version"; shift ;;
2174 COMMAND="short-version"; shift ;;
2181 -b | -ba | --build )
2182 COMMAND="build"; shift ;;
2183 -bb | --build-binary )
2184 COMMAND="build-binary"; shift ;;
2186 COMMAND="build-build"; shift ;;
2188 COMMAND="build-install"; shift ;;
2190 COMMAND="build-list"; shift ;;
2191 -bp | --build-prep )
2192 COMMAND="build-prep"; shift ;;
2193 -bs | --build-source )
2194 COMMAND="build-source"; shift ;;
2196 COMMAND="branch"; shift; TAG="${1}"; shift;;
2198 CLEAN="--clean"; shift ;;
2200 CVS_FORCE="-f"; shift;;
2206 COMMAND="get"; shift ;;
2208 COMMAND="usage"; shift ;;
2210 PROTOCOL="ftp"; shift ;;
2212 PROTOCOL="http"; shift ;;
2214 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2218 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2222 PARALLEL_DOWNLOADS=$2
2226 PARALLEL_DOWNLOADS=${1#-p}
2230 shift; LOGFILE="${1}"; shift ;;
2232 shift; DEF_NICE_LEVEL=${1}; shift ;;
2233 -ske | --skip-existing-files)
2234 SKIP_EXISTING_FILES="yes"; shift ;;
2236 COMMAND="mr-proper"; shift ;;
2237 -ncs | --no-cvs-specs )
2238 NOCVSSPEC="yes"; shift ;;
2239 -nd | --no-distfiles )
2240 NODIST="yes"; shift ;;
2241 -nm | --no-mirrors )
2242 NOMIRRORS="yes"; shift ;;
2244 NOURLS="yes"; shift ;;
2246 NOSRCS="yes"; shift ;;
2247 -ns0 | --no-source0 )
2248 NOSOURCE0="yes"; shift ;;
2257 -pm | --prefer-mirrors )
2260 --noinit | --no-init )
2264 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2266 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2267 --skip-patch | -sp )
2268 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2270 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2273 --with | --without )
2274 case $GROUP_BCONDS in
2278 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2279 while ! `echo ${1}|grep -qE '(^-|spec)'`
2281 BCOND="$BCOND $COND $1"
2285 if [[ "$2" = *,* ]]; then
2286 for a in $(echo "$2" | tr , ' '); do
2287 BCOND="$BCOND $1 $a"
2290 BCOND="$BCOND $1 $2"
2296 shift; TARGET="${1}"; shift ;;
2298 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2300 QUIET="--quiet"; shift ;;
2302 CVSDATE="${2}"; shift 2
2303 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2313 -R | --fetch-build-requires)
2314 FETCH_BUILD_REQUIRES="yes"
2315 NOT_INSTALLED_PACKAGES=
2317 -RB | --remove-build-requires)
2318 REMOVE_BUILD_REQUIRES="nice"
2320 -FRB | --force-remove-build-requires)
2321 REMOVE_BUILD_REQUIRES="force"
2324 COMMAND="list-sources-cvs"
2326 -sd | --source-distfiles)
2327 COMMAND="list-sources-distfiles"
2329 -sdp | --source-distfiles-paths)
2330 COMMAND="list-sources-distfiles-paths"
2332 -sf | --source-files)
2333 COMMAND="list-sources-files"
2335 -lsp | --source-paths)
2336 COMMAND="list-sources-local-paths"
2338 -su | --source-urls)
2339 COMMAND="list-sources-urls"
2341 -Tvs | --tag-version-stable )
2346 -Ts | --tag-stable )
2351 -Tv | --tag-version )
2356 -Tp | --tag-prefix )
2368 -ir | --integer-release-only )
2369 INTEGER_RELEASE="yes"
2372 COMMAND="update_md5"
2377 -Upi | --update-poldek-indexes )
2378 UPDATE_POLDEK_INDEXES="yes"
2381 COMMAND="init_rpm_dir"
2383 -u | --try-upgrade )
2384 TRY_UPGRADE="1"; shift ;;
2386 shift; UPGRADE_VERSION="$1"; shift;;
2387 -un | --try-upgrade-with-float-version )
2388 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2390 BE_VERBOSE="1"; shift ;;
2395 if echo "${MACRO}" | grep -q '\W'; then
2396 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2400 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2405 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2409 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2412 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2413 COMMAND="show_bconds"
2417 COMMAND="show_bcond_args"
2420 --show-avail-bconds)
2421 COMMAND="show_avail_bconds"
2426 RPMOPTS="${RPMOPTS} --nodeps"
2429 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2432 Exit_error err_invalid_cmdline "$1"
2435 SPECFILE=${1%/}; shift
2436 # check if specname was passed as specname:cvstag
2437 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2438 CVSTAG="${SPECFILE##*:}"
2439 SPECFILE="${SPECFILE%%:*}"
2441 # always have SPECFILE ending with .spec extension
2442 SPECFILE=${SPECFILE%%.spec}.spec
2443 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2447 if [ "$CVSTAG" ]; then
2448 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2449 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2452 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2453 echo >&2 "--all branches requires --depth <number>"
2454 Exit_error err_invalid_cmdline
2457 if [ -n "$DEBUG" ]; then
2462 if [ -n "$TARGET" ]; then
2465 TARGET_SWITCH="--target $TARGET" ;;
2467 TARGET_SWITCH="--target=$TARGET" ;;
2471 if [ "$SCHEDTOOL" != "no" ]; then
2472 NICE_COMMAND="$SCHEDTOOL"
2474 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2477 # see time(1) for output format that could be used
2478 TIME_COMMAND="time -p"
2480 update_shell_title "$COMMAND"
2484 if [ -z "$SPECFILE" ]; then
2485 Exit_error err_no_spec_in_cmdl
2487 get_spec > /dev/null
2494 if [ -z "$SPECFILE" ]; then
2495 Exit_error err_no_spec_in_cmdl
2497 get_spec > /dev/null
2502 "show_avail_bconds")
2504 if [ -z "$SPECFILE" ]; then
2505 Exit_error err_no_spec_in_cmdl
2508 get_spec > /dev/null
2510 local bcond_avail=$(find_spec_bcond $SPECFILE)
2511 local opt bcond bconds
2512 for opt in $bcond_avail; do
2515 bcond=${opt#without_}
2516 bconds="$bconds $bcond"
2520 bconds="$bconds $bcond"
2523 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2531 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2533 if [ -z "$SPECFILE" ]; then
2534 Exit_error err_no_spec_in_cmdl
2537 # display SMP make flags if set
2538 smp_mflags=$(rpm -E %{?_smp_mflags})
2539 if [ "$smp_mflags" ]; then
2540 echo "builder: SMP make flags are set to $smp_mflags"
2548 if [ "$COMMAND" != "build-source" ]; then
2551 fetch_build_requires
2552 if [ "$INTEGER_RELEASE" = "yes" ]; then
2553 echo "Checking release $PACKAGE_RELEASE..."
2554 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2555 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2559 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2560 if [ -n "$TEST_TAG" ]; then
2561 local TAGVER=`make_tagver`
2562 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2563 # check also tags created in CVS
2564 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2565 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2566 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2567 || Exit_error err_tag_exists $TAGVER_CVS
2568 # - do not allow to build from HEAD when XX-branch exists
2569 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2570 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2571 TAG_BRANCH="${TREE_PREFIX}-branch"
2572 if [ -n "$DEPTH" ]; then
2573 cmd_branches="git ls-remote --heads"
2574 ref_prefix=refs/heads
2576 cmd_branches="git show-ref"
2577 ref_prefix=refs/remotes/${REMOTE_PLD}
2579 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2580 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2581 Exit_error err_branch_exists "$TAG_STATUS"
2587 if [ -n "$NOSOURCE0" ] ; then
2588 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2593 get_files $SOURCES $PATCHES
2594 check_md5 $SOURCES $PATCHES
2597 NODIST="yes" get_files $SOURCES $PATCHES
2598 update_md5 $SOURCES $PATCHES
2602 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2603 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2605 remove_build_requires
2609 if [ -z "$SPECFILE" ]; then
2610 Exit_error err_no_spec_in_cmdl
2619 if [ -z "$SPECFILE" ]; then
2620 Exit_error err_no_spec_in_cmdl
2624 if [ -n "$NEW_REPO" ]; then
2627 for file in $SOURCES $PATCHES; do
2628 if [ -z $(src_md5 "$file") ]; then
2629 git add $file || Exit_error err_no_source_in_repo $file
2631 cvsignore_df `nourl $file`
2635 echo "When you are ready commit your changes and run git push origin master"
2637 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2642 if [ -z "$SPECFILE" ]; then
2643 Exit_error err_no_spec_in_cmdl
2649 if [ -n "$NOSOURCE0" ] ; then
2650 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2652 get_files $SOURCES $PATCHES
2657 if [ -z "$SPECFILE" ]; then
2658 Exit_error err_no_spec_in_cmdl
2664 if [ -n "$NOSOURCE0" ] ; then
2665 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2667 update_md5 $SOURCES $PATCHES
2673 if [ -z "$SPECFILE" ]; then
2674 Exit_error err_no_spec_in_cmdl
2678 if [ ! -d .git ]; then
2679 echo "No git reposiotory" >&2
2687 "list-sources-files" )
2690 DONT_PRINT_REVISION="yes"
2693 for SAP in $SOURCES $PATCHES; do
2694 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2697 "list-sources-urls" )
2700 DONT_PRINT_REVISION="yes"
2703 SAPS="$SOURCES $PATCHES"
2704 for SAP in $SAPS; do
2708 "list-sources-local-paths" )
2711 DONT_PRINT_REVISION="yes"
2714 for SAP in $SOURCES $PATCHES; do
2715 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2718 "list-sources-distfiles-paths" )
2721 DONT_PRINT_REVISION="yes"
2724 for SAP in $SOURCES $PATCHES; do
2725 if [ -n "$(src_md5 "$SAP")" ]; then
2726 distfiles_path "$SAP"
2730 "list-sources-distfiles" )
2733 DONT_PRINT_REVISION="yes"
2736 for SAP in $SOURCES $PATCHES; do
2737 if [ -n "$(src_md5 "$SAP")" ]; then
2738 distfiles_url "$SAP"
2742 "list-sources-cvs" )
2745 DONT_PRINT_REVISION="yes"
2748 for SAP in $SOURCES $PATCHES; do
2749 if [ -z "$(src_md5 "$SAP")" ]; then
2750 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2764 echo "$VERSIONSTRING"
2767 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2768 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2772 # vi:syntax=sh:ts=4:sw=4:noet