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
13 # 8 - Failed installing buildrequirements and subrequirements
16 # - builder -u fetches current version first
17 # - tries to get new version from distfiles without new md5
18 # - after fetching new version doesn't update md5
19 # - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
20 # when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
21 # - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov
22 # - when Icon: field is present, -5 and -a5 doesn't work
25 Build package utility from PLD CVS repository
26 V 0.11 (C) 1999-2004 Free Penguins".
27 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
44 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
47 # It can be used i.e. in log file naming.
48 # See LOGFILE example.
49 DATE=`date +%Y-%m-%d_%H-%M-%S`
51 # Example: LOGFILE='../log.$PACKAGE_NAME'
52 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
53 # Yes, you can use variable name! Note _single_ quotes!
74 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
75 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
80 CVS_SERVER="cvs.pld-linux.org"
81 DISTFILES_SERVER="://distfiles.pld-linux.org"
85 FAIL_IF_NO_SOURCES="yes"
87 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
88 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
90 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
91 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
94 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
102 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
104 POLDEK_CMD="/usr/bin/poldek --noask"
106 # Here we load saved user environment used to
107 # predefine options set above, or passed to builder
109 # This one reads global system environment settings:
110 if [ -f ~/etc/builderrc ]; then
113 # And this one cascades settings using user personal
115 # Example of ~/.builderrc:
117 #UPDATE_POLDEK_INDEXES="yes"
118 #FETCH_BUILD_REQUIRES="yes"
119 #REMOVE_BUILD_REQUIRES="force"
121 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
123 if [ -n "$HOME_ETC" ]; then
124 USER_CFG="$HOME_ETC/.builderrc"
126 USER_CFG=~/.builderrc
129 [ -f "$USER_CFG" ] && . "$USER_CFG"
133 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
134 if [ -n "$LOGFILE" ]; then
135 LOG=`eval echo $LOGFILE`
136 if [ -n "$LASTLOG_FILE" ]; then
137 echo "LASTLOG=$LOG" > $LASTLOG_FILE
139 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee $LOG
142 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
143 return `cat ${RES_FILE}`
148 # Example grep cvs /etc/poldek.conf:
149 # source = cvs /home/users/yoshi/rpm/RPMS/
150 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
151 run_poldek -l -n ${POLDEK_SOURCE} 1>&2 > /dev/null
152 if [ ! "$?" == "0" ]; then
153 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
154 echo "Fix it and try to continue"
159 #---------------------------------------------
164 if [ -n "$DEBUG" ]; then set -xv; fi
166 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
168 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
169 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
170 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
171 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
172 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
173 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
174 [{-Tp|--tag-prefix} <prefix>]
175 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
176 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
178 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
179 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
180 -n5, --no-md5 - ignore md5 comments in spec
181 -D, --debug - enable script debugging mode,
182 -V, --version - output builder version
183 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
184 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
186 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
187 only package from <package>.spec,
188 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
190 -bp, --build-prep - execute the %prep phase of <package>.spec,
191 -B, --branch - add branch
192 -c, --clean - clean all temporarily created files (in BUILD, SOURCES,
193 SPECS and \$RPM_BUILD_ROOT),
194 -d <cvsroot>, --cvsroot <cvsroot>
196 --define <macro> <value>
197 - define a macro <macro> with value <value>,
198 --nodeps - rpm won't check any dependences
199 -g, --get - get <package>.spec and all related files from CVS repo
201 -h, --help - this message,
202 --http - use http instead of ftp,
203 -l <logfile>, --logtofile <logfile>
205 -m, --mr-proper - only remove all files related to spec file and all work
207 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
209 - don't check specs in CVS
210 -nd, --no-distfiles - don't download from distfiles
211 -nm, --no-mirrors - don't download from mirror, if source URL is given,
212 -nu, --no-urls - don't try to download from FTP/HTTP location,
213 -ns, --no-srcs - don't download Sources
214 -ns0, --no-source0 - don't download Source0
215 -nn, --no-net - don't download anything from the net
216 --opts <rpm opts> - additional options for rpm
217 -q, --quiet - be quiet,
218 --date yyyy-mm-dd - build package using resources from specified CVS date,
219 -r <cvstag>, --cvstag <cvstag>
220 - build package using resources from specified CVS tag,
221 -R, --fetch-build-requires
222 - fetch what is BuildRequired,
223 -RB, --remove-build-requires
224 - remove all you fetched with -R or --fetch-build-requires
225 remember, this option requires confirmation,
226 -FRB, --force-remove-build-requires
227 - remove all you fetched with -R or --fetch-build-requires
228 remember, this option works without confirmation,
229 -T <cvstag> , --tag <cvstag>
230 - add cvs tag <cvstag> for files,
231 -Tvs, --tag-version-stable
232 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
233 -Tvn, --tag-version-nest
234 - add cvs tags NEST and NAME-VERSION-RELESE for files,
236 - add cvs tag STABLE for files,
238 - add cvs tag NEST for files,
240 - add cvs tag NAME-VERSION-RELESE for files,
241 -Tp, --tag-prefix <prefix>
242 - add <prefix> to NAME-VERSION-RELEASE tags,
243 -v, --verbose - be verbose,
244 -u, --try-upgrade - check version, and try to upgrade package
245 -un, --try-upgrade-with-float-version
246 - as above, but allow float version
247 -U, --update - refetch sources, don't use distfiles, and update md5 comments
248 -Upi, --update-poldek-indexes
249 - refresh or make poldek package index files.
250 --with/--without <feature>
251 - conditional build package depending on %_with_<feature>/
252 %_without_<feature> macro switch. You may now use
253 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
254 constructions. Set GROUP_BCONDS to yes to make use of it.
262 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
265 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
271 if [ -z "$rpm_dump_cache" ] ; then
272 echo "internal error: cache_rpm_dump not called!" 1>&2
274 echo "$rpm_dump_cache"
279 if [ -n "$DEBUG" ]; then
288 if [ "$NOSRCS" != "yes" ]; then
289 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
291 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
292 FAIL_IF_NO_SOURCES="no"
295 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
296 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
297 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
298 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -n 1`"
299 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
301 if [ -n "$BE_VERBOSE" ]; then
302 echo "- Sources : `nourl $SOURCES`"
303 if [ -n "$PATCHES" ]; then
304 echo "- Patches : `nourl $PATCHES`"
306 echo "- Patches : *no patches needed*"
308 if [ -n "$ICONS" ]; then
309 echo "- Icon : `nourl $ICONS`"
311 echo "- Icon : *no package icon*"
313 echo "- Name : $PACKAGE_NAME"
314 echo "- Version : $PACKAGE_VERSION"
315 echo "- Release : $PACKAGE_RELEASE"
321 if [ -n "$DEBUG" ]; then
329 "err_no_spec_in_cmdl" )
330 remove_build_requires
331 echo "ERROR: spec file name not specified.";
333 "err_no_spec_in_repo" )
334 remove_build_requires
335 echo "Error: spec file not stored in CVS repo.";
337 "err_no_source_in_repo" )
338 remove_build_requires
339 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
342 remove_build_requires
343 echo "Error: package build failed. (${2:-no more info})";
350 if [ -n "$DEBUG" ]; then
355 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
356 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
363 if [ -n "$DEBUG" ]; then
369 if [ \! -f "$SPECFILE" ]; then
370 SPECFILE="`basename $SPECFILE .spec`.spec";
372 if [ "$NOCVSSPEC" != "yes" ]; then
375 if [ -n "$CVSROOT" ]; then
376 OPTIONS="-d $CVSROOT $OPTIONS"
378 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
379 echo "warning: No cvs access defined - using local .spec file"
384 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
385 OPTIONS="$OPTIONS -A"
387 if [ -n "$CVSDATE" ]; then
388 OPTIONS="$OPTIONS -D $CVSDATE"
390 if [ -n "$CVSTAG" ]; then
391 OPTIONS="$OPTIONS -r $CVSTAG"
397 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
399 retries_counter=$(( $retries_counter + 1 ))
400 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
402 [ -n "$output" ] && echo "$output"
403 if [ "$result" -ne "0" ]; then
404 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
405 echo "Trying again [$SPECFILE]... ($retries_counter)"
409 Exit_error err_no_spec_in_repo;
413 if [ ! -f "$SPECFILE" ]; then
414 Exit_error err_no_spec_in_repo;
417 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
418 chmod $CHMOD_MODE $SPECFILE
421 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
428 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
429 cvs update mirrors >&2
433 while read origin mirror name rest
435 ol=`echo -n "$origin"|wc -c`
436 prefix="`echo -n "$url" | head -c $ol`"
437 if [ "$prefix" = "$origin" ] ; then
438 suffix="`echo "$url"|cut -b $ol-`"
439 echo -n "$mirror$suffix"
450 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
451 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
457 [ X"$NO5" = X"yes" ] && return
459 [ -z "$no" ] && return
461 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
462 if [ -z "$spec_rev" ]; then
463 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
465 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
466 md5=$(grep -s -v '^#' additional-md5sums | \
467 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
468 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
469 grep -E '^[0-9a-f]{32}$')
470 if [ X"$md5" = X"" ] ; then
471 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
473 if [ $(echo "$md5" | wc -l) != 1 ] ; then
474 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
476 echo "$md5" | tail -n 1
482 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
485 distfiles_attic_url ()
487 echo "$PROTOCOL$DISTFILES_SERVER/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
494 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
501 if [ -n "$DEBUG" ]; then
506 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
510 if [ -n "$CVSROOT" ]; then
511 OPTIONS="-d $CVSROOT $OPTIONS"
513 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
514 echo "warning: No cvs access defined for SOURCES"
518 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
519 OPTIONS="$OPTIONS -A"
521 if [ -n "$CVSDATE" ]; then
522 OPTIONS="$OPTIONS -D $CVSDATE"
524 if [ -n "$CVSTAG" ]; then
525 OPTIONS="$OPTIONS -r $CVSTAG"
530 if [ -n "$UPDATE5" ]; then
531 if [ -n "$ADD5" ]; then
532 [ `nourl $i` = "$i" ] && continue
533 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
535 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
539 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
540 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
541 echo "Warning: no URL given for $i"
544 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
545 if good_md5 "$i"; then
546 echo "$(nourl "$i") having proper md5sum already exists"
550 url=$(distfiles_url "$i")
551 url_attic=$(distfiles_attic_url "$i")
553 if [ `echo $url | grep -E '^(\.|/)'` ]; then
554 ${GETLOCAL} $url $target
556 if [ -z "$NOMIRRORS" ]; then
557 url="`find_mirror "$url"`"
559 ${GETURI} -O "$target" "$url" || \
560 if [ `echo $url | grep -E 'ftp://'` ]; then
561 ${GETURI2} -O "$target" "$url"
564 if ! test -s "$target"; then
566 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
567 ${GETLOCAL} $url_attic $target
569 if [ -z "$NOMIRRORS" ]; then
570 url_attic="`find_mirror "$url_attic"`"
572 ${GETURI} -O "$target" "$url_attic" || \
573 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
574 ${GETURI2} -O "$target" "$url_attic"
578 if ! test -s "$target"; then
582 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
583 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
586 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
588 retries_counter=$(( $retries_counter + 1 ))
589 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
591 [ -n "$output" ] && echo "$output"
592 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
593 echo "Trying again [`nourl $i`]... ($retries_counter)"
602 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
603 if [ -z "$NOMIRRORS" ]; then
604 im="`find_mirror "$i"`"
609 if [ `echo $im | grep -E 'ftp://'` ]; then
616 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
617 Exit_error err_no_source_in_repo $i;
618 elif [ -n "$UPDATE5" ] && \
619 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
620 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
621 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
623 echo "Updating source-$srcno md5."
624 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
626 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
627 print "# Source'$srcno'-md5:\t'$md5'\n"
628 if /^Source'$srcno'\s*:\s+/;
633 if good_md5 "$i"; then
635 elif [ "$FROM_DISTFILES" = 1 ]; then
636 # wrong md5 from distfiles: remove the file and try again
638 echo "MD5 sum mismatch. Trying full fetch."
641 ${GETURI} -O "$target" "$url" || \
642 if [ `echo $url | grep -E 'ftp://'` ]; then
643 ${GETURI2} -O "$target" "$url"
645 if ! test -s "$target"; then
647 ${GETURI} -O "$target" "$url_attic" || \
648 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
649 ${GETURI2} -O "$target" "$url_attic"
652 test -s "$target" || rm -f "$target"
655 if good_md5 "$i"; then
658 echo "MD5 sum mismatch. Use -U to refetch sources,"
659 echo "or -5 to update md5 sums, if you're sure files are correct."
660 Exit_error err_no_source_in_repo $i
664 if [ "$CHMOD" = "yes" ]; then
665 CHMOD_FILES="`nourl $GET_FILES`"
666 if [ -n "$CHMOD_FILES" ]; then
667 chmod $CHMOD_MODE $CHMOD_FILES
678 if [ -n "$DEBUG" ]; then
683 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
684 echo "Version: $PACKAGE_VERSION"
685 echo "Release: $PACKAGE_RELEASE"
686 # Check whether first character of PACKAGE_NAME is legal for tag name
687 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
690 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"`
691 # Remove #kernel.version_release from TAGVER because tagging sources
692 # could occur with different kernel-headers than kernel-headers used at build time.
693 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
694 if [ "$TAG_VERSION" = "yes" ]; then
695 echo "CVS tag: $TAGVER"
697 if [ -n "$TAG" ]; then
702 if [ -n "$CVSROOT" ]; then
703 OPTIONS="-d $CVSROOT $OPTIONS"
709 # don't tag files stored on distfiles
710 [ -n "`src_md5 $i`" ] && continue
711 if [ -f "`nourl $i`" ]; then
712 if [ "$TAG_VERSION" = "yes" ]; then
713 cvs $OPTIONS $TAGVER `nourl $i`
715 if [ -n "$TAG" ]; then
716 cvs $OPTIONS $TAG `nourl $i`
719 Exit_error err_no_source_in_repo $i
724 if [ "$TAG_VERSION" = "yes" ]; then
725 cvs $OPTIONS $TAGVER $SPECFILE
727 if [ -n "$TAG" ]; then
728 cvs $OPTIONS $TAG $SPECFILE
738 echo "CVS branch tag: $TAG"
743 if [ -n "$DEBUG" ]; then
748 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
751 if [ -n "$CVSROOT" ]; then
752 OPTIONS="-d $CVSROOT $OPTIONS"
757 if [ -f `nourl $i` ]; then
758 cvs $OPTIONS $TAG `nourl $i`
760 Exit_error err_no_source_in_repo $i
764 cvs $OPTIONS $TAG $SPECFILE
774 if [ -n "$DEBUG" ]; then
781 if [ -n "$TRY_UPGRADE" ]; then
782 if [ -n "$FLOAT_VERSION" ]; then
783 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
785 TNOTIFY=`./pldnotify.awk $SPECFILE`
788 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
790 if [ -n "$TNEWVER" ]; then
791 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
792 echo "New version found, updating spec file to version " $TNEWVER
793 cp -f $SPECFILE $SPECFILE.bak
795 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
796 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
798 get_files "$SOURCES $PATCHES";
799 unset TOLDVER TNEWVER TNOTIFY
806 BUILD_SWITCH="-ba" ;;
808 BUILD_SWITCH="-bb" ;;
810 BUILD_SWITCH="-bs --nodeps" ;;
812 BUILD_SWITCH="-bp --nodeps" ;;
814 if [ -n "$LOGFILE" ]; then
815 LOG=`eval echo $LOGFILE`
816 if [ -d "$LOG" ]; then
817 echo "Log file $LOG is a directory."
818 echo "Parse error in the spec?"
819 Exit_error err_build_fail;
821 if [ -n "$LASTLOG_FILE" ]; then
822 echo "LASTLOG=$LOG" > $LASTLOG_FILE
824 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
825 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
826 RETVAL=`cat $RES_FILE`
828 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
829 if [ "$RETVAL" -eq "0" ]; then
836 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
839 if [ "$RETVAL" -ne "0" ]; then
840 if [ -n "$TRY_UPGRADE" ]; then
841 echo "\n!!! Package with new version cannot be build automagically\n"
842 mv -f $SPECFILE.bak $SPECFILE
844 Exit_error err_build_fail;
851 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
855 install_required_packages()
863 AVAIL_BCONDS_WITHOUT=""
865 if `grep -q ^%bcond ${SPECFILE}`; then
867 elif `grep -q bcond ${SPECFILE}`; then
872 case "${BCOND_VERSION}" in
877 echo "Warning: This spec has old style bconds. Fix it || die."
878 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
880 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
881 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
882 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
884 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
888 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
890 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
891 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
892 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
894 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
899 cond_type="" # with || without
900 for opt in `$RPMBUILD --bcond $SPECFILE`
913 AVAIL_BCOND_WITH="$opt"
914 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
915 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
917 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
922 AVAIL_BCOND_WITHOUT="$opt"
923 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
924 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
926 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
940 echo -ne "Package installation failed:\t$package_name\n"
942 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
943 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
944 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
945 # jakby nie bylo tego kawalka kodu.
947 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
948 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
956 # Istnieje taki spec? ${package}.spec
957 if [ -f "${SPECS_DIR}${package}.spec" ]; then
958 parent_spec_name=${package}.spec
959 elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
960 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
962 for provides_line in `grep ^Provides:.*$package ${SPECS_DIR} -R`
968 if [ "${parent_spec_name}" != "" ]; then
970 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
971 sub_builder_opts="${sub_builder_opts} -R"
973 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
974 sub_builder_opts="${sub_builder_opts} -RB"
975 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
976 sub_builder_opts="${sub_builder_opts} -FRB"
978 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
979 sub_builder_opts="${sub_builder_opts} -Upi"
982 ./builder ${sub_builder_opts} ${parent_spec_name}
984 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
987 remove_build_requires()
989 if [ "$INSTALLED_PACKAGES" != "" ]; then
990 case "$REMOVE_BUILD_REQUIRES" in
992 run_poldek --noask -ve $INSTALLED_PACKAGES
995 run_poldek --ask -ve $INSTALLED_PACKAGES
998 echo You may want to manually remove following BuildRequires fetched:
999 echo $INSTALLED_PACKAGES
1000 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1008 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1009 if [ "$BCOND" != "" ]; then
1010 echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1013 echo -ne "\nNo conditional flags passed"
1015 echo -ne "\n\nfrom available:\n"
1016 echo -ne "--with :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1020 fetch_build_requires()
1022 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1023 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1024 CONF=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print "@" $3 } ' | xargs)
1025 DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print "@" $3 } ' | xargs)
1026 if [ -n "$CONF" -o -n "$DEPS" ]; then
1027 /usr/bin/poldek --update; /usr/bin/poldek --upa
1029 if [ -n "$CONF" ]; then
1030 echo "Trying to uninstall conflicting packages ($CONF):"
1031 /usr/bin/poldek --noask --nofollow -ev $CONF
1033 if [ -n "$DEPS" ]; then
1034 echo "Trying to install dependencies ($DEPS):"
1035 /usr/bin/poldek -uGv $DEPS
1040 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1041 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1042 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1043 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1044 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1045 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`
1047 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`"
1049 package=`basename "$package_item"|sed -e "s/}$//g"`
1050 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1053 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1054 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1055 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
1060 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1063 if `echo $COND_TST|grep -q 'without_'`; then
1064 COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1065 if `echo $COND_TST|grep -q !`; then
1070 if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1076 elif `echo $COND_TST|grep -q 'with_'`; then
1077 COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1078 if `echo $COND_TST|grep -q !`; then
1083 if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1089 RESULT="${COND_STATE}-${COND_ARGV}"
1091 "with-wout" | "wout-with" )
1094 "wout-wout" | "with-with" )
1098 echo "Action '$RESULT' was not defined for package '$package_item'"
1104 if [ "$GO" = "yes" ]; then
1105 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1106 echo "Testing if $package has subrequirements..."
1107 run_poldek -t -i $package --dumpn=".$package-req.txt"
1108 if [ -f ".$package-req.txt" ]; then
1109 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1111 if [ "$package_name" = "$package" ]; then
1112 echo -ne "Installing BuildRequired package:\t$package_name\n"
1113 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1114 install_required_packages $package;
1116 echo -ne "Installing (sub)Required package:\t$package_name\n"
1117 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1118 install_required_packages $package_name;
1122 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1123 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1126 echo "Attempting to run spawn sub - builder..."
1127 run_sub_builder $package_name
1128 if [ $? -eq 0 ]; then
1129 install_required_packages $package_name;
1132 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1133 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1136 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1143 rm -f ".$package-req.txt"
1145 echo "Attempting to run spawn sub - builder..."
1146 run_sub_builder $package
1147 if [ $? -eq 0 ]; then
1148 install_required_packages $package;
1151 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1152 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1155 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1161 echo "Package $package is already installed. BuildRequirement satisfied."
1165 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1166 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1167 echo "Unable to install following packages and their dependencies:"
1168 for pkg in "$NOT_INSTALLED_PACKAGES"
1172 remove_build_requires
1178 #---------------------------------------------
1181 if [ "$#" = 0 ]; then
1207 DEBUG="yes"; shift ;;
1209 COMMAND="version"; shift ;;
1211 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1212 -b | -ba | --build )
1213 COMMAND="build"; shift ;;
1214 -bb | --build-binary )
1215 COMMAND="build-binary"; shift ;;
1216 -bs | --build-source )
1217 COMMAND="build-source"; shift ;;
1218 -bp | --build-prep )
1219 COMMAND="build-prep"; shift ;;
1221 COMMAND="branch"; shift; TAG="${1}"; shift;;
1223 CLEAN="--clean --rmspec --rmsource"; shift ;;
1225 shift; CVSROOT="${1}"; shift ;;
1227 COMMAND="get"; shift ;;
1229 COMMAND="usage"; shift ;;
1231 PROTOCOL="http"; shift ;;
1233 shift; LOGFILE="${1}"; shift ;;
1235 shift; DEF_NICE_LEVEL=${1}; shift ;;
1237 COMMAND="mr-proper"; shift ;;
1239 NOCVS="yes"; shift ;;
1240 -ncs | --no-cvs-specs )
1241 NOCVSSPEC="yes"; shift ;;
1242 -nd | --no-distfiles )
1243 NODIST="yes"; shift ;;
1244 -nm | --no-mirrors )
1245 NOMIRRORS="yes"; shift ;;
1247 NOURLS="yes"; shift ;;
1249 NOSRCS="yes"; shift ;;
1250 -ns0 | --no-source0 )
1251 NOSOURCE0="yes"; shift ;;
1261 shift; RPMOPTS="${1}"; shift ;;
1262 --with | --without )
1263 case $GROUP_BCONDS in
1267 while ! `echo ${1}|grep -qE '(^-|spec)'`
1269 BCOND="$BCOND $COND $1"
1273 BCOND="$BCOND $1 $2" ; shift 2 ;;
1277 QUIET="--quiet"; shift ;;
1279 CVSDATE="${2}"; shift 2 ;;
1281 shift; CVSTAG="${1}"; shift ;;
1282 -R | --fetch-build-requires)
1283 FETCH_BUILD_REQUIRES="yes"
1284 NOT_INSTALLED_PACKAGES=
1286 -RB | --remove-build-requires)
1287 REMOVE_BUILD_REQUIRES="nice"
1289 -FRB | --force-remove-build-requires)
1290 REMOVE_BUILD_REQUIRES="force"
1292 -Tvs | --tag-version-stable )
1297 -Tvn | --tag-version-nest )
1302 -Ts | --tag-stable )
1312 -Tv | --tag-version )
1317 -Tp | --tag-prefix )
1333 -Upi | --update-poldek-indexes )
1334 UPDATE_POLDEK_INDEXES="yes"
1336 -u | --try-upgrade )
1337 TRY_UPGRADE="1"; shift ;;
1338 -un | --try-upgrade-with-float-version )
1339 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1341 BE_VERBOSE="1"; shift ;;
1347 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1351 RPMOPTS="${RPMOPTS} --nodeps"
1355 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1360 if [ -n "$DEBUG" ]; then
1366 "build" | "build-binary" | "build-source" | "build-prep" )
1368 if [ -n "$SPECFILE" ]; then
1372 fetch_build_requires;
1375 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
1376 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1377 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
1378 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1380 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
1381 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
1385 if [ -n "$ICONS" ]; then
1389 if [ -n "$NOSOURCE0" ] ; then
1390 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1392 get_files "$SOURCES $PATCHES";
1394 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1395 run_poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1396 run_poldek --sn ${POLDEK_SOURCE} --up
1398 remove_build_requires;
1400 Exit_error err_no_spec_in_cmdl;
1405 if [ -n "$SPECFILE" ]; then
1408 if [ -n "$ICONS" ]; then
1412 get_files $SOURCES $PATCHES;
1413 branch_files $TAG "$SOURCES $PATCHES $ICONS";
1415 Exit_error err_no_spec_in_cmdl;
1420 if [ -n "$SPECFILE" ]; then
1423 if [ -n "$ICONS" ]; then
1427 if [ -n "$NOSOURCE0" ] ; then
1428 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1430 get_files $SOURCES $PATCHES
1432 Exit_error err_no_spec_in_cmdl;
1439 if [ -n "$SPECFILE" ]; then
1442 if [ -n "$ICONS" ]; then
1446 # don't fetch sources from remote locations
1448 for file in $SOURCES
1450 [ -n "`src_md5 $file`" ] && continue
1451 new_SOURCES="$new_SOURCES $file"
1453 SOURCES="$new_SOURCES"
1454 get_files $SOURCES $PATCHES;
1455 tag_files "$SOURCES $PATCHES $ICONS";
1457 Exit_error err_no_spec_in_cmdl;
1461 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1468 test -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES && rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1471 # vi:syntax=sh:ts=3:sw=4