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".
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!
47 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
48 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
52 FAIL_IF_NO_SOURCES="yes"
54 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
55 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
57 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
65 if [ -f ~/etc/builderrc ]; then
67 elif [ -f ~/.builderrc ]; then
71 #---------------------------------------------
76 if [ -n "$DEBUG" ]; then set -xv; fi
78 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
80 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
81 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
82 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
83 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
84 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
85 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
86 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
87 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
89 -D, --debug - enable script debugging mode,
90 -V, --version - output builder version
91 -a, --as_anon - get files via pserver as cvs@anoncvs.pld.org.pl,
93 --build - get all files from CVS repo or HTTP/FTP and build
94 package from <package>.spec,
96 - get all files from CVS repo or HTTP/FTP and build
97 binary only package from <package>.spec,
99 --build-source - get all files from CVS repo or HTTP/FTP and only
100 pack them into src.rpm,
101 -B, --branch - add branch
102 -c, --clean - clean all temporarily created files (in BUILD,
103 SOURCES, SPECS and \$RPM_BUILD_ROOT),
104 -d <cvsroot>, --cvsroot <cvsroot>
106 --define <macro> <value>
107 - define a macro <macro> with value <value>,
108 -g, --get - get <package>.spec and all related files from
109 CVS repo or HTTP/FTP,
110 -h, --help - this message,
111 -l <logfile>, --logtofile <logfile>
113 -m, --mr-proper - only remove all files related to spec file and
115 -nc, --no-cvs - don't download sources from CVS, if source URL is
118 - don't check specs in CVS
119 -nm, --no-mirrors - don't download from mirror, if source URL is given,
120 -nu, --no-urls - don't try to download from FTP/HTTP location,
121 -ns, --no-srcs - don't download Sources
123 - don't download Source0
125 - additional options for rpm
126 -q, --quiet - be quiet,
128 - build package using resources from specified CVS
130 -r <cvstag>, --cvstag <cvstag>
131 - build package using resources from specified CVS
133 -T <cvstag> , --tag <cvstag>
134 - add cvs tag <cvstag> for files,
135 -Tvs, --tag-version-stable
136 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
137 -Tvn, --tag-version-nest
138 - add cvs tags NEST and NAME-VERSION-RELESE for files,
140 - add cvs tag STABLE for files,
142 - add cvs tag NEST for files,
144 - add cvs tag NAME-VERSION-RELESE for files,
145 -v, --verbose - be verbose,
147 - check version, and try to upgrade package
148 --with/--without <feature>
149 - conditional build package depending on
150 %_with_<feature>/%_without_<feature> macro
157 if [ -n "$DEBUG" ]; then
163 if [ "$NOSRCS" != "yes" ]; then
164 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
166 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
167 FAIL_IF_NO_SOURCES="no"
170 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
171 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
172 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
173 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
174 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
176 if [ -n "$BE_VERBOSE" ]; then
177 echo "- Sources : `nourl $SOURCES`"
178 if [ -n "$PATCHES" ]; then
179 echo "- Patches : `nourl $PATCHES`"
181 echo "- Patches : *no patches needed*"
183 if [ -n "$ICONS" ]; then
184 echo "- Icon : `nourl $ICONS`"
186 echo "- Icon : *no package icon*"
188 echo "- Name : $PACKAGE_NAME"
189 echo "- Version : $PACKAGE_VERSION"
190 echo "- Release : $PACKAGE_RELEASE"
196 if [ -n "$DEBUG" ]; then
204 "err_no_spec_in_cmdl" )
205 echo "ERROR: spec file name not specified.";
207 "err_no_spec_in_repo" )
208 echo "Error: spec file not stored in CVS repo.";
210 "err_no_source_in_repo" )
211 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
214 echo "Error: package build failed. (${2:-no more info})";
221 if [ -n "$DEBUG" ]; then
226 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
227 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
234 if [ -n "$DEBUG" ]; then
239 if [ "$NOCVSSPEC" != "yes" ]; then
244 if [ -n "$CVSROOT" ]; then
245 OPTIONS="-d $CVSROOT $OPTIONS"
247 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
248 echo "warning: No cvs access defined - using local .spec file"
253 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
254 OPTIONS="$OPTIONS -A"
256 if [ -n "$CVSDATE" ]; then
257 OPTIONS="$OPTIONS -D $CVSDATE"
259 if [ -n "$CVSTAG" ]; then
260 OPTIONS="$OPTIONS -r $CVSTAG"
266 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
267 retries_counter=$(( $retries_counter + 1 ))
268 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
270 [ -n "$output" ] && echo "$output"
271 if [ "$result" -ne "0" ]; then
272 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
273 echo "Trying again [$SPECFILE]... ($retries_counter)"
277 Exit_error err_no_spec_in_repo;
281 if [ ! -f "$SPECFILE" ]; then
282 Exit_error err_no_spec_in_repo;
285 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
286 chmod $CHMOD_MODE $SPECFILE
289 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
296 if [ ! -f "mirrors" ] ; then
297 cvs update mirrors >&2
301 while read origin mirror name rest; do
302 ol=`echo -n "$origin"|wc -c`
303 prefix="`echo -n "$url" | head -c $ol`"
304 if [ "$prefix" = "$origin" ] ; then
305 suffix="`echo "$url"|cut -b $ol-`"
306 echo -n "$mirror$suffix"
317 if [ -n "$DEBUG" ]; then
322 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
326 if [ -n "$CVSROOT" ]; then
327 OPTIONS="-d $CVSROOT $OPTIONS"
329 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
330 echo "warning: No cvs access defined for SOURCES"
334 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
335 OPTIONS="$OPTIONS -A"
337 if [ -n "$CVSDATE" ]; then
338 OPTIONS="$OPTIONS -D $CVSDATE"
340 if [ -n "$CVSTAG" ]; then
341 OPTIONS="$OPTIONS -r $CVSTAG"
344 for i in $GET_FILES; do
345 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
346 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
347 echo "Warning: no URL given for $i"
350 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
353 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
354 retries_counter=$(( $retries_counter + 1 ))
355 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
357 [ -n "$output" ] && echo "$output"
358 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
359 echo "Trying again [`nourl $i`]... ($retries_counter)"
368 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
369 if [ -z "$NOMIRRORS" ] ; then
370 i="`find_mirror "$i"`"
373 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
376 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
377 Exit_error err_no_source_in_repo $i;
382 if [ "$CHMOD" = "yes" ]; then
383 CHMOD_FILES="`nourl $GET_FILES`"
384 if [ -n "$CHMOD_FILES" ]; then
385 chmod $CHMOD_MODE $CHMOD_FILES
396 if [ -n "$DEBUG" ]; then
401 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
402 echo $PACKAGE_VERSION
403 echo $PACKAGE_RELEASE
404 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
405 if [ "$TAG_VERSION" = "yes" ]; then
406 echo "CVS tag: $TAGVER"
408 if [ -n "$TAG" ]; then
413 if [ -n "$CVSROOT" ]; then
414 OPTIONS="-d $CVSROOT $OPTIONS"
418 for i in $TAG_FILES; do
419 if [ -f `nourl $i` ]; then
420 if [ "$TAG_VERSION" = "yes" ]; then
421 cvs $OPTIONS $TAGVER `nourl $i`
423 if [ -n "$TAG" ]; then
424 cvs $OPTIONS $TAG `nourl $i`
427 Exit_error err_no_source_in_repo $i
432 if [ "$TAG_VERSION" = "yes" ]; then
433 cvs $OPTIONS $TAGVER $SPECFILE
435 if [ -n "$TAG" ]; then
436 cvs $OPTIONS $TAG $SPECFILE
446 echo "CVS branch tag: $TAG"
451 if [ -n "$DEBUG" ]; then
456 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
459 if [ -n "$CVSROOT" ]; then
460 OPTIONS="-d $CVSROOT $OPTIONS"
463 for i in $TAG_FILES; do
464 if [ -f `nourl $i` ]; then
465 cvs $OPTIONS $TAG `nourl $i`
467 Exit_error err_no_source_in_repo $i
471 cvs $OPTIONS $TAG $SPECFILE
481 if [ -n "$DEBUG" ]; then
488 if [ -n "$TRY_UPGRADE" ]; then
490 if [ -n "FLOAT_VERSION" ]; then
491 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
493 TNOTIFY=`./pldnotify.awk $SPECFILE`
496 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
498 if [ -n "$TNEWVER" ]; then
500 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
502 echo "New version found, updating spec file to version " $TNEWVER
504 cp -f $SPECFILE $SPECFILE.bak
508 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
509 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
513 get_files "$SOURCES $PATCHES";
515 unset TOLDVER TNEWVER TNOTIFY
525 BUILD_SWITCH="-ba" ;;
527 BUILD_SWITCH="-bb" ;;
529 BUILD_SWITCH="-bs --nodeps" ;;
531 if [ -n "$LOGFILE" ]; then
532 LOG=`eval echo $LOGFILE`
533 mknod ~/tmp/builder_log_fifo p
534 cat ~/tmp/builder_log_fifo | tee $LOG & eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE > ~/tmp/builder_log_fifo 2>&1
536 rm ~/tmp/builder_log_fifo
538 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
542 if [ "$RETVAL" -ne "0" ]; then
544 if [ -n "$TRY_UPGRADE" ]; then
545 echo "\n!!! Package with new version cannot be build automagically\n"
546 mv -f $SPECFILE.bak $SPECFILE
549 Exit_error err_build_fail;
557 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
559 #---------------------------------------------
562 if [ "$#" = 0 ]; then
567 while test $# -gt 0 ; do
570 DEBUG="yes"; shift ;;
572 COMMAND="version"; shift ;;
574 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
576 COMMAND="build"; shift ;;
577 -bb | --build-binary )
578 COMMAND="build-binary"; shift ;;
579 -bs | --build-source )
580 COMMAND="build-source"; shift ;;
582 COMMAND="branch"; shift; TAG="${1}"; shift;;
584 CLEAN="--clean --rmspec --rmsource"; shift ;;
586 shift; CVSROOT="${1}"; shift ;;
588 COMMAND="get"; shift ;;
590 COMMAND="usage"; shift ;;
592 shift; LOGFILE="${1}"; shift ;;
594 shift; DEF_NICE_LEVEL=${1}; shift ;;
596 COMMAND="mr-proper"; shift ;;
598 NOCVS="yes"; shift ;;
599 -ncs | --no-cvs-spec )
600 NOCVSSPEC="yes"; shift ;;
602 NOMIRRORS="yes"; shift ;;
604 NOURLS="yes"; shift ;;
606 NOSRCS="yes"; shift ;;
607 -ns0 | --no-source0 )
608 NOSOURCE0="yes"; shift ;;
610 shift; RPMOPTS="${1}"; shift ;;
612 BCOND="$BCOND $1 $2" ; shift 2 ;;
614 QUIET="--quiet"; shift ;;
616 CVSDATE="${2}"; shift 2 ;;
618 shift; CVSTAG="${1}"; shift ;;
619 -Tvs | --tag-version-stable )
624 -Tvn | --tag-version-nest )
639 -Tv | --tag-version )
651 BE_VERBOSE="1"; shift ;;
653 TRY_UPGRADE="1"; shift ;;
654 -un | --try-upgrade-with-float-version )
655 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
661 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
664 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
668 if [ -n "$DEBUG" ]; then
674 "build" | "build-binary" | "build-source" )
676 if [ -n "$SPECFILE" ]; then
680 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
681 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
682 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
683 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
685 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
686 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
690 if [ -n "$ICONS" ]; then
694 if [ -n "$NOSOURCE0" ] ; then
695 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
697 get_files "$SOURCES $PATCHES";
700 Exit_error err_no_spec_in_cmdl;
705 if [ -n "$SPECFILE" ]; then
708 if [ -n "$ICONS" ]; then
712 get_files $SOURCES $PATCHES;
713 branch_files $TAG "$SOURCES $PATCHES $ICONS";
715 Exit_error err_no_spec_in_cmdl;
720 if [ -n "$SPECFILE" ]; then
723 if [ -n "$ICONS" ]; then
727 if [ -n "$NOSOURCE0" ] ; then
728 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
730 get_files $SOURCES $PATCHES
732 Exit_error err_no_spec_in_cmdl;
737 if [ -n "$SPECFILE" ]; then
740 if [ -n "$ICONS" ]; then
744 get_files $SOURCES $PATCHES;
745 tag_files "$SOURCES $PATCHES $ICONS";
747 Exit_error err_no_spec_in_cmdl;
751 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE