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)"
354 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
355 if [ -z "$NOMIRRORS" ] ; then
356 i="`find_mirror "$i"`"
359 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
362 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
363 Exit_error err_no_source_in_repo $i;
368 if [ "$CHMOD" = "yes" ]; then
369 CHMOD_FILES="`nourl $GET_FILES`"
370 if [ -n "$CHMOD_FILES" ]; then
371 chmod $CHMOD_MODE $CHMOD_FILES
382 if [ -n "$DEBUG" ]; then
387 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
388 echo $PACKAGE_VERSION
389 echo $PACKAGE_RELEASE
390 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
391 if [ "$TAG_VERSION" = "yes" ]; then
392 echo "CVS tag: $TAGVER"
394 if [ -n "$TAG" ]; then
399 if [ -n "$CVSROOT" ]; then
400 OPTIONS="-d $CVSROOT $OPTIONS"
404 for i in $TAG_FILES; do
405 if [ -f `nourl $i` ]; then
406 if [ "$TAG_VERSION" = "yes" ]; then
407 cvs $OPTIONS $TAGVER `nourl $i`
409 if [ -n "$TAG" ]; then
410 cvs $OPTIONS $TAG `nourl $i`
413 Exit_error err_no_source_in_repo $i
418 if [ "$TAG_VERSION" = "yes" ]; then
419 cvs $OPTIONS $TAGVER $SPECFILE
421 if [ -n "$TAG" ]; then
422 cvs $OPTIONS $TAG $SPECFILE
432 echo "CVS branch tag: $TAG"
437 if [ -n "$DEBUG" ]; then
442 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
445 if [ -n "$CVSROOT" ]; then
446 OPTIONS="-d $CVSROOT $OPTIONS"
449 for i in $TAG_FILES; do
450 if [ -f `nourl $i` ]; then
451 cvs $OPTIONS $TAG `nourl $i`
453 Exit_error err_no_source_in_repo $i
457 cvs $OPTIONS $TAG $SPECFILE
465 if [ -n "$DEBUG" ]; then
472 if [ -n "$TRY_UPGRADE" ]; then
474 if [ -n "FLOAT_VERSION" ]; then
475 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
477 TNOTIFY=`./pldnotify.awk $SPECFILE`
480 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
482 if [ -n "$TNEWVER" ]; then
484 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
486 echo "New version found, updating spec file to version " $TNEWVER
488 cp -f $SPECFILE $SPECFILE.bak
492 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
493 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
497 get_files "$SOURCES $PATCHES";
499 unset TOLDVER TNEWVER TNOTIFY
509 BUILD_SWITCH="-ba" ;;
511 BUILD_SWITCH="-bb" ;;
513 BUILD_SWITCH="-bs --nodeps" ;;
515 if [ -n "$LOGFILE" ]; then
516 LOG=`eval echo $LOGFILE`
517 eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
519 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
522 if [ "$?" -ne "0" ]; then
524 if [ -n "$TRY_UPGRADE" ]; then
525 echo "\n!!! Package with new version cannot be build automagically\n"
526 mv -f $SPECFILE.bak $SPECFILE
529 Exit_error err_build_fail;
537 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
539 #---------------------------------------------
542 if [ "$#" = 0 ]; then
547 while test $# -gt 0 ; do
550 DEBUG="yes"; shift ;;
552 COMMAND="version"; shift ;;
554 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
556 COMMAND="build"; shift ;;
557 -bb | --build-binary )
558 COMMAND="build-binary"; shift ;;
559 -bs | --build-source )
560 COMMAND="build-source"; shift ;;
562 COMMAND="branch"; shift; TAG="${1}"; shift;;
564 CLEAN="--clean --rmspec --rmsource"; shift ;;
566 shift; CVSROOT="${1}"; shift ;;
568 COMMAND="get"; shift ;;
570 COMMAND="usage"; shift ;;
572 shift; LOGFILE="${1}"; shift ;;
574 shift; DEF_NICE_LEVEL=${1}; shift ;;
576 COMMAND="mr-proper"; shift ;;
578 NOCVS="yes"; shift ;;
579 -ncs | --no-cvs-spec )
580 NOCVSSPEC="yes"; shift ;;
582 NOMIRRORS="yes"; shift ;;
584 NOURLS="yes"; shift ;;
586 NOSRCS="yes"; shift ;;
587 -ns0 | --no-source0 )
588 NOSOURCE0="yes"; shift ;;
590 shift; RPMOPTS="${1}"; shift ;;
592 BCOND="$BCOND $1 $2" ; shift 2 ;;
594 QUIET="--quiet"; shift ;;
596 shift; CVSTAG="${1}"; shift ;;
597 -Tvs | --tag-version-stable )
602 -Tvn | --tag-version-nest )
617 -Tv | --tag-version )
629 BE_VERBOSE="1"; shift ;;
631 TRY_UPGRADE="1"; shift ;;
632 -un | --try-upgrade-with-float-version )
633 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
639 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
642 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
646 if [ -n "$DEBUG" ]; then
652 "build" | "build-binary" | "build-source" )
654 if [ -n "$SPECFILE" ]; then
658 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
659 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
660 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
661 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
663 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
664 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
668 if [ -n "$ICONS" ]; then
672 if [ -n "$NOSOURCE0" ] ; then
673 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
675 get_files "$SOURCES $PATCHES";
678 Exit_error err_no_spec_in_cmdl;
683 if [ -n "$SPECFILE" ]; then
686 if [ -n "$ICONS" ]; then
690 get_files $SOURCES $PATCHES;
691 branch_files $TAG "$SOURCES $PATCHES $ICONS";
693 Exit_error err_no_spec_in_cmdl;
698 if [ -n "$SPECFILE" ]; then
701 if [ -n "$ICONS" ]; then
705 if [ -n "$NOSOURCE0" ] ; then
706 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
708 get_files $SOURCES $PATCHES
710 Exit_error err_no_spec_in_cmdl;
715 if [ -n "$SPECFILE" ]; then
718 if [ -n "$ICONS" ]; then
722 get_files $SOURCES $PATCHES;
723 tag_files "$SOURCES $PATCHES $ICONS";
725 Exit_error err_no_spec_in_cmdl;
729 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE