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"
43 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
46 # It can be used i.e. in log file naming.
47 # See LOGFILE example.
48 DATE=`date +%Y-%m-%d_%H-%M-%S`
50 # Example: LOGFILE='../log.$PACKAGE_NAME'
51 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
52 # Yes, you can use variable name! Note _single_ quotes!
73 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
74 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
79 CVS_SERVER="cvs.pld-linux.org"
80 DISTFILES_SERVER="://distfiles.pld-linux.org"
84 FAIL_IF_NO_SOURCES="yes"
86 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
87 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
89 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
90 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
93 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
101 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
103 POLDEK_CMD="/usr/bin/poldek --noask"
105 # Here we load saved user environment used to
106 # predefine options set above, or passed to builder
108 # This one reads global system environment settings:
109 if [ -f ~/etc/builderrc ]; then
112 # And this one cascades settings using user personal
114 # Example of ~/.builderrc:
116 #UPDATE_POLDEK_INDEXES="yes"
117 #FETCH_BUILD_REQUIRES="yes"
118 #REMOVE_BUILD_REQUIRES="force"
120 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
122 if [ -n "$HOME_ETC" ]; then
123 USER_CFG="$HOME_ETC/.builderrc"
125 USER_CFG=~/.builderrc
128 [ -f "$USER_CFG" ] && . "$USER_CFG"
132 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
133 if [ -n "$LOGFILE" ]; then
134 LOG=`eval echo $LOGFILE`
135 if [ -n "$LASTLOG_FILE" ]; then
136 echo "LASTLOG=$LOG" > $LASTLOG_FILE
138 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee $LOG
141 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
142 return `cat ${RES_FILE}`
147 # Example grep cvs /etc/poldek.conf:
148 # source = cvs /home/users/yoshi/rpm/RPMS/
149 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
150 run_poldek -l -n ${POLDEK_SOURCE} 1>&2 > /dev/null
151 if [ ! "$?" == "0" ]; then
152 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
153 echo "Fix it and try to continue"
158 #---------------------------------------------
163 if [ -n "$DEBUG" ]; then set -xv; fi
165 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
167 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
168 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
169 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
170 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
171 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
172 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
173 [{-Tp|--tag-prefix} <prefix>]
174 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
175 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
177 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
178 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
179 -D, --debug - enable script debugging mode,
180 -V, --version - output builder version
181 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
182 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
184 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
185 only package from <package>.spec,
186 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
188 -bp, --build-prep - execute the %prep phase of <package>.spec,
189 -B, --branch - add branch
190 -c, --clean - clean all temporarily created files (in BUILD, SOURCES,
191 SPECS and \$RPM_BUILD_ROOT),
192 -d <cvsroot>, --cvsroot <cvsroot>
194 --define <macro> <value>
195 - define a macro <macro> with value <value>,
196 --nodeps - rpm won't check any dependences
197 -g, --get - get <package>.spec and all related files from CVS repo
199 -h, --help - this message,
200 --http - use http instead of ftp,
201 -l <logfile>, --logtofile <logfile>
203 -m, --mr-proper - only remove all files related to spec file and all work
205 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
207 - don't check specs in CVS
208 -nd, --no-distfiles - don't download from distfiles
209 -nm, --no-mirrors - don't download from mirror, if source URL is given,
210 -nu, --no-urls - don't try to download from FTP/HTTP location,
211 -ns, --no-srcs - don't download Sources
212 -ns0, --no-source0 - don't download Source0
213 -nn, --no-net - don't download anything from the net
214 --opts <rpm opts> - additional options for rpm
215 -q, --quiet - be quiet,
216 --date yyyy-mm-dd - build package using resources from specified CVS date,
217 -r <cvstag>, --cvstag <cvstag>
218 - build package using resources from specified CVS tag,
219 -R, --fetch-build-requires
220 - fetch what is BuildRequired,
221 -RB, --remove-build-requires
222 - remove all you fetched with -R or --fetch-build-requires
223 remember, this option requires confirmation,
224 -FRB, --force-remove-build-requires
225 - remove all you fetched with -R or --fetch-build-requires
226 remember, this option works without confirmation,
227 -T <cvstag> , --tag <cvstag>
228 - add cvs tag <cvstag> for files,
229 -Tvs, --tag-version-stable
230 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
231 -Tvn, --tag-version-nest
232 - add cvs tags NEST and NAME-VERSION-RELESE for files,
234 - add cvs tag STABLE for files,
236 - add cvs tag NEST for files,
238 - add cvs tag NAME-VERSION-RELESE for files,
239 -Tp, --tag-prefix <prefix>
240 - add <prefix> to NAME-VERSION-RELEASE tags,
241 -v, --verbose - be verbose,
242 -u, --try-upgrade - check version, and try to upgrade package
243 -un, --try-upgrade-with-float-version
244 - as above, but allow float version
245 -U, --update - refetch sources, don't use distfiles, and update md5 comments
246 -Upi, --update-poldek-indexes
247 - refresh or make poldek package index files.
248 --with/--without <feature>
249 - conditional build package depending on %_with_<feature>/
250 %_without_<feature> macro switch. You may now use
251 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
252 constructions. Set GROUP_BCONDS to yes to make use of it.
260 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
263 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
269 if [ -z "$rpm_dump_cache" ] ; then
270 echo "internal error: cache_rpm_dump not called!" 1>&2
272 echo "$rpm_dump_cache"
277 if [ -n "$DEBUG" ]; then
286 if [ "$NOSRCS" != "yes" ]; then
287 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
289 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
290 FAIL_IF_NO_SOURCES="no"
293 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
294 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
295 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
296 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -n 1`"
297 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
299 if [ -n "$BE_VERBOSE" ]; then
300 echo "- Sources : `nourl $SOURCES`"
301 if [ -n "$PATCHES" ]; then
302 echo "- Patches : `nourl $PATCHES`"
304 echo "- Patches : *no patches needed*"
306 if [ -n "$ICONS" ]; then
307 echo "- Icon : `nourl $ICONS`"
309 echo "- Icon : *no package icon*"
311 echo "- Name : $PACKAGE_NAME"
312 echo "- Version : $PACKAGE_VERSION"
313 echo "- Release : $PACKAGE_RELEASE"
319 if [ -n "$DEBUG" ]; then
327 "err_no_spec_in_cmdl" )
328 remove_build_requires
329 echo "ERROR: spec file name not specified.";
331 "err_no_spec_in_repo" )
332 remove_build_requires
333 echo "Error: spec file not stored in CVS repo.";
335 "err_no_source_in_repo" )
336 remove_build_requires
337 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
340 remove_build_requires
341 echo "Error: package build failed. (${2:-no more info})";
348 if [ -n "$DEBUG" ]; then
353 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
354 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
361 if [ -n "$DEBUG" ]; then
367 if [ \! -f "$SPECFILE" ]; then
368 SPECFILE="`basename $SPECFILE .spec`.spec";
370 if [ "$NOCVSSPEC" != "yes" ]; then
373 if [ -n "$CVSROOT" ]; then
374 OPTIONS="-d $CVSROOT $OPTIONS"
376 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
377 echo "warning: No cvs access defined - using local .spec file"
382 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
383 OPTIONS="$OPTIONS -A"
385 if [ -n "$CVSDATE" ]; then
386 OPTIONS="$OPTIONS -D $CVSDATE"
388 if [ -n "$CVSTAG" ]; then
389 OPTIONS="$OPTIONS -r $CVSTAG"
395 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
397 retries_counter=$(( $retries_counter + 1 ))
398 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
400 [ -n "$output" ] && echo "$output"
401 if [ "$result" -ne "0" ]; then
402 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
403 echo "Trying again [$SPECFILE]... ($retries_counter)"
407 Exit_error err_no_spec_in_repo;
411 if [ ! -f "$SPECFILE" ]; then
412 Exit_error err_no_spec_in_repo;
415 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
416 chmod $CHMOD_MODE $SPECFILE
419 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
426 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
427 cvs update mirrors >&2
431 while read origin mirror name rest
433 ol=`echo -n "$origin"|wc -c`
434 prefix="`echo -n "$url" | head -c $ol`"
435 if [ "$prefix" = "$origin" ] ; then
436 suffix="`echo "$url"|cut -b $ol-`"
437 echo -n "$mirror$suffix"
448 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
449 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
456 [ -z "$no" ] && return
458 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
459 if [ -z "$spec_rev" ]; then
460 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
462 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
463 md5=$(grep -s -v '^#' additional-md5sums | \
464 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
465 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
466 grep -E '^[0-9a-f]{32}$')
467 if [ X"$md5" = X"" ] ; then
468 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
470 if [ $(echo "$md5" | wc -l) != 1 ] ; then
471 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
473 echo "$md5" | tail -n 1
479 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
482 distfiles_attic_url ()
484 echo "$PROTOCOL$DISTFILES_SERVER/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
491 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
498 if [ -n "$DEBUG" ]; then
503 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
507 if [ -n "$CVSROOT" ]; then
508 OPTIONS="-d $CVSROOT $OPTIONS"
510 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
511 echo "warning: No cvs access defined for SOURCES"
515 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
516 OPTIONS="$OPTIONS -A"
518 if [ -n "$CVSDATE" ]; then
519 OPTIONS="$OPTIONS -D $CVSDATE"
521 if [ -n "$CVSTAG" ]; then
522 OPTIONS="$OPTIONS -r $CVSTAG"
527 if [ -n "$UPDATE5" ]; then
528 if [ -n "$ADD5" ]; then
529 [ `nourl $i` = "$i" ] && continue
530 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
532 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
536 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
537 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
538 echo "Warning: no URL given for $i"
541 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
542 if good_md5 "$i"; then
543 echo "$(nourl "$i") having proper md5sum already exists"
547 url=$(distfiles_url "$i")
548 url_attic=$(distfiles_attic_url "$i")
550 if [ `echo $url | grep -E '^(\.|/)'` ]; then
551 ${GETLOCAL} $url $target
553 if [ -z "$NOMIRRORS" ]; then
554 url="`find_mirror "$url"`"
556 ${GETURI} -O "$target" "$url" || \
557 if [ `echo $url | grep -E 'ftp://'` ]; then
558 ${GETURI2} -O "$target" "$url"
561 if ! test -s "$target"; then
563 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
564 ${GETLOCAL} $url_attic $target
566 if [ -z "$NOMIRRORS" ]; then
567 url_attic="`find_mirror "$url_attic"`"
569 ${GETURI} -O "$target" "$url_attic" || \
570 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
571 ${GETURI2} -O "$target" "$url_attic"
575 if ! test -s "$target"; then
579 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
580 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
583 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
585 retries_counter=$(( $retries_counter + 1 ))
586 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
588 [ -n "$output" ] && echo "$output"
589 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
590 echo "Trying again [`nourl $i`]... ($retries_counter)"
599 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
600 if [ -z "$NOMIRRORS" ]; then
601 im="`find_mirror "$i"`"
606 if [ `echo $im | grep -E 'ftp://'` ]; then
613 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
614 Exit_error err_no_source_in_repo $i;
615 elif [ -n "$UPDATE5" ] && \
616 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
617 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
618 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
620 echo "Updating source-$srcno md5."
621 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
623 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
624 print "# Source'$srcno'-md5:\t'$md5'\n"
625 if /^Source'$srcno'\s*:\s+/;
630 if good_md5 "$i"; then
632 elif [ "$FROM_DISTFILES" = 1 ]; then
633 # wrong md5 from distfiles: remove the file and try again
635 echo "MD5 sum mismatch. Trying full fetch."
638 ${GETURI} -O "$target" "$url" || \
639 if [ `echo $url | grep -E 'ftp://'` ]; then
640 ${GETURI2} -O "$target" "$url"
642 if ! test -s "$target"; then
644 ${GETURI} -O "$target" "$url_attic" || \
645 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
646 ${GETURI2} -O "$target" "$url_attic"
649 test -s "$target" || rm -f "$target"
652 if good_md5 "$i"; then
655 echo "MD5 sum mismatch. Use -U to refetch sources,"
656 echo "or -5 to update md5 sums, if you're sure files are correct."
657 Exit_error err_no_source_in_repo $i
661 if [ "$CHMOD" = "yes" ]; then
662 CHMOD_FILES="`nourl $GET_FILES`"
663 if [ -n "$CHMOD_FILES" ]; then
664 chmod $CHMOD_MODE $CHMOD_FILES
675 if [ -n "$DEBUG" ]; then
680 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
681 echo "Version: $PACKAGE_VERSION"
682 echo "Release: $PACKAGE_RELEASE"
683 # Check whether first character of PACKAGE_NAME is legal for tag name
684 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
687 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"`
688 # Remove #kernel.version_release from TAGVER because tagging sources
689 # could occur with different kernel-headers than kernel-headers used at build time.
690 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
691 if [ "$TAG_VERSION" = "yes" ]; then
692 echo "CVS tag: $TAGVER"
694 if [ -n "$TAG" ]; then
699 if [ -n "$CVSROOT" ]; then
700 OPTIONS="-d $CVSROOT $OPTIONS"
706 # don't tag files stored on distfiles
707 [ -n "`src_md5 $i`" ] && continue
708 if [ -f "`nourl $i`" ]; then
709 if [ "$TAG_VERSION" = "yes" ]; then
710 cvs $OPTIONS $TAGVER `nourl $i`
712 if [ -n "$TAG" ]; then
713 cvs $OPTIONS $TAG `nourl $i`
716 Exit_error err_no_source_in_repo $i
721 if [ "$TAG_VERSION" = "yes" ]; then
722 cvs $OPTIONS $TAGVER $SPECFILE
724 if [ -n "$TAG" ]; then
725 cvs $OPTIONS $TAG $SPECFILE
735 echo "CVS branch tag: $TAG"
740 if [ -n "$DEBUG" ]; then
745 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
748 if [ -n "$CVSROOT" ]; then
749 OPTIONS="-d $CVSROOT $OPTIONS"
754 if [ -f `nourl $i` ]; then
755 cvs $OPTIONS $TAG `nourl $i`
757 Exit_error err_no_source_in_repo $i
761 cvs $OPTIONS $TAG $SPECFILE
771 if [ -n "$DEBUG" ]; then
778 if [ -n "$TRY_UPGRADE" ]; then
779 if [ -n "$FLOAT_VERSION" ]; then
780 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
782 TNOTIFY=`./pldnotify.awk $SPECFILE`
785 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
787 if [ -n "$TNEWVER" ]; then
788 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
789 echo "New version found, updating spec file to version " $TNEWVER
790 cp -f $SPECFILE $SPECFILE.bak
792 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
793 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
795 get_files "$SOURCES $PATCHES";
796 unset TOLDVER TNEWVER TNOTIFY
803 BUILD_SWITCH="-ba" ;;
805 BUILD_SWITCH="-bb" ;;
807 BUILD_SWITCH="-bs --nodeps" ;;
809 BUILD_SWITCH="-bp --nodeps" ;;
811 if [ -n "$LOGFILE" ]; then
812 LOG=`eval echo $LOGFILE`
813 if [ -d "$LOG" ]; then
814 echo "Log file $LOG is a directory."
815 echo "Parse error in the spec?"
816 Exit_error err_build_fail;
818 if [ -n "$LASTLOG_FILE" ]; then
819 echo "LASTLOG=$LOG" > $LASTLOG_FILE
821 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
822 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
823 RETVAL=`cat $RES_FILE`
825 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
826 if [ "$RETVAL" -eq "0" ]; then
833 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
836 if [ "$RETVAL" -ne "0" ]; then
837 if [ -n "$TRY_UPGRADE" ]; then
838 echo "\n!!! Package with new version cannot be build automagically\n"
839 mv -f $SPECFILE.bak $SPECFILE
841 Exit_error err_build_fail;
848 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
852 install_required_packages()
860 AVAIL_BCONDS_WITHOUT=""
862 if `grep -q ^%bcond ${SPECFILE}`; then
864 elif `grep -q bcond ${SPECFILE}`; then
869 case "${BCOND_VERSION}" in
874 echo "Warning: This spec has old style bconds. Fix it || die."
875 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
877 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
878 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
879 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
881 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
885 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
887 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
888 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
889 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
891 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
896 cond_type="" # with || without
897 for opt in `$RPMBUILD --bcond $SPECFILE`
910 AVAIL_BCOND_WITH="$opt"
911 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
912 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
914 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
919 AVAIL_BCOND_WITHOUT="$opt"
920 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
921 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
923 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
937 echo -ne "Package installation failed:\t$package_name\n"
939 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
940 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
941 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
942 # jakby nie bylo tego kawalka kodu.
944 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
945 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
953 # Istnieje taki spec? ${package}.spec
954 if [ -f "${SPECS_DIR}${package}.spec" ]; then
955 parent_spec_name=${package}.spec
956 elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
957 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
959 for provides_line in `grep ^Provides:.*$package ${SPECS_DIR} -R`
965 if [ "${parent_spec_name}" != "" ]; then
967 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
968 sub_builder_opts="${sub_builder_opts} -R"
970 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
971 sub_builder_opts="${sub_builder_opts} -RB"
972 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
973 sub_builder_opts="${sub_builder_opts} -FRB"
975 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
976 sub_builder_opts="${sub_builder_opts} -Upi"
979 ./builder ${sub_builder_opts} ${parent_spec_name}
981 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
984 remove_build_requires()
986 if [ "$INSTALLED_PACKAGES" != "" ]; then
987 case "$REMOVE_BUILD_REQUIRES" in
989 run_poldek --noask -ve $INSTALLED_PACKAGES
992 run_poldek --ask -ve $INSTALLED_PACKAGES
995 echo You may want to manually remove following BuildRequires fetched:
996 echo $INSTALLED_PACKAGES
997 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1005 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1006 echo -ne "We are going to build $SPECFILE with the following conditional flags:\n"
1007 if [ "$BCOND" != "" ]; then
1010 echo -ne "No --with || --without conditions passed to $0"
1012 echo -ne "\n\nfrom available:\n\n"
1013 echo -ne "--with :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1017 fetch_build_requires()
1019 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
1020 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1021 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1022 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1023 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1024 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1025 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`
1027 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`"
1029 package=`basename "$package_item"|sed -e "s/}$//g"`
1030 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1033 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1034 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1035 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
1040 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1043 if `echo $COND_TST|grep -q 'without_'`; then
1044 COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1045 if `echo $COND_TST|grep -q !`; then
1050 if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1056 elif `echo $COND_TST|grep -q 'with_'`; then
1057 COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1058 if `echo $COND_TST|grep -q !`; then
1063 if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1069 RESULT="${COND_STATE}-${COND_ARGV}"
1071 "with-wout" | "wout-with" )
1074 "wout-wout" | "with-with" )
1078 echo "Action '$RESULT' was not defined for package '$package_item'"
1084 if [ "$GO" = "yes" ]; then
1085 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1086 echo "Testing if $package has subrequirements..."
1087 run_poldek -t -i $package --dumpn=".$package-req.txt"
1088 if [ -f ".$package-req.txt" ]; then
1089 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1091 if [ "$package_name" = "$package" ]; then
1092 echo -ne "Installing BuildRequired package:\t$package_name\n"
1093 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1094 install_required_packages $package;
1096 echo -ne "Installing (sub)Required package:\t$package_name\n"
1097 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1098 install_required_packages $package_name;
1102 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1103 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1106 echo "Attempting to run spawn sub - builder..."
1107 run_sub_builder $package_name
1108 if [ $? -eq 0 ]; then
1109 install_required_packages $package_name;
1112 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1113 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1116 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1123 rm -f ".$package-req.txt"
1125 echo "Attempting to run spawn sub - builder..."
1126 run_sub_builder $package
1127 if [ $? -eq 0 ]; then
1128 install_required_packages $package;
1131 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1132 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1135 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1141 echo "Package $package is already installed. BuildRequirement satisfied."
1145 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1146 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1147 echo "Nie uda³o siê zainstalowaæ nastêpuj±cych pakietów i ich zale¿no¶ci:"
1148 for pkg in "$NOT_INSTALLED_PACKAGES"
1152 remove_build_requires
1158 #---------------------------------------------
1161 if [ "$#" = 0 ]; then
1184 DEBUG="yes"; shift ;;
1186 COMMAND="version"; shift ;;
1188 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1189 -b | -ba | --build )
1190 COMMAND="build"; shift ;;
1191 -bb | --build-binary )
1192 COMMAND="build-binary"; shift ;;
1193 -bs | --build-source )
1194 COMMAND="build-source"; shift ;;
1195 -bp | --build-prep )
1196 COMMAND="build-prep"; shift ;;
1198 COMMAND="branch"; shift; TAG="${1}"; shift;;
1200 CLEAN="--clean --rmspec --rmsource"; shift ;;
1202 shift; CVSROOT="${1}"; shift ;;
1204 COMMAND="get"; shift ;;
1206 COMMAND="usage"; shift ;;
1208 PROTOCOL="http"; shift ;;
1210 shift; LOGFILE="${1}"; shift ;;
1212 shift; DEF_NICE_LEVEL=${1}; shift ;;
1214 COMMAND="mr-proper"; shift ;;
1216 NOCVS="yes"; shift ;;
1217 -ncs | --no-cvs-specs )
1218 NOCVSSPEC="yes"; shift ;;
1219 -nd | --no-distfiles )
1220 NODIST="yes"; shift ;;
1221 -nm | --no-mirrors )
1222 NOMIRRORS="yes"; shift ;;
1224 NOURLS="yes"; shift ;;
1226 NOSRCS="yes"; shift ;;
1227 -ns0 | --no-source0 )
1228 NOSOURCE0="yes"; shift ;;
1238 shift; RPMOPTS="${1}"; shift ;;
1239 --with | --without )
1240 case $GROUP_BCONDS in
1244 while ! `echo ${1}|grep -qE '(^-|spec)'`
1246 BCOND="$BCOND $COND $1"
1250 BCOND="$BCOND $1 $2" ; shift 2 ;;
1254 QUIET="--quiet"; shift ;;
1256 CVSDATE="${2}"; shift 2 ;;
1258 shift; CVSTAG="${1}"; shift ;;
1259 -R | --fetch-build-requires)
1260 FETCH_BUILD_REQUIRES="yes"
1261 NOT_INSTALLED_PACKAGES=
1263 -RB | --remove-build-requires)
1264 REMOVE_BUILD_REQUIRES="nice"
1266 -FRB | --force-remove-build-requires)
1267 REMOVE_BUILD_REQUIRES="force"
1269 -Tvs | --tag-version-stable )
1274 -Tvn | --tag-version-nest )
1279 -Ts | --tag-stable )
1289 -Tv | --tag-version )
1294 -Tp | --tag-prefix )
1310 -Upi | --update-poldek-indexes )
1311 UPDATE_POLDEK_INDEXES="yes"
1313 -u | --try-upgrade )
1314 TRY_UPGRADE="1"; shift ;;
1315 -un | --try-upgrade-with-float-version )
1316 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1318 BE_VERBOSE="1"; shift ;;
1324 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1328 RPMOPTS="${RPMOPTS} --nodeps"
1332 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1337 if [ -n "$DEBUG" ]; then
1343 "build" | "build-binary" | "build-source" | "build-prep" )
1345 if [ -n "$SPECFILE" ]; then
1349 fetch_build_requires;
1352 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
1353 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1354 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
1355 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1357 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
1358 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
1362 if [ -n "$ICONS" ]; then
1366 if [ -n "$NOSOURCE0" ] ; then
1367 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1369 get_files "$SOURCES $PATCHES";
1371 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1372 run_poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1373 run_poldek --sn ${POLDEK_SOURCE} --up
1375 remove_build_requires;
1377 Exit_error err_no_spec_in_cmdl;
1382 if [ -n "$SPECFILE" ]; then
1385 if [ -n "$ICONS" ]; then
1389 get_files $SOURCES $PATCHES;
1390 branch_files $TAG "$SOURCES $PATCHES $ICONS";
1392 Exit_error err_no_spec_in_cmdl;
1397 if [ -n "$SPECFILE" ]; then
1400 if [ -n "$ICONS" ]; then
1404 if [ -n "$NOSOURCE0" ] ; then
1405 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1407 get_files $SOURCES $PATCHES
1409 Exit_error err_no_spec_in_cmdl;
1416 if [ -n "$SPECFILE" ]; then
1419 if [ -n "$ICONS" ]; then
1423 # don't fetch sources from remote locations
1425 for file in $SOURCES
1427 [ -n "`src_md5 $file`" ] && continue
1428 new_SOURCES="$new_SOURCES $file"
1430 SOURCES="$new_SOURCES"
1431 get_files $SOURCES $PATCHES;
1432 tag_files "$SOURCES $PATCHES $ICONS";
1434 Exit_error err_no_spec_in_cmdl;
1438 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1445 test -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES && rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1448 # vi:syntax=sh:ts=3:sw=4