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!
76 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
77 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
82 CVS_SERVER="cvs.pld-linux.org"
83 DISTFILES_SERVER="://distfiles.pld-linux.org"
87 FAIL_IF_NO_SOURCES="yes"
89 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
90 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
92 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
93 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
96 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
104 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
106 POLDEK_CMD="/usr/bin/poldek --noask"
108 # Here we load saved user environment used to
109 # predefine options set above, or passed to builder
111 # This one reads global system environment settings:
112 if [ -f ~/etc/builderrc ]; then
115 # And this one cascades settings using user personal
117 # Example of ~/.builderrc:
119 #UPDATE_POLDEK_INDEXES="yes"
120 #FETCH_BUILD_REQUIRES="yes"
121 #REMOVE_BUILD_REQUIRES="force"
123 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
125 if [ -n "$HOME_ETC" ]; then
126 USER_CFG="$HOME_ETC/.builderrc"
128 USER_CFG=~/.builderrc
131 [ -f "$USER_CFG" ] && . "$USER_CFG"
135 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
136 if [ -n "$LOGFILE" ]; then
137 LOG=`eval echo $LOGFILE`
138 if [ -n "$LASTLOG_FILE" ]; then
139 echo "LASTLOG=$LOG" > $LASTLOG_FILE
141 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee $LOG
144 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
145 return `cat ${RES_FILE}`
150 # Example grep cvs /etc/poldek.conf:
151 # source = cvs /home/users/yoshi/rpm/RPMS/
152 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
153 run_poldek -l -n ${POLDEK_SOURCE} 1>&2 > /dev/null
154 if [ ! "$?" == "0" ]; then
155 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
156 echo "Fix it and try to continue"
161 #---------------------------------------------
166 if [ -n "$DEBUG" ]; then set -xv; fi
168 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
170 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
171 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
172 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
173 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
174 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
175 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
176 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
177 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
178 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
180 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
181 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
182 -n5, --no-md5 - ignore md5 comments in spec
183 -D, --debug - enable script debugging mode,
184 -V, --version - output builder version
185 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
186 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
188 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
189 only package from <package>.spec,
190 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
192 -bp, --build-prep - execute the %prep phase of <package>.spec,
193 -B, --branch - add branch
194 -c, --clean - clean all temporarily created files (in BUILD, SOURCES,
195 SPECS and \$RPM_BUILD_ROOT),
196 -d <cvsroot>, --cvsroot <cvsroot>
198 --define <macro> <value>
199 - define a macro <macro> with value <value>,
200 --nodeps - rpm won't check any dependences
201 -g, --get - get <package>.spec and all related files from CVS repo
203 -h, --help - this message,
204 --http - use http instead of ftp,
205 -l <logfile>, --logtofile <logfile>
207 -m, --mr-proper - only remove all files related to spec file and all work
209 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
211 - don't check specs in CVS
212 -nd, --no-distfiles - don't download from distfiles
213 -nm, --no-mirrors - don't download from mirror, if source URL is given,
214 -nu, --no-urls - don't try to download from FTP/HTTP location,
215 -ns, --no-srcs - don't download Sources
216 -ns0, --no-source0 - don't download Source0
217 -nn, --no-net - don't download anything from the net
218 --opts <rpm opts> - additional options for rpm
219 -q, --quiet - be quiet,
220 --date yyyy-mm-dd - build package using resources from specified CVS date,
221 -r <cvstag>, --cvstag <cvstag>
222 - build package using resources from specified CVS tag,
223 -R, --fetch-build-requires
224 - fetch what is BuildRequired,
225 -RB, --remove-build-requires
226 - remove all you fetched with -R or --fetch-build-requires
227 remember, this option requires confirmation,
228 -FRB, --force-remove-build-requires
229 - remove all you fetched with -R or --fetch-build-requires
230 remember, this option works without confirmation,
231 -T <cvstag> , --tag <cvstag>
232 - add cvs tag <cvstag> for files,
233 -Tvs, --tag-version-stable
234 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
235 -Tvn, --tag-version-nest
236 - add cvs tags NEST and NAME-VERSION-RELESE for files,
238 - add cvs tag STABLE for files,
240 - add cvs tag NEST for files,
242 - add cvs tag NAME-VERSION-RELESE for files,
243 -Tp, --tag-prefix <prefix>
244 - add <prefix> to NAME-VERSION-RELEASE tags,
245 -tt, --test-tag <prefix>
246 - fail if tag is already present,
247 -v, --verbose - be verbose,
248 -u, --try-upgrade - check version, and try to upgrade package
249 -un, --try-upgrade-with-float-version
250 - as above, but allow float version
251 -U, --update - refetch sources, don't use distfiles, and update md5 comments
252 -Upi, --update-poldek-indexes
253 - refresh or make poldek package index files.
254 --with/--without <feature>
255 - conditional build package depending on %_with_<feature>/
256 %_without_<feature> macro switch. You may now use
257 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
258 constructions. Set GROUP_BCONDS to yes to make use of it.
260 - build for platform <platform>.
268 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
271 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
277 if [ -z "$rpm_dump_cache" ] ; then
278 echo "internal error: cache_rpm_dump not called!" 1>&2
280 echo "$rpm_dump_cache"
285 if [ -n "$DEBUG" ]; then
294 if [ "$NOSRCS" != "yes" ]; then
295 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
297 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
298 FAIL_IF_NO_SOURCES="no"
301 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
302 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
303 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
304 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -n 1`"
305 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
307 if [ -n "$BE_VERBOSE" ]; then
308 echo "- Sources : `nourl $SOURCES`"
309 if [ -n "$PATCHES" ]; then
310 echo "- Patches : `nourl $PATCHES`"
312 echo "- Patches : *no patches needed*"
314 if [ -n "$ICONS" ]; then
315 echo "- Icon : `nourl $ICONS`"
317 echo "- Icon : *no package icon*"
319 echo "- Name : $PACKAGE_NAME"
320 echo "- Version : $PACKAGE_VERSION"
321 echo "- Release : $PACKAGE_RELEASE"
327 if [ -n "$DEBUG" ]; then
335 "err_no_spec_in_cmdl" )
336 remove_build_requires
337 echo "ERROR: spec file name not specified.";
339 "err_no_spec_in_repo" )
340 remove_build_requires
341 echo "Error: spec file not stored in CVS repo.";
343 "err_no_source_in_repo" )
344 remove_build_requires
345 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
348 remove_build_requires
349 echo "Error: package build failed. (${2:-no more info})";
356 if [ -n "$DEBUG" ]; then
361 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
362 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
369 if [ -n "$DEBUG" ]; then
375 if [ \! -f "$SPECFILE" ]; then
376 SPECFILE="`basename $SPECFILE .spec`.spec";
378 if [ "$NOCVSSPEC" != "yes" ]; then
381 if [ -n "$CVSROOT" ]; then
382 OPTIONS="-d $CVSROOT $OPTIONS"
384 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
385 echo "warning: No cvs access defined - using local .spec file"
390 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
391 OPTIONS="$OPTIONS -A"
393 if [ -n "$CVSDATE" ]; then
394 OPTIONS="$OPTIONS -D $CVSDATE"
396 if [ -n "$CVSTAG" ]; then
397 OPTIONS="$OPTIONS -r $CVSTAG"
403 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
405 retries_counter=$(( $retries_counter + 1 ))
406 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
408 [ -n "$output" ] && echo "$output"
409 if [ "$result" -ne "0" ]; then
410 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
411 echo "Trying again [$SPECFILE]... ($retries_counter)"
415 Exit_error err_no_spec_in_repo;
419 if [ ! -f "$SPECFILE" ]; then
420 Exit_error err_no_spec_in_repo;
423 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
424 chmod $CHMOD_MODE $SPECFILE
427 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
434 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
435 cvs update mirrors >&2
439 while read origin mirror name rest
441 ol=`echo -n "$origin"|wc -c`
442 prefix="`echo -n "$url" | head -c $ol`"
443 if [ "$prefix" = "$origin" ] ; then
444 suffix="`echo "$url"|cut -b $ol-`"
445 echo -n "$mirror$suffix"
456 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
457 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
463 [ X"$NO5" = X"yes" ] && return
465 [ -z "$no" ] && return
467 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
468 if [ -z "$spec_rev" ]; then
469 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
471 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
472 md5=$(grep -s -v '^#' additional-md5sums | \
473 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
474 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
475 grep -E '^[0-9a-f]{32}$')
476 if [ X"$md5" = X"" ] ; then
477 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
479 if [ $(echo "$md5" | wc -l) != 1 ] ; then
480 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
482 echo "$md5" | tail -n 1
488 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
491 distfiles_attic_url ()
493 echo "$PROTOCOL$DISTFILES_SERVER/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
500 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
505 if [ "$CVSIGNORE_DF" != "yes" ]; then
508 cvsignore=${SOURCE_DIR}/.cvsignore
509 if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
510 echo "$1" >> $cvsignore
518 if [ -n "$DEBUG" ]; then
523 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
527 if [ -n "$CVSROOT" ]; then
528 OPTIONS="-d $CVSROOT $OPTIONS"
530 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
531 echo "warning: No cvs access defined for SOURCES"
535 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
536 OPTIONS="$OPTIONS -A"
538 if [ -n "$CVSDATE" ]; then
539 OPTIONS="$OPTIONS -D $CVSDATE"
541 if [ -n "$CVSTAG" ]; then
542 OPTIONS="$OPTIONS -r $CVSTAG"
547 if [ -n "$UPDATE5" ]; then
548 if [ -n "$ADD5" ]; then
549 [ `nourl $i` = "$i" ] && continue
550 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
552 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
556 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
557 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
558 echo "Warning: no URL given for $i"
561 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
562 if good_md5 "$i"; then
563 echo "$(nourl "$i") having proper md5sum already exists"
567 url=$(distfiles_url "$i")
568 url_attic=$(distfiles_attic_url "$i")
570 if [ `echo $url | grep -E '^(\.|/)'` ]; then
571 ${GETLOCAL} $url $target
573 if [ -z "$NOMIRRORS" ]; then
574 url="`find_mirror "$url"`"
576 ${GETURI} -O "$target" "$url" || \
577 if [ `echo $url | grep -E 'ftp://'` ]; then
578 ${GETURI2} -O "$target" "$url"
581 if ! test -s "$target"; then
583 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
584 ${GETLOCAL} $url_attic $target
586 if [ -z "$NOMIRRORS" ]; then
587 url_attic="`find_mirror "$url_attic"`"
589 ${GETURI} -O "$target" "$url_attic" || \
590 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
591 ${GETURI2} -O "$target" "$url_attic"
595 if test -s "$target"; then
601 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
602 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
605 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
607 retries_counter=$(( $retries_counter + 1 ))
608 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
610 [ -n "$output" ] && echo "$output"
611 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
612 echo "Trying again [`nourl $i`]... ($retries_counter)"
621 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
622 if [ -z "$NOMIRRORS" ]; then
623 im="`find_mirror "$i"`"
628 if [ `echo $im | grep -E 'ftp://'` ]; then
635 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
636 Exit_error err_no_source_in_repo $i;
637 elif [ -n "$UPDATE5" ] && \
638 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
639 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
640 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
642 echo "Updating source-$srcno md5."
643 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
645 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
646 print "# Source'$srcno'-md5:\t'$md5'\n"
647 if /^Source'$srcno'\s*:\s+/;
652 if good_md5 "$i"; then
654 elif [ "$FROM_DISTFILES" = 1 ]; then
655 # wrong md5 from distfiles: remove the file and try again
657 echo "MD5 sum mismatch. Trying full fetch."
660 ${GETURI} -O "$target" "$url" || \
661 if [ `echo $url | grep -E 'ftp://'` ]; then
662 ${GETURI2} -O "$target" "$url"
664 if ! test -s "$target"; then
666 ${GETURI} -O "$target" "$url_attic" || \
667 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
668 ${GETURI2} -O "$target" "$url_attic"
671 test -s "$target" || rm -f "$target"
674 if good_md5 "$i"; then
677 echo "MD5 sum mismatch. Use -U to refetch sources,"
678 echo "or -5 to update md5 sums, if you're sure files are correct."
679 Exit_error err_no_source_in_repo $i
683 if [ "$CHMOD" = "yes" ]; then
684 CHMOD_FILES="`nourl $GET_FILES`"
685 if [ -n "$CHMOD_FILES" ]; then
686 chmod $CHMOD_MODE $CHMOD_FILES
694 # Check whether first character of PACKAGE_NAME is legal for tag name
695 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
698 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"`
699 # Remove #kernel.version_release from TAGVER because tagging sources
700 # could occur with different kernel-headers than kernel-headers used at build time.
701 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
709 if [ -n "$DEBUG" ]; then
714 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
715 echo "Version: $PACKAGE_VERSION"
716 echo "Release: $PACKAGE_RELEASE"
720 if [ "$TAG_VERSION" = "yes" ]; then
721 echo "CVS tag: $TAGVER"
723 if [ -n "$TAG" ]; then
728 if [ -n "$CVSROOT" ]; then
729 OPTIONS="-d $CVSROOT $OPTIONS"
735 # don't tag files stored on distfiles
736 [ -n "`src_md5 $i`" ] && continue
737 if [ -f "`nourl $i`" ]; then
738 if [ "$TAG_VERSION" = "yes" ]; then
739 cvs $OPTIONS $TAGVER `nourl $i`
741 if [ -n "$TAG" ]; then
742 cvs $OPTIONS $TAG `nourl $i`
745 Exit_error err_no_source_in_repo $i
750 if [ "$TAG_VERSION" = "yes" ]; then
751 cvs $OPTIONS $TAGVER $SPECFILE
753 if [ -n "$TAG" ]; then
754 cvs $OPTIONS $TAG $SPECFILE
764 echo "CVS branch tag: $TAG"
769 if [ -n "$DEBUG" ]; then
774 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
777 if [ -n "$CVSROOT" ]; then
778 OPTIONS="-d $CVSROOT $OPTIONS"
783 if [ -f `nourl $i` ]; then
784 cvs $OPTIONS $TAG `nourl $i`
786 Exit_error err_no_source_in_repo $i
790 cvs $OPTIONS $TAG $SPECFILE
800 if [ -n "$DEBUG" ]; then
807 if [ -n "$TRY_UPGRADE" ]; then
808 if [ -n "$FLOAT_VERSION" ]; then
809 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
811 TNOTIFY=`./pldnotify.awk $SPECFILE`
814 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
816 if [ -n "$TNEWVER" ]; then
817 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
818 echo "New version found, updating spec file to version " $TNEWVER
819 cp -f $SPECFILE $SPECFILE.bak
821 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
822 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
824 get_files "$SOURCES $PATCHES";
825 unset TOLDVER TNEWVER TNOTIFY
830 if [ -n "$TARGET" ]; then
831 TARGET_SWITCH="--target $TARGET"
836 BUILD_SWITCH="-ba" ;;
838 BUILD_SWITCH="-bb" ;;
840 BUILD_SWITCH="-bs --nodeps" ;;
842 BUILD_SWITCH="-bp --nodeps" ;;
844 if [ -n "$LOGFILE" ]; then
845 LOG=`eval echo $LOGFILE`
846 if [ -d "$LOG" ]; then
847 echo "Log file $LOG is a directory."
848 echo "Parse error in the spec?"
849 Exit_error err_build_fail;
851 if [ -n "$LASTLOG_FILE" ]; then
852 echo "LASTLOG=$LOG" > $LASTLOG_FILE
854 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
855 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH $TARGET_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
856 RETVAL=`cat $RES_FILE`
858 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
859 if [ "$RETVAL" -eq "0" ]; then
866 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH $TARGET_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
869 if [ "$RETVAL" -ne "0" ]; then
870 if [ -n "$TRY_UPGRADE" ]; then
871 echo "\n!!! Package with new version cannot be build automagically\n"
872 mv -f $SPECFILE.bak $SPECFILE
874 Exit_error err_build_fail;
882 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
886 install_required_packages()
894 AVAIL_BCONDS_WITHOUT=""
896 if `grep -q ^%bcond ${SPECFILE}`; then
898 elif `egrep -q ^#\ *_with ${SPECFILE}`; then
903 case "${BCOND_VERSION}" in
908 echo "Warning: This spec has old style bconds. Fix it || die."
909 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
911 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
912 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
913 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
915 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
919 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
921 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
922 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
923 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
925 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
930 cond_type="" # with || without
931 for opt in `$RPMBUILD --bcond $SPECFILE`
944 AVAIL_BCOND_WITH="$opt"
945 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
946 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
948 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
953 AVAIL_BCOND_WITHOUT="$opt"
954 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
955 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
957 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
971 echo -ne "Package installation failed:\t$package_name\n"
973 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
974 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
975 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
976 # jakby nie bylo tego kawalka kodu.
978 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
979 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
987 # Istnieje taki spec? ${package}.spec
988 if [ -f "${SPECS_DIR}${package}.spec" ]; then
989 parent_spec_name=${package}.spec
990 elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
991 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
993 for provides_line in `grep ^Provides:.*$package ${SPECS_DIR} -R`
999 if [ "${parent_spec_name}" != "" ]; then
1001 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
1002 sub_builder_opts="${sub_builder_opts} -R"
1004 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
1005 sub_builder_opts="${sub_builder_opts} -RB"
1006 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
1007 sub_builder_opts="${sub_builder_opts} -FRB"
1009 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
1010 sub_builder_opts="${sub_builder_opts} -Upi"
1013 ./builder ${sub_builder_opts} ${parent_spec_name}
1015 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1018 remove_build_requires()
1020 if [ "$INSTALLED_PACKAGES" != "" ]; then
1021 case "$REMOVE_BUILD_REQUIRES" in
1023 run_poldek --noask -ve $INSTALLED_PACKAGES
1026 run_poldek --ask -ve $INSTALLED_PACKAGES
1029 echo You may want to manually remove following BuildRequires fetched:
1030 echo $INSTALLED_PACKAGES
1031 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1039 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1040 if [ "$BCOND" != "" ]; then
1041 echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1044 echo -ne "\nNo conditional flags passed"
1046 echo -ne "\n\nfrom available:\n"
1047 echo -ne "--with :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1051 fetch_build_requires()
1053 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1054 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1055 CONF=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print "@" $3 } ' | xargs)
1056 DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print "@" $3 } ' | xargs)
1057 if [ -n "$CONF" -o -n "$DEPS" ]; then
1058 /usr/bin/poldek --update; /usr/bin/poldek --upa
1060 if [ -n "$CONF" ]; then
1061 echo "Trying to uninstall conflicting packages ($CONF):"
1062 /usr/bin/poldek --noask --nofollow -ev $CONF
1064 if [ -n "$DEPS" ]; then
1065 echo "Trying to install dependencies ($DEPS):"
1066 /usr/bin/poldek --caplookup -uGv $DEPS
1071 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1072 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1073 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1074 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1075 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1076 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`
1078 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`"
1080 package=`basename "$package_item"|sed -e "s/}$//g"`
1081 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1084 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1085 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1086 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
1091 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1094 if `echo $COND_TST|grep -q 'without_'`; then
1095 COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1096 if `echo $COND_TST|grep -q !`; then
1101 if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1107 elif `echo $COND_TST|grep -q 'with_'`; then
1108 COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1109 if `echo $COND_TST|grep -q !`; then
1114 if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1120 RESULT="${COND_STATE}-${COND_ARGV}"
1122 "with-wout" | "wout-with" )
1125 "wout-wout" | "with-with" )
1129 echo "Action '$RESULT' was not defined for package '$package_item'"
1135 if [ "$GO" = "yes" ]; then
1136 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1137 echo "Testing if $package has subrequirements..."
1138 run_poldek -t -i $package --dumpn=".$package-req.txt"
1139 if [ -f ".$package-req.txt" ]; then
1140 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1142 if [ "$package_name" = "$package" ]; then
1143 echo -ne "Installing BuildRequired package:\t$package_name\n"
1144 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1145 install_required_packages $package;
1147 echo -ne "Installing (sub)Required package:\t$package_name\n"
1148 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1149 install_required_packages $package_name;
1153 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1154 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1157 echo "Attempting to run spawn sub - builder..."
1158 run_sub_builder $package_name
1159 if [ $? -eq 0 ]; then
1160 install_required_packages $package_name;
1163 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1164 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1167 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1174 rm -f ".$package-req.txt"
1176 echo "Attempting to run spawn sub - builder..."
1177 run_sub_builder $package
1178 if [ $? -eq 0 ]; then
1179 install_required_packages $package;
1182 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1183 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1186 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1192 echo "Package $package is already installed. BuildRequirement satisfied."
1196 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1197 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1198 echo "Unable to install following packages and their dependencies:"
1199 for pkg in "$NOT_INSTALLED_PACKAGES"
1203 remove_build_requires
1209 #---------------------------------------------
1212 if [ "$#" = 0 ]; then
1238 DEBUG="yes"; shift ;;
1240 COMMAND="version"; shift ;;
1242 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1243 -b | -ba | --build )
1244 COMMAND="build"; shift ;;
1245 -bb | --build-binary )
1246 COMMAND="build-binary"; shift ;;
1247 -bs | --build-source )
1248 COMMAND="build-source"; shift ;;
1249 -bp | --build-prep )
1250 COMMAND="build-prep"; shift ;;
1252 COMMAND="branch"; shift; TAG="${1}"; shift;;
1254 CLEAN="--clean --rmspec --rmsource"; shift ;;
1256 shift; CVSROOT="${1}"; shift ;;
1258 COMMAND="get"; shift ;;
1260 COMMAND="usage"; shift ;;
1262 PROTOCOL="http"; shift ;;
1264 shift; LOGFILE="${1}"; shift ;;
1266 shift; DEF_NICE_LEVEL=${1}; shift ;;
1268 COMMAND="mr-proper"; shift ;;
1270 NOCVS="yes"; shift ;;
1271 -ncs | --no-cvs-specs )
1272 NOCVSSPEC="yes"; shift ;;
1273 -nd | --no-distfiles )
1274 NODIST="yes"; shift ;;
1275 -nm | --no-mirrors )
1276 NOMIRRORS="yes"; shift ;;
1278 NOURLS="yes"; shift ;;
1280 NOSRCS="yes"; shift ;;
1281 -ns0 | --no-source0 )
1282 NOSOURCE0="yes"; shift ;;
1292 shift; RPMOPTS="${1}"; shift ;;
1293 --with | --without )
1294 case $GROUP_BCONDS in
1298 while ! `echo ${1}|grep -qE '(^-|spec)'`
1300 BCOND="$BCOND $COND $1"
1304 BCOND="$BCOND $1 $2" ; shift 2 ;;
1308 shift; TARGET="${1}"; shift ;;
1310 QUIET="--quiet"; shift ;;
1312 CVSDATE="${2}"; shift 2 ;;
1314 shift; CVSTAG="${1}"; shift ;;
1315 -R | --fetch-build-requires)
1316 FETCH_BUILD_REQUIRES="yes"
1317 NOT_INSTALLED_PACKAGES=
1319 -RB | --remove-build-requires)
1320 REMOVE_BUILD_REQUIRES="nice"
1322 -FRB | --force-remove-build-requires)
1323 REMOVE_BUILD_REQUIRES="force"
1325 -Tvs | --tag-version-stable )
1330 -Tvn | --tag-version-nest )
1335 -Ts | --tag-stable )
1345 -Tv | --tag-version )
1350 -Tp | --tag-prefix )
1369 -Upi | --update-poldek-indexes )
1370 UPDATE_POLDEK_INDEXES="yes"
1372 -u | --try-upgrade )
1373 TRY_UPGRADE="1"; shift ;;
1374 -un | --try-upgrade-with-float-version )
1375 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1377 BE_VERBOSE="1"; shift ;;
1383 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1387 RPMOPTS="${RPMOPTS} --nodeps"
1391 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1396 if [ -n "$DEBUG" ]; then
1402 "build" | "build-binary" | "build-source" | "build-prep" )
1404 if [ -n "$SPECFILE" ]; then
1408 fetch_build_requires;
1411 if [ -n "$TEST_TAG" ]; then
1412 TAGVER=`make_tagver`
1413 echo "Searching for tag $TAGVER..."
1414 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1416 if [ -n "$TAGREL" ]; then
1417 Exit_error err_build_fail "Tag $TAGVER already present (spec release: $TAGREL)"
1421 if [ -n "$ICONS" ]; then
1425 if [ -n "$NOSOURCE0" ] ; then
1426 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1428 get_files "$SOURCES $PATCHES";
1430 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1431 run_poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1432 run_poldek --sn ${POLDEK_SOURCE} --up
1434 remove_build_requires;
1436 Exit_error err_no_spec_in_cmdl;
1441 if [ -n "$SPECFILE" ]; then
1444 if [ -n "$ICONS" ]; then
1448 get_files $SOURCES $PATCHES;
1449 branch_files $TAG "$SOURCES $PATCHES $ICONS";
1451 Exit_error err_no_spec_in_cmdl;
1456 if [ -n "$SPECFILE" ]; then
1459 if [ -n "$ICONS" ]; then
1463 if [ -n "$NOSOURCE0" ] ; then
1464 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1466 get_files $SOURCES $PATCHES
1468 Exit_error err_no_spec_in_cmdl;
1475 if [ -n "$SPECFILE" ]; then
1478 if [ -n "$ICONS" ]; then
1482 # don't fetch sources from remote locations
1484 for file in $SOURCES
1486 [ -n "`src_md5 $file`" ] && continue
1487 new_SOURCES="$new_SOURCES $file"
1489 SOURCES="$new_SOURCES"
1490 get_files $SOURCES $PATCHES;
1491 tag_files "$SOURCES $PATCHES $ICONS";
1493 Exit_error err_no_spec_in_cmdl;
1497 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1504 test -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES && rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1507 # vi:syntax=sh:ts=3:sw=4