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
13 # - builder -u fetches current version first
14 # - tries to get new version from distfiles without new md5
15 # - after fetching new version doesn't update md5
18 Build package utility from PLD CVS repository
19 V 0.11 (C) 1999-2003 Free Penguins".
20 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
36 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
37 if [ -s CVS/Root ]; then
38 CVSROOT=$(cat CVS/Root)
40 CVSROOT=${CVSROOT:-""}
42 # Example: LOGFILE='../log.$PACKAGE_NAME'
43 # Yes, you can use variable name! Note _single_ quotes!
62 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
63 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
68 CVS_SERVER="cvs.pld-linux.org"
69 DISTFILES_SERVER="ftp://distfiles.pld-linux.org"
73 FAIL_IF_NO_SOURCES="yes"
75 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
76 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
79 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
87 if [ -f ~/etc/builderrc ]; then
89 elif [ -f ~/.builderrc ]; then
93 #---------------------------------------------
98 if [ -n "$DEBUG" ]; then set -xv; fi
100 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
102 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
103 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
104 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
105 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
106 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
107 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
108 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
109 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
112 - update md5 comments in spec, implies -nd
113 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd
114 -D, --debug - enable script debugging mode,
115 -V, --version - output builder version
116 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
118 --build - get all files from CVS repo or HTTP/FTP and build
119 package from <package>.spec,
121 - get all files from CVS repo or HTTP/FTP and build
122 binary only package from <package>.spec,
124 --build-source - get all files from CVS repo or HTTP/FTP and only
125 pack them into src.rpm,
126 -B, --branch - add branch
127 -c, --clean - clean all temporarily created files (in BUILD,
128 SOURCES, SPECS and \$RPM_BUILD_ROOT),
129 -d <cvsroot>, --cvsroot <cvsroot>
131 --define <macro> <value>
132 - define a macro <macro> with value <value>,
133 -g, --get - get <package>.spec and all related files from
134 CVS repo or HTTP/FTP,
135 -h, --help - this message,
136 -l <logfile>, --logtofile <logfile>
138 -m, --mr-proper - only remove all files related to spec file and
140 -nc, --no-cvs - don't download sources from CVS, if source URL is
143 - don't check specs in CVS
145 - don't download from distfiles
146 -nm, --no-mirrors - don't download from mirror, if source URL is given,
147 -nu, --no-urls - don't try to download from FTP/HTTP location,
148 -ns, --no-srcs - don't download Sources
150 - don't download Source0
152 - additional options for rpm
153 -q, --quiet - be quiet,
155 - build package using resources from specified CVS
157 -r <cvstag>, --cvstag <cvstag>
158 - build package using resources from specified CVS
160 -T <cvstag> , --tag <cvstag>
161 - add cvs tag <cvstag> for files,
162 -Tvs, --tag-version-stable
163 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
164 -Tvn, --tag-version-nest
165 - add cvs tags NEST and NAME-VERSION-RELESE for files,
167 - add cvs tag STABLE for files,
169 - add cvs tag NEST for files,
171 - add cvs tag NAME-VERSION-RELESE for files,
172 -v, --verbose - be verbose,
174 - check version, and try to upgrade package
175 -un, --try-upgrade-with-float-version
176 - as above, but allow float version
178 - refetch sources, don't use distfiles, and update md5
180 --with/--without <feature>
181 - conditional build package depending on
182 %_with_<feature>/%_without_<feature> macro
190 rpm -bp --define 'prep %dump' $BCOND $SPECFILE 2>&1
193 rpmbuild --define 'prep %dump' $BCOND $SPECFILE 2>&1
200 if [ -n "$DEBUG" ]; then
206 if [ "$NOSRCS" != "yes" ]; then
207 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
209 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
210 FAIL_IF_NO_SOURCES="no"
213 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
214 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
215 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
216 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
217 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
219 if [ -n "$BE_VERBOSE" ]; then
220 echo "- Sources : `nourl $SOURCES`"
221 if [ -n "$PATCHES" ]; then
222 echo "- Patches : `nourl $PATCHES`"
224 echo "- Patches : *no patches needed*"
226 if [ -n "$ICONS" ]; then
227 echo "- Icon : `nourl $ICONS`"
229 echo "- Icon : *no package icon*"
231 echo "- Name : $PACKAGE_NAME"
232 echo "- Version : $PACKAGE_VERSION"
233 echo "- Release : $PACKAGE_RELEASE"
239 if [ -n "$DEBUG" ]; then
247 "err_no_spec_in_cmdl" )
248 echo "ERROR: spec file name not specified.";
250 "err_no_spec_in_repo" )
251 echo "Error: spec file not stored in CVS repo.";
253 "err_no_source_in_repo" )
254 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
257 echo "Error: package build failed. (${2:-no more info})";
264 if [ -n "$DEBUG" ]; then
269 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
270 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
277 if [ -n "$DEBUG" ]; then
282 if [ "$NOCVSSPEC" != "yes" ]; then
287 if [ -n "$CVSROOT" ]; then
288 OPTIONS="-d $CVSROOT $OPTIONS"
290 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
291 echo "warning: No cvs access defined - using local .spec file"
296 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
297 OPTIONS="$OPTIONS -A"
299 if [ -n "$CVSDATE" ]; then
300 OPTIONS="$OPTIONS -D $CVSDATE"
302 if [ -n "$CVSTAG" ]; then
303 OPTIONS="$OPTIONS -r $CVSTAG"
309 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
310 retries_counter=$(( $retries_counter + 1 ))
311 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
313 [ -n "$output" ] && echo "$output"
314 if [ "$result" -ne "0" ]; then
315 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
316 echo "Trying again [$SPECFILE]... ($retries_counter)"
320 Exit_error err_no_spec_in_repo;
324 if [ ! -f "$SPECFILE" ]; then
325 Exit_error err_no_spec_in_repo;
328 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
329 chmod $CHMOD_MODE $SPECFILE
332 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
339 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
340 cvs update mirrors >&2
344 while read origin mirror name rest; do
345 ol=`echo -n "$origin"|wc -c`
346 prefix="`echo -n "$url" | head -c $ol`"
347 if [ "$prefix" = "$origin" ] ; then
348 suffix="`echo "$url"|cut -b $ol-`"
349 echo -n "$mirror$suffix"
360 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
361 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
368 [ -z "$no" ] && return
370 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
371 if [ -z "$spec_rev" ]; then
372 spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
374 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
375 md5=$(grep -s -v '^#' additional-md5sums | \
376 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
377 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
378 grep -E '^[0-9a-f]{32}$')
379 if [ X"$md5" = X"" ] ; then
380 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
382 if [ $(echo "$md5" | wc -l) != 1 ] ; then
383 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
385 echo "$md5" | tail -1
391 echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
398 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
405 if [ -n "$DEBUG" ]; then
410 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
414 if [ -n "$CVSROOT" ]; then
415 OPTIONS="-d $CVSROOT $OPTIONS"
417 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
418 echo "warning: No cvs access defined for SOURCES"
422 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
423 OPTIONS="$OPTIONS -A"
425 if [ -n "$CVSDATE" ]; then
426 OPTIONS="$OPTIONS -D $CVSDATE"
428 if [ -n "$CVSTAG" ]; then
429 OPTIONS="$OPTIONS -r $CVSTAG"
432 for i in $GET_FILES; do
433 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
434 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
435 echo "Warning: no URL given for $i"
438 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
439 if good_md5 "$i"; then
440 echo "$(nourl "$i") having proper md5sum already exists"
444 url=$(distfiles_url "$i")
445 if [ `echo $url | grep -E '^(\.|/)'` ] ; then
446 ${GETLOCAL} $url $target
448 if [ -z "$NOMIRRORS" ] ; then
449 url="`find_mirror "$url"`"
451 ${GETURI} -O "$target" "$url" || \
452 if [ `echo $url | grep -E 'ftp://'` ]; then
453 ${GETURI2} -O "$target" "$url"
455 test -s "$target" || rm -f "$target"
457 elif [ -z "$(src_md5 "$i")" ] && \
458 ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then
461 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
462 retries_counter=$(( $retries_counter + 1 ))
463 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
465 [ -n "$output" ] && echo "$output"
466 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
467 echo "Trying again [`nourl $i`]... ($retries_counter)"
476 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
477 if [ -z "$NOMIRRORS" ] ; then
478 im="`find_mirror "$i"`"
483 if [ `echo $im | grep -E 'ftp://'` ]; then ${GETURI2} "$im" ; fi
489 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
490 Exit_error err_no_source_in_repo $i;
491 elif [ -n "$UPDATE5" ] && \
492 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
493 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
494 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
496 echo "Updating source-$srcno md5."
497 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
499 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
500 print "# Source'$srcno'-md5:\t'$md5'\n"
501 if /^Source'$srcno'\s*:\s+/;
506 if good_md5 "$i"; then
509 echo "MD5 sum mismatch. Use -U to refetch sources,"
510 echo "or -5 to update md5 sums, if you're sure files are correct."
511 Exit_error err_no_source_in_repo $i
515 if [ "$CHMOD" = "yes" ]; then
516 CHMOD_FILES="`nourl $GET_FILES`"
517 if [ -n "$CHMOD_FILES" ]; then
518 chmod $CHMOD_MODE $CHMOD_FILES
529 if [ -n "$DEBUG" ]; then
534 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
535 echo $PACKAGE_VERSION
536 echo $PACKAGE_RELEASE
537 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
538 if [ "$TAG_VERSION" = "yes" ]; then
539 echo "CVS tag: $TAGVER"
541 if [ -n "$TAG" ]; then
546 if [ -n "$CVSROOT" ]; then
547 OPTIONS="-d $CVSROOT $OPTIONS"
551 for i in $TAG_FILES; do
552 if [ -f `nourl $i` ]; then
553 if [ "$TAG_VERSION" = "yes" ]; then
554 cvs $OPTIONS $TAGVER `nourl $i`
556 if [ -n "$TAG" ]; then
557 cvs $OPTIONS $TAG `nourl $i`
560 Exit_error err_no_source_in_repo $i
565 if [ "$TAG_VERSION" = "yes" ]; then
566 cvs $OPTIONS $TAGVER $SPECFILE
568 if [ -n "$TAG" ]; then
569 cvs $OPTIONS $TAG $SPECFILE
579 echo "CVS branch tag: $TAG"
584 if [ -n "$DEBUG" ]; then
589 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
592 if [ -n "$CVSROOT" ]; then
593 OPTIONS="-d $CVSROOT $OPTIONS"
596 for i in $TAG_FILES; do
597 if [ -f `nourl $i` ]; then
598 cvs $OPTIONS $TAG `nourl $i`
600 Exit_error err_no_source_in_repo $i
604 cvs $OPTIONS $TAG $SPECFILE
614 if [ -n "$DEBUG" ]; then
621 if [ -n "$TRY_UPGRADE" ]; then
623 if [ -n "FLOAT_VERSION" ]; then
624 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
626 TNOTIFY=`./pldnotify.awk $SPECFILE`
629 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
631 if [ -n "$TNEWVER" ]; then
633 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
635 echo "New version found, updating spec file to version " $TNEWVER
637 cp -f $SPECFILE $SPECFILE.bak
641 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
642 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
646 get_files "$SOURCES $PATCHES";
648 unset TOLDVER TNEWVER TNOTIFY
658 BUILD_SWITCH="-ba" ;;
660 BUILD_SWITCH="-bb" ;;
662 BUILD_SWITCH="-bs --nodeps" ;;
664 if [ -n "$LOGFILE" ]; then
665 if [ -n "$CVSTAG" ]; then
666 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
670 LOG=`eval echo $LOGFILE`
671 if [ -n "$LASTLOG_FILE" ]; then
672 echo "LASTLOG=$LOG" > $LASTLOG_FILE
674 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
675 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
676 RETVAL=`cat $RES_FILE`
678 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
679 if [ "$RETVAL" -eq "0" ]; then
686 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
690 if [ "$RETVAL" -ne "0" ]; then
692 if [ -n "$TRY_UPGRADE" ]; then
693 echo "\n!!! Package with new version cannot be build automagically\n"
694 mv -f $SPECFILE.bak $SPECFILE
697 Exit_error err_build_fail;
705 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
707 #---------------------------------------------
710 if [ "$#" = 0 ]; then
715 while test $# -gt 0 ; do
730 DEBUG="yes"; shift ;;
732 COMMAND="version"; shift ;;
734 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
736 COMMAND="build"; shift ;;
737 -bb | --build-binary )
738 COMMAND="build-binary"; shift ;;
739 -bs | --build-source )
740 COMMAND="build-source"; shift ;;
742 COMMAND="branch"; shift; TAG="${1}"; shift;;
744 CLEAN="--clean --rmspec --rmsource"; shift ;;
746 shift; CVSROOT="${1}"; shift ;;
748 COMMAND="get"; shift ;;
750 COMMAND="usage"; shift ;;
752 shift; LOGFILE="${1}"; shift ;;
754 shift; DEF_NICE_LEVEL=${1}; shift ;;
756 COMMAND="mr-proper"; shift ;;
758 NOCVS="yes"; shift ;;
759 -ncs | --no-cvs-specs )
760 NOCVSSPEC="yes"; shift ;;
761 -nd | --no-distfiles )
762 NODIST="yes"; shift ;;
764 NOMIRRORS="yes"; shift ;;
766 NOURLS="yes"; shift ;;
768 NOSRCS="yes"; shift ;;
769 -ns0 | --no-source0 )
770 NOSOURCE0="yes"; shift ;;
772 shift; RPMOPTS="${1}"; shift ;;
774 BCOND="$BCOND $1 $2" ; shift 2 ;;
776 QUIET="--quiet"; shift ;;
778 CVSDATE="${2}"; shift 2 ;;
780 shift; CVSTAG="${1}"; shift ;;
781 -Tvs | --tag-version-stable )
786 -Tvn | --tag-version-nest )
801 -Tv | --tag-version )
819 TRY_UPGRADE="1"; shift ;;
820 -un | --try-upgrade-with-float-version )
821 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
823 BE_VERBOSE="1"; shift ;;
829 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
832 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
836 if [ -n "$DEBUG" ]; then
842 "build" | "build-binary" | "build-source" )
844 if [ -n "$SPECFILE" ]; then
848 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
849 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
850 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
851 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
853 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
854 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
858 if [ -n "$ICONS" ]; then
862 if [ -n "$NOSOURCE0" ] ; then
863 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
865 get_files "$SOURCES $PATCHES";
868 Exit_error err_no_spec_in_cmdl;
873 if [ -n "$SPECFILE" ]; then
876 if [ -n "$ICONS" ]; then
880 get_files $SOURCES $PATCHES;
881 branch_files $TAG "$SOURCES $PATCHES $ICONS";
883 Exit_error err_no_spec_in_cmdl;
888 if [ -n "$SPECFILE" ]; then
891 if [ -n "$ICONS" ]; then
895 if [ -n "$NOSOURCE0" ] ; then
896 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
898 get_files $SOURCES $PATCHES
900 Exit_error err_no_spec_in_cmdl;
905 if [ -n "$SPECFILE" ]; then
908 if [ -n "$ICONS" ]; then
912 get_files $SOURCES $PATCHES;
913 tag_files "$SOURCES $PATCHES $ICONS";
915 Exit_error err_no_spec_in_cmdl;
919 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE