7 # 2 - no spec file name in cmdl parameters
8 # 3 - spec file not stored in repo
9 # 4 - some source, patch or icon files not stored in repo
10 # 5 - package build failed
11 # 6 - spec file with errors
12 # 7 - wrong source in /etc/poldek.conf
15 # - builder -u fetches current version first
16 # - tries to get new version from distfiles without new md5
17 # - after fetching new version doesn't update md5
18 # - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
19 # when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
20 # - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov
21 # - when Icon: field is present, -5 and -a5 doesn't work
24 Build package utility from PLD CVS repository
25 V 0.11 (C) 1999-2003 Free Penguins".
26 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
42 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
45 # It can be used i.e. in log file naming.
46 # See LOGFILE example.
47 DATE=`date +%Y-%m-%d_%H-%M-%S`
49 # Example: LOGFILE='../log.$PACKAGE_NAME'
50 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
51 # Yes, you can use variable name! Note _single_ quotes!
72 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
73 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
78 CVS_SERVER="cvs.pld-linux.org"
79 DISTFILES_SERVER="://distfiles.pld-linux.org"
83 FAIL_IF_NO_SOURCES="yes"
85 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
86 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
88 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
89 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
92 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
100 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
103 # Here we load saved user environment used to
104 # predefine options set above, or passed to builder
106 # This one reads global system environment settings:
107 if [ -f ~/etc/builderrc ]; then
110 # And this one cascades settings using user personal
112 # Example of ~/.builderrc:
114 #UPDATE_POLDEK_INDEXES="yes"
115 #FETCH_BUILD_REQUIRES="yes"
116 #REMOVE_BUILD_REQUIRES="force"
118 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
120 if [ -n "$HOME_ETC" ]; then
121 USER_CFG=$HOME_ETC/.builderrc
123 USER_CFG=~/.builderrc
126 [ -f $USER_CFG ] && . $USER_CFG
128 # Example grep cvs /etc/poldek.conf:
129 # source = cvs /home/users/yoshi/rpm/RPMS/
130 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
131 POLDEK_SOURCE_VALIDITY="`grep ${POLDEK_SOURCE} /etc/poldek.conf|grep -v ^#`"
132 if [ "${POLDEK_SOURCE_VALIDITY}" = "" ]; then
133 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
134 echo "Fix it and try to continue"
139 #---------------------------------------------
144 if [ -n "$DEBUG" ]; then set -xv; fi
146 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
148 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
149 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
150 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
151 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
152 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
153 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
154 [{-Tp|--tag-prefix} <prefix>]
155 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
156 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
158 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
159 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
160 -D, --debug - enable script debugging mode,
161 -V, --version - output builder version
162 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
163 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
165 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
166 only package from <package>.spec,
167 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
169 -bp, --build-prep - execute the %prep phase of <package>.spec,
170 -B, --branch - add branch
171 -c, --clean - clean all temporarily created files (in BUILD, SOURCES,
172 SPECS and \$RPM_BUILD_ROOT),
173 -d <cvsroot>, --cvsroot <cvsroot>
175 --define <macro> <value>
176 - define a macro <macro> with value <value>,
177 --nodeps - rpm won't check any dependences
178 -g, --get - get <package>.spec and all related files from CVS repo
180 -h, --help - this message,
181 --http - use http instead of ftp,
182 -l <logfile>, --logtofile <logfile>
184 -m, --mr-proper - only remove all files related to spec file and all work
186 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
188 - don't check specs in CVS
189 -nd, --no-distfiles - don't download from distfiles
190 -nm, --no-mirrors - don't download from mirror, if source URL is given,
191 -nu, --no-urls - don't try to download from FTP/HTTP location,
192 -ns, --no-srcs - don't download Sources
193 -ns0, --no-source0 - don't download Source0
194 --opts <rpm opts> - additional options for rpm
195 -q, --quiet - be quiet,
196 --date yyyy-mm-dd - build package using resources from specified CVS date,
197 -r <cvstag>, --cvstag <cvstag>
198 - build package using resources from specified CVS tag,
199 -R, --fetch-build-requires
200 - fetch what is BuildRequired,
201 -RB, --remove-build-requires
202 - remove all you fetched with -R or --fetch-build-requires
203 remember, this option requires confirmation,
204 -FRB, --force-remove-build-requires
205 - remove all you fetched with -R or --fetch-build-requires
206 remember, this option works without confirmation,
207 -T <cvstag> , --tag <cvstag>
208 - add cvs tag <cvstag> for files,
209 -Tvs, --tag-version-stable
210 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
211 -Tvn, --tag-version-nest
212 - add cvs tags NEST and NAME-VERSION-RELESE for files,
214 - add cvs tag STABLE for files,
216 - add cvs tag NEST for files,
218 - add cvs tag NAME-VERSION-RELESE for files,
219 -Tp, --tag-prefix <prefix>
220 - add <prefix> to NAME-VERSION-RELEASE tags,
221 -v, --verbose - be verbose,
222 -u, --try-upgrade - check version, and try to upgrade package
223 -un, --try-upgrade-with-float-version
224 - as above, but allow float version
225 -U, --update - refetch sources, don't use distfiles, and update md5 comments
226 -Upi, --update-poldek-indexes
227 - refresh or make poldek package index files.
228 --with/--without <feature>
229 - conditional build package depending on %_with_<feature>/
230 %_without_<feature> macro switch. You may now use
231 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
232 constructions. Set GROUP_BCONDS to yes to make use of it.
240 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
243 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
249 if [ -z "$rpm_dump_cache" ] ; then
250 echo "internal error: cache_rpm_dump not called!" 1>&2
252 echo "$rpm_dump_cache"
257 if [ -n "$DEBUG" ]; then
266 if [ "$NOSRCS" != "yes" ]; then
267 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
269 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
270 FAIL_IF_NO_SOURCES="no"
273 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
274 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
275 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
276 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
277 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
279 if [ -n "$BE_VERBOSE" ]; then
280 echo "- Sources : `nourl $SOURCES`"
281 if [ -n "$PATCHES" ]; then
282 echo "- Patches : `nourl $PATCHES`"
284 echo "- Patches : *no patches needed*"
286 if [ -n "$ICONS" ]; then
287 echo "- Icon : `nourl $ICONS`"
289 echo "- Icon : *no package icon*"
291 echo "- Name : $PACKAGE_NAME"
292 echo "- Version : $PACKAGE_VERSION"
293 echo "- Release : $PACKAGE_RELEASE"
299 if [ -n "$DEBUG" ]; then
307 "err_no_spec_in_cmdl" )
308 remove_build_requires
309 echo "ERROR: spec file name not specified.";
311 "err_no_spec_in_repo" )
312 remove_build_requires
313 echo "Error: spec file not stored in CVS repo.";
315 "err_no_source_in_repo" )
316 remove_build_requires
317 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
320 remove_build_requires
321 echo "Error: package build failed. (${2:-no more info})";
328 if [ -n "$DEBUG" ]; then
333 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
334 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
341 if [ -n "$DEBUG" ]; then
346 if [ "$NOCVSSPEC" != "yes" ]; then
351 if [ -n "$CVSROOT" ]; then
352 OPTIONS="-d $CVSROOT $OPTIONS"
354 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
355 echo "warning: No cvs access defined - using local .spec file"
360 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
361 OPTIONS="$OPTIONS -A"
363 if [ -n "$CVSDATE" ]; then
364 OPTIONS="$OPTIONS -D $CVSDATE"
366 if [ -n "$CVSTAG" ]; then
367 OPTIONS="$OPTIONS -r $CVSTAG"
373 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
375 retries_counter=$(( $retries_counter + 1 ))
376 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
378 [ -n "$output" ] && echo "$output"
379 if [ "$result" -ne "0" ]; then
380 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
381 echo "Trying again [$SPECFILE]... ($retries_counter)"
385 Exit_error err_no_spec_in_repo;
389 if [ ! -f "$SPECFILE" ]; then
390 Exit_error err_no_spec_in_repo;
393 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
394 chmod $CHMOD_MODE $SPECFILE
397 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
404 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
405 cvs update mirrors >&2
409 while read origin mirror name rest
411 ol=`echo -n "$origin"|wc -c`
412 prefix="`echo -n "$url" | head -c $ol`"
413 if [ "$prefix" = "$origin" ] ; then
414 suffix="`echo "$url"|cut -b $ol-`"
415 echo -n "$mirror$suffix"
426 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
427 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
434 [ -z "$no" ] && return
436 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
437 if [ -z "$spec_rev" ]; then
438 spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
440 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
441 md5=$(grep -s -v '^#' additional-md5sums | \
442 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
443 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
444 grep -E '^[0-9a-f]{32}$')
445 if [ X"$md5" = X"" ] ; then
446 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
448 if [ $(echo "$md5" | wc -l) != 1 ] ; then
449 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
451 echo "$md5" | tail -1
457 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
464 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
471 if [ -n "$DEBUG" ]; then
476 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
480 if [ -n "$CVSROOT" ]; then
481 OPTIONS="-d $CVSROOT $OPTIONS"
483 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
484 echo "warning: No cvs access defined for SOURCES"
488 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
489 OPTIONS="$OPTIONS -A"
491 if [ -n "$CVSDATE" ]; then
492 OPTIONS="$OPTIONS -D $CVSDATE"
494 if [ -n "$CVSTAG" ]; then
495 OPTIONS="$OPTIONS -r $CVSTAG"
500 if [ -n "$UPDATE5" ]; then
501 if [ -n "$ADD5" ]; then
502 [ `nourl $i` = "$i" ] && continue
503 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
505 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
509 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
510 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
511 echo "Warning: no URL given for $i"
514 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
515 if good_md5 "$i"; then
516 echo "$(nourl "$i") having proper md5sum already exists"
520 url=$(distfiles_url "$i")
521 if [ `echo $url | grep -E '^(\.|/)'` ]; then
522 ${GETLOCAL} $url $target
525 if [ -z "$NOMIRRORS" ]; then
526 url="`find_mirror "$url"`"
528 ${GETURI} -O "$target" "$url" || \
529 if [ `echo $url | grep -E 'ftp://'` ]; then
530 ${GETURI2} -O "$target" "$url"
532 if ! test -s "$target"; then
537 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
538 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
541 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
543 retries_counter=$(( $retries_counter + 1 ))
544 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
546 [ -n "$output" ] && echo "$output"
547 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
548 echo "Trying again [`nourl $i`]... ($retries_counter)"
557 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
558 if [ -z "$NOMIRRORS" ]; then
559 im="`find_mirror "$i"`"
564 if [ `echo $im | grep -E 'ftp://'` ]; then
572 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
573 Exit_error err_no_source_in_repo $i;
574 elif [ -n "$UPDATE5" ] && \
575 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
576 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
577 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
579 echo "Updating source-$srcno md5."
580 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
582 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
583 print "# Source'$srcno'-md5:\t'$md5'\n"
584 if /^Source'$srcno'\s*:\s+/;
589 if good_md5 "$i"; then
591 elif [ "$FROM_DISTFILES" = 1 ]; then
592 # wrong md5 from distfiles: remove the file and try again
594 echo "MD5 sum mismatch. Trying full fetch."
597 ${GETURI} -O "$target" "$url" || \
598 if [ `echo $url | grep -E 'ftp://'` ]; then
599 ${GETURI2} -O "$target" "$url"
601 test -s "$target" || rm -f "$target"
604 if good_md5 "$i"; then
607 echo "MD5 sum mismatch. Use -U to refetch sources,"
608 echo "or -5 to update md5 sums, if you're sure files are correct."
609 Exit_error err_no_source_in_repo $i
613 if [ "$CHMOD" = "yes" ]; then
614 CHMOD_FILES="`nourl $GET_FILES`"
615 if [ -n "$CHMOD_FILES" ]; then
616 chmod $CHMOD_MODE $CHMOD_FILES
627 if [ -n "$DEBUG" ]; then
632 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
633 echo "Version: $PACKAGE_VERSION"
634 echo "Release: $PACKAGE_RELEASE"
635 # Check whether first character of PACKAGE_NAME is legal for tag name
636 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
639 TAGVER=$TAG_PREFIX$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
640 # Remove #kernel.version_release from TAGVER because tagging sources
641 # could occur with different kernel-headers than kernel-headers used at build time.
642 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
643 if [ "$TAG_VERSION" = "yes" ]; then
644 echo "CVS tag: $TAGVER"
646 if [ -n "$TAG" ]; then
651 if [ -n "$CVSROOT" ]; then
652 OPTIONS="-d $CVSROOT $OPTIONS"
658 # don't tag non cvs files (ie. stored on distfiles)
659 [ "`nourl $i`" != "$i" ] && continue
660 if [ -f "`nourl $i`" ]; then
661 if [ "$TAG_VERSION" = "yes" ]; then
662 cvs $OPTIONS $TAGVER `nourl $i`
664 if [ -n "$TAG" ]; then
665 cvs $OPTIONS $TAG `nourl $i`
668 Exit_error err_no_source_in_repo $i
673 if [ "$TAG_VERSION" = "yes" ]; then
674 cvs $OPTIONS $TAGVER $SPECFILE
676 if [ -n "$TAG" ]; then
677 cvs $OPTIONS $TAG $SPECFILE
687 echo "CVS branch tag: $TAG"
692 if [ -n "$DEBUG" ]; then
697 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
700 if [ -n "$CVSROOT" ]; then
701 OPTIONS="-d $CVSROOT $OPTIONS"
706 if [ -f `nourl $i` ]; then
707 cvs $OPTIONS $TAG `nourl $i`
709 Exit_error err_no_source_in_repo $i
713 cvs $OPTIONS $TAG $SPECFILE
723 if [ -n "$DEBUG" ]; then
730 if [ -n "$TRY_UPGRADE" ]; then
731 if [ -n "$FLOAT_VERSION" ]; then
732 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
734 TNOTIFY=`./pldnotify.awk $SPECFILE`
737 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
739 if [ -n "$TNEWVER" ]; then
740 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
741 echo "New version found, updating spec file to version " $TNEWVER
742 cp -f $SPECFILE $SPECFILE.bak
744 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
745 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
747 get_files "$SOURCES $PATCHES";
748 unset TOLDVER TNEWVER TNOTIFY
755 BUILD_SWITCH="-ba" ;;
757 BUILD_SWITCH="-bb" ;;
759 BUILD_SWITCH="-bs --nodeps" ;;
761 BUILD_SWITCH="-bp --nodeps" ;;
763 if [ -n "$LOGFILE" ]; then
764 LOG=`eval echo $LOGFILE`
765 if [ -n "$LASTLOG_FILE" ]; then
766 echo "LASTLOG=$LOG" > $LASTLOG_FILE
768 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
769 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
770 RETVAL=`cat $RES_FILE`
772 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
773 if [ "$RETVAL" -eq "0" ]; then
780 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
783 if [ "$RETVAL" -ne "0" ]; then
784 if [ -n "$TRY_UPGRADE" ]; then
785 echo "\n!!! Package with new version cannot be build automagically\n"
786 mv -f $SPECFILE.bak $SPECFILE
788 Exit_error err_build_fail;
795 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
800 AVAIL_BCONDS_WITHOUT=""
802 TEST_BCOND_VERSION="`grep ^%bcond ${SPECFILE}`"
803 if [ "${TEST_BCOND_VERSION}" == "" ]; then
809 case "${BCOND_VERSION}" in
811 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
813 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
814 if [ "`echo $BCOND|grep -- "--without $AVAIL_BCOND_WITHOUT"`" != "" ];then
815 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
817 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
821 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
823 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
824 if [ "`echo $BCOND|grep -- "--with $AVAIL_BCOND_WITH"`" != "" ];then
825 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
827 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
832 cond_type="" # with || without
833 for opt in `$RPMBUILD --bcond $SPECFILE`
846 AVAIL_BCOND_WITH="$opt"
847 if [ "`echo $BCOND|grep -- "--with $AVAIL_BCOND_WITH"`" != "" ];then
848 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
850 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
855 AVAIL_BCOND_WITHOUT="$opt"
856 if [ "`echo $BCOND|grep -- "--without $AVAIL_BCOND_WITHOUT"`" != "" ];then
857 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
859 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
873 echo -ne "Package installation failed:\t$package_name\n"
875 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
876 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
877 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
878 # jakby nie bylo tego kawalka kodu.
880 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
881 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
889 # Istnieje taki spec? ${package}.spec
890 if [ -f "${POLDEK_INDEX_DIR}/../SPECS/${package}.spec" ]; then
891 parent_spec_name=${package}.spec
892 elif [ -f "${POLDEK_INDEX_DIR}/../SPECS/`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
893 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
895 for provides_line in `grep ^Provides:.*$package ${POLDEK_INDEX_DIR}/../SPECS/ -R`
901 if [ "${parent_spec_name}" != "" ]; then
903 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
904 sub_builder_opts="${sub_builder_opts} -R"
906 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
907 sub_builder_opts="${sub_builder_opts} -RB"
908 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
909 sub_builder_opts="${sub_builder_opts} -FRB"
911 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
912 sub_builder_opts="${sub_builder_opts} -Upi"
914 cd "${POLDEK_INDEX_DIR}/../SPECS"
915 ./builder ${sub_builder_opts} ${parent_spec_name}
917 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
920 remove_build_requires()
922 if [ "$INSTALLED_PACKAGES" != "" ]; then
923 case "$REMOVE_BUILD_REQUIRES" in
925 poldek --noask -e $INSTALLED_PACKAGES
928 poldek --ask -e $INSTALLED_PACKAGES
931 echo You may want to manually remove following BuildRequires fetched:
932 echo $INSTALLED_PACKAGES
933 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
941 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
942 echo -ne "We are going to build $SPECFILE with the following conditional flags:\n"
943 if [ "$BCOND" != "" ]; then
946 echo -ne "No --with || --without conditions passed to $0!"
948 echo -ne "\n\nfrom available:\n\n"
949 echo -ne "--with :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
953 fetch_build_requires()
955 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
956 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
957 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
958 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
959 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
960 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
961 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,kgcc_package,gcc,g -e s,\),,g`
963 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`"
965 package=`basename "$package_item"|sed -e "s/}$//g"`
966 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
969 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
970 if [ "`echo $COND_TST|grep '^BuildRequires:'`" != "" ]; then
971 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
976 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
979 if [ "`echo $COND_TST|grep 'without_'`" != "" ]; then
980 COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
981 if [ "`echo $COND_TST|grep !`" != "" ]; then
986 if [ "`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`" != "" ]; then
992 elif [ "`echo $COND_TST|grep 'with_'`" != "" ]; then
993 COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
994 if [ "`echo $COND_TST|grep !`" != "" ]; then
999 if [ "`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`" != "" ]; then
1005 RESULT="${COND_STATE}-${COND_ARGV}"
1007 "with-wout" | "wout-with" )
1010 "wout-wout" | "with-with" )
1014 echo "Action '$RESULT' was not defined for package '$package_item'"
1020 if [ "$GO" = "yes" ]; then
1021 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1022 echo "Testing if $package has subrequirements..."
1023 poldek -t -i $package --dumpn=".$package-req.txt"
1024 if [ -f ".$package-req.txt" ]; then
1025 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1027 if [ "$package_name" = "$package" ]; then
1028 echo -ne "Installing BuildRequired package:\t$package_name\n"
1029 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1030 poldek -i $package_name
1032 echo -ne "Installing (sub)Required package:\t$package_name\n"
1033 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1034 poldek -i $package_name
1038 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1039 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1042 echo "Attempting to run spawn sub - builder..."
1043 run_sub_builder $package_name
1044 if [ $? -eq 0 ]; then
1045 poldek -i $package_name
1048 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1049 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1052 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1059 rm -f ".$package-req.txt"
1061 echo "Attempting to run spawn sub - builder..."
1062 run_sub_builder $package
1063 if [ $? -eq 0 ]; then
1064 poldek -i $package_name
1067 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1068 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1071 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1077 echo "Package $package is already installed. BuildRequirement satisfied."
1081 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1082 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1083 echo "Nie uda³o siê zainstalowaæ nastêpuj±cych pakietów i ich zale¿no¶ci:"
1084 for pkg in "$NOT_INSTALLED_PACKAGES"
1088 remove_build_requires
1094 #---------------------------------------------
1097 if [ "$#" = 0 ]; then
1120 DEBUG="yes"; shift ;;
1122 COMMAND="version"; shift ;;
1124 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1125 -b | -ba | --build )
1126 COMMAND="build"; shift ;;
1127 -bb | --build-binary )
1128 COMMAND="build-binary"; shift ;;
1129 -bs | --build-source )
1130 COMMAND="build-source"; shift ;;
1131 -bp | --build-prep )
1132 COMMAND="build-prep"; shift ;;
1134 COMMAND="branch"; shift; TAG="${1}"; shift;;
1136 CLEAN="--clean --rmspec --rmsource"; shift ;;
1138 shift; CVSROOT="${1}"; shift ;;
1140 COMMAND="get"; shift ;;
1142 COMMAND="usage"; shift ;;
1144 PROTOCOL="http"; shift ;;
1146 shift; LOGFILE="${1}"; shift ;;
1148 shift; DEF_NICE_LEVEL=${1}; shift ;;
1150 COMMAND="mr-proper"; shift ;;
1152 NOCVS="yes"; shift ;;
1153 -ncs | --no-cvs-specs )
1154 NOCVSSPEC="yes"; shift ;;
1155 -nd | --no-distfiles )
1156 NODIST="yes"; shift ;;
1157 -nm | --no-mirrors )
1158 NOMIRRORS="yes"; shift ;;
1160 NOURLS="yes"; shift ;;
1162 NOSRCS="yes"; shift ;;
1163 -ns0 | --no-source0 )
1164 NOSOURCE0="yes"; shift ;;
1166 shift; RPMOPTS="${1}"; shift ;;
1167 --with | --without )
1168 case $GROUP_BCONDS in
1172 while [ "`echo ${1}|grep ^-`" = "" ] && [ "`echo ${1}|grep spec`" = "" ]
1174 BCOND="$BCOND $COND $1"
1178 BCOND="$BCOND $1 $2" ; shift 2 ;;
1182 QUIET="--quiet"; shift ;;
1184 CVSDATE="${2}"; shift 2 ;;
1186 shift; CVSTAG="${1}"; shift ;;
1187 -R | --fetch-build-requires)
1188 FETCH_BUILD_REQUIRES="yes"
1189 NOT_INSTALLED_PACKAGES=
1191 -RB | --remove-build-requires)
1192 REMOVE_BUILD_REQUIRES="nice"
1194 -FRB | --force-remove-build-requires)
1195 REMOVE_BUILD_REQUIRES="force"
1197 -Tvs | --tag-version-stable )
1202 -Tvn | --tag-version-nest )
1207 -Ts | --tag-stable )
1217 -Tv | --tag-version )
1222 -Tp | --tag-prefix )
1238 -Upi | --update-poldek-indexes )
1239 UPDATE_POLDEK_INDEXES="yes"
1241 -u | --try-upgrade )
1242 TRY_UPGRADE="1"; shift ;;
1243 -un | --try-upgrade-with-float-version )
1244 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1246 BE_VERBOSE="1"; shift ;;
1252 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1256 RPMOPTS="${RPMOPTS} --nodeps"
1259 SPECFILE="`basename ${1} .spec`.spec";
1260 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1265 if [ -n "$DEBUG" ]; then
1271 "build" | "build-binary" | "build-source" | "build-prep" )
1273 if [ -n "$SPECFILE" ]; then
1277 fetch_build_requires;
1280 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
1281 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1282 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
1283 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1285 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
1286 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
1290 if [ -n "$ICONS" ]; then
1294 if [ -n "$NOSOURCE0" ] ; then
1295 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1297 get_files "$SOURCES $PATCHES";
1299 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1300 poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1301 poldek --sn ${POLDEK_SOURCE} --up
1303 remove_build_requires;
1305 Exit_error err_no_spec_in_cmdl;
1310 if [ -n "$SPECFILE" ]; then
1313 if [ -n "$ICONS" ]; then
1317 get_files $SOURCES $PATCHES;
1318 branch_files $TAG "$SOURCES $PATCHES $ICONS";
1320 Exit_error err_no_spec_in_cmdl;
1325 if [ -n "$SPECFILE" ]; then
1328 if [ -n "$ICONS" ]; then
1332 if [ -n "$NOSOURCE0" ] ; then
1333 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1335 get_files $SOURCES $PATCHES
1337 Exit_error err_no_spec_in_cmdl;
1342 if [ -n "$SPECFILE" ]; then
1345 if [ -n "$ICONS" ]; then
1349 # don't fetch sources from remote locations
1351 for file in $SOURCES
1353 [ "`nourl $file`" != "$file" ] && continue
1354 new_SOURCES="$new_SOURCES $file"
1356 SOURCES="$new_SOURCES"
1357 get_files $SOURCES $PATCHES;
1358 tag_files "$SOURCES $PATCHES $ICONS";
1360 Exit_error err_no_spec_in_cmdl;
1364 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1373 # vi:syntax=sh:tw=80:ts=3:sw=4