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.10 (C) 1999-2001 Tomasz K³oczko".
16 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!
48 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
49 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
53 FAIL_IF_NO_SOURCES="yes"
55 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
56 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
58 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
66 if [ -f ~/etc/builderrc ]; then
68 elif [ -f ~/.builderrc ]; then
72 #---------------------------------------------
77 if [ -n "$DEBUG" ]; then set -xv; fi
79 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
81 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
82 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
83 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
84 [-q|--quiet] [-r <cvstag>] [{-T--tag <cvstag>]
85 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
86 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
87 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
88 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
90 -D, --debug - enable script debugging mode,
91 -V, --version - output builder version
92 -a, --as_anon - get files via pserver as cvs@anoncvs.pld.org.pl,
94 --build - get all files from CVS repo or HTTP/FTP and build
95 package from <package>.spec,
97 - get all files from CVS repo or HTTP/FTP and build
98 binary only package from <package>.spec,
100 --build-source - get all files from CVS repo or HTTP/FTP and only
101 pack them into src.rpm,
102 -B, --branch - add branch
103 -c, --clean - clean all temporarily created files (in BUILD,
104 SOURCES, SPECS and \$RPM_BUILD_ROOT),
105 -d <cvsroot>, --cvsroot <cvsroot>
107 --define <macro> <value>
108 - define a macro <macro> with value <value>,
109 -g, --get - get <package>.spec and all related files from
110 CVS repo or HTTP/FTP,
111 -h, --help - this message,
112 -l <logfile>, --logtofile <logfile>
114 -m, --mr-proper - only remove all files related to spec file and
116 -nc, --no-cvs - don't download sources from CVS, if source URL is
119 - don't check specs in CVS
120 -nm, --no-mirrors - don't download from mirror, if source URL is given,
121 -nu, --no-urls - don't try to download from FTP/HTTP location,
122 -ns, --no-srcs - don't downland Sources
124 - don't downland Source0
126 - additional options for rpm
127 -q, --quiet - be quiet,
128 -r <cvstag>, --cvstag <cvstag>
129 - build package using resources from specified CVS
131 -T <cvstag> , --tag <cvstag>
132 - add cvs tag <cvstag> for files,
133 -Tvs, --tag-version-stable
134 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
135 -Tvn, --tag-version-nest
136 - add cvs tags NEST and NAME-VERSION-RELESE for files,
138 - add cvs tag STABLE for files,
140 - add cvs tag NEST for files,
142 - add cvs tag NAME-VERSION-RELESE for files,
143 -v, --verbose - be verbose,
145 - check version, and try to upgrade package
146 --with/--without <feature>
147 - conditional build package depending on
148 %_with_<feature>/%_without_<feature> macro
155 if [ -n "$DEBUG" ]; then
162 if [ "$NOSRCS" != "yes" ]; then
163 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
165 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
166 FAIL_IF_NO_SOURCES="no"
169 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
170 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
171 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
172 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
173 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
175 if [ -n "$BE_VERBOSE" ]; then
176 echo "- Sources : `nourl $SOURCES`"
177 if [ -n "$PATCHES" ]; then
178 echo "- Patches : `nourl $PATCHES`"
180 echo "- Patches : *no patches needed*"
182 if [ -n "$ICONS" ]; then
183 echo "- Icon : `nourl $ICONS`"
185 echo "- Icon : *no package icon*"
187 echo "- Name : $PACKAGE_NAME"
188 echo "- Version : $PACKAGE_VERSION"
189 echo "- Release : $PACKAGE_RELEASE"
195 if [ -n "$DEBUG" ]; then
203 "err_no_spec_in_cmdl" )
204 echo "ERROR: spec file name not specified.";
206 "err_no_spec_in_repo" )
207 echo "Error: spec file not stored in CVS repo.";
209 "err_no_source_in_repo" )
210 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
213 echo "Error: package build failed. (${2:-no more info})";
220 if [ -n "$DEBUG" ]; then
225 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
226 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
233 if [ -n "$DEBUG" ]; then
238 if [ "$NOCVSSPEC" != "yes" ]; then
243 if [ -n "$CVSROOT" ]; then
244 OPTIONS="-d $CVSROOT $OPTIONS"
246 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
247 echo "warning: No cvs access defined - using local .spec file"
251 if [ -n "$CVSTAG" ]; then
252 OPTIONS="$OPTIONS -r $CVSTAG"
254 OPTIONS="$OPTIONS -A"
259 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
260 retries_counter=$(( $retries_counter + 1 ))
261 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
264 if [ "$result" -ne "0" ]; then
265 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
266 echo "Trying again... ($retries_counter)"
269 Exit_error err_no_spec_in_repo;
273 if [ ! -f "$SPECFILE" ]; then
274 Exit_error err_no_spec_in_repo;
277 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
278 chmod $CHMOD_MODE $SPECFILE
281 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
288 if [ ! -f "mirrors" ] ; then
289 cvs update mirrors >&2
293 while read origin mirror name rest; do
294 ol=`echo -n "$origin"|wc -c`
295 prefix="`echo -n "$url" | head -c $ol`"
296 if [ "$prefix" = "$origin" ] ; then
297 suffix="`echo "$url"|cut -b $ol-`"
298 echo -n "$mirror$suffix"
309 if [ -n "$DEBUG" ]; then
314 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
318 if [ -n "$CVSROOT" ]; then
319 OPTIONS="-d $CVSROOT $OPTIONS"
321 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
322 echo "warning: No cvs access defined for SOURCES"
326 if [ -n "$CVSTAG" ]; then
327 OPTIONS="$OPTIONS -r $CVSTAG"
329 OPTIONS="$OPTIONS -A"
331 for i in $GET_FILES; do
332 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
333 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
334 echo "Warning: no URL given for $i"
337 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
340 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
341 retries_counter=$(( $retries_counter + 1 ))
342 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
345 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
346 echo "Trying again... ($retries_counter)"
352 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
353 if [ -z "$NOMIRRORS" ] ; then
354 i="`find_mirror "$i"`"
357 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
360 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
361 Exit_error err_no_source_in_repo $i;
366 if [ "$CHMOD" = "yes" ]; then
367 CHMOD_FILES="`nourl $GET_FILES`"
368 if [ -n "$CHMOD_FILES" ]; then
369 chmod $CHMOD_MODE $CHMOD_FILES
380 if [ -n "$DEBUG" ]; then
385 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
386 echo $PACKAGE_VERSION
387 echo $PACKAGE_RELEASE
388 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
389 if [ "$TAG_VERSION" = "yes" ]; then
390 echo "CVS tag: $TAGVER"
392 if [ -n "$TAG" ]; then
397 if [ -n "$CVSROOT" ]; then
398 OPTIONS="-d $CVSROOT $OPTIONS"
402 for i in $TAG_FILES; do
403 if [ -f `nourl $i` ]; then
404 if [ "$TAG_VERSION" = "yes" ]; then
405 cvs $OPTIONS $TAGVER `nourl $i`
407 if [ -n "$TAG" ]; then
408 cvs $OPTIONS $TAG `nourl $i`
411 Exit_error err_no_source_in_repo $i
416 if [ "$TAG_VERSION" = "yes" ]; then
417 cvs $OPTIONS $TAGVER $SPECFILE
419 if [ -n "$TAG" ]; then
420 cvs $OPTIONS $TAG $SPECFILE
430 echo "CVS branch tag: $TAG"
435 if [ -n "$DEBUG" ]; then
440 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
443 if [ -n "$CVSROOT" ]; then
444 OPTIONS="-d $CVSROOT $OPTIONS"
447 for i in $TAG_FILES; do
448 if [ -f `nourl $i` ]; then
449 cvs $OPTIONS $TAG `nourl $i`
451 Exit_error err_no_source_in_repo $i
455 cvs $OPTIONS $TAG $SPECFILE
463 if [ -n "$DEBUG" ]; then
470 if [ -n "$TRY_UPGRADE" ]; then
472 if [ -n "FLOAT_VERSION" ]; then
473 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
475 TNOTIFY=`./pldnotify.awk $SPECFILE`
478 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
480 if [ -n "$TNEWVER" ]; then
482 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
484 echo "New version found, updating spec file to version " $TNEWVER
486 cp -f $SPECFILE $SPECFILE.bak
490 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
491 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
495 get_files "$SOURCES $PATCHES";
497 unset TOLDVER TNEWVER TNOTIFY
507 BUILD_SWITCH="-ba" ;;
509 BUILD_SWITCH="-bb" ;;
511 BUILD_SWITCH="-bs --nodeps" ;;
513 if [ -n "$LOGFILE" ]; then
514 LOG=`eval echo $LOGFILE`
515 eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
517 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
520 if [ "$?" -ne "0" ]; then
522 if [ -n "$TRY_UPGRADE" ]; then
523 echo "\n!!! Package with new version cannot be build automagically\n"
524 mv -f $SPECFILE.bak $SPECFILE
527 Exit_error err_build_fail;
535 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
537 #---------------------------------------------
540 if [ "$#" = 0 ]; then
545 while test $# -gt 0 ; do
548 DEBUG="yes"; shift ;;
550 COMMAND="version"; shift ;;
552 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
554 COMMAND="build"; shift ;;
555 -bb | --build-binary )
556 COMMAND="build-binary"; shift ;;
557 -bs | --build-source )
558 COMMAND="build-source"; shift ;;
560 COMMAND="branch"; shift; TAG="${1}"; shift;;
562 CLEAN="--clean --rmspec --rmsource"; shift ;;
564 shift; CVSROOT="${1}"; shift ;;
566 COMMAND="get"; shift ;;
568 COMMAND="usage"; shift ;;
570 shift; LOGFILE="${1}"; shift ;;
572 shift; DEF_NICE_LEVEL=${1}; shift ;;
574 COMMAND="mr-proper"; shift ;;
576 NOCVS="yes"; shift ;;
577 -ncs | --no-cvs-spec )
578 NOCVSSPEC="yes"; shift ;;
580 NOMIRRORS="yes"; shift ;;
582 NOURLS="yes"; shift ;;
584 NOSRCS="yes"; shift ;;
585 -ns0 | --no-source0 )
586 NOSOURCE0="yes"; shift ;;
588 shift; RPMOPTS="${1}"; shift ;;
590 BCOND="$BCOND $1 $2" ; shift 2 ;;
592 QUIET="--quiet"; shift ;;
594 shift; CVSTAG="${1}"; shift ;;
595 -Tvs | --tag-version-stable )
600 -Tvn | --tag-version-nest )
615 -Tv | --tag-version )
627 BE_VERBOSE="1"; shift ;;
629 TRY_UPGRADE="1"; shift ;;
630 -un | --try-upgrade-with-float-version )
631 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
637 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
640 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
644 if [ -n "$DEBUG" ]; then
650 "build" | "build-binary" | "build-source" )
652 if [ -n "$SPECFILE" ]; then
656 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
657 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
658 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
659 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
661 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
662 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
666 if [ -n "$ICONS" ]; then
670 if [ -n "$NOSOURCE0" ] ; then
671 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
673 get_files "$SOURCES $PATCHES";
676 Exit_error err_no_spec_in_cmdl;
681 if [ -n "$SPECFILE" ]; then
684 if [ -n "$ICONS" ]; then
688 get_files $SOURCES $PATCHES;
689 branch_files $TAG "$SOURCES $PATCHES $ICONS";
691 Exit_error err_no_spec_in_cmdl;
696 if [ -n "$SPECFILE" ]; then
699 if [ -n "$ICONS" ]; then
703 if [ -n "$NOSOURCE0" ] ; then
704 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
706 get_files $SOURCES $PATCHES
708 Exit_error err_no_spec_in_cmdl;
713 if [ -n "$SPECFILE" ]; then
716 if [ -n "$ICONS" ]; then
720 get_files $SOURCES $PATCHES;
721 tag_files "$SOURCES $PATCHES $ICONS";
723 Exit_error err_no_spec_in_cmdl;
727 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE