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"
27 ALLWAYS_CVSUP=${ALLWAYS_CVSUP:-"yes"}
28 if [ -s CVS/Root ]; then
29 CVSROOT=$(cat CVS/Root)
31 CVSROOT=${CVSROOT:-""}
33 # Example: LOGFILE='../log.$PACKAGE_NAME'
34 # Yes, you can use variable name! Note _single_ quotes!
53 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
54 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
61 FAIL_IF_NO_SOURCES="yes"
63 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
64 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
66 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
74 if [ -f ~/etc/builderrc ]; then
76 elif [ -f ~/.builderrc ]; then
80 #---------------------------------------------
85 if [ -n "$DEBUG" ]; then set -xv; fi
87 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
89 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
90 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
91 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
92 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
93 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
94 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
95 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
96 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
98 -D, --debug - enable script debugging mode,
99 -V, --version - output builder version
100 -a, --as_anon - get files via pserver as cvs@cvs.pld-linux.org,
102 --build - get all files from CVS repo or HTTP/FTP and build
103 package from <package>.spec,
105 - get all files from CVS repo or HTTP/FTP and build
106 binary only package from <package>.spec,
108 --build-source - get all files from CVS repo or HTTP/FTP and only
109 pack them into src.rpm,
110 -B, --branch - add branch
111 -c, --clean - clean all temporarily created files (in BUILD,
112 SOURCES, SPECS and \$RPM_BUILD_ROOT),
113 -d <cvsroot>, --cvsroot <cvsroot>
115 --define <macro> <value>
116 - define a macro <macro> with value <value>,
117 -g, --get - get <package>.spec and all related files from
118 CVS repo or HTTP/FTP,
119 -h, --help - this message,
120 -l <logfile>, --logtofile <logfile>
122 -m, --mr-proper - only remove all files related to spec file and
124 -nc, --no-cvs - don't download sources from CVS, if source URL is
127 - don't check specs in CVS
128 -nm, --no-mirrors - don't download from mirror, if source URL is given,
129 -nu, --no-urls - don't try to download from FTP/HTTP location,
130 -ns, --no-srcs - don't download Sources
132 - don't download Source0
134 - additional options for rpm
135 -q, --quiet - be quiet,
137 - build package using resources from specified CVS
139 -r <cvstag>, --cvstag <cvstag>
140 - build package using resources from specified CVS
142 -T <cvstag> , --tag <cvstag>
143 - add cvs tag <cvstag> for files,
144 -Tvs, --tag-version-stable
145 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
146 -Tvn, --tag-version-nest
147 - add cvs tags NEST and NAME-VERSION-RELESE for files,
149 - add cvs tag STABLE for files,
151 - add cvs tag NEST for files,
153 - add cvs tag NAME-VERSION-RELESE for files,
154 -v, --verbose - be verbose,
156 - check version, and try to upgrade package
157 --with/--without <feature>
158 - conditional build package depending on
159 %_with_<feature>/%_without_<feature> macro
166 if [ -n "$DEBUG" ]; then
172 if [ "$NOSRCS" != "yes" ]; then
173 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
175 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
176 FAIL_IF_NO_SOURCES="no"
179 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
180 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
181 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
182 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
183 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
185 if [ -n "$BE_VERBOSE" ]; then
186 echo "- Sources : `nourl $SOURCES`"
187 if [ -n "$PATCHES" ]; then
188 echo "- Patches : `nourl $PATCHES`"
190 echo "- Patches : *no patches needed*"
192 if [ -n "$ICONS" ]; then
193 echo "- Icon : `nourl $ICONS`"
195 echo "- Icon : *no package icon*"
197 echo "- Name : $PACKAGE_NAME"
198 echo "- Version : $PACKAGE_VERSION"
199 echo "- Release : $PACKAGE_RELEASE"
205 if [ -n "$DEBUG" ]; then
213 "err_no_spec_in_cmdl" )
214 echo "ERROR: spec file name not specified.";
216 "err_no_spec_in_repo" )
217 echo "Error: spec file not stored in CVS repo.";
219 "err_no_source_in_repo" )
220 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
223 echo "Error: package build failed. (${2:-no more info})";
230 if [ -n "$DEBUG" ]; then
235 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
236 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
243 if [ -n "$DEBUG" ]; then
248 if [ "$NOCVSSPEC" != "yes" ]; then
253 if [ -n "$CVSROOT" ]; then
254 OPTIONS="-d $CVSROOT $OPTIONS"
256 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
257 echo "warning: No cvs access defined - using local .spec file"
262 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
263 OPTIONS="$OPTIONS -A"
265 if [ -n "$CVSDATE" ]; then
266 OPTIONS="$OPTIONS -D $CVSDATE"
268 if [ -n "$CVSTAG" ]; then
269 OPTIONS="$OPTIONS -r $CVSTAG"
275 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
276 retries_counter=$(( $retries_counter + 1 ))
277 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
279 [ -n "$output" ] && echo "$output"
280 if [ "$result" -ne "0" ]; then
281 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
282 echo "Trying again [$SPECFILE]... ($retries_counter)"
286 Exit_error err_no_spec_in_repo;
290 if [ ! -f "$SPECFILE" ]; then
291 Exit_error err_no_spec_in_repo;
294 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
295 chmod $CHMOD_MODE $SPECFILE
298 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
305 if [ ! -f "mirrors" ] ; then
306 cvs update mirrors >&2
310 while read origin mirror name rest; do
311 ol=`echo -n "$origin"|wc -c`
312 prefix="`echo -n "$url" | head -c $ol`"
313 if [ "$prefix" = "$origin" ] ; then
314 suffix="`echo "$url"|cut -b $ol-`"
315 echo -n "$mirror$suffix"
325 $RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \
326 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
327 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
334 [ -z "$no" ] && return
336 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
341 echo "ftp://distfiles.pld-ppc.org/src/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')"
348 if [ -n "$DEBUG" ]; then
353 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
357 if [ -n "$CVSROOT" ]; then
358 OPTIONS="-d $CVSROOT $OPTIONS"
360 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
361 echo "warning: No cvs access defined for SOURCES"
365 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
366 OPTIONS="$OPTIONS -A"
368 if [ -n "$CVSDATE" ]; then
369 OPTIONS="$OPTIONS -D $CVSDATE"
371 if [ -n "$CVSTAG" ]; then
372 OPTIONS="$OPTIONS -r $CVSTAG"
375 for i in $GET_FILES; do
376 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
377 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
378 echo "Warning: no URL given for $i"
381 if [ -n "$(src_md5 "$i")" ] ; then
383 url=$(distfiles_url "$i")
384 if [ -z "$NOMIRRORS" ] ; then
385 url="`find_mirror "$url"`"
387 ${GETURI} -O "$target" "$url" || \
388 if [ `echo $url | grep -E 'ftp://'` ]; then
389 ${GETURI2} -O "$target" "$url"
391 elif [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
394 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
395 retries_counter=$(( $retries_counter + 1 ))
396 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
398 [ -n "$output" ] && echo "$output"
399 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
400 echo "Trying again [`nourl $i`]... ($retries_counter)"
409 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
410 if [ -z "$NOMIRRORS" ] ; then
411 i="`find_mirror "$i"`"
414 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
417 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
418 Exit_error err_no_source_in_repo $i;
423 if [ "$CHMOD" = "yes" ]; then
424 CHMOD_FILES="`nourl $GET_FILES`"
425 if [ -n "$CHMOD_FILES" ]; then
426 chmod $CHMOD_MODE $CHMOD_FILES
437 if [ -n "$DEBUG" ]; then
442 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
443 echo $PACKAGE_VERSION
444 echo $PACKAGE_RELEASE
445 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
446 if [ "$TAG_VERSION" = "yes" ]; then
447 echo "CVS tag: $TAGVER"
449 if [ -n "$TAG" ]; then
454 if [ -n "$CVSROOT" ]; then
455 OPTIONS="-d $CVSROOT $OPTIONS"
459 for i in $TAG_FILES; do
460 if [ -f `nourl $i` ]; then
461 if [ "$TAG_VERSION" = "yes" ]; then
462 cvs $OPTIONS $TAGVER `nourl $i`
464 if [ -n "$TAG" ]; then
465 cvs $OPTIONS $TAG `nourl $i`
468 Exit_error err_no_source_in_repo $i
473 if [ "$TAG_VERSION" = "yes" ]; then
474 cvs $OPTIONS $TAGVER $SPECFILE
476 if [ -n "$TAG" ]; then
477 cvs $OPTIONS $TAG $SPECFILE
487 echo "CVS branch tag: $TAG"
492 if [ -n "$DEBUG" ]; then
497 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
500 if [ -n "$CVSROOT" ]; then
501 OPTIONS="-d $CVSROOT $OPTIONS"
504 for i in $TAG_FILES; do
505 if [ -f `nourl $i` ]; then
506 cvs $OPTIONS $TAG `nourl $i`
508 Exit_error err_no_source_in_repo $i
512 cvs $OPTIONS $TAG $SPECFILE
522 if [ -n "$DEBUG" ]; then
529 if [ -n "$TRY_UPGRADE" ]; then
531 if [ -n "FLOAT_VERSION" ]; then
532 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
534 TNOTIFY=`./pldnotify.awk $SPECFILE`
537 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
539 if [ -n "$TNEWVER" ]; then
541 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
543 echo "New version found, updating spec file to version " $TNEWVER
545 cp -f $SPECFILE $SPECFILE.bak
549 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
550 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
554 get_files "$SOURCES $PATCHES";
556 unset TOLDVER TNEWVER TNOTIFY
566 BUILD_SWITCH="-ba" ;;
568 BUILD_SWITCH="-bb" ;;
570 BUILD_SWITCH="-bs --nodeps" ;;
572 if [ -n "$LOGFILE" ]; then
573 if [ -n "$CVSTAG" ]; then
574 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
578 LOG=`eval echo $LOGFILE`
579 if [ -n "$LASTLOG_FILE" ]; then
580 echo "LASTLOG=$LOG" > $LASTLOG_FILE
582 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
583 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
584 RETVAL=`cat $RES_FILE`
586 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
587 if [ "$RETVAL" -eq "0" ]; then
594 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
598 if [ "$RETVAL" -ne "0" ]; then
600 if [ -n "$TRY_UPGRADE" ]; then
601 echo "\n!!! Package with new version cannot be build automagically\n"
602 mv -f $SPECFILE.bak $SPECFILE
605 Exit_error err_build_fail;
613 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
615 #---------------------------------------------
618 if [ "$#" = 0 ]; then
623 while test $# -gt 0 ; do
626 DEBUG="yes"; shift ;;
628 COMMAND="version"; shift ;;
630 CVSROOT=":pserver:cvs@cvs.pld-linux.org:/cvsroot"; shift ;;
632 COMMAND="build"; shift ;;
633 -bb | --build-binary )
634 COMMAND="build-binary"; shift ;;
635 -bs | --build-source )
636 COMMAND="build-source"; shift ;;
638 COMMAND="branch"; shift; TAG="${1}"; shift;;
640 CLEAN="--clean --rmspec --rmsource"; shift ;;
642 shift; CVSROOT="${1}"; shift ;;
644 COMMAND="get"; shift ;;
646 COMMAND="usage"; shift ;;
648 shift; LOGFILE="${1}"; shift ;;
650 shift; DEF_NICE_LEVEL=${1}; shift ;;
652 COMMAND="mr-proper"; shift ;;
654 NOCVS="yes"; shift ;;
655 -ncs | --no-cvs-specs )
656 NOCVSSPEC="yes"; shift ;;
658 NOMIRRORS="yes"; shift ;;
660 NOURLS="yes"; shift ;;
662 NOSRCS="yes"; shift ;;
663 -ns0 | --no-source0 )
664 NOSOURCE0="yes"; shift ;;
666 shift; RPMOPTS="${1}"; shift ;;
668 BCOND="$BCOND $1 $2" ; shift 2 ;;
670 QUIET="--quiet"; shift ;;
672 CVSDATE="${2}"; shift 2 ;;
674 shift; CVSTAG="${1}"; shift ;;
675 -Tvs | --tag-version-stable )
680 -Tvn | --tag-version-nest )
695 -Tv | --tag-version )
707 BE_VERBOSE="1"; shift ;;
709 TRY_UPGRADE="1"; shift ;;
710 -un | --try-upgrade-with-float-version )
711 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
717 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
720 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
724 if [ -n "$DEBUG" ]; then
730 "build" | "build-binary" | "build-source" )
732 if [ -n "$SPECFILE" ]; then
736 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
737 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
738 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
739 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
741 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
742 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
746 if [ -n "$ICONS" ]; then
750 if [ -n "$NOSOURCE0" ] ; then
751 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
753 get_files "$SOURCES $PATCHES";
756 Exit_error err_no_spec_in_cmdl;
761 if [ -n "$SPECFILE" ]; then
764 if [ -n "$ICONS" ]; then
768 get_files $SOURCES $PATCHES;
769 branch_files $TAG "$SOURCES $PATCHES $ICONS";
771 Exit_error err_no_spec_in_cmdl;
776 if [ -n "$SPECFILE" ]; then
779 if [ -n "$ICONS" ]; then
783 if [ -n "$NOSOURCE0" ] ; then
784 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
786 get_files $SOURCES $PATCHES
788 Exit_error err_no_spec_in_cmdl;
793 if [ -n "$SPECFILE" ]; then
796 if [ -n "$ICONS" ]; then
800 get_files $SOURCES $PATCHES;
801 tag_files "$SOURCES $PATCHES $ICONS";
803 Exit_error err_no_spec_in_cmdl;
807 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE