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] [--date <yyyy-mm-dd> [-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 download Sources
124 - don't download Source0
126 - additional options for rpm
127 -q, --quiet - be quiet,
129 - build package using resources from specified CVS
131 -r <cvstag>, --cvstag <cvstag>
132 - build package using resources from specified CVS
134 -T <cvstag> , --tag <cvstag>
135 - add cvs tag <cvstag> for files,
136 -Tvs, --tag-version-stable
137 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
138 -Tvn, --tag-version-nest
139 - add cvs tags NEST and NAME-VERSION-RELESE for files,
141 - add cvs tag STABLE for files,
143 - add cvs tag NEST for files,
145 - add cvs tag NAME-VERSION-RELESE for files,
146 -v, --verbose - be verbose,
148 - check version, and try to upgrade package
149 --with/--without <feature>
150 - conditional build package depending on
151 %_with_<feature>/%_without_<feature> macro
158 if [ -n "$DEBUG" ]; then
164 if [ "$NOSRCS" != "yes" ]; then
165 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
167 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
168 FAIL_IF_NO_SOURCES="no"
171 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
172 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
173 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
174 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
175 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
177 if [ -n "$BE_VERBOSE" ]; then
178 echo "- Sources : `nourl $SOURCES`"
179 if [ -n "$PATCHES" ]; then
180 echo "- Patches : `nourl $PATCHES`"
182 echo "- Patches : *no patches needed*"
184 if [ -n "$ICONS" ]; then
185 echo "- Icon : `nourl $ICONS`"
187 echo "- Icon : *no package icon*"
189 echo "- Name : $PACKAGE_NAME"
190 echo "- Version : $PACKAGE_VERSION"
191 echo "- Release : $PACKAGE_RELEASE"
197 if [ -n "$DEBUG" ]; then
205 "err_no_spec_in_cmdl" )
206 echo "ERROR: spec file name not specified.";
208 "err_no_spec_in_repo" )
209 echo "Error: spec file not stored in CVS repo.";
211 "err_no_source_in_repo" )
212 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
215 echo "Error: package build failed. (${2:-no more info})";
222 if [ -n "$DEBUG" ]; then
227 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
228 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
235 if [ -n "$DEBUG" ]; then
240 if [ "$NOCVSSPEC" != "yes" ]; then
245 if [ -n "$CVSROOT" ]; then
246 OPTIONS="-d $CVSROOT $OPTIONS"
248 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
249 echo "warning: No cvs access defined - using local .spec file"
254 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
255 OPTIONS="$OPTIONS -A"
257 if [ -n "$CVSDATE" ]; then
258 OPTIONS="$OPTIONS -D $CVSDATE"
260 if [ -n "$CVSTAG" ]; then
261 OPTIONS="$OPTIONS -r $CVSTAG"
267 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
268 retries_counter=$(( $retries_counter + 1 ))
269 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
271 [ -n "$output" ] && echo "$output"
272 if [ "$result" -ne "0" ]; then
273 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
274 echo "Trying again [$SPECFILE]... ($retries_counter)"
278 Exit_error err_no_spec_in_repo;
282 if [ ! -f "$SPECFILE" ]; then
283 Exit_error err_no_spec_in_repo;
286 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
287 chmod $CHMOD_MODE $SPECFILE
290 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
297 if [ ! -f "mirrors" ] ; then
298 cvs update mirrors >&2
302 while read origin mirror name rest; do
303 ol=`echo -n "$origin"|wc -c`
304 prefix="`echo -n "$url" | head -c $ol`"
305 if [ "$prefix" = "$origin" ] ; then
306 suffix="`echo "$url"|cut -b $ol-`"
307 echo -n "$mirror$suffix"
318 if [ -n "$DEBUG" ]; then
323 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
327 if [ -n "$CVSROOT" ]; then
328 OPTIONS="-d $CVSROOT $OPTIONS"
330 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
331 echo "warning: No cvs access defined for SOURCES"
335 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
336 OPTIONS="$OPTIONS -A"
338 if [ -n "$CVSDATE" ]; then
339 OPTIONS="$OPTIONS -D $CVSDATE"
341 if [ -n "$CVSTAG" ]; then
342 OPTIONS="$OPTIONS -r $CVSTAG"
345 for i in $GET_FILES; do
346 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
347 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
348 echo "Warning: no URL given for $i"
351 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
354 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
355 retries_counter=$(( $retries_counter + 1 ))
356 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
358 [ -n "$output" ] && echo "$output"
359 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
360 echo "Trying again [`nourl $i`]... ($retries_counter)"
369 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
370 if [ -z "$NOMIRRORS" ] ; then
371 i="`find_mirror "$i"`"
374 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
377 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
378 Exit_error err_no_source_in_repo $i;
383 if [ "$CHMOD" = "yes" ]; then
384 CHMOD_FILES="`nourl $GET_FILES`"
385 if [ -n "$CHMOD_FILES" ]; then
386 chmod $CHMOD_MODE $CHMOD_FILES
397 if [ -n "$DEBUG" ]; then
402 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
403 echo $PACKAGE_VERSION
404 echo $PACKAGE_RELEASE
405 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
406 if [ "$TAG_VERSION" = "yes" ]; then
407 echo "CVS tag: $TAGVER"
409 if [ -n "$TAG" ]; then
414 if [ -n "$CVSROOT" ]; then
415 OPTIONS="-d $CVSROOT $OPTIONS"
419 for i in $TAG_FILES; do
420 if [ -f `nourl $i` ]; then
421 if [ "$TAG_VERSION" = "yes" ]; then
422 cvs $OPTIONS $TAGVER `nourl $i`
424 if [ -n "$TAG" ]; then
425 cvs $OPTIONS $TAG `nourl $i`
428 Exit_error err_no_source_in_repo $i
433 if [ "$TAG_VERSION" = "yes" ]; then
434 cvs $OPTIONS $TAGVER $SPECFILE
436 if [ -n "$TAG" ]; then
437 cvs $OPTIONS $TAG $SPECFILE
447 echo "CVS branch tag: $TAG"
452 if [ -n "$DEBUG" ]; then
457 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
460 if [ -n "$CVSROOT" ]; then
461 OPTIONS="-d $CVSROOT $OPTIONS"
464 for i in $TAG_FILES; do
465 if [ -f `nourl $i` ]; then
466 cvs $OPTIONS $TAG `nourl $i`
468 Exit_error err_no_source_in_repo $i
472 cvs $OPTIONS $TAG $SPECFILE
480 if [ -n "$DEBUG" ]; then
487 if [ -n "$TRY_UPGRADE" ]; then
489 if [ -n "FLOAT_VERSION" ]; then
490 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
492 TNOTIFY=`./pldnotify.awk $SPECFILE`
495 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
497 if [ -n "$TNEWVER" ]; then
499 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
501 echo "New version found, updating spec file to version " $TNEWVER
503 cp -f $SPECFILE $SPECFILE.bak
507 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
508 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
512 get_files "$SOURCES $PATCHES";
514 unset TOLDVER TNEWVER TNOTIFY
524 BUILD_SWITCH="-ba" ;;
526 BUILD_SWITCH="-bb" ;;
528 BUILD_SWITCH="-bs --nodeps" ;;
530 if [ -n "$LOGFILE" ]; then
531 LOG=`eval echo $LOGFILE`
532 eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
534 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
537 if [ "$?" -ne "0" ]; then
539 if [ -n "$TRY_UPGRADE" ]; then
540 echo "\n!!! Package with new version cannot be build automagically\n"
541 mv -f $SPECFILE.bak $SPECFILE
544 Exit_error err_build_fail;
552 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
554 #---------------------------------------------
557 if [ "$#" = 0 ]; then
562 while test $# -gt 0 ; do
565 DEBUG="yes"; shift ;;
567 COMMAND="version"; shift ;;
569 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
571 COMMAND="build"; shift ;;
572 -bb | --build-binary )
573 COMMAND="build-binary"; shift ;;
574 -bs | --build-source )
575 COMMAND="build-source"; shift ;;
577 COMMAND="branch"; shift; TAG="${1}"; shift;;
579 CLEAN="--clean --rmspec --rmsource"; shift ;;
581 shift; CVSROOT="${1}"; shift ;;
583 COMMAND="get"; shift ;;
585 COMMAND="usage"; shift ;;
587 shift; LOGFILE="${1}"; shift ;;
589 shift; DEF_NICE_LEVEL=${1}; shift ;;
591 COMMAND="mr-proper"; shift ;;
593 NOCVS="yes"; shift ;;
594 -ncs | --no-cvs-spec )
595 NOCVSSPEC="yes"; shift ;;
597 NOMIRRORS="yes"; shift ;;
599 NOURLS="yes"; shift ;;
601 NOSRCS="yes"; shift ;;
602 -ns0 | --no-source0 )
603 NOSOURCE0="yes"; shift ;;
605 shift; RPMOPTS="${1}"; shift ;;
607 BCOND="$BCOND $1 $2" ; shift 2 ;;
609 QUIET="--quiet"; shift ;;
611 CVSDATE="${2}"; shift 2 ;;
613 shift; CVSTAG="${1}"; shift ;;
614 -Tvs | --tag-version-stable )
619 -Tvn | --tag-version-nest )
634 -Tv | --tag-version )
646 BE_VERBOSE="1"; shift ;;
648 TRY_UPGRADE="1"; shift ;;
649 -un | --try-upgrade-with-float-version )
650 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
656 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
659 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
663 if [ -n "$DEBUG" ]; then
669 "build" | "build-binary" | "build-source" )
671 if [ -n "$SPECFILE" ]; then
675 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
676 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
677 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
678 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
680 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
681 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
685 if [ -n "$ICONS" ]; then
689 if [ -n "$NOSOURCE0" ] ; then
690 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
692 get_files "$SOURCES $PATCHES";
695 Exit_error err_no_spec_in_cmdl;
700 if [ -n "$SPECFILE" ]; then
703 if [ -n "$ICONS" ]; then
707 get_files $SOURCES $PATCHES;
708 branch_files $TAG "$SOURCES $PATCHES $ICONS";
710 Exit_error err_no_spec_in_cmdl;
715 if [ -n "$SPECFILE" ]; then
718 if [ -n "$ICONS" ]; then
722 if [ -n "$NOSOURCE0" ] ; then
723 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
725 get_files $SOURCES $PATCHES
727 Exit_error err_no_spec_in_cmdl;
732 if [ -n "$SPECFILE" ]; then
735 if [ -n "$ICONS" ]; then
739 get_files $SOURCES $PATCHES;
740 tag_files "$SOURCES $PATCHES $ICONS";
742 Exit_error err_no_spec_in_cmdl;
746 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE