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
12 # TODO: "NoSource: N" should disallow adding "SourceN-md5:" tag
15 Build package utility from PLD CVS repository
16 V 0.11 (C) 1999-2003 Free Penguins".
17 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
33 ALLWAYS_CVSUP=${ALLWAYS_CVSUP:-"yes"}
34 if [ -s CVS/Root ]; then
35 CVSROOT=$(cat CVS/Root)
37 CVSROOT=${CVSROOT:-""}
39 # Example: LOGFILE='../log.$PACKAGE_NAME'
40 # Yes, you can use variable name! Note _single_ quotes!
59 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
60 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
65 CVS_SERVER="cvs.pld-linux.org"
66 DISTFILES_SERVER="ftp://distfiles.pld-linux.org"
70 FAIL_IF_NO_SOURCES="yes"
72 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
73 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
76 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
84 if [ -f ~/etc/builderrc ]; then
86 elif [ -f ~/.builderrc ]; then
90 #---------------------------------------------
95 if [ -n "$DEBUG" ]; then set -xv; fi
97 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
99 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
100 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
101 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
102 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
103 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
104 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
105 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
106 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
109 - update md5 comments in spec, implies -nd
110 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd
111 -D, --debug - enable script debugging mode,
112 -V, --version - output builder version
113 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
115 --build - get all files from CVS repo or HTTP/FTP and build
116 package from <package>.spec,
118 - get all files from CVS repo or HTTP/FTP and build
119 binary only package from <package>.spec,
121 --build-source - get all files from CVS repo or HTTP/FTP and only
122 pack them into src.rpm,
123 -B, --branch - add branch
124 -c, --clean - clean all temporarily created files (in BUILD,
125 SOURCES, SPECS and \$RPM_BUILD_ROOT),
126 -d <cvsroot>, --cvsroot <cvsroot>
128 --define <macro> <value>
129 - define a macro <macro> with value <value>,
130 -g, --get - get <package>.spec and all related files from
131 CVS repo or HTTP/FTP,
132 -h, --help - this message,
133 -l <logfile>, --logtofile <logfile>
135 -m, --mr-proper - only remove all files related to spec file and
137 -nc, --no-cvs - don't download sources from CVS, if source URL is
140 - don't check specs in CVS
142 - don't download from distfiles
143 -nm, --no-mirrors - don't download from mirror, if source URL is given,
144 -nu, --no-urls - don't try to download from FTP/HTTP location,
145 -ns, --no-srcs - don't download Sources
147 - don't download Source0
149 - additional options for rpm
150 -q, --quiet - be quiet,
152 - build package using resources from specified CVS
154 -r <cvstag>, --cvstag <cvstag>
155 - build package using resources from specified CVS
157 -T <cvstag> , --tag <cvstag>
158 - add cvs tag <cvstag> for files,
159 -Tvs, --tag-version-stable
160 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
161 -Tvn, --tag-version-nest
162 - add cvs tags NEST and NAME-VERSION-RELESE for files,
164 - add cvs tag STABLE for files,
166 - add cvs tag NEST for files,
168 - add cvs tag NAME-VERSION-RELESE for files,
169 -v, --verbose - be verbose,
171 - check version, and try to upgrade package
172 -un, --try-upgrade-with-float-version
173 - as above, but allow float version
175 - refetch sources, don't use distfiles, and update md5
177 --with/--without <feature>
178 - conditional build package depending on
179 %_with_<feature>/%_without_<feature> macro
186 if [ -n "$DEBUG" ]; then
192 if [ "$NOSRCS" != "yes" ]; then
193 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
195 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
196 FAIL_IF_NO_SOURCES="no"
199 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
200 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
201 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
202 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
203 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
205 if [ -n "$BE_VERBOSE" ]; then
206 echo "- Sources : `nourl $SOURCES`"
207 if [ -n "$PATCHES" ]; then
208 echo "- Patches : `nourl $PATCHES`"
210 echo "- Patches : *no patches needed*"
212 if [ -n "$ICONS" ]; then
213 echo "- Icon : `nourl $ICONS`"
215 echo "- Icon : *no package icon*"
217 echo "- Name : $PACKAGE_NAME"
218 echo "- Version : $PACKAGE_VERSION"
219 echo "- Release : $PACKAGE_RELEASE"
225 if [ -n "$DEBUG" ]; then
233 "err_no_spec_in_cmdl" )
234 echo "ERROR: spec file name not specified.";
236 "err_no_spec_in_repo" )
237 echo "Error: spec file not stored in CVS repo.";
239 "err_no_source_in_repo" )
240 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
243 echo "Error: package build failed. (${2:-no more info})";
250 if [ -n "$DEBUG" ]; then
255 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
256 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
263 if [ -n "$DEBUG" ]; then
268 if [ "$NOCVSSPEC" != "yes" ]; then
273 if [ -n "$CVSROOT" ]; then
274 OPTIONS="-d $CVSROOT $OPTIONS"
276 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
277 echo "warning: No cvs access defined - using local .spec file"
282 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
283 OPTIONS="$OPTIONS -A"
285 if [ -n "$CVSDATE" ]; then
286 OPTIONS="$OPTIONS -D $CVSDATE"
288 if [ -n "$CVSTAG" ]; then
289 OPTIONS="$OPTIONS -r $CVSTAG"
295 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
296 retries_counter=$(( $retries_counter + 1 ))
297 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
299 [ -n "$output" ] && echo "$output"
300 if [ "$result" -ne "0" ]; then
301 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
302 echo "Trying again [$SPECFILE]... ($retries_counter)"
306 Exit_error err_no_spec_in_repo;
310 if [ ! -f "$SPECFILE" ]; then
311 Exit_error err_no_spec_in_repo;
314 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
315 chmod $CHMOD_MODE $SPECFILE
318 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
325 if [ ! -f "mirrors" ] ; then
326 cvs update mirrors >&2
330 while read origin mirror name rest; do
331 ol=`echo -n "$origin"|wc -c`
332 prefix="`echo -n "$url" | head -c $ol`"
333 if [ "$prefix" = "$origin" ] ; then
334 suffix="`echo "$url"|cut -b $ol-`"
335 echo -n "$mirror$suffix"
345 $RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \
346 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
347 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
354 [ -z "$no" ] && return
356 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
361 echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
368 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
375 if [ -n "$DEBUG" ]; then
380 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
384 if [ -n "$CVSROOT" ]; then
385 OPTIONS="-d $CVSROOT $OPTIONS"
387 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
388 echo "warning: No cvs access defined for SOURCES"
392 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
393 OPTIONS="$OPTIONS -A"
395 if [ -n "$CVSDATE" ]; then
396 OPTIONS="$OPTIONS -D $CVSDATE"
398 if [ -n "$CVSTAG" ]; then
399 OPTIONS="$OPTIONS -r $CVSTAG"
402 for i in $GET_FILES; do
403 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
404 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
405 echo "Warning: no URL given for $i"
408 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
409 if good_md5 "$i"; then
410 echo "$(nourl "$i") having proper md5sum already exists"
414 url=$(distfiles_url "$i")
415 if [ `echo $url | grep -E '^(\.|/)'` ] ; then
416 ${GETLOCAL} $url $target
418 if [ -z "$NOMIRRORS" ] ; then
419 url="`find_mirror "$url"`"
421 ${GETURI} -O "$target" "$url" || \
422 if [ `echo $url | grep -E 'ftp://'` ]; then
423 ${GETURI2} -O "$target" "$url"
425 test -s "$target" || rm -f "$target"
427 elif [ -z "$(src_md5 "$i")" ] && \
428 ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then
431 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
432 retries_counter=$(( $retries_counter + 1 ))
433 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
435 [ -n "$output" ] && echo "$output"
436 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
437 echo "Trying again [`nourl $i`]... ($retries_counter)"
446 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
447 if [ -z "$NOMIRRORS" ] ; then
448 i="`find_mirror "$i"`"
451 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
455 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
456 Exit_error err_no_source_in_repo $i;
457 elif [ -n "$UPDATE5" ] && \
458 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' ) || \
459 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
462 echo "Updating source-$srcno md5."
463 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
464 perl -i -ne 'print "# Source'$srcno'-md5:\t'$md5'\n"
465 if /^Source'$srcno'\s*:\s+/;
466 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i' \
470 if good_md5 "$i"; then
473 echo "MD5 sum mismatch. Use -U to refetch sources,"
474 echo "or -5 to update md5 sums, if you're sure files are correct."
475 Exit_error err_no_source_in_repo $i
480 if [ "$CHMOD" = "yes" ]; then
481 CHMOD_FILES="`nourl $GET_FILES`"
482 if [ -n "$CHMOD_FILES" ]; then
483 chmod $CHMOD_MODE $CHMOD_FILES
494 if [ -n "$DEBUG" ]; then
499 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
500 echo $PACKAGE_VERSION
501 echo $PACKAGE_RELEASE
502 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
503 if [ "$TAG_VERSION" = "yes" ]; then
504 echo "CVS tag: $TAGVER"
506 if [ -n "$TAG" ]; then
511 if [ -n "$CVSROOT" ]; then
512 OPTIONS="-d $CVSROOT $OPTIONS"
516 for i in $TAG_FILES; do
517 if [ -f `nourl $i` ]; then
518 if [ "$TAG_VERSION" = "yes" ]; then
519 cvs $OPTIONS $TAGVER `nourl $i`
521 if [ -n "$TAG" ]; then
522 cvs $OPTIONS $TAG `nourl $i`
525 Exit_error err_no_source_in_repo $i
530 if [ "$TAG_VERSION" = "yes" ]; then
531 cvs $OPTIONS $TAGVER $SPECFILE
533 if [ -n "$TAG" ]; then
534 cvs $OPTIONS $TAG $SPECFILE
544 echo "CVS branch tag: $TAG"
549 if [ -n "$DEBUG" ]; then
554 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
557 if [ -n "$CVSROOT" ]; then
558 OPTIONS="-d $CVSROOT $OPTIONS"
561 for i in $TAG_FILES; do
562 if [ -f `nourl $i` ]; then
563 cvs $OPTIONS $TAG `nourl $i`
565 Exit_error err_no_source_in_repo $i
569 cvs $OPTIONS $TAG $SPECFILE
579 if [ -n "$DEBUG" ]; then
586 if [ -n "$TRY_UPGRADE" ]; then
588 if [ -n "FLOAT_VERSION" ]; then
589 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
591 TNOTIFY=`./pldnotify.awk $SPECFILE`
594 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
596 if [ -n "$TNEWVER" ]; then
598 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
600 echo "New version found, updating spec file to version " $TNEWVER
602 cp -f $SPECFILE $SPECFILE.bak
606 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
607 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
611 get_files "$SOURCES $PATCHES";
613 unset TOLDVER TNEWVER TNOTIFY
623 BUILD_SWITCH="-ba" ;;
625 BUILD_SWITCH="-bb" ;;
627 BUILD_SWITCH="-bs --nodeps" ;;
629 if [ -n "$LOGFILE" ]; then
630 if [ -n "$CVSTAG" ]; then
631 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
635 LOG=`eval echo $LOGFILE`
636 if [ -n "$LASTLOG_FILE" ]; then
637 echo "LASTLOG=$LOG" > $LASTLOG_FILE
639 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
640 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
641 RETVAL=`cat $RES_FILE`
643 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
644 if [ "$RETVAL" -eq "0" ]; then
651 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
655 if [ "$RETVAL" -ne "0" ]; then
657 if [ -n "$TRY_UPGRADE" ]; then
658 echo "\n!!! Package with new version cannot be build automagically\n"
659 mv -f $SPECFILE.bak $SPECFILE
662 Exit_error err_build_fail;
670 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
672 #---------------------------------------------
675 if [ "$#" = 0 ]; then
680 while test $# -gt 0 ; do
695 DEBUG="yes"; shift ;;
697 COMMAND="version"; shift ;;
699 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
701 COMMAND="build"; shift ;;
702 -bb | --build-binary )
703 COMMAND="build-binary"; shift ;;
704 -bs | --build-source )
705 COMMAND="build-source"; shift ;;
707 COMMAND="branch"; shift; TAG="${1}"; shift;;
709 CLEAN="--clean --rmspec --rmsource"; shift ;;
711 shift; CVSROOT="${1}"; shift ;;
713 COMMAND="get"; shift ;;
715 COMMAND="usage"; shift ;;
717 shift; LOGFILE="${1}"; shift ;;
719 shift; DEF_NICE_LEVEL=${1}; shift ;;
721 COMMAND="mr-proper"; shift ;;
723 NOCVS="yes"; shift ;;
724 -ncs | --no-cvs-specs )
725 NOCVSSPEC="yes"; shift ;;
726 -nd | --no-distfiles )
727 NODIST="yes"; shift ;;
729 NOMIRRORS="yes"; shift ;;
731 NOURLS="yes"; shift ;;
733 NOSRCS="yes"; shift ;;
734 -ns0 | --no-source0 )
735 NOSOURCE0="yes"; shift ;;
737 shift; RPMOPTS="${1}"; shift ;;
739 BCOND="$BCOND $1 $2" ; shift 2 ;;
741 QUIET="--quiet"; shift ;;
743 CVSDATE="${2}"; shift 2 ;;
745 shift; CVSTAG="${1}"; shift ;;
746 -Tvs | --tag-version-stable )
751 -Tvn | --tag-version-nest )
766 -Tv | --tag-version )
784 TRY_UPGRADE="1"; shift ;;
785 -un | --try-upgrade-with-float-version )
786 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
788 BE_VERBOSE="1"; shift ;;
794 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
797 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
801 if [ -n "$DEBUG" ]; then
807 "build" | "build-binary" | "build-source" )
809 if [ -n "$SPECFILE" ]; then
813 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
814 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
815 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
816 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
818 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
819 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
823 if [ -n "$ICONS" ]; then
827 if [ -n "$NOSOURCE0" ] ; then
828 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
830 get_files "$SOURCES $PATCHES";
833 Exit_error err_no_spec_in_cmdl;
838 if [ -n "$SPECFILE" ]; then
841 if [ -n "$ICONS" ]; then
845 get_files $SOURCES $PATCHES;
846 branch_files $TAG "$SOURCES $PATCHES $ICONS";
848 Exit_error err_no_spec_in_cmdl;
853 if [ -n "$SPECFILE" ]; then
856 if [ -n "$ICONS" ]; then
860 if [ -n "$NOSOURCE0" ] ; then
861 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
863 get_files $SOURCES $PATCHES
865 Exit_error err_no_spec_in_cmdl;
870 if [ -n "$SPECFILE" ]; then
873 if [ -n "$ICONS" ]; then
877 get_files $SOURCES $PATCHES;
878 tag_files "$SOURCES $PATCHES $ICONS";
880 Exit_error err_no_spec_in_cmdl;
884 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE