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"
45 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
48 # It can be used i.e. in log file naming.
49 # See LOGFILE example.
50 DATE=`date +%Y-%m-%d_%H-%M-%S`
52 # Example: LOGFILE='../log.$PACKAGE_NAME'
53 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
54 # Yes, you can use variable name! Note _single_ quotes!
75 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
76 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
81 CVS_SERVER="cvs.pld-linux.org"
82 DISTFILES_SERVER="://distfiles.pld-linux.org"
86 FAIL_IF_NO_SOURCES="yes"
88 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
89 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
91 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
92 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
95 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
103 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
105 POLDEK_CMD="/usr/bin/poldek --noask"
107 # Here we load saved user environment used to
108 # predefine options set above, or passed to builder
110 # This one reads global system environment settings:
111 if [ -f ~/etc/builderrc ]; then
114 # And this one cascades settings using user personal
116 # Example of ~/.builderrc:
118 #UPDATE_POLDEK_INDEXES="yes"
119 #FETCH_BUILD_REQUIRES="yes"
120 #REMOVE_BUILD_REQUIRES="force"
122 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
124 if [ -n "$HOME_ETC" ]; then
125 USER_CFG="$HOME_ETC/.builderrc"
127 USER_CFG=~/.builderrc
130 [ -f "$USER_CFG" ] && . "$USER_CFG"
134 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
135 if [ -n "$LOGFILE" ]; then
136 LOG=`eval echo $LOGFILE`
137 if [ -n "$LASTLOG_FILE" ]; then
138 echo "LASTLOG=$LOG" > $LASTLOG_FILE
140 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee $LOG
143 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
144 return `cat ${RES_FILE}`
149 # Example grep cvs /etc/poldek.conf:
150 # source = cvs /home/users/yoshi/rpm/RPMS/
151 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
152 run_poldek -l -n ${POLDEK_SOURCE} 1>&2 > /dev/null
153 if [ ! "$?" == "0" ]; then
154 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
155 echo "Fix it and try to continue"
160 #---------------------------------------------
165 if [ -n "$DEBUG" ]; then set -xv; fi
167 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
169 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
170 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
171 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
172 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
173 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
174 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
175 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
176 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
177 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
179 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
180 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
181 -n5, --no-md5 - ignore md5 comments in spec
182 -D, --debug - enable script debugging mode,
183 -V, --version - output builder version
184 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
185 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
187 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
188 only package from <package>.spec,
189 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
191 -bp, --build-prep - execute the %prep phase of <package>.spec,
192 -B, --branch - add branch
193 -c, --clean - clean all temporarily created files (in BUILD, SOURCES,
194 SPECS and \$RPM_BUILD_ROOT),
195 -d <cvsroot>, --cvsroot <cvsroot>
197 --define <macro> <value>
198 - define a macro <macro> with value <value>,
199 --nodeps - rpm won't check any dependences
200 -g, --get - get <package>.spec and all related files from CVS repo
202 -h, --help - this message,
203 --http - use http instead of ftp,
204 -l <logfile>, --logtofile <logfile>
206 -m, --mr-proper - only remove all files related to spec file and all work
208 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
210 - don't check specs in CVS
211 -nd, --no-distfiles - don't download from distfiles
212 -nm, --no-mirrors - don't download from mirror, if source URL is given,
213 -nu, --no-urls - don't try to download from FTP/HTTP location,
214 -ns, --no-srcs - don't download Sources
215 -ns0, --no-source0 - don't download Source0
216 -nn, --no-net - don't download anything from the net
217 --opts <rpm opts> - additional options for rpm
218 -q, --quiet - be quiet,
219 --date yyyy-mm-dd - build package using resources from specified CVS date,
220 -r <cvstag>, --cvstag <cvstag>
221 - build package using resources from specified CVS tag,
222 -R, --fetch-build-requires
223 - fetch what is BuildRequired,
224 -RB, --remove-build-requires
225 - remove all you fetched with -R or --fetch-build-requires
226 remember, this option requires confirmation,
227 -FRB, --force-remove-build-requires
228 - remove all you fetched with -R or --fetch-build-requires
229 remember, this option works without confirmation,
230 -T <cvstag> , --tag <cvstag>
231 - add cvs tag <cvstag> for files,
232 -Tvs, --tag-version-stable
233 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
234 -Tvn, --tag-version-nest
235 - add cvs tags NEST and NAME-VERSION-RELESE for files,
237 - add cvs tag STABLE for files,
239 - add cvs tag NEST for files,
241 - add cvs tag NAME-VERSION-RELESE for files,
242 -Tp, --tag-prefix <prefix>
243 - add <prefix> to NAME-VERSION-RELEASE tags,
244 -tt, --test-tag <prefix>
245 - fail if tag is already present,
246 -v, --verbose - be verbose,
247 -u, --try-upgrade - check version, and try to upgrade package
248 -un, --try-upgrade-with-float-version
249 - as above, but allow float version
250 -U, --update - refetch sources, don't use distfiles, and update md5 comments
251 -Upi, --update-poldek-indexes
252 - refresh or make poldek package index files.
253 --with/--without <feature>
254 - conditional build package depending on %_with_<feature>/
255 %_without_<feature> macro switch. You may now use
256 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
257 constructions. Set GROUP_BCONDS to yes to make use of it.
259 - build for platform <platform>.
267 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
270 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
276 if [ -z "$rpm_dump_cache" ] ; then
277 echo "internal error: cache_rpm_dump not called!" 1>&2
279 echo "$rpm_dump_cache"
284 if [ -n "$DEBUG" ]; then
293 if [ "$NOSRCS" != "yes" ]; then
294 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
296 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
297 FAIL_IF_NO_SOURCES="no"
300 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
301 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
302 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
303 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -n 1`"
304 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
306 if [ -n "$BE_VERBOSE" ]; then
307 echo "- Sources : `nourl $SOURCES`"
308 if [ -n "$PATCHES" ]; then
309 echo "- Patches : `nourl $PATCHES`"
311 echo "- Patches : *no patches needed*"
313 if [ -n "$ICONS" ]; then
314 echo "- Icon : `nourl $ICONS`"
316 echo "- Icon : *no package icon*"
318 echo "- Name : $PACKAGE_NAME"
319 echo "- Version : $PACKAGE_VERSION"
320 echo "- Release : $PACKAGE_RELEASE"
326 if [ -n "$DEBUG" ]; then
334 "err_no_spec_in_cmdl" )
335 remove_build_requires
336 echo "ERROR: spec file name not specified.";
338 "err_no_spec_in_repo" )
339 remove_build_requires
340 echo "Error: spec file not stored in CVS repo.";
342 "err_no_source_in_repo" )
343 remove_build_requires
344 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
347 remove_build_requires
348 echo "Error: package build failed. (${2:-no more info})";
355 if [ -n "$DEBUG" ]; then
360 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
361 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
368 if [ -n "$DEBUG" ]; then
374 if [ \! -f "$SPECFILE" ]; then
375 SPECFILE="`basename $SPECFILE .spec`.spec";
377 if [ "$NOCVSSPEC" != "yes" ]; then
380 if [ -n "$CVSROOT" ]; then
381 OPTIONS="-d $CVSROOT $OPTIONS"
383 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
384 echo "warning: No cvs access defined - using local .spec file"
389 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
390 OPTIONS="$OPTIONS -A"
392 if [ -n "$CVSDATE" ]; then
393 OPTIONS="$OPTIONS -D $CVSDATE"
395 if [ -n "$CVSTAG" ]; then
396 OPTIONS="$OPTIONS -r $CVSTAG"
402 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
404 retries_counter=$(( $retries_counter + 1 ))
405 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
407 [ -n "$output" ] && echo "$output"
408 if [ "$result" -ne "0" ]; then
409 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
410 echo "Trying again [$SPECFILE]... ($retries_counter)"
414 Exit_error err_no_spec_in_repo;
418 if [ ! -f "$SPECFILE" ]; then
419 Exit_error err_no_spec_in_repo;
422 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
423 chmod $CHMOD_MODE $SPECFILE
426 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
433 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
434 cvs update mirrors >&2
438 while read origin mirror name rest
440 ol=`echo -n "$origin"|wc -c`
441 prefix="`echo -n "$url" | head -c $ol`"
442 if [ "$prefix" = "$origin" ] ; then
443 suffix="`echo "$url"|cut -b $ol-`"
444 echo -n "$mirror$suffix"
455 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
456 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
462 [ X"$NO5" = X"yes" ] && return
464 [ -z "$no" ] && return
466 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
467 if [ -z "$spec_rev" ]; then
468 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
470 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
471 md5=$(grep -s -v '^#' additional-md5sums | \
472 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
473 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
474 grep -E '^[0-9a-f]{32}$')
475 if [ X"$md5" = X"" ] ; then
476 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
478 if [ $(echo "$md5" | wc -l) != 1 ] ; then
479 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
481 echo "$md5" | tail -n 1
487 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
490 distfiles_attic_url ()
492 echo "$PROTOCOL$DISTFILES_SERVER/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
499 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
506 if [ -n "$DEBUG" ]; then
511 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
515 if [ -n "$CVSROOT" ]; then
516 OPTIONS="-d $CVSROOT $OPTIONS"
518 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
519 echo "warning: No cvs access defined for SOURCES"
523 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
524 OPTIONS="$OPTIONS -A"
526 if [ -n "$CVSDATE" ]; then
527 OPTIONS="$OPTIONS -D $CVSDATE"
529 if [ -n "$CVSTAG" ]; then
530 OPTIONS="$OPTIONS -r $CVSTAG"
535 if [ -n "$UPDATE5" ]; then
536 if [ -n "$ADD5" ]; then
537 [ `nourl $i` = "$i" ] && continue
538 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
540 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
544 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
545 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
546 echo "Warning: no URL given for $i"
549 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
550 if good_md5 "$i"; then
551 echo "$(nourl "$i") having proper md5sum already exists"
555 url=$(distfiles_url "$i")
556 url_attic=$(distfiles_attic_url "$i")
558 if [ `echo $url | grep -E '^(\.|/)'` ]; then
559 ${GETLOCAL} $url $target
561 if [ -z "$NOMIRRORS" ]; then
562 url="`find_mirror "$url"`"
564 ${GETURI} -O "$target" "$url" || \
565 if [ `echo $url | grep -E 'ftp://'` ]; then
566 ${GETURI2} -O "$target" "$url"
569 if ! test -s "$target"; then
571 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
572 ${GETLOCAL} $url_attic $target
574 if [ -z "$NOMIRRORS" ]; then
575 url_attic="`find_mirror "$url_attic"`"
577 ${GETURI} -O "$target" "$url_attic" || \
578 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
579 ${GETURI2} -O "$target" "$url_attic"
583 if ! test -s "$target"; then
587 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
588 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
591 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
593 retries_counter=$(( $retries_counter + 1 ))
594 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
596 [ -n "$output" ] && echo "$output"
597 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
598 echo "Trying again [`nourl $i`]... ($retries_counter)"
607 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
608 if [ -z "$NOMIRRORS" ]; then
609 im="`find_mirror "$i"`"
614 if [ `echo $im | grep -E 'ftp://'` ]; then
621 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
622 Exit_error err_no_source_in_repo $i;
623 elif [ -n "$UPDATE5" ] && \
624 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
625 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
626 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
628 echo "Updating source-$srcno md5."
629 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
631 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
632 print "# Source'$srcno'-md5:\t'$md5'\n"
633 if /^Source'$srcno'\s*:\s+/;
638 if good_md5 "$i"; then
640 elif [ "$FROM_DISTFILES" = 1 ]; then
641 # wrong md5 from distfiles: remove the file and try again
643 echo "MD5 sum mismatch. Trying full fetch."
646 ${GETURI} -O "$target" "$url" || \
647 if [ `echo $url | grep -E 'ftp://'` ]; then
648 ${GETURI2} -O "$target" "$url"
650 if ! test -s "$target"; then
652 ${GETURI} -O "$target" "$url_attic" || \
653 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
654 ${GETURI2} -O "$target" "$url_attic"
657 test -s "$target" || rm -f "$target"
660 if good_md5 "$i"; then
663 echo "MD5 sum mismatch. Use -U to refetch sources,"
664 echo "or -5 to update md5 sums, if you're sure files are correct."
665 Exit_error err_no_source_in_repo $i
669 if [ "$CHMOD" = "yes" ]; then
670 CHMOD_FILES="`nourl $GET_FILES`"
671 if [ -n "$CHMOD_FILES" ]; then
672 chmod $CHMOD_MODE $CHMOD_FILES
680 # Check whether first character of PACKAGE_NAME is legal for tag name
681 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
684 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"`
685 # Remove #kernel.version_release from TAGVER because tagging sources
686 # could occur with different kernel-headers than kernel-headers used at build time.
687 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
695 if [ -n "$DEBUG" ]; then
700 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
701 echo "Version: $PACKAGE_VERSION"
702 echo "Release: $PACKAGE_RELEASE"
706 if [ "$TAG_VERSION" = "yes" ]; then
707 echo "CVS tag: $TAGVER"
709 if [ -n "$TAG" ]; then
714 if [ -n "$CVSROOT" ]; then
715 OPTIONS="-d $CVSROOT $OPTIONS"
721 # don't tag files stored on distfiles
722 [ -n "`src_md5 $i`" ] && continue
723 if [ -f "`nourl $i`" ]; then
724 if [ "$TAG_VERSION" = "yes" ]; then
725 cvs $OPTIONS $TAGVER `nourl $i`
727 if [ -n "$TAG" ]; then
728 cvs $OPTIONS $TAG `nourl $i`
731 Exit_error err_no_source_in_repo $i
736 if [ "$TAG_VERSION" = "yes" ]; then
737 cvs $OPTIONS $TAGVER $SPECFILE
739 if [ -n "$TAG" ]; then
740 cvs $OPTIONS $TAG $SPECFILE
750 echo "CVS branch tag: $TAG"
755 if [ -n "$DEBUG" ]; then
760 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
763 if [ -n "$CVSROOT" ]; then
764 OPTIONS="-d $CVSROOT $OPTIONS"
769 if [ -f `nourl $i` ]; then
770 cvs $OPTIONS $TAG `nourl $i`
772 Exit_error err_no_source_in_repo $i
776 cvs $OPTIONS $TAG $SPECFILE
786 if [ -n "$DEBUG" ]; then
793 if [ -n "$TRY_UPGRADE" ]; then
794 if [ -n "$FLOAT_VERSION" ]; then
795 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
797 TNOTIFY=`./pldnotify.awk $SPECFILE`
800 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
802 if [ -n "$TNEWVER" ]; then
803 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
804 echo "New version found, updating spec file to version " $TNEWVER
805 cp -f $SPECFILE $SPECFILE.bak
807 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
808 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
810 get_files "$SOURCES $PATCHES";
811 unset TOLDVER TNEWVER TNOTIFY
816 if [ -n "$TARGET" ]; then
817 TARGET_SWITCH="--target $TARGET"
822 BUILD_SWITCH="-ba" ;;
824 BUILD_SWITCH="-bb" ;;
826 BUILD_SWITCH="-bs --nodeps" ;;
828 BUILD_SWITCH="-bp --nodeps" ;;
830 if [ -n "$LOGFILE" ]; then
831 LOG=`eval echo $LOGFILE`
832 if [ -d "$LOG" ]; then
833 echo "Log file $LOG is a directory."
834 echo "Parse error in the spec?"
835 Exit_error err_build_fail;
837 if [ -n "$LASTLOG_FILE" ]; then
838 echo "LASTLOG=$LOG" > $LASTLOG_FILE
840 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
841 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH $TARGET_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
842 RETVAL=`cat $RES_FILE`
844 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
845 if [ "$RETVAL" -eq "0" ]; then
852 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH $TARGET_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
855 if [ "$RETVAL" -ne "0" ]; then
856 if [ -n "$TRY_UPGRADE" ]; then
857 echo "\n!!! Package with new version cannot be build automagically\n"
858 mv -f $SPECFILE.bak $SPECFILE
860 Exit_error err_build_fail;
868 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
872 install_required_packages()
880 AVAIL_BCONDS_WITHOUT=""
882 if `grep -q ^%bcond ${SPECFILE}`; then
884 elif `grep -q bcond ${SPECFILE}`; then
889 case "${BCOND_VERSION}" in
894 echo "Warning: This spec has old style bconds. Fix it || die."
895 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
897 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
898 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
899 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
901 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
905 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
907 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
908 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
909 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
911 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
916 cond_type="" # with || without
917 for opt in `$RPMBUILD --bcond $SPECFILE`
930 AVAIL_BCOND_WITH="$opt"
931 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
932 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
934 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
939 AVAIL_BCOND_WITHOUT="$opt"
940 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
941 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
943 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
957 echo -ne "Package installation failed:\t$package_name\n"
959 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
960 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
961 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
962 # jakby nie bylo tego kawalka kodu.
964 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
965 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
973 # Istnieje taki spec? ${package}.spec
974 if [ -f "${SPECS_DIR}${package}.spec" ]; then
975 parent_spec_name=${package}.spec
976 elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
977 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
979 for provides_line in `grep ^Provides:.*$package ${SPECS_DIR} -R`
985 if [ "${parent_spec_name}" != "" ]; then
987 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
988 sub_builder_opts="${sub_builder_opts} -R"
990 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
991 sub_builder_opts="${sub_builder_opts} -RB"
992 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
993 sub_builder_opts="${sub_builder_opts} -FRB"
995 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
996 sub_builder_opts="${sub_builder_opts} -Upi"
999 ./builder ${sub_builder_opts} ${parent_spec_name}
1001 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1004 remove_build_requires()
1006 if [ "$INSTALLED_PACKAGES" != "" ]; then
1007 case "$REMOVE_BUILD_REQUIRES" in
1009 run_poldek --noask -ve $INSTALLED_PACKAGES
1012 run_poldek --ask -ve $INSTALLED_PACKAGES
1015 echo You may want to manually remove following BuildRequires fetched:
1016 echo $INSTALLED_PACKAGES
1017 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1025 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1026 if [ "$BCOND" != "" ]; then
1027 echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1030 echo -ne "\nNo conditional flags passed"
1032 echo -ne "\n\nfrom available:\n"
1033 echo -ne "--with :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1037 fetch_build_requires()
1039 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1040 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1041 CONF=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print "@" $3 } ' | xargs)
1042 DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print "@" $3 } ' | xargs)
1043 if [ -n "$CONF" -o -n "$DEPS" ]; then
1044 /usr/bin/poldek --update; /usr/bin/poldek --upa
1046 if [ -n "$CONF" ]; then
1047 echo "Trying to uninstall conflicting packages ($CONF):"
1048 /usr/bin/poldek --noask --nofollow -ev $CONF
1050 if [ -n "$DEPS" ]; then
1051 echo "Trying to install dependencies ($DEPS):"
1052 /usr/bin/poldek --caplookup -uGv $DEPS
1057 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1058 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1059 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1060 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1061 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1062 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`
1064 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`"
1066 package=`basename "$package_item"|sed -e "s/}$//g"`
1067 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1070 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1071 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1072 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
1077 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1080 if `echo $COND_TST|grep -q 'without_'`; then
1081 COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1082 if `echo $COND_TST|grep -q !`; then
1087 if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1093 elif `echo $COND_TST|grep -q 'with_'`; then
1094 COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1095 if `echo $COND_TST|grep -q !`; then
1100 if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1106 RESULT="${COND_STATE}-${COND_ARGV}"
1108 "with-wout" | "wout-with" )
1111 "wout-wout" | "with-with" )
1115 echo "Action '$RESULT' was not defined for package '$package_item'"
1121 if [ "$GO" = "yes" ]; then
1122 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1123 echo "Testing if $package has subrequirements..."
1124 run_poldek -t -i $package --dumpn=".$package-req.txt"
1125 if [ -f ".$package-req.txt" ]; then
1126 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1128 if [ "$package_name" = "$package" ]; then
1129 echo -ne "Installing BuildRequired package:\t$package_name\n"
1130 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1131 install_required_packages $package;
1133 echo -ne "Installing (sub)Required package:\t$package_name\n"
1134 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1135 install_required_packages $package_name;
1139 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1140 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1143 echo "Attempting to run spawn sub - builder..."
1144 run_sub_builder $package_name
1145 if [ $? -eq 0 ]; then
1146 install_required_packages $package_name;
1149 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1150 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1153 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1160 rm -f ".$package-req.txt"
1162 echo "Attempting to run spawn sub - builder..."
1163 run_sub_builder $package
1164 if [ $? -eq 0 ]; then
1165 install_required_packages $package;
1168 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1169 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1172 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1178 echo "Package $package is already installed. BuildRequirement satisfied."
1182 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1183 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1184 echo "Unable to install following packages and their dependencies:"
1185 for pkg in "$NOT_INSTALLED_PACKAGES"
1189 remove_build_requires
1195 #---------------------------------------------
1198 if [ "$#" = 0 ]; then
1224 DEBUG="yes"; shift ;;
1226 COMMAND="version"; shift ;;
1228 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1229 -b | -ba | --build )
1230 COMMAND="build"; shift ;;
1231 -bb | --build-binary )
1232 COMMAND="build-binary"; shift ;;
1233 -bs | --build-source )
1234 COMMAND="build-source"; shift ;;
1235 -bp | --build-prep )
1236 COMMAND="build-prep"; shift ;;
1238 COMMAND="branch"; shift; TAG="${1}"; shift;;
1240 CLEAN="--clean --rmspec --rmsource"; shift ;;
1242 shift; CVSROOT="${1}"; shift ;;
1244 COMMAND="get"; shift ;;
1246 COMMAND="usage"; shift ;;
1248 PROTOCOL="http"; shift ;;
1250 shift; LOGFILE="${1}"; shift ;;
1252 shift; DEF_NICE_LEVEL=${1}; shift ;;
1254 COMMAND="mr-proper"; shift ;;
1256 NOCVS="yes"; shift ;;
1257 -ncs | --no-cvs-specs )
1258 NOCVSSPEC="yes"; shift ;;
1259 -nd | --no-distfiles )
1260 NODIST="yes"; shift ;;
1261 -nm | --no-mirrors )
1262 NOMIRRORS="yes"; shift ;;
1264 NOURLS="yes"; shift ;;
1266 NOSRCS="yes"; shift ;;
1267 -ns0 | --no-source0 )
1268 NOSOURCE0="yes"; shift ;;
1278 shift; RPMOPTS="${1}"; shift ;;
1279 --with | --without )
1280 case $GROUP_BCONDS in
1284 while ! `echo ${1}|grep -qE '(^-|spec)'`
1286 BCOND="$BCOND $COND $1"
1290 BCOND="$BCOND $1 $2" ; shift 2 ;;
1294 shift; TARGET="${1}"; shift ;;
1296 QUIET="--quiet"; shift ;;
1298 CVSDATE="${2}"; shift 2 ;;
1300 shift; CVSTAG="${1}"; shift ;;
1301 -R | --fetch-build-requires)
1302 FETCH_BUILD_REQUIRES="yes"
1303 NOT_INSTALLED_PACKAGES=
1305 -RB | --remove-build-requires)
1306 REMOVE_BUILD_REQUIRES="nice"
1308 -FRB | --force-remove-build-requires)
1309 REMOVE_BUILD_REQUIRES="force"
1311 -Tvs | --tag-version-stable )
1316 -Tvn | --tag-version-nest )
1321 -Ts | --tag-stable )
1331 -Tv | --tag-version )
1336 -Tp | --tag-prefix )
1355 -Upi | --update-poldek-indexes )
1356 UPDATE_POLDEK_INDEXES="yes"
1358 -u | --try-upgrade )
1359 TRY_UPGRADE="1"; shift ;;
1360 -un | --try-upgrade-with-float-version )
1361 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1363 BE_VERBOSE="1"; shift ;;
1369 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1373 RPMOPTS="${RPMOPTS} --nodeps"
1377 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1382 if [ -n "$DEBUG" ]; then
1388 "build" | "build-binary" | "build-source" | "build-prep" )
1390 if [ -n "$SPECFILE" ]; then
1394 fetch_build_requires;
1397 if [ -n "$TEST_TAG" ]; then
1398 TAGVER=`make_tagver`
1399 echo "Searching for tag $TAGVER..."
1400 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1402 if [ -n "$TAGREL" ]; then
1403 Exit_error err_build_fail "Tag $TAGVER already present (spec release: $TAGREL)"
1407 if [ -n "$ICONS" ]; then
1411 if [ -n "$NOSOURCE0" ] ; then
1412 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1414 get_files "$SOURCES $PATCHES";
1416 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1417 run_poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1418 run_poldek --sn ${POLDEK_SOURCE} --up
1420 remove_build_requires;
1422 Exit_error err_no_spec_in_cmdl;
1427 if [ -n "$SPECFILE" ]; then
1430 if [ -n "$ICONS" ]; then
1434 get_files $SOURCES $PATCHES;
1435 branch_files $TAG "$SOURCES $PATCHES $ICONS";
1437 Exit_error err_no_spec_in_cmdl;
1442 if [ -n "$SPECFILE" ]; then
1445 if [ -n "$ICONS" ]; then
1449 if [ -n "$NOSOURCE0" ] ; then
1450 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1452 get_files $SOURCES $PATCHES
1454 Exit_error err_no_spec_in_cmdl;
1461 if [ -n "$SPECFILE" ]; then
1464 if [ -n "$ICONS" ]; then
1468 # don't fetch sources from remote locations
1470 for file in $SOURCES
1472 [ -n "`src_md5 $file`" ] && continue
1473 new_SOURCES="$new_SOURCES $file"
1475 SOURCES="$new_SOURCES"
1476 get_files $SOURCES $PATCHES;
1477 tag_files "$SOURCES $PATCHES $ICONS";
1479 Exit_error err_no_spec_in_cmdl;
1483 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1490 test -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES && rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1493 # vi:syntax=sh:ts=3:sw=4