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>] [{-tt|--test-tag}]
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 -tt, --test-tag <prefix>
244 - fail if tag is already present,
245 -v, --verbose - be verbose,
246 -u, --try-upgrade - check version, and try to upgrade package
247 -un, --try-upgrade-with-float-version
248 - as above, but allow float version
249 -U, --update - refetch sources, don't use distfiles, and update md5 comments
250 -Upi, --update-poldek-indexes
251 - refresh or make poldek package index files.
252 --with/--without <feature>
253 - conditional build package depending on %_with_<feature>/
254 %_without_<feature> macro switch. You may now use
255 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
256 constructions. Set GROUP_BCONDS to yes to make use of it.
264 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
267 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
273 if [ -z "$rpm_dump_cache" ] ; then
274 echo "internal error: cache_rpm_dump not called!" 1>&2
276 echo "$rpm_dump_cache"
281 if [ -n "$DEBUG" ]; then
290 if [ "$NOSRCS" != "yes" ]; then
291 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
293 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
294 FAIL_IF_NO_SOURCES="no"
297 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
298 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
299 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
300 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -n 1`"
301 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
303 if [ -n "$BE_VERBOSE" ]; then
304 echo "- Sources : `nourl $SOURCES`"
305 if [ -n "$PATCHES" ]; then
306 echo "- Patches : `nourl $PATCHES`"
308 echo "- Patches : *no patches needed*"
310 if [ -n "$ICONS" ]; then
311 echo "- Icon : `nourl $ICONS`"
313 echo "- Icon : *no package icon*"
315 echo "- Name : $PACKAGE_NAME"
316 echo "- Version : $PACKAGE_VERSION"
317 echo "- Release : $PACKAGE_RELEASE"
323 if [ -n "$DEBUG" ]; then
331 "err_no_spec_in_cmdl" )
332 remove_build_requires
333 echo "ERROR: spec file name not specified.";
335 "err_no_spec_in_repo" )
336 remove_build_requires
337 echo "Error: spec file not stored in CVS repo.";
339 "err_no_source_in_repo" )
340 remove_build_requires
341 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
344 remove_build_requires
345 echo "Error: package build failed. (${2:-no more info})";
352 if [ -n "$DEBUG" ]; then
357 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
358 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
365 if [ -n "$DEBUG" ]; then
371 if [ \! -f "$SPECFILE" ]; then
372 SPECFILE="`basename $SPECFILE .spec`.spec";
374 if [ "$NOCVSSPEC" != "yes" ]; then
377 if [ -n "$CVSROOT" ]; then
378 OPTIONS="-d $CVSROOT $OPTIONS"
380 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
381 echo "warning: No cvs access defined - using local .spec file"
386 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
387 OPTIONS="$OPTIONS -A"
389 if [ -n "$CVSDATE" ]; then
390 OPTIONS="$OPTIONS -D $CVSDATE"
392 if [ -n "$CVSTAG" ]; then
393 OPTIONS="$OPTIONS -r $CVSTAG"
399 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
401 retries_counter=$(( $retries_counter + 1 ))
402 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
404 [ -n "$output" ] && echo "$output"
405 if [ "$result" -ne "0" ]; then
406 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
407 echo "Trying again [$SPECFILE]... ($retries_counter)"
411 Exit_error err_no_spec_in_repo;
415 if [ ! -f "$SPECFILE" ]; then
416 Exit_error err_no_spec_in_repo;
419 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
420 chmod $CHMOD_MODE $SPECFILE
423 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
430 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
431 cvs update mirrors >&2
435 while read origin mirror name rest
437 ol=`echo -n "$origin"|wc -c`
438 prefix="`echo -n "$url" | head -c $ol`"
439 if [ "$prefix" = "$origin" ] ; then
440 suffix="`echo "$url"|cut -b $ol-`"
441 echo -n "$mirror$suffix"
452 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
453 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
459 [ X"$NO5" = X"yes" ] && return
461 [ -z "$no" ] && return
463 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
464 if [ -z "$spec_rev" ]; then
465 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
467 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
468 md5=$(grep -s -v '^#' additional-md5sums | \
469 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
470 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
471 grep -E '^[0-9a-f]{32}$')
472 if [ X"$md5" = X"" ] ; then
473 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
475 if [ $(echo "$md5" | wc -l) != 1 ] ; then
476 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
478 echo "$md5" | tail -n 1
484 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
487 distfiles_attic_url ()
489 echo "$PROTOCOL$DISTFILES_SERVER/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
496 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
503 if [ -n "$DEBUG" ]; then
508 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
512 if [ -n "$CVSROOT" ]; then
513 OPTIONS="-d $CVSROOT $OPTIONS"
515 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
516 echo "warning: No cvs access defined for SOURCES"
520 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
521 OPTIONS="$OPTIONS -A"
523 if [ -n "$CVSDATE" ]; then
524 OPTIONS="$OPTIONS -D $CVSDATE"
526 if [ -n "$CVSTAG" ]; then
527 OPTIONS="$OPTIONS -r $CVSTAG"
532 if [ -n "$UPDATE5" ]; then
533 if [ -n "$ADD5" ]; then
534 [ `nourl $i` = "$i" ] && continue
535 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
537 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
541 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
542 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
543 echo "Warning: no URL given for $i"
546 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
547 if good_md5 "$i"; then
548 echo "$(nourl "$i") having proper md5sum already exists"
552 url=$(distfiles_url "$i")
553 url_attic=$(distfiles_attic_url "$i")
555 if [ `echo $url | grep -E '^(\.|/)'` ]; then
556 ${GETLOCAL} $url $target
558 if [ -z "$NOMIRRORS" ]; then
559 url="`find_mirror "$url"`"
561 ${GETURI} -O "$target" "$url" || \
562 if [ `echo $url | grep -E 'ftp://'` ]; then
563 ${GETURI2} -O "$target" "$url"
566 if ! test -s "$target"; then
568 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
569 ${GETLOCAL} $url_attic $target
571 if [ -z "$NOMIRRORS" ]; then
572 url_attic="`find_mirror "$url_attic"`"
574 ${GETURI} -O "$target" "$url_attic" || \
575 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
576 ${GETURI2} -O "$target" "$url_attic"
580 if ! test -s "$target"; then
584 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
585 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
588 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
590 retries_counter=$(( $retries_counter + 1 ))
591 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
593 [ -n "$output" ] && echo "$output"
594 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
595 echo "Trying again [`nourl $i`]... ($retries_counter)"
604 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
605 if [ -z "$NOMIRRORS" ]; then
606 im="`find_mirror "$i"`"
611 if [ `echo $im | grep -E 'ftp://'` ]; then
618 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
619 Exit_error err_no_source_in_repo $i;
620 elif [ -n "$UPDATE5" ] && \
621 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
622 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
623 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
625 echo "Updating source-$srcno md5."
626 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
628 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
629 print "# Source'$srcno'-md5:\t'$md5'\n"
630 if /^Source'$srcno'\s*:\s+/;
635 if good_md5 "$i"; then
637 elif [ "$FROM_DISTFILES" = 1 ]; then
638 # wrong md5 from distfiles: remove the file and try again
640 echo "MD5 sum mismatch. Trying full fetch."
643 ${GETURI} -O "$target" "$url" || \
644 if [ `echo $url | grep -E 'ftp://'` ]; then
645 ${GETURI2} -O "$target" "$url"
647 if ! test -s "$target"; then
649 ${GETURI} -O "$target" "$url_attic" || \
650 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
651 ${GETURI2} -O "$target" "$url_attic"
654 test -s "$target" || rm -f "$target"
657 if good_md5 "$i"; then
660 echo "MD5 sum mismatch. Use -U to refetch sources,"
661 echo "or -5 to update md5 sums, if you're sure files are correct."
662 Exit_error err_no_source_in_repo $i
666 if [ "$CHMOD" = "yes" ]; then
667 CHMOD_FILES="`nourl $GET_FILES`"
668 if [ -n "$CHMOD_FILES" ]; then
669 chmod $CHMOD_MODE $CHMOD_FILES
677 # Check whether first character of PACKAGE_NAME is legal for tag name
678 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
681 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"`
682 # Remove #kernel.version_release from TAGVER because tagging sources
683 # could occur with different kernel-headers than kernel-headers used at build time.
684 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
692 if [ -n "$DEBUG" ]; then
697 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
698 echo "Version: $PACKAGE_VERSION"
699 echo "Release: $PACKAGE_RELEASE"
703 if [ "$TAG_VERSION" = "yes" ]; then
704 echo "CVS tag: $TAGVER"
706 if [ -n "$TAG" ]; then
711 if [ -n "$CVSROOT" ]; then
712 OPTIONS="-d $CVSROOT $OPTIONS"
718 # don't tag files stored on distfiles
719 [ -n "`src_md5 $i`" ] && continue
720 if [ -f "`nourl $i`" ]; then
721 if [ "$TAG_VERSION" = "yes" ]; then
722 cvs $OPTIONS $TAGVER `nourl $i`
724 if [ -n "$TAG" ]; then
725 cvs $OPTIONS $TAG `nourl $i`
728 Exit_error err_no_source_in_repo $i
733 if [ "$TAG_VERSION" = "yes" ]; then
734 cvs $OPTIONS $TAGVER $SPECFILE
736 if [ -n "$TAG" ]; then
737 cvs $OPTIONS $TAG $SPECFILE
747 echo "CVS branch tag: $TAG"
752 if [ -n "$DEBUG" ]; then
757 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
760 if [ -n "$CVSROOT" ]; then
761 OPTIONS="-d $CVSROOT $OPTIONS"
766 if [ -f `nourl $i` ]; then
767 cvs $OPTIONS $TAG `nourl $i`
769 Exit_error err_no_source_in_repo $i
773 cvs $OPTIONS $TAG $SPECFILE
783 if [ -n "$DEBUG" ]; then
790 if [ -n "$TRY_UPGRADE" ]; then
791 if [ -n "$FLOAT_VERSION" ]; then
792 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
794 TNOTIFY=`./pldnotify.awk $SPECFILE`
797 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
799 if [ -n "$TNEWVER" ]; then
800 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
801 echo "New version found, updating spec file to version " $TNEWVER
802 cp -f $SPECFILE $SPECFILE.bak
804 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
805 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
807 get_files "$SOURCES $PATCHES";
808 unset TOLDVER TNEWVER TNOTIFY
815 BUILD_SWITCH="-ba" ;;
817 BUILD_SWITCH="-bb" ;;
819 BUILD_SWITCH="-bs --nodeps" ;;
821 BUILD_SWITCH="-bp --nodeps" ;;
823 if [ -n "$LOGFILE" ]; then
824 LOG=`eval echo $LOGFILE`
825 if [ -d "$LOG" ]; then
826 echo "Log file $LOG is a directory."
827 echo "Parse error in the spec?"
828 Exit_error err_build_fail;
830 if [ -n "$LASTLOG_FILE" ]; then
831 echo "LASTLOG=$LOG" > $LASTLOG_FILE
833 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
834 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
835 RETVAL=`cat $RES_FILE`
837 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
838 if [ "$RETVAL" -eq "0" ]; then
845 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
848 if [ "$RETVAL" -ne "0" ]; then
849 if [ -n "$TRY_UPGRADE" ]; then
850 echo "\n!!! Package with new version cannot be build automagically\n"
851 mv -f $SPECFILE.bak $SPECFILE
853 Exit_error err_build_fail;
860 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
864 install_required_packages()
872 AVAIL_BCONDS_WITHOUT=""
874 if `grep -q ^%bcond ${SPECFILE}`; then
876 elif `grep -q bcond ${SPECFILE}`; then
881 case "${BCOND_VERSION}" in
886 echo "Warning: This spec has old style bconds. Fix it || die."
887 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
889 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
890 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
891 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
893 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
897 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
899 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
900 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
901 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
903 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
908 cond_type="" # with || without
909 for opt in `$RPMBUILD --bcond $SPECFILE`
922 AVAIL_BCOND_WITH="$opt"
923 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
924 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
926 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
931 AVAIL_BCOND_WITHOUT="$opt"
932 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
933 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
935 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
949 echo -ne "Package installation failed:\t$package_name\n"
951 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
952 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
953 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
954 # jakby nie bylo tego kawalka kodu.
956 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
957 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
965 # Istnieje taki spec? ${package}.spec
966 if [ -f "${SPECS_DIR}${package}.spec" ]; then
967 parent_spec_name=${package}.spec
968 elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
969 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
971 for provides_line in `grep ^Provides:.*$package ${SPECS_DIR} -R`
977 if [ "${parent_spec_name}" != "" ]; then
979 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
980 sub_builder_opts="${sub_builder_opts} -R"
982 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
983 sub_builder_opts="${sub_builder_opts} -RB"
984 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
985 sub_builder_opts="${sub_builder_opts} -FRB"
987 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
988 sub_builder_opts="${sub_builder_opts} -Upi"
991 ./builder ${sub_builder_opts} ${parent_spec_name}
993 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
996 remove_build_requires()
998 if [ "$INSTALLED_PACKAGES" != "" ]; then
999 case "$REMOVE_BUILD_REQUIRES" in
1001 run_poldek --noask -ve $INSTALLED_PACKAGES
1004 run_poldek --ask -ve $INSTALLED_PACKAGES
1007 echo You may want to manually remove following BuildRequires fetched:
1008 echo $INSTALLED_PACKAGES
1009 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1017 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1018 if [ "$BCOND" != "" ]; then
1019 echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1022 echo -ne "\nNo conditional flags passed"
1024 echo -ne "\n\nfrom available:\n"
1025 echo -ne "--with :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1029 fetch_build_requires()
1031 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1032 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1033 CONF=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print "@" $3 } ' | xargs)
1034 DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print "@" $3 } ' | xargs)
1035 if [ -n "$CONF" -o -n "$DEPS" ]; then
1036 /usr/bin/poldek --update; /usr/bin/poldek --upa
1038 if [ -n "$CONF" ]; then
1039 echo "Trying to uninstall conflicting packages ($CONF):"
1040 /usr/bin/poldek --noask --nofollow -ev $CONF
1042 if [ -n "$DEPS" ]; then
1043 echo "Trying to install dependencies ($DEPS):"
1044 /usr/bin/poldek --caplookup -uGv $DEPS
1049 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1050 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1051 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1052 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1053 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1054 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`
1056 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`"
1058 package=`basename "$package_item"|sed -e "s/}$//g"`
1059 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1062 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1063 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1064 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
1069 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1072 if `echo $COND_TST|grep -q 'without_'`; then
1073 COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1074 if `echo $COND_TST|grep -q !`; then
1079 if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1085 elif `echo $COND_TST|grep -q 'with_'`; then
1086 COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1087 if `echo $COND_TST|grep -q !`; then
1092 if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1098 RESULT="${COND_STATE}-${COND_ARGV}"
1100 "with-wout" | "wout-with" )
1103 "wout-wout" | "with-with" )
1107 echo "Action '$RESULT' was not defined for package '$package_item'"
1113 if [ "$GO" = "yes" ]; then
1114 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1115 echo "Testing if $package has subrequirements..."
1116 run_poldek -t -i $package --dumpn=".$package-req.txt"
1117 if [ -f ".$package-req.txt" ]; then
1118 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1120 if [ "$package_name" = "$package" ]; then
1121 echo -ne "Installing BuildRequired package:\t$package_name\n"
1122 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1123 install_required_packages $package;
1125 echo -ne "Installing (sub)Required package:\t$package_name\n"
1126 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1127 install_required_packages $package_name;
1131 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1132 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1135 echo "Attempting to run spawn sub - builder..."
1136 run_sub_builder $package_name
1137 if [ $? -eq 0 ]; then
1138 install_required_packages $package_name;
1141 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1142 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1145 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1152 rm -f ".$package-req.txt"
1154 echo "Attempting to run spawn sub - builder..."
1155 run_sub_builder $package
1156 if [ $? -eq 0 ]; then
1157 install_required_packages $package;
1160 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1161 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1164 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1170 echo "Package $package is already installed. BuildRequirement satisfied."
1174 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1175 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1176 echo "Unable to install following packages and their dependencies:"
1177 for pkg in "$NOT_INSTALLED_PACKAGES"
1181 remove_build_requires
1187 #---------------------------------------------
1190 if [ "$#" = 0 ]; then
1216 DEBUG="yes"; shift ;;
1218 COMMAND="version"; shift ;;
1220 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1221 -b | -ba | --build )
1222 COMMAND="build"; shift ;;
1223 -bb | --build-binary )
1224 COMMAND="build-binary"; shift ;;
1225 -bs | --build-source )
1226 COMMAND="build-source"; shift ;;
1227 -bp | --build-prep )
1228 COMMAND="build-prep"; shift ;;
1230 COMMAND="branch"; shift; TAG="${1}"; shift;;
1232 CLEAN="--clean --rmspec --rmsource"; shift ;;
1234 shift; CVSROOT="${1}"; shift ;;
1236 COMMAND="get"; shift ;;
1238 COMMAND="usage"; shift ;;
1240 PROTOCOL="http"; shift ;;
1242 shift; LOGFILE="${1}"; shift ;;
1244 shift; DEF_NICE_LEVEL=${1}; shift ;;
1246 COMMAND="mr-proper"; shift ;;
1248 NOCVS="yes"; shift ;;
1249 -ncs | --no-cvs-specs )
1250 NOCVSSPEC="yes"; shift ;;
1251 -nd | --no-distfiles )
1252 NODIST="yes"; shift ;;
1253 -nm | --no-mirrors )
1254 NOMIRRORS="yes"; shift ;;
1256 NOURLS="yes"; shift ;;
1258 NOSRCS="yes"; shift ;;
1259 -ns0 | --no-source0 )
1260 NOSOURCE0="yes"; shift ;;
1270 shift; RPMOPTS="${1}"; shift ;;
1271 --with | --without )
1272 case $GROUP_BCONDS in
1276 while ! `echo ${1}|grep -qE '(^-|spec)'`
1278 BCOND="$BCOND $COND $1"
1282 BCOND="$BCOND $1 $2" ; shift 2 ;;
1286 QUIET="--quiet"; shift ;;
1288 CVSDATE="${2}"; shift 2 ;;
1290 shift; CVSTAG="${1}"; shift ;;
1291 -R | --fetch-build-requires)
1292 FETCH_BUILD_REQUIRES="yes"
1293 NOT_INSTALLED_PACKAGES=
1295 -RB | --remove-build-requires)
1296 REMOVE_BUILD_REQUIRES="nice"
1298 -FRB | --force-remove-build-requires)
1299 REMOVE_BUILD_REQUIRES="force"
1301 -Tvs | --tag-version-stable )
1306 -Tvn | --tag-version-nest )
1311 -Ts | --tag-stable )
1321 -Tv | --tag-version )
1326 -Tp | --tag-prefix )
1345 -Upi | --update-poldek-indexes )
1346 UPDATE_POLDEK_INDEXES="yes"
1348 -u | --try-upgrade )
1349 TRY_UPGRADE="1"; shift ;;
1350 -un | --try-upgrade-with-float-version )
1351 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1353 BE_VERBOSE="1"; shift ;;
1359 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1363 RPMOPTS="${RPMOPTS} --nodeps"
1367 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1372 if [ -n "$DEBUG" ]; then
1378 "build" | "build-binary" | "build-source" | "build-prep" )
1380 if [ -n "$SPECFILE" ]; then
1384 fetch_build_requires;
1387 if [ -n "$TEST_TAG" ]; then
1388 TAGVER=`make_tagver`
1389 echo "Searching for tag $TAGVER..."
1390 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1392 if [ -n "$TAGREL" ]; then
1393 Exit_error err_build_fail "Tag $TAGVER already present (spec release: $TAGREL)"
1397 if [ -n "$ICONS" ]; then
1401 if [ -n "$NOSOURCE0" ] ; then
1402 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1404 get_files "$SOURCES $PATCHES";
1406 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1407 run_poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1408 run_poldek --sn ${POLDEK_SOURCE} --up
1410 remove_build_requires;
1412 Exit_error err_no_spec_in_cmdl;
1417 if [ -n "$SPECFILE" ]; then
1420 if [ -n "$ICONS" ]; then
1424 get_files $SOURCES $PATCHES;
1425 branch_files $TAG "$SOURCES $PATCHES $ICONS";
1427 Exit_error err_no_spec_in_cmdl;
1432 if [ -n "$SPECFILE" ]; then
1435 if [ -n "$ICONS" ]; then
1439 if [ -n "$NOSOURCE0" ] ; then
1440 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1442 get_files $SOURCES $PATCHES
1444 Exit_error err_no_spec_in_cmdl;
1451 if [ -n "$SPECFILE" ]; then
1454 if [ -n "$ICONS" ]; then
1458 # don't fetch sources from remote locations
1460 for file in $SOURCES
1462 [ -n "`src_md5 $file`" ] && continue
1463 new_SOURCES="$new_SOURCES $file"
1465 SOURCES="$new_SOURCES"
1466 get_files $SOURCES $PATCHES;
1467 tag_files "$SOURCES $PATCHES $ICONS";
1469 Exit_error err_no_spec_in_cmdl;
1473 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1480 test -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES && rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1483 # vi:syntax=sh:ts=3:sw=4