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"
28 ALLWAYS_CVSUP=${ALLWAYS_CVSUP:-"yes"}
29 if [ -s CVS/Root ]; then
30 CVSROOT=$(cat CVS/Root)
32 CVSROOT=${CVSROOT:-""}
34 # Example: LOGFILE='../log.$PACKAGE_NAME'
35 # Yes, you can use variable name! Note _single_ quotes!
54 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
55 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
60 CVS_SERVER="cvs.pld-linux.org"
61 DISTFILES_SERVER="ftp://distfiles.pld-ppc.org"
65 FAIL_IF_NO_SOURCES="yes"
67 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
68 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
70 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
78 if [ -f ~/etc/builderrc ]; then
80 elif [ -f ~/.builderrc ]; then
84 #---------------------------------------------
89 if [ -n "$DEBUG" ]; then set -xv; fi
91 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
93 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
94 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
95 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
96 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
97 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
98 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
99 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
100 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
102 -D, --debug - enable script debugging mode,
103 -V, --version - output builder version
104 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
106 --build - get all files from CVS repo or HTTP/FTP and build
107 package from <package>.spec,
109 - get all files from CVS repo or HTTP/FTP and build
110 binary only package from <package>.spec,
112 --build-source - get all files from CVS repo or HTTP/FTP and only
113 pack them into src.rpm,
114 -B, --branch - add branch
115 -c, --clean - clean all temporarily created files (in BUILD,
116 SOURCES, SPECS and \$RPM_BUILD_ROOT),
117 -d <cvsroot>, --cvsroot <cvsroot>
119 --define <macro> <value>
120 - define a macro <macro> with value <value>,
121 -g, --get - get <package>.spec and all related files from
122 CVS repo or HTTP/FTP,
123 -h, --help - this message,
124 -l <logfile>, --logtofile <logfile>
126 -m, --mr-proper - only remove all files related to spec file and
128 -nc, --no-cvs - don't download sources from CVS, if source URL is
131 - don't check specs in CVS
133 - don't download from distfiles
134 -nm, --no-mirrors - don't download from mirror, if source URL is given,
135 -nu, --no-urls - don't try to download from FTP/HTTP location,
136 -ns, --no-srcs - don't download Sources
138 - don't download Source0
140 - additional options for rpm
141 -q, --quiet - be quiet,
143 - build package using resources from specified CVS
145 -r <cvstag>, --cvstag <cvstag>
146 - build package using resources from specified CVS
148 -T <cvstag> , --tag <cvstag>
149 - add cvs tag <cvstag> for files,
150 -Tvs, --tag-version-stable
151 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
152 -Tvn, --tag-version-nest
153 - add cvs tags NEST and NAME-VERSION-RELESE for files,
155 - add cvs tag STABLE for files,
157 - add cvs tag NEST for files,
159 - add cvs tag NAME-VERSION-RELESE for files,
160 -v, --verbose - be verbose,
162 - check version, and try to upgrade package
163 --with/--without <feature>
164 - conditional build package depending on
165 %_with_<feature>/%_without_<feature> macro
172 if [ -n "$DEBUG" ]; then
178 if [ "$NOSRCS" != "yes" ]; then
179 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
181 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
182 FAIL_IF_NO_SOURCES="no"
185 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
186 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
187 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
188 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
189 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
191 if [ -n "$BE_VERBOSE" ]; then
192 echo "- Sources : `nourl $SOURCES`"
193 if [ -n "$PATCHES" ]; then
194 echo "- Patches : `nourl $PATCHES`"
196 echo "- Patches : *no patches needed*"
198 if [ -n "$ICONS" ]; then
199 echo "- Icon : `nourl $ICONS`"
201 echo "- Icon : *no package icon*"
203 echo "- Name : $PACKAGE_NAME"
204 echo "- Version : $PACKAGE_VERSION"
205 echo "- Release : $PACKAGE_RELEASE"
211 if [ -n "$DEBUG" ]; then
219 "err_no_spec_in_cmdl" )
220 echo "ERROR: spec file name not specified.";
222 "err_no_spec_in_repo" )
223 echo "Error: spec file not stored in CVS repo.";
225 "err_no_source_in_repo" )
226 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
229 echo "Error: package build failed. (${2:-no more info})";
236 if [ -n "$DEBUG" ]; then
241 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
242 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
249 if [ -n "$DEBUG" ]; then
254 if [ "$NOCVSSPEC" != "yes" ]; then
259 if [ -n "$CVSROOT" ]; then
260 OPTIONS="-d $CVSROOT $OPTIONS"
262 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
263 echo "warning: No cvs access defined - using local .spec file"
268 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
269 OPTIONS="$OPTIONS -A"
271 if [ -n "$CVSDATE" ]; then
272 OPTIONS="$OPTIONS -D $CVSDATE"
274 if [ -n "$CVSTAG" ]; then
275 OPTIONS="$OPTIONS -r $CVSTAG"
281 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
282 retries_counter=$(( $retries_counter + 1 ))
283 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
285 [ -n "$output" ] && echo "$output"
286 if [ "$result" -ne "0" ]; then
287 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
288 echo "Trying again [$SPECFILE]... ($retries_counter)"
292 Exit_error err_no_spec_in_repo;
296 if [ ! -f "$SPECFILE" ]; then
297 Exit_error err_no_spec_in_repo;
300 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
301 chmod $CHMOD_MODE $SPECFILE
304 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
311 if [ ! -f "mirrors" ] ; then
312 cvs update mirrors >&2
316 while read origin mirror name rest; do
317 ol=`echo -n "$origin"|wc -c`
318 prefix="`echo -n "$url" | head -c $ol`"
319 if [ "$prefix" = "$origin" ] ; then
320 suffix="`echo "$url"|cut -b $ol-`"
321 echo -n "$mirror$suffix"
331 $RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \
332 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
333 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
340 [ -z "$no" ] && return
342 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
347 echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')"
354 if [ -n "$DEBUG" ]; then
359 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
363 if [ -n "$CVSROOT" ]; then
364 OPTIONS="-d $CVSROOT $OPTIONS"
366 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
367 echo "warning: No cvs access defined for SOURCES"
371 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
372 OPTIONS="$OPTIONS -A"
374 if [ -n "$CVSDATE" ]; then
375 OPTIONS="$OPTIONS -D $CVSDATE"
377 if [ -n "$CVSTAG" ]; then
378 OPTIONS="$OPTIONS -r $CVSTAG"
381 for i in $GET_FILES; do
382 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
383 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
384 echo "Warning: no URL given for $i"
387 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
388 if [ "$(src_md5 "$i")" = "$(md5sum $(nourl "$i")|sed -e 's/ .*//')" ]; then
389 echo "$(nourl "$i") having proper md5sum already exists"
393 url=$(distfiles_url "$i")
394 if [ -z "$NOMIRRORS" ] ; then
395 url="`find_mirror "$url"`"
397 ${GETURI} -O "$target" "$url" || \
398 if [ `echo $url | grep -E 'ftp://'` ]; then
399 ${GETURI2} -O "$target" "$url"
401 elif [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
404 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
405 retries_counter=$(( $retries_counter + 1 ))
406 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
408 [ -n "$output" ] && echo "$output"
409 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
410 echo "Trying again [`nourl $i`]... ($retries_counter)"
419 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
420 if [ -z "$NOMIRRORS" ] ; then
421 i="`find_mirror "$i"`"
424 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
425 # echo -n "#Source$(src_no $i)-md5: " >> $SPECS_DIR/$SPECFILE.md5
426 # md5sum `echo $i | perl -ne '/.*\/(.*)/; print "$1\n"'` | cut -f1 -d' ' >> $SPECS_DIR/$SPECFILE.md5
429 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
430 Exit_error err_no_source_in_repo $i;
435 if [ "$CHMOD" = "yes" ]; then
436 CHMOD_FILES="`nourl $GET_FILES`"
437 if [ -n "$CHMOD_FILES" ]; then
438 chmod $CHMOD_MODE $CHMOD_FILES
449 if [ -n "$DEBUG" ]; then
454 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
455 echo $PACKAGE_VERSION
456 echo $PACKAGE_RELEASE
457 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
458 if [ "$TAG_VERSION" = "yes" ]; then
459 echo "CVS tag: $TAGVER"
461 if [ -n "$TAG" ]; then
466 if [ -n "$CVSROOT" ]; then
467 OPTIONS="-d $CVSROOT $OPTIONS"
471 for i in $TAG_FILES; do
472 if [ -f `nourl $i` ]; then
473 if [ "$TAG_VERSION" = "yes" ]; then
474 cvs $OPTIONS $TAGVER `nourl $i`
476 if [ -n "$TAG" ]; then
477 cvs $OPTIONS $TAG `nourl $i`
480 Exit_error err_no_source_in_repo $i
485 if [ "$TAG_VERSION" = "yes" ]; then
486 cvs $OPTIONS $TAGVER $SPECFILE
488 if [ -n "$TAG" ]; then
489 cvs $OPTIONS $TAG $SPECFILE
499 echo "CVS branch tag: $TAG"
504 if [ -n "$DEBUG" ]; then
509 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
512 if [ -n "$CVSROOT" ]; then
513 OPTIONS="-d $CVSROOT $OPTIONS"
516 for i in $TAG_FILES; do
517 if [ -f `nourl $i` ]; then
518 cvs $OPTIONS $TAG `nourl $i`
520 Exit_error err_no_source_in_repo $i
524 cvs $OPTIONS $TAG $SPECFILE
534 if [ -n "$DEBUG" ]; then
541 if [ -n "$TRY_UPGRADE" ]; then
543 if [ -n "FLOAT_VERSION" ]; then
544 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
546 TNOTIFY=`./pldnotify.awk $SPECFILE`
549 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
551 if [ -n "$TNEWVER" ]; then
553 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
555 echo "New version found, updating spec file to version " $TNEWVER
557 cp -f $SPECFILE $SPECFILE.bak
561 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
562 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
566 get_files "$SOURCES $PATCHES";
568 unset TOLDVER TNEWVER TNOTIFY
578 BUILD_SWITCH="-ba" ;;
580 BUILD_SWITCH="-bb" ;;
582 BUILD_SWITCH="-bs --nodeps" ;;
584 if [ -n "$LOGFILE" ]; then
585 if [ -n "$CVSTAG" ]; then
586 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
590 LOG=`eval echo $LOGFILE`
591 if [ -n "$LASTLOG_FILE" ]; then
592 echo "LASTLOG=$LOG" > $LASTLOG_FILE
594 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
595 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
596 RETVAL=`cat $RES_FILE`
598 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
599 if [ "$RETVAL" -eq "0" ]; then
606 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
610 if [ "$RETVAL" -ne "0" ]; then
612 if [ -n "$TRY_UPGRADE" ]; then
613 echo "\n!!! Package with new version cannot be build automagically\n"
614 mv -f $SPECFILE.bak $SPECFILE
617 Exit_error err_build_fail;
625 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
627 #---------------------------------------------
630 if [ "$#" = 0 ]; then
635 while test $# -gt 0 ; do
638 DEBUG="yes"; shift ;;
640 COMMAND="version"; shift ;;
642 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
644 COMMAND="build"; shift ;;
645 -bb | --build-binary )
646 COMMAND="build-binary"; shift ;;
647 -bs | --build-source )
648 COMMAND="build-source"; shift ;;
650 COMMAND="branch"; shift; TAG="${1}"; shift;;
652 CLEAN="--clean --rmspec --rmsource"; shift ;;
654 shift; CVSROOT="${1}"; shift ;;
656 COMMAND="get"; shift ;;
658 COMMAND="usage"; shift ;;
660 shift; LOGFILE="${1}"; shift ;;
662 shift; DEF_NICE_LEVEL=${1}; shift ;;
664 COMMAND="mr-proper"; shift ;;
666 NOCVS="yes"; shift ;;
667 -ncs | --no-cvs-specs )
668 NOCVSSPEC="yes"; shift ;;
669 -nd | --no-distfiles )
670 NODIST="yes"; shift ;;
672 NOMIRRORS="yes"; shift ;;
674 NOURLS="yes"; shift ;;
676 NOSRCS="yes"; shift ;;
677 -ns0 | --no-source0 )
678 NOSOURCE0="yes"; shift ;;
680 shift; RPMOPTS="${1}"; shift ;;
682 BCOND="$BCOND $1 $2" ; shift 2 ;;
684 QUIET="--quiet"; shift ;;
686 CVSDATE="${2}"; shift 2 ;;
688 shift; CVSTAG="${1}"; shift ;;
689 -Tvs | --tag-version-stable )
694 -Tvn | --tag-version-nest )
709 -Tv | --tag-version )
721 BE_VERBOSE="1"; shift ;;
723 TRY_UPGRADE="1"; shift ;;
724 -un | --try-upgrade-with-float-version )
725 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
731 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
734 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
738 if [ -n "$DEBUG" ]; then
744 "build" | "build-binary" | "build-source" )
746 if [ -n "$SPECFILE" ]; then
750 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
751 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
752 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
753 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
755 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
756 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
760 if [ -n "$ICONS" ]; then
764 if [ -n "$NOSOURCE0" ] ; then
765 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
767 get_files "$SOURCES $PATCHES";
770 Exit_error err_no_spec_in_cmdl;
775 if [ -n "$SPECFILE" ]; then
778 if [ -n "$ICONS" ]; then
782 get_files $SOURCES $PATCHES;
783 branch_files $TAG "$SOURCES $PATCHES $ICONS";
785 Exit_error err_no_spec_in_cmdl;
790 if [ -n "$SPECFILE" ]; then
793 if [ -n "$ICONS" ]; then
797 if [ -n "$NOSOURCE0" ] ; then
798 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
800 get_files $SOURCES $PATCHES
802 Exit_error err_no_spec_in_cmdl;
807 if [ -n "$SPECFILE" ]; then
810 if [ -n "$ICONS" ]; then
814 get_files $SOURCES $PATCHES;
815 tag_files "$SOURCES $PATCHES $ICONS";
817 Exit_error err_no_spec_in_cmdl;
821 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE