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 Build package utility from PLD CVS repository
14 V 0.11 (C) 1999-2001 Free Penguins".
15 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
30 ALLWAYS_CVSUP=${ALLWAYS_CVSUP:-"yes"}
31 if [ -s CVS/Root ]; then
32 CVSROOT=$(cat CVS/Root)
34 CVSROOT=${CVSROOT:-""}
36 # Example: LOGFILE='../log.$PACKAGE_NAME'
37 # Yes, you can use variable name! Note _single_ quotes!
56 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
57 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
62 CVS_SERVER="cvs.pld-linux.org"
63 DISTFILES_SERVER="ftp://distfiles.pld-ppc.org"
67 FAIL_IF_NO_SOURCES="yes"
69 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
70 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
72 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
80 if [ -f ~/etc/builderrc ]; then
82 elif [ -f ~/.builderrc ]; then
86 #---------------------------------------------
91 if [ -n "$DEBUG" ]; then set -xv; fi
93 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
95 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
96 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
97 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
98 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
99 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
100 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
101 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
102 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
104 -5 - update md5 comments in spec
105 -D, --debug - enable script debugging mode,
106 -V, --version - output builder version
107 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
109 --build - get all files from CVS repo or HTTP/FTP and build
110 package from <package>.spec,
112 - get all files from CVS repo or HTTP/FTP and build
113 binary only package from <package>.spec,
115 --build-source - get all files from CVS repo or HTTP/FTP and only
116 pack them into src.rpm,
117 -B, --branch - add branch
118 -c, --clean - clean all temporarily created files (in BUILD,
119 SOURCES, SPECS and \$RPM_BUILD_ROOT),
120 -d <cvsroot>, --cvsroot <cvsroot>
122 --define <macro> <value>
123 - define a macro <macro> with value <value>,
124 -g, --get - get <package>.spec and all related files from
125 CVS repo or HTTP/FTP,
126 -h, --help - this message,
127 -l <logfile>, --logtofile <logfile>
129 -m, --mr-proper - only remove all files related to spec file and
131 -nc, --no-cvs - don't download sources from CVS, if source URL is
134 - don't check specs in CVS
136 - don't download from distfiles
137 -nm, --no-mirrors - don't download from mirror, if source URL is given,
138 -nu, --no-urls - don't try to download from FTP/HTTP location,
139 -ns, --no-srcs - don't download Sources
141 - don't download Source0
143 - additional options for rpm
144 -q, --quiet - be quiet,
146 - build package using resources from specified CVS
148 -r <cvstag>, --cvstag <cvstag>
149 - build package using resources from specified CVS
151 -T <cvstag> , --tag <cvstag>
152 - add cvs tag <cvstag> for files,
153 -Tvs, --tag-version-stable
154 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
155 -Tvn, --tag-version-nest
156 - add cvs tags NEST and NAME-VERSION-RELESE for files,
158 - add cvs tag STABLE for files,
160 - add cvs tag NEST for files,
162 - add cvs tag NAME-VERSION-RELESE for files,
163 -v, --verbose - be verbose,
165 - check version, and try to upgrade package
166 -un, --try-upgrade-with-float-version
167 - as above, but allow float version
169 - refetch sources (makes sense with -nc -nd)
170 (CVS updates are controlled by ALLWAYS_CVSUP environment
171 variable, distfiles are checked against md5 sum)
172 --with/--without <feature>
173 - conditional build package depending on
174 %_with_<feature>/%_without_<feature> macro
181 if [ -n "$DEBUG" ]; then
187 if [ "$NOSRCS" != "yes" ]; then
188 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
190 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
191 FAIL_IF_NO_SOURCES="no"
194 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
195 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
196 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
197 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
198 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
200 if [ -n "$BE_VERBOSE" ]; then
201 echo "- Sources : `nourl $SOURCES`"
202 if [ -n "$PATCHES" ]; then
203 echo "- Patches : `nourl $PATCHES`"
205 echo "- Patches : *no patches needed*"
207 if [ -n "$ICONS" ]; then
208 echo "- Icon : `nourl $ICONS`"
210 echo "- Icon : *no package icon*"
212 echo "- Name : $PACKAGE_NAME"
213 echo "- Version : $PACKAGE_VERSION"
214 echo "- Release : $PACKAGE_RELEASE"
220 if [ -n "$DEBUG" ]; then
228 "err_no_spec_in_cmdl" )
229 echo "ERROR: spec file name not specified.";
231 "err_no_spec_in_repo" )
232 echo "Error: spec file not stored in CVS repo.";
234 "err_no_source_in_repo" )
235 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
238 echo "Error: package build failed. (${2:-no more info})";
245 if [ -n "$DEBUG" ]; then
250 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
251 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
258 if [ -n "$DEBUG" ]; then
263 if [ "$NOCVSSPEC" != "yes" ]; then
268 if [ -n "$CVSROOT" ]; then
269 OPTIONS="-d $CVSROOT $OPTIONS"
271 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
272 echo "warning: No cvs access defined - using local .spec file"
277 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
278 OPTIONS="$OPTIONS -A"
280 if [ -n "$CVSDATE" ]; then
281 OPTIONS="$OPTIONS -D $CVSDATE"
283 if [ -n "$CVSTAG" ]; then
284 OPTIONS="$OPTIONS -r $CVSTAG"
290 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
291 retries_counter=$(( $retries_counter + 1 ))
292 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
294 [ -n "$output" ] && echo "$output"
295 if [ "$result" -ne "0" ]; then
296 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
297 echo "Trying again [$SPECFILE]... ($retries_counter)"
301 Exit_error err_no_spec_in_repo;
305 if [ ! -f "$SPECFILE" ]; then
306 Exit_error err_no_spec_in_repo;
309 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
310 chmod $CHMOD_MODE $SPECFILE
313 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
320 if [ ! -f "mirrors" ] ; then
321 cvs update mirrors >&2
325 while read origin mirror name rest; do
326 ol=`echo -n "$origin"|wc -c`
327 prefix="`echo -n "$url" | head -c $ol`"
328 if [ "$prefix" = "$origin" ] ; then
329 suffix="`echo "$url"|cut -b $ol-`"
330 echo -n "$mirror$suffix"
340 $RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \
341 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
342 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
349 [ -z "$no" ] && return
351 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
356 echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')"
363 if [ -n "$DEBUG" ]; then
368 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
372 if [ -n "$CVSROOT" ]; then
373 OPTIONS="-d $CVSROOT $OPTIONS"
375 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
376 echo "warning: No cvs access defined for SOURCES"
380 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
381 OPTIONS="$OPTIONS -A"
383 if [ -n "$CVSDATE" ]; then
384 OPTIONS="$OPTIONS -D $CVSDATE"
386 if [ -n "$CVSTAG" ]; then
387 OPTIONS="$OPTIONS -r $CVSTAG"
390 for i in $GET_FILES; do
391 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
392 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
393 echo "Warning: no URL given for $i"
396 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
397 if [ "$(src_md5 "$i")" = "$(md5sum $(nourl "$i") 2> /dev/null | sed -e 's/ .*//')" ]; then
398 echo "$(nourl "$i") having proper md5sum already exists"
402 url=$(distfiles_url "$i")
403 if [ -z "$NOMIRRORS" ] ; then
404 url="`find_mirror "$url"`"
406 ${GETURI} -O "$target" "$url" || \
407 if [ `echo $url | grep -E 'ftp://'` ]; then
408 ${GETURI2} -O "$target" "$url"
410 elif [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
413 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
414 retries_counter=$(( $retries_counter + 1 ))
415 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
417 [ -n "$output" ] && echo "$output"
418 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
419 echo "Trying again [`nourl $i`]... ($retries_counter)"
428 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
429 if [ -z "$NOMIRRORS" ] ; then
430 i="`find_mirror "$i"`"
433 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
436 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
437 Exit_error err_no_source_in_repo $i;
439 if [ -n "$UPDATE5" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
440 tmp_spec=`mktemp ${TMPDIR:-/tmp}/$SPECFILE.XXXXXX`
442 md5=$(md5sum `echo $i | perl -ne '/.*\/(.*)/; print "$1\n"'` 2> /dev/null | cut -f1 -d' ')
443 perl -ne 'print "# Source'$srcno'-md5: '$md5'\n" if /^Source'$srcno':[ ]*/;
444 print unless /^#[ ]*Source'$srcno'-md5:[ ]*/' < $SPECS_DIR/$SPECFILE > $tmp_spec
445 mv -f $tmp_spec $SPECS_DIR/$SPECFILE
451 if [ "$CHMOD" = "yes" ]; then
452 CHMOD_FILES="`nourl $GET_FILES`"
453 if [ -n "$CHMOD_FILES" ]; then
454 chmod $CHMOD_MODE $CHMOD_FILES
465 if [ -n "$DEBUG" ]; then
470 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
471 echo $PACKAGE_VERSION
472 echo $PACKAGE_RELEASE
473 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
474 if [ "$TAG_VERSION" = "yes" ]; then
475 echo "CVS tag: $TAGVER"
477 if [ -n "$TAG" ]; then
482 if [ -n "$CVSROOT" ]; then
483 OPTIONS="-d $CVSROOT $OPTIONS"
487 for i in $TAG_FILES; do
488 if [ -f `nourl $i` ]; then
489 if [ "$TAG_VERSION" = "yes" ]; then
490 cvs $OPTIONS $TAGVER `nourl $i`
492 if [ -n "$TAG" ]; then
493 cvs $OPTIONS $TAG `nourl $i`
496 Exit_error err_no_source_in_repo $i
501 if [ "$TAG_VERSION" = "yes" ]; then
502 cvs $OPTIONS $TAGVER $SPECFILE
504 if [ -n "$TAG" ]; then
505 cvs $OPTIONS $TAG $SPECFILE
515 echo "CVS branch tag: $TAG"
520 if [ -n "$DEBUG" ]; then
525 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
528 if [ -n "$CVSROOT" ]; then
529 OPTIONS="-d $CVSROOT $OPTIONS"
532 for i in $TAG_FILES; do
533 if [ -f `nourl $i` ]; then
534 cvs $OPTIONS $TAG `nourl $i`
536 Exit_error err_no_source_in_repo $i
540 cvs $OPTIONS $TAG $SPECFILE
550 if [ -n "$DEBUG" ]; then
557 if [ -n "$TRY_UPGRADE" ]; then
559 if [ -n "FLOAT_VERSION" ]; then
560 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
562 TNOTIFY=`./pldnotify.awk $SPECFILE`
565 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
567 if [ -n "$TNEWVER" ]; then
569 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
571 echo "New version found, updating spec file to version " $TNEWVER
573 cp -f $SPECFILE $SPECFILE.bak
577 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
578 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
582 get_files "$SOURCES $PATCHES";
584 unset TOLDVER TNEWVER TNOTIFY
594 BUILD_SWITCH="-ba" ;;
596 BUILD_SWITCH="-bb" ;;
598 BUILD_SWITCH="-bs --nodeps" ;;
600 if [ -n "$LOGFILE" ]; then
601 if [ -n "$CVSTAG" ]; then
602 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
606 LOG=`eval echo $LOGFILE`
607 if [ -n "$LASTLOG_FILE" ]; then
608 echo "LASTLOG=$LOG" > $LASTLOG_FILE
610 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
611 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
612 RETVAL=`cat $RES_FILE`
614 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
615 if [ "$RETVAL" -eq "0" ]; then
622 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
626 if [ "$RETVAL" -ne "0" ]; then
628 if [ -n "$TRY_UPGRADE" ]; then
629 echo "\n!!! Package with new version cannot be build automagically\n"
630 mv -f $SPECFILE.bak $SPECFILE
633 Exit_error err_build_fail;
641 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
643 #---------------------------------------------
646 if [ "$#" = 0 ]; then
651 while test $# -gt 0 ; do
659 DEBUG="yes"; shift ;;
661 COMMAND="version"; shift ;;
663 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
665 COMMAND="build"; shift ;;
666 -bb | --build-binary )
667 COMMAND="build-binary"; shift ;;
668 -bs | --build-source )
669 COMMAND="build-source"; shift ;;
671 COMMAND="branch"; shift; TAG="${1}"; shift;;
673 CLEAN="--clean --rmspec --rmsource"; shift ;;
675 shift; CVSROOT="${1}"; shift ;;
677 COMMAND="get"; shift ;;
679 COMMAND="usage"; shift ;;
681 shift; LOGFILE="${1}"; shift ;;
683 shift; DEF_NICE_LEVEL=${1}; shift ;;
685 COMMAND="mr-proper"; shift ;;
687 NOCVS="yes"; shift ;;
688 -ncs | --no-cvs-specs )
689 NOCVSSPEC="yes"; shift ;;
690 -nd | --no-distfiles )
691 NODIST="yes"; shift ;;
693 NOMIRRORS="yes"; shift ;;
695 NOURLS="yes"; shift ;;
697 NOSRCS="yes"; shift ;;
698 -ns0 | --no-source0 )
699 NOSOURCE0="yes"; shift ;;
701 shift; RPMOPTS="${1}"; shift ;;
703 BCOND="$BCOND $1 $2" ; shift 2 ;;
705 QUIET="--quiet"; shift ;;
707 CVSDATE="${2}"; shift 2 ;;
709 shift; CVSTAG="${1}"; shift ;;
710 -Tvs | --tag-version-stable )
715 -Tvn | --tag-version-nest )
730 -Tv | --tag-version )
742 UPDATE="yes"; shift ;;
744 TRY_UPGRADE="1"; shift ;;
745 -un | --try-upgrade-with-float-version )
746 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
748 BE_VERBOSE="1"; shift ;;
754 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
757 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
761 if [ -n "$DEBUG" ]; then
767 "build" | "build-binary" | "build-source" )
769 if [ -n "$SPECFILE" ]; then
773 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
774 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
775 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
776 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
778 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
779 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
783 if [ -n "$ICONS" ]; then
787 if [ -n "$NOSOURCE0" ] ; then
788 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
790 get_files "$SOURCES $PATCHES";
793 Exit_error err_no_spec_in_cmdl;
798 if [ -n "$SPECFILE" ]; then
801 if [ -n "$ICONS" ]; then
805 get_files $SOURCES $PATCHES;
806 branch_files $TAG "$SOURCES $PATCHES $ICONS";
808 Exit_error err_no_spec_in_cmdl;
813 if [ -n "$SPECFILE" ]; then
816 if [ -n "$ICONS" ]; then
820 if [ -n "$NOSOURCE0" ] ; then
821 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
823 get_files $SOURCES $PATCHES
825 Exit_error err_no_spec_in_cmdl;
830 if [ -n "$SPECFILE" ]; then
833 if [ -n "$ICONS" ]; then
837 get_files $SOURCES $PATCHES;
838 tag_files "$SOURCES $PATCHES $ICONS";
840 Exit_error err_no_spec_in_cmdl;
844 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE