6 # 2 - no spec file name in cmdl parameters
7 # 3 - spec file not stored in repo
8 # 4 - some source, patch or icon files not stored in repo
9 # 5 - package build failed
10 # 6 - spec file with errors
11 # 7 - wrong source in /etc/poldek.conf
12 # 8 - Failed installing buildrequirements and subrequirements
13 # 9 - Requested tag already exist
14 # 10 - Refused to build fractional release
15 # 100 - Unknown error (should not happen)
18 # - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
19 # - when Icon: field is present, -5 and -a5 doesn't work
20 # - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
27 Build package utility from PLD Linux CVS repository
28 $VERSION (C) 1999-2007 Free Penguins".
30 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
49 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
52 # user agent when fetching files
53 USER_AGENT="PLD/Builder($VERSION)"
55 # It can be used i.e. in log file naming.
56 # See LOGFILE example.
57 DATE=`date +%Y-%m-%d_%H-%M-%S`
59 # Example: LOGFILE='../log.$PACKAGE_NAME'
60 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
61 # Yes, you can use variable name! Note _single_ quotes!
85 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
86 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
92 CVS_SERVER="cvs.pld-linux.org"
93 DISTFILES_SERVER="://distfiles.pld-linux.org"
94 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
99 FAIL_IF_NO_SOURCES="yes"
101 # let get_files skip over files which are present to get those damn files fetched
102 SKIP_EXISTING_FILES="no"
105 # should the specfile be restored if upgrade failed?
106 REVERT_BROKEN_UPGRADE="yes"
108 if [ -x /usr/bin/rpm-getdeps ]; then
109 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
111 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
114 # Here we load saved user environment used to
115 # predefine options set above, or passed to builder
117 # This one reads global system environment settings:
118 if [ -f ~/etc/builderrc ]; then
121 # And this one cascades settings using user personal
123 # Example of ~/.builderrc:
125 #UPDATE_POLDEK_INDEXES="yes"
126 #FETCH_BUILD_REQUIRES="yes"
127 #REMOVE_BUILD_REQUIRES="force"
129 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
133 if [ -n "$HOME_ETC" ]; then
134 USER_CFG="$HOME_ETC/.builderrc"
135 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
137 USER_CFG=~/.builderrc
138 BUILDER_MACROS=~/.builder-rpmmacros
141 [ -f "$USER_CFG" ] && . "$USER_CFG"
143 if [ "$SCHEDTOOL" = "auto" ]; then
144 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
145 SCHEDTOOL="schedtool -B -e"
151 if [ -n "$USE_PROZILLA" ]; then
152 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
155 elif [ -n "$USE_AXEL" ]; then
156 GETURI="axel -a $AXEL_OPTS"
160 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
161 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
162 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
163 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
165 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
166 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
172 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
180 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
181 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
185 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
186 if [ -n "$LOGFILE" ]; then
187 LOG=`eval echo $LOGFILE`
188 if [ -n "$LASTLOG_FILE" ]; then
189 echo "LASTLOG=$LOG" > $LASTLOG_FILE
191 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
194 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
195 return `cat ${RES_FILE}`
200 #---------------------------------------------
205 if [ -n "$DEBUG" ]; then set -xv; fi
207 Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|-ba|--build]
208 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
209 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
210 [-g|--get] [-h|--help] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
211 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
212 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
213 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
214 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
215 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
216 <package>[.spec][:cvstag]
218 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
219 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
220 -n5, --no-md5 - ignore md5 comments in spec
221 -D, --debug - enable builder script debugging mode,
222 -debug - produce rpm debug package (same as --opts -debug)
223 -V, --version - output builder version string
224 --short-version - output builder short version
225 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
226 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
228 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
229 only package from <package>.spec,
230 -bp, --build-prep - execute the %prep phase of <package>.spec,
231 -bc - execute the %build phase of <package>.spec,
232 -bi - execute the %install phase of <package>.spec
233 -bl - execute the %files phase of <package>.spec
234 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
236 --short-circuit - short-circuit build
237 -B, --branch - add branch
238 -c, --clean - clean all temporarily created files (in BUILD, SOURCES,
239 SPECS and \$RPM_BUILD_ROOT),
240 -cf, --cvs-force - use -F when tagging (useful when moving branches)
241 -d <cvsroot>, --cvsroot <cvsroot>
243 --define <macro> <value>
244 - define a macro <macro> with value <value>,
245 --nodeps - rpm won't check any dependences
246 -g, --get - get <package>.spec and all related files from CVS repo
248 -h, --help - this message,
249 --http - use http instead of ftp,
250 -l <logfile>, --logtofile <logfile>
252 -m, --mr-proper - only remove all files related to spec file and all work
254 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
256 - don't check specs in CVS
257 -nd, --no-distfiles - don't download from distfiles
258 -nm, --no-mirrors - don't download from mirror, if source URL is given,
259 -nu, --no-urls - don't try to download from FTP/HTTP location,
260 -ns, --no-srcs - don't download Sources
261 -ns0, --no-source0 - don't download Source0
262 -nn, --no-net - don't download anything from the net
263 -pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES
264 --no-init - don't initialize builder paths (SPECS and SOURCES)
266 --skip-existing-files - skip existing files in get_files
267 --opts <rpm opts> - additional options for rpm
268 -q, --quiet - be quiet,
269 --date yyyy-mm-dd - build package using resources from specified CVS date,
270 -r <cvstag>, --cvstag <cvstag>
271 - build package using resources from specified CVS tag,
272 -A - build package using CVS resources as any sticky tags/date/kopts being reset.
273 -R, --fetch-build-requires
274 - fetch what is BuildRequired,
275 -RB, --remove-build-requires
276 - remove all you fetched with -R or --fetch-build-requires
277 remember, this option requires confirmation,
278 -FRB, --force-remove-build-requires
279 - remove all you fetched with -R or --fetch-build-requires
280 remember, this option works without confirmation,
281 -sd, --source-distfiles - list sources available from distfiles (intended for offline
282 operations; does not work when Icon field is present
283 but icon file is absent),
284 -sc, --source-cvs - list sources available from CVS
285 -sdp, --source-distfiles-paths - list sources available from distfiles -
286 paths relative to distfiles directory (intended for offline
287 operations; does not work when Icon field is present
288 but icon file is absent),
289 -sf, --source-files - list sources - bare filenames (intended for offline
290 operations; does not work when Icon field is present
291 but icon file is absent),
292 -sp, --source-paths - list sources - filenames with full local paths (intended for
293 offline operations; does not work when Icon field is present
294 but icon file is absent),
295 -su, --source-urls - list urls - urls to sources and patches
296 intended for copying urls with spec with lots of macros in urls
297 -T <cvstag> , --tag <cvstag>
298 - add cvs tag <cvstag> for files,
299 -Tvs, --tag-version-stable
300 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
302 - add cvs tag STABLE for files,
304 - add cvs tag NAME-VERSION-RELEASE for files,
305 -Tp, --tag-prefix <prefix>
306 - add <prefix> to NAME-VERSION-RELEASE tags,
307 -tt, --test-tag <prefix>
308 - fail if tag is already present,
309 -ir, --integer-release-only
310 - allow only integer and snapshot releases
311 -v, --verbose - be verbose,
312 -u, --try-upgrade - check version, and try to upgrade package
313 -un, --try-upgrade-with-float-version
314 - as above, but allow float version
315 -U, --update - refetch sources, don't use distfiles, and update md5 comments
316 -Upi, --update-poldek-indexes
317 - refresh or make poldek package index files.
318 -np, --nopatch <patchnumber>
319 - don't apply <patchnumber>
320 --show-bconds - show available conditional builds, which can be used
321 - with --with and/or --without switches.
322 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by
323 ./repackage.sh script. in other words, the output is
324 parseable by scripts.
325 --with/--without <feature>
326 - conditional build package depending on %_with_<feature>/
327 %_without_<feature> macro switch. You may now use
328 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
329 constructions. Set GROUP_BCONDS to yes to make use of it.
330 --target <platform>, --target=<platform>
331 - build for platform <platform>.
332 --init-rpm-dir - initialize ~/rpm directory structure
336 update_shell_title() {
338 local len=${COLUMNS:-80}
339 local msg=$(echo "$*" | cut -c-$len)
341 if [ -n "$BE_VERBOSE" ]; then
342 echo >&2 "$(date +%s.%N) $*"
345 if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then
347 if [ -n "$PACKAGE_NAME" ]; then
348 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
353 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
354 msg="$(echo $msg | tr -d '\n\r')"
357 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
360 echo >&2 -ne "\033]0;$msg\007"
366 # set TARGET from BuildArch: from SPECFILE
368 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
369 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
371 target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
375 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
377 TARGET_SWITCH="--target=$TARGET" ;;
383 # runs rpm with minimal macroset
385 # we reset macros not to contain macros.build as all the %() macros are
386 # executed here, while none of them are actually needed.
387 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
388 safe_macrofiles=$(rpm --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
390 # TODO: move these to /usr/lib/rpm/macros
391 cat > $BUILDER_MACROS <<'EOF'
392 %x8664 x86_64 amd64 ia32e
395 %requires_releq_kernel_up %{nil}
396 %requires_releq_kernel_smp %{nil}
397 %requires_releq_kernel %{nil}
398 %requires_releq() %{nil}
399 %pyrequires_eq() %{nil}
400 %requires_eq() %{nil}
401 %requires_eq_to() %{nil}
402 %releq_kernel_up ERROR
403 %releq_kernel_smp ERROR
408 %ruby_ver_requires_eq() %{nil}
409 %ruby_mod_ver_requires_eq() %{nil}
410 %__php_api_requires() %{nil}
411 %php_major_version ERROR
412 %php_api_version ERROR
414 %perl_vendorarch ERROR
415 %perl_vendorlib ERROR
416 # damn. need it here! - copied from /usr/lib/rpm/macros.build
417 %tmpdir %(echo "${TMPDIR:-/tmp}")
418 %patchset_source(f:b:) %(
419 base=%{-b*}%{!-b*:10000};
420 start=$(expr $base + %1);
421 end=$(expr $base + %{?2}%{!?2:%{1}});
422 # we need to call seq twice as it doesn't allow two formats
423 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
424 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
425 paste %{tmpdir}/__ps{1,2};
426 rm -f %{tmpdir}/__ps{1,2};
430 if [ "$NOINIT" = "yes" ] ; then
431 cat >> $BUILDER_MACROS <<'EOF'
436 eval $RPMBUILD --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $* 2>&1
440 if [ -n "$DEBUG" ]; then
445 update_shell_title "cache_rpm_dump"
448 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
449 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
455 ARGS='--nodigest --nosignature --nobuild'
458 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
460 if [ $? -gt 0 ]; then
461 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
463 Exit_error err_build_fail
466 # make small dump cache
467 rpm_dump_cache=`echo "$rpm_dump" | awk '
468 $2 ~ /^SOURCEURL/ {print}
469 $2 ~ /^PATCHURL/ {print}
470 $2 ~ /^nosource/ {print}
471 $2 ~ /^PACKAGE_/ {print}
474 update_shell_title "cache_rpm_dump: OK!"
478 if [ -z "$rpm_dump_cache" ] ; then
479 echo "internal error: cache_rpm_dump not called! (missing %prep?)" 1>&2
481 echo "$rpm_dump_cache"
486 update_shell_title "get icons"
487 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
488 if [ -z "$ICONS" ]; then
492 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
497 update_shell_title "parsing specfile"
498 if [ -n "$DEBUG" ]; then
503 # icons are needed for successful spec parse
509 if [ "$NOSRCS" != "yes" ]; then
510 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
513 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
514 FAIL_IF_NO_SOURCES="no"
517 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
518 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
519 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
520 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
521 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
523 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
524 echo "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
527 if [ -n "$BE_VERBOSE" ]; then
528 echo "- Sources : `nourl $SOURCES`"
529 if [ -n "$PATCHES" ]; then
530 echo "- Patches : `nourl $PATCHES`"
532 echo "- Patches : *no patches needed*"
534 if [ -n "$ICONS" ]; then
535 echo "- Icon : `nourl $ICONS`"
537 echo "- Icon : *no package icon*"
539 echo "- Name : $PACKAGE_NAME"
540 echo "- Version : $PACKAGE_VERSION"
541 echo "- Release : $PACKAGE_RELEASE"
544 update_shell_title "parse_spec: OK!"
549 if [ -n "$DEBUG" ]; then
557 "err_no_spec_in_cmdl" )
558 remove_build_requires
559 echo "ERROR: spec file name not specified."
561 "err_invalid_cmdline" )
562 echo "ERROR: invalid command line arg ($2)."
564 "err_no_spec_in_repo" )
565 remove_build_requires
566 echo "Error: spec file not stored in CVS repo."
568 "err_no_source_in_repo" )
569 remove_build_requires
570 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)"
573 remove_build_requires
574 echo "Error: package build failed. (${2:-no more info})"
576 "err_no_package_data" )
577 remove_build_requires
578 echo "Error: couldn't get out package name/version/release from spec file."
581 remove_build_requires
582 echo "Tag ${2} already exists (spec release: ${3})."
585 remove_build_requires
586 echo "Release ${2} not integer and not a snapshot."
588 "err_branch_exists" )
589 remove_build_requires
590 echo "Tree branch already exists (${2})."
593 remove_build_requires
594 echo "Error: conditions reject building this spec (${2})."
597 echo "Unknown error."
603 if [ -n "$DEBUG" ]; then
608 if [ "$NOINIT" != "yes" ] ; then
609 SOURCE_DIR="`eval $RPM $RPMOPTS --define '"name $ASSUMED_NAME"' --eval '%{_sourcedir}'`"
610 SPECS_DIR="`eval $RPM $RPMOPTS --define '"name $ASSUMED_NAME"' --eval '%{_specdir}'`"
622 update_shell_title "get_spec"
624 if [ -n "$DEBUG" ]; then
630 if [ ! -f "$SPECFILE" ]; then
631 SPECFILE="`basename $SPECFILE .spec`.spec"
633 if [ "$NOCVSSPEC" != "yes" ]; then
635 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
636 echo "Warning: No CVS access defined - using local .spec file"
640 cvsup "$SPECFILE" || Exit_error err_no_spec_in_repo
643 if [ ! -f "$SPECFILE" ]; then
644 Exit_error err_no_spec_in_repo
647 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
648 chmod $CHMOD_MODE $SPECFILE
651 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
660 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
661 cvs update mirrors >&2
665 local origin mirror name rest ol prefix
666 while read origin mirror name rest; do
667 # skip comments and empty lines
668 if [ -z "$origin" ] || [[ $origin == \#* ]]; then
671 ol=`echo -n "$origin"|wc -c`
672 prefix="`echo -n "$url" | head -c $ol`"
673 if [ "$prefix" = "$origin" ] ; then
674 suffix="`echo "$url"|cut -b $((ol+1))-`"
675 echo -n "$mirror$suffix"
682 # Warning: unpredictable results if same URL used twice
687 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
688 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
694 [ "$NO5" = "yes" ] && return
696 [ -z "$no" ] && return
700 if [ -f additional-md5sums ]; then
701 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
702 if [ -z "$spec_rev" ]; then
703 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
705 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
706 md5=$(grep -s -v '^#' additional-md5sums | \
707 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
708 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
709 grep -E '^[0-9a-f]{32}$')
712 if [ $(echo "$md5" | wc -l) != 1 ] ; then
713 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
715 echo "$md5" | tail -n 1
720 source_md5=`grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
721 if [ -n "$source_md5" ]; then
724 # we have empty SourceX-md5, but it is still possible
725 # that we have NoSourceX-md5 AND NoSource: X
726 nosource_md5=`grep -i "#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
727 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
735 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
740 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
743 distfiles_attic_url ()
745 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
752 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
757 size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
758 [ -n "$size" -a "$size" -gt 0 ]
763 if [ "$CVSIGNORE_DF" != "yes" ]; then
766 cvsignore=${SOURCE_DIR}/.cvsignore
767 if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
768 echo "$1" >> $cvsignore
774 update_shell_title "cvsup"
776 if [ -n "$CVSROOT" ]; then
777 OPTIONS="-d $CVSROOT $OPTIONS"
780 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
781 OPTIONS="$OPTIONS -A"
783 if [ -n "$CVSDATE" ]; then
784 OPTIONS="$OPTIONS -D $CVSDATE"
786 if [ -n "$CVSTAG" ]; then
787 OPTIONS="$OPTIONS -r $CVSTAG"
792 local retries_counter=0
794 update_shell_title "cvsup: $*"
796 update_shell_title "cvsup: $# files"
798 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
799 retries_counter=$(( $retries_counter + 1 ))
800 output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1)
802 [ -n "$output" ] && echo "$output"
803 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
804 echo "Trying again [$*]... ($retries_counter)"
805 update_shell_title "cvsup: retry #$retries_counter"
812 update_shell_title "cvsup: done!"
816 # returns true if "$1" is ftp, http or https protocol url
820 ftp://*|http://*|https://*)
829 if [ $# -eq 0 ]; then
833 update_shell_title "update md5"
834 if [ -n "$DEBUG" ]; then
841 # pass 1: check files to be fetched
845 local fp=$(nourl "$i")
846 local srcno=$(src_no "$i")
847 if [ -n "$ADD5" ]; then
848 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
849 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
851 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
853 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
854 need_files="$need_files $i"
858 # pass 1a: get needed files
859 if [ "$need_files" ]; then
860 get_files $need_files
863 # pass 2: proceed with md5 adding or updating
865 local fp=$(nourl "$i")
866 local srcno=$(src_no "$i")
867 local md5=$(grep -iE '^#[ ]*(No)?Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
868 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
869 local tag="Source$srcno-md5"
870 if [[ "$md5" == *NoSource* ]]; then
871 tag="NoSource$srcno-md5"
873 md5=$(md5sum "$fp" | cut -f1 -d' ')
874 echo "Updating $tag ($md5: $fp)."
876 print unless /^\s*#\s*(No)?Source'$srcno'-md5\s*:/i;
877 print "# '$tag':\t'$md5'\n" if /^Source'$srcno'\s*:\s+/;
886 update_shell_title "check md5"
889 if good_md5 "$i" && good_size "$i"; then
893 echo "MD5 sum mismatch or 0 size. Use -U to refetch sources,"
894 echo "or -5 to update md5 sums, if you're sure files are correct."
895 Exit_error err_no_source_in_repo $i
901 update_shell_title "get_files"
903 if [ -n "$DEBUG" ]; then
908 if [ $# -gt 0 ]; then
911 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
912 echo "Warning: No CVS access defined for SOURCES"
917 local get_files_cvs=""
921 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
922 update_shell_title "$i"
923 local fp=`nourl "$i"`
924 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
929 local srcmd5=$(src_md5 "$i")
931 # we know if source/patch is present in cvs/distfiles
932 # - has md5 (in distfiles)
935 # CHECK: local file didn't exist or always cvs up (first) requested.
936 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
937 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
938 echo "Warning: no URL given for $i"
941 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
942 if good_md5 "$i" && good_size "$i"; then
943 echo "$fp having proper md5sum already exists"
948 # optionally prefer mirror over distfiles if there's mirror
949 # TODO: build url list and then try each url from the list
950 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
953 url=$(distfiles_url "$i")
956 url_attic=$(distfiles_attic_url "$i")
958 # is $url local file?
959 if [[ "$url" = [./]* ]]; then
960 update_shell_title "${GETLOCAL%% *}: $url"
961 ${GETLOCAL} $url $target
963 if [ -z "$NOMIRRORS" ]; then
964 url=$(find_mirror "$url")
968 # make shorter message for distfiles urls
969 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
970 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
971 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
974 update_shell_title "${GETURI%% *}: $uri"
975 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
976 if [ "`echo $url | grep -E 'ftp://'`" ]; then
977 update_shell_title "${GETURI2%% *}: $url"
978 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
983 if [ ! -s "$target" ]; then
985 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
986 update_shell_title "${GETLOCAL%% *}: $url_attic"
987 ${GETLOCAL} $url_attic $target
989 if [ -z "$NOMIRRORS" ]; then
990 url_attic="`find_mirror "$url_attic"`"
992 update_shell_title "${GETURI%% *}: $url_attic"
993 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
994 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
995 update_shell_title "${GETURI2%% *}: $url_attic"
996 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1001 if [ -s "$target" ]; then
1002 cvsignore_df $target
1007 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
1008 if [ $# -gt 1 ]; then
1009 get_files_cvs="$get_files_cvs $fp"
1010 update_shell_title "$fp (will cvs up later)"
1017 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1018 if [ -z "$NOMIRRORS" ]; then
1019 im="`find_mirror "$i"`"
1023 update_shell_title "${GETURI%% *}: $im"
1024 ${GETURI} "$im" || \
1025 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1026 update_shell_title "${GETURI2%% *}: $im"
1031 if [ "$cvsup" = 1 ]; then
1037 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1038 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1039 Exit_error err_no_source_in_repo $i
1042 # we check md5 here just only to refetch immediately
1043 if good_md5 "$i" && good_size "$i"; then
1045 elif [ "$FROM_DISTFILES" = 1 ]; then
1046 # wrong md5 from distfiles: remove the file and try again
1048 echo "MD5 sum mismatch. Trying full fetch."
1051 update_shell_title "${GETURI%% *}: $url"
1052 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1053 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1054 update_shell_title "${GETURI2%% *}: $url"
1055 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1057 if [ ! -s "$target" ]; then
1059 update_shell_title "${GETURI%% *}: $url_attic"
1060 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1061 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1062 update_shell_title "${GETURI2%% *}: $url_attic"
1063 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1066 test -s "$target" || rm -f "$target"
1069 SHELL_TITLE_PREFIX=""
1071 if [ "$get_files_cvs" ]; then
1072 cvsup $get_files_cvs
1075 if [ "$CHMOD" = "yes" ]; then
1076 CHMOD_FILES="`nourl "$@"`"
1077 if [ -n "$CHMOD_FILES" ]; then
1078 chmod $CHMOD_MODE $CHMOD_FILES
1085 if [ -n "$DEBUG" ]; then
1090 # Check whether first character of PACKAGE_NAME is legal for tag name
1091 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1095 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1096 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]')
1098 # Remove #kernel.version_release from TAGVER because tagging sources
1099 # could occur with different kernel-headers than kernel-headers used at build time.
1100 # besides, %{_kernel_ver_str} is not expanded.
1102 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str}
1103 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1113 if [ -n "$DEBUG" ]; then
1118 echo "Version: $PACKAGE_VERSION"
1119 echo "Release: $PACKAGE_RELEASE"
1122 if [ "$TAG_VERSION" = "yes" ]; then
1123 TAGVER=`make_tagver`
1124 echo "CVS tag: $TAGVER"
1126 if [ -n "$TAG" ]; then
1127 echo "CVS tag: $TAG"
1130 local OPTIONS="tag $CVS_FORCE"
1131 if [ -n "$CVSROOT" ]; then
1132 OPTIONS="-d $CVSROOT $OPTIONS"
1137 for i in $TAG_FILES; do
1138 # don't tag files stored on distfiles
1139 [ -n "`src_md5 $i`" ] && continue
1140 local fp=`nourl "$i"`
1141 if [ -f "$fp" ]; then
1142 tag_files="$tag_files $fp"
1144 Exit_error err_no_source_in_repo $i
1148 if [ "$tag_files" ]; then
1149 if [ "$TAG_VERSION" = "yes" ]; then
1150 update_shell_title "tag sources: $TAGVER"
1151 cvs $OPTIONS $TAGVER $tag_files || exit
1153 if [ -n "$TAG" ]; then
1154 update_shell_title "tag sources: $TAG"
1155 cvs $OPTIONS $TAG $tag_files || exit
1160 if [ "$TAG_VERSION" = "yes" ]; then
1161 update_shell_title "tag spec: $TAGVER"
1162 cvs $OPTIONS $TAGVER $SPECFILE || exit
1164 if [ -n "$TAG" ]; then
1165 update_shell_title "tag spec: $TAG"
1166 cvs $OPTIONS $TAG $SPECFILE || exit
1173 echo "CVS branch tag: $TAG"
1178 if [ -n "$DEBUG" ]; then
1183 local OPTIONS="tag $CVS_FORCE -b"
1184 if [ -n "$CVSROOT" ]; then
1185 OPTIONS="-d $CVSROOT $OPTIONS"
1189 for i in $TAG_FILES; do
1190 local fp=`nourl "$i"`
1191 if [ -f "$fp" ]; then
1192 tag_files="$tag_files $fp"
1194 Exit_error err_no_source_in_repo $i
1197 if [ "$tag_files" ]; then
1198 cvs $OPTIONS $TAG $tag_files || exit
1202 cvs $OPTIONS $TAG $SPECFILE || exit
1206 # this function should exit early if package can't be built for this arch
1207 # this avoids unneccessary BR filling.
1210 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1212 if [ $ret -ne 0 ]; then
1221 update_shell_title "build_package"
1222 if [ -n "$DEBUG" ]; then
1229 if [ -n "$TRY_UPGRADE" ]; then
1230 update_shell_title "build_package: try_upgrade"
1231 if [ -n "$FLOAT_VERSION" ]; then
1232 TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1
1234 TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1
1237 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
1239 if [ -n "$TNEWVER" ]; then
1240 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1241 echo "New version found, updating spec file to version " $TNEWVER
1242 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1243 cp -f $SPECFILE $SPECFILE.bak
1246 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
1247 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
1249 NODIST="yes" get_files $SOURCES $PATCHES
1252 unset TOLDVER TNEWVER TNOTIFY
1259 BUILD_SWITCH="-ba" ;;
1261 BUILD_SWITCH="-bb" ;;
1263 BUILD_SWITCH="-bs --nodeps" ;;
1265 BUILD_SWITCH="-bp --nodeps" ;;
1267 BUILD_SWITCH="-bc" ;;
1269 BUILD_SWITCH="-bi" ;;
1271 BUILD_SWITCH="-bl" ;;
1275 update_shell_title "build_package: $COMMAND"
1276 if [ -n "$LOGFILE" ]; then
1277 LOG=`eval echo $LOGFILE`
1278 if [ -d "$LOG" ]; then
1279 echo "Log file $LOG is a directory."
1280 echo "Parse error in the spec?"
1281 Exit_error err_build_fail
1283 if [ -n "$LASTLOG_FILE" ]; then
1284 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1286 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
1287 (time eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
1288 RETVAL=`cat $RES_FILE`
1290 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1291 if [ "$RETVAL" -eq "0" ]; then
1298 eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE
1301 if [ "$RETVAL" -ne "0" ]; then
1302 if [ -n "$TRY_UPGRADE" ]; then
1303 echo "\n!!! Package with new version cannot be built automagically\n"
1304 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1305 mv -f $SPECFILE.bak $SPECFILE
1308 Exit_error err_build_fail
1315 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1318 install_required_packages()
1325 # taken from find-spec-bcond, but with just getting the list
1327 # quick revert hint: '$RPMBUILD --bcond $SPEC'
1329 /^%changelog/ { exit }
1330 /_with(out)?_[_a-zA-Z0-9]+/{
1331 match($0, /_with(out)?_[_a-zA-Z0-9]+/);
1332 print substr($0, RSTART, RLENGTH);
1335 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1336 bcond = substr($0, RSTART +5 , RLENGTH -5);
1337 gsub(/[ \t]+/,"_",bcond);
1339 }' $SPEC | LC_ALL=C sort -u
1343 # expand bconds from ~/.bcondrc
1344 # The file structure is like gentoo's package.use:
1347 # samba -mysql -pgsql
1348 # w32codec-installer license_agreement
1351 if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
1357 SN=${SPECFILE%%\.spec}
1359 local bcondrc=$HOME/.bcondrc
1360 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1362 local bcond_avail=$(find_spec_bcond $SPECFILE)
1364 while read pkg flags; do
1366 [[ "$pkg" == \#* ]] && continue
1368 # any package or current package?
1369 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1370 for flag in $flags; do
1371 local opt=${flag#[+-]}
1373 # use only flags which are in this package.
1374 if [[ $bcond_avail = *${opt}* ]]; then
1375 if [[ $flag = -* ]]; then
1376 if [[ $BCOND != *--with?${opt}* ]]; then
1377 BCOND="$BCOND --without $opt"
1380 if [[ $BCOND != *--without?${opt}* ]]; then
1381 BCOND="$BCOND --with $opt"
1388 update_shell_title "parse ~/.bcondrc: DONE!"
1393 update_shell_title "set bcond values"
1395 AVAIL_BCONDS_WITHOUT=""
1396 AVAIL_BCONDS_WITH=""
1397 if `grep -q ^%bcond ${SPECFILE}`; then
1399 elif `egrep -q ^#\ *_with ${SPECFILE}`; then
1405 local bcond_avail=$(find_spec_bcond $SPECFILE)
1406 process_bcondrc "$SPECFILE"
1408 update_shell_title "parse bconds"
1409 case "${BCOND_VERSION}" in
1414 echo "Warning: This spec has old style bconds. Fix it || die."
1415 for opt in `echo "$bcond_avail" | grep ^_without_`
1417 AVAIL_BCOND_WITHOUT=${opt#_without_}
1418 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
1419 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1421 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1425 for opt in `echo "$bcond_avail" | grep ^_with_`
1427 AVAIL_BCOND_WITH=${opt#_with_}
1428 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
1429 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1431 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1436 local cond_type="" # with || without
1437 for opt in $bcond_avail; do
1446 AVAIL_BCOND_WITHOUT=${opt#_without_}
1447 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
1448 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1450 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1454 AVAIL_BCOND_WITH=${opt#_with_}
1455 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
1456 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1458 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1462 case "$cond_type" in
1465 AVAIL_BCOND_WITH="$opt"
1466 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
1467 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1469 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1474 AVAIL_BCOND_WITHOUT="$opt"
1475 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
1476 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1478 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1492 update_shell_title "run_sub_builder $package_name"
1494 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1495 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1496 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1497 # jakby nie bylo tego kawalka kodu.
1499 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1500 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1507 # Istnieje taki spec? ${package}.spec
1508 if [ -f "${SPECS_DIR}/${package}.spec" ]; then
1509 parent_spec_name=${package}.spec
1510 elif [ -f "${SPECS_DIR}/`echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
1511 parent_spec_name="`echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g`.spec"
1513 for provides_line in `grep ^Provides:.*$package ${SPECS_DIR} -R`
1519 if [ "${parent_spec_name}" != "" ]; then
1520 spawn_sub_builder $parent_spec_name
1522 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1528 update_shell_title "spawn_sub_builder $package_name"
1531 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
1532 sub_builder_opts="${sub_builder_opts} -R"
1534 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
1535 sub_builder_opts="${sub_builder_opts} -RB"
1536 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
1537 sub_builder_opts="${sub_builder_opts} -FRB"
1539 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
1540 sub_builder_opts="${sub_builder_opts} -Upi"
1544 ./builder ${sub_builder_opts} "$@"
1547 remove_build_requires()
1549 if [ "$INSTALLED_PACKAGES" != "" ]; then
1550 case "$REMOVE_BUILD_REQUIRES" in
1552 run_poldek --noask -ve $INSTALLED_PACKAGES
1555 run_poldek --ask -ve $INSTALLED_PACKAGES
1558 echo You may want to manually remove following BuildRequires fetched:
1559 echo $INSTALLED_PACKAGES
1560 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1568 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1569 if [ "$BCOND" != "" ]; then
1570 echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1573 echo -ne "\nNo conditional flags passed"
1575 echo -ne "\n\nfrom available:\n"
1576 echo -ne "--with :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1582 if [ "$NOCVSSPEC" != "yes" ]; then
1583 echo -ne "Available branches: "
1584 cvs status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
1588 # checks a given list of packages/files/provides agains current rpmdb.
1589 # outputs all dependencies whcih current rpmdb doesn't satisfy.
1590 # input can be either STDIN or parameters
1595 if [ "$#" -gt 0 ]; then
1601 DEPS=$(rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1604 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1606 # other deps (files)
1607 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1610 # checks if given package/files/provides exists in rpmdb.
1611 # inout can be either stdin or parameters
1612 # returns packages wchi hare present in the rpmdb
1617 if [ "$#" -gt 0 ]; then
1623 rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1626 fetch_build_requires()
1628 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1629 update_shell_title "fetch build requires"
1630 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1631 # TODO: Conflicts list doesn't check versions
1632 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1633 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1635 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1636 echo "fetch builderequires: install $DEPS; remove $CNFL"
1637 update_shell_title "poldek: install $DEPS; remove $CNFL"
1638 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1640 if [ -n "$CNFL" ]; then
1641 update_shell_title "uninstall conflicting packages: $CNFL"
1642 echo "Trying to uninstall conflicting packages ($CNFL):"
1643 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1646 while [ "$DEPS" ]; do
1647 update_shell_title "install deps: $DEPS"
1648 echo "Trying to install dependencies ($DEPS):"
1649 local log=.${SPECFILE}_poldek.log
1650 $SU_SUDO /usr/bin/poldek --caplookup -uGq $DEPS | tee $log
1651 failed=$(awk -F: '/^error:/{print $2}' $log)
1654 if [ -n "$failed" ]; then
1655 for package in $failed; do
1656 # FIXME: sanitise, deps could be not .spec files
1657 spawn_sub_builder -bb $package && ok="$ok $package"
1667 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1668 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1669 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1670 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1671 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1672 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`
1674 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`"
1676 package=`basename "$package_item"|sed -e "s/}$//g"`
1677 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1680 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1681 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1682 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
1687 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1690 if `echo $COND_TST|grep -q 'without_'`; then
1691 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1692 if `echo $COND_TST|grep -q !`; then
1697 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1698 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1699 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1705 elif `echo $COND_TST|grep -q 'with_'`; then
1706 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1707 if `echo $COND_TST|grep -q !`; then
1712 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1713 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1714 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
1720 RESULT="${COND_STATE}-${COND_ARGV}"
1722 "with-wout" | "wout-with" )
1725 "wout-wout" | "with-with" )
1729 echo "Action '$RESULT' was not defined for package '$package_item'"
1735 if [ "$GO" = "yes" ]; then
1736 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1737 echo "Testing if $package has subrequirements..."
1738 run_poldek -t -i $package --dumpn=".$package-req.txt"
1739 if [ -f ".$package-req.txt" ]; then
1740 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1742 if [ "$package_name" = "$package" ]; then
1743 echo -ne "Installing BuildRequired package:\t$package_name\n"
1744 update_shell_title "Installing BuildRequired package: ${package_name}"
1745 install_required_packages $package
1747 echo -ne "Installing (sub)Required package:\t$package_name\n"
1748 update_shell_title "Installing (sub)Required package: ${package_name}"
1749 install_required_packages $package_name
1753 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1754 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1757 echo "Attempting to run spawn sub - builder..."
1758 echo -ne "Package installation failed:\t$package_name\n"
1759 run_sub_builder $package_name
1760 if [ $? -eq 0 ]; then
1761 install_required_packages $package_name
1764 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1765 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1768 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1775 rm -f ".$package-req.txt"
1777 echo "Attempting to run spawn sub - builder..."
1778 echo -ne "Package installation failed:\t$package\n"
1779 run_sub_builder $package
1780 if [ $? -eq 0 ]; then
1781 install_required_packages $package
1784 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1785 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1788 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1794 echo "Package $package is already installed. BuildRequirement satisfied."
1798 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1799 echo "Unable to install following packages and their dependencies:"
1800 for pkg in "$NOT_INSTALLED_PACKAGES"
1804 remove_build_requires
1812 TOP_DIR="`eval $RPM $RPMOPTS --eval '%{_topdir}'`"
1813 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
1815 mkdir -p $TOP_DIR/{RPMS,BUILD,SRPMS}
1817 cvs -d $CVSROOT co SOURCES/.cvsignore SPECS/{mirrors,adapter{,.awk},fetchsrc_request,builder,{relup,compile,repackage}.sh}
1821 echo "To checkout *all* .spec files:"
1822 echo "- remove $SPECS_DIR/CVS/Entries.Static"
1823 echo "- run cvs up in $SPECS_DIR dir"
1826 echo "To commit with your developer account:"
1827 echo "- edit $SPECS_DIR/CVS/Root"
1828 echo "- edit $SOURCE_DIR/CVS/Root"
1831 #---------------------------------------------
1839 while [ $# -gt 0 ]; do
1842 COMMAND="update_md5"
1847 COMMAND="update_md5"
1857 DEBUG="yes"; shift ;;
1859 COMMAND="version"; shift ;;
1861 COMMAND="short-version"; shift ;;
1863 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1864 -b | -ba | --build )
1865 COMMAND="build"; shift ;;
1866 -bb | --build-binary )
1867 COMMAND="build-binary"; shift ;;
1869 COMMAND="build-build"; shift ;;
1871 COMMAND="build-install"; shift ;;
1873 COMMAND="build-list"; shift ;;
1874 -bp | --build-prep )
1875 COMMAND="build-prep"; shift ;;
1876 -bs | --build-source )
1877 COMMAND="build-source"; shift ;;
1879 COMMAND="branch"; shift; TAG="${1}"; shift;;
1881 CLEAN="--clean --rmspec --rmsource"; shift ;;
1883 CVS_FORCE="-F"; shift;;
1885 shift; CVSROOT="${1}"; shift ;;
1887 COMMAND="get"; shift ;;
1889 COMMAND="usage"; shift ;;
1891 PROTOCOL="http"; shift ;;
1893 shift; LOGFILE="${1}"; shift ;;
1895 shift; DEF_NICE_LEVEL=${1}; shift ;;
1896 -ske | --skip-existing-files)
1897 SKIP_EXISTING_FILES="yes"; shift ;;
1899 COMMAND="mr-proper"; shift ;;
1901 NOCVS="yes"; shift ;;
1902 -ncs | --no-cvs-specs )
1903 NOCVSSPEC="yes"; shift ;;
1904 -nd | --no-distfiles )
1905 NODIST="yes"; shift ;;
1906 -nm | --no-mirrors )
1907 NOMIRRORS="yes"; shift ;;
1909 NOURLS="yes"; shift ;;
1911 NOSRCS="yes"; shift ;;
1912 -ns0 | --no-source0 )
1913 NOSOURCE0="yes"; shift ;;
1923 -pm | --prefer-mirrors )
1930 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
1932 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
1933 --with | --without )
1934 case $GROUP_BCONDS in
1938 while ! `echo ${1}|grep -qE '(^-|spec)'`
1940 BCOND="$BCOND $COND $1"
1944 if [[ "$2" = *,* ]]; then
1945 for a in $(echo "$2" | tr , ' '); do
1946 BCOND="$BCOND $1 $a"
1949 BCOND="$BCOND $1 $2"
1955 shift; TARGET="${1}"; shift ;;
1957 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
1959 QUIET="--quiet"; shift ;;
1961 CVSDATE="${2}"; shift 2 ;;
1963 shift; CVSTAG="${1}"; shift ;;
1965 shift; CVSTAG="HEAD"; ;;
1966 -R | --fetch-build-requires)
1967 FETCH_BUILD_REQUIRES="yes"
1968 NOT_INSTALLED_PACKAGES=
1970 -RB | --remove-build-requires)
1971 REMOVE_BUILD_REQUIRES="nice"
1973 -FRB | --force-remove-build-requires)
1974 REMOVE_BUILD_REQUIRES="force"
1976 -sc | --sources-cvs)
1977 COMMAND="list-sources-cvs"
1979 -sd | --sources-distfiles)
1980 COMMAND="list-sources-distfiles"
1982 -sdp | --sources-distfiles-paths)
1983 COMMAND="list-sources-distfiles-paths"
1985 -sf | --sources-files)
1986 COMMAND="list-sources-files"
1988 -sp | --sources-paths)
1989 COMMAND="list-sources-local-paths"
1991 -su | --sources-urls)
1992 COMMAND="list-sources-urls"
1994 -Tvs | --tag-version-stable )
1999 -Ts | --tag-stable )
2004 -Tv | --tag-version )
2009 -Tp | --tag-prefix )
2021 -ir | --integer-release-only )
2022 INTEGER_RELEASE="yes"
2025 COMMAND="update_md5"
2030 -Upi | --update-poldek-indexes )
2031 UPDATE_POLDEK_INDEXES="yes"
2034 COMMAND="init_rpm_dir"
2036 -u | --try-upgrade )
2037 TRY_UPGRADE="1"; shift ;;
2038 -un | --try-upgrade-with-float-version )
2039 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2041 BE_VERBOSE="1"; shift ;;
2046 if echo "${MACRO}" | grep -q '\W'; then
2047 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2051 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2055 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2058 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2059 COMMAND="show_bconds"
2063 COMMAND="show_bcond_args"
2068 RPMOPTS="${RPMOPTS} --nodeps"
2071 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2074 Exit_error err_invalid_cmdline "$1"
2078 # check if specname was passed as specname:cvstag
2079 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2080 CVSTAG="${SPECFILE##*:}"
2081 SPECFILE="${SPECFILE%%:*}"
2083 ASSUMED_NAME="$(basename ${SPECFILE%%.spec})"
2088 if [ -f CVS/Entries ] && [ -z "$CVSTAG" ]; then
2089 CVSTAG=$(awk -vSPECFILE="${SPECFILE%.spec}.spec" -F/ '$2 == SPECFILE && $6 ~ /^T/{print substr($6, 2)}' CVS/Entries)
2090 if [ "$CVSTAG" ]; then
2091 echo >&2 "builder: Stick tag $CVSTAG active. Use -r TAGNAME to override."
2093 elif [ "$CVSTAG" = "HEAD" ]; then
2094 # assume -r HEAD is same as -A
2098 if [ -n "$DEBUG" ]; then
2103 if [ -n "$TARGET" ]; then
2106 TARGET_SWITCH="--target $TARGET" ;;
2108 TARGET_SWITCH="--target=$TARGET" ;;
2112 if [ "$SCHEDTOOL" != "no" ]; then
2113 NICE_COMMAND="$SCHEDTOOL"
2115 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2118 update_shell_title "$COMMAND"
2122 if [ -n "$SPECFILE" ]; then
2123 get_spec > /dev/null
2131 if [ -n "$SPECFILE" ]; then
2132 get_spec > /dev/null
2138 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2140 if [ -n "$SPECFILE" ]; then
2146 if [ "$COMMAND" != "build-source" ]; then
2149 fetch_build_requires
2150 if [ "$INTEGER_RELEASE" = "yes" ]; then
2151 echo "Checking release $PACKAGE_RELEASE..."
2152 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2153 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2157 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2158 if [ -n "$TEST_TAG" ]; then
2159 # - do not allow utf8 encoded specs on AC-branch
2160 if [ "$CVSTAG" = "AC-branch-disabled" ]; then
2162 t=$(grep '^Summary(.*\.UTF-8):' $SPECFILE)
2164 Exit_error err_acl_deny "UTF-8 .specs not allowed on $CVSTAG"
2168 local TAGVER=`make_tagver`
2169 echo "Searching for tag $TAGVER..."
2170 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
2171 if [ -n "$TAGREL" ]; then
2172 Exit_error err_tag_exists "$TAGVER" "$TAGREL"
2175 # - do not allow to build from HEAD when XX-branch exists
2176 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
2177 if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2178 TAG_BRANCH="${TREE_PREFIX}-branch"
2179 TAG_STATUS=$(cvs status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
2180 if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
2181 Exit_error err_branch_exists "$TAG_STATUS"
2187 if [ -n "$NOSOURCE0" ] ; then
2188 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2190 get_files $SOURCES $PATCHES
2193 if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
2194 run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
2196 remove_build_requires
2198 Exit_error err_no_spec_in_cmdl
2203 if [ -n "$SPECFILE" ]; then
2206 # don't fetch sources from remote locations
2208 for file in $SOURCES; do
2209 [ -n "`src_md5 $file`" ] && continue
2210 new_SOURCES="$new_SOURCES $file"
2212 SOURCES="$new_SOURCES"
2213 get_files $SOURCES $PATCHES
2215 branch_files $TAG $SOURCES $PATCHES $ICONS
2217 Exit_error err_no_spec_in_cmdl
2222 if [ -n "$SPECFILE" ]; then
2226 if [ -n "$NOSOURCE0" ] ; then
2227 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2229 get_files $SOURCES $PATCHES
2232 Exit_error err_no_spec_in_cmdl
2237 if [ -n "$SPECFILE" ]; then
2241 if [ -n "$NOSOURCE0" ] ; then
2242 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2246 Exit_error err_no_spec_in_cmdl
2253 if [ -n "$SPECFILE" ]; then
2257 # don't fetch sources from remote locations
2259 for file in $SOURCES; do
2260 [ -n "`src_md5 $file`" ] && continue
2261 new_SOURCES="$new_SOURCES $file"
2263 SOURCES="$new_SOURCES"
2264 get_files $SOURCES $PATCHES
2266 tag_files $SOURCES $PATCHES $ICONS
2268 Exit_error err_no_spec_in_cmdl
2272 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
2274 "list-sources-files" )
2277 DONT_PRINT_REVISION="yes"
2280 for SAP in $SOURCES $PATCHES; do
2281 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2284 "list-sources-urls" )
2287 DONT_PRINT_REVISION="yes"
2290 SAPS="$SOURCES $PATCHES"
2291 for SAP in $SAPS ; do
2295 "list-sources-local-paths" )
2298 DONT_PRINT_REVISION="yes"
2301 for SAP in $SOURCES $PATCHES; do
2302 echo $SOURCE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2305 "list-sources-distfiles-paths" )
2308 DONT_PRINT_REVISION="yes"
2311 for SAP in $SOURCES $PATCHES; do
2312 if [ -n "$(src_md5 "$SAP")" ]; then
2313 distfiles_path "$SAP"
2317 "list-sources-distfiles" )
2320 DONT_PRINT_REVISION="yes"
2323 for SAP in $SOURCES $PATCHES; do
2324 if [ -n "$(src_md5 "$SAP")" ]; then
2325 distfiles_url "$SAP"
2329 "list-sources-cvs" )
2332 DONT_PRINT_REVISION="yes"
2335 for SAP in $SOURCES $PATCHES; do
2336 if [ -z "$(src_md5 "$SAP")" ]; then
2337 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2351 echo "$VERSIONSTRING"
2354 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2355 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2359 # vi:syntax=sh:ts=4:sw=4:noet