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)"
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)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
359 echo "Trying again [`nourl $i`]... ($retries_counter)"
367 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
368 if [ -z "$NOMIRRORS" ] ; then
369 i="`find_mirror "$i"`"
372 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
375 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
376 Exit_error err_no_source_in_repo $i;
381 if [ "$CHMOD" = "yes" ]; then
382 CHMOD_FILES="`nourl $GET_FILES`"
383 if [ -n "$CHMOD_FILES" ]; then
384 chmod $CHMOD_MODE $CHMOD_FILES
395 if [ -n "$DEBUG" ]; then
400 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
401 echo $PACKAGE_VERSION
402 echo $PACKAGE_RELEASE
403 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
404 if [ "$TAG_VERSION" = "yes" ]; then
405 echo "CVS tag: $TAGVER"
407 if [ -n "$TAG" ]; then
412 if [ -n "$CVSROOT" ]; then
413 OPTIONS="-d $CVSROOT $OPTIONS"
417 for i in $TAG_FILES; do
418 if [ -f `nourl $i` ]; then
419 if [ "$TAG_VERSION" = "yes" ]; then
420 cvs $OPTIONS $TAGVER `nourl $i`
422 if [ -n "$TAG" ]; then
423 cvs $OPTIONS $TAG `nourl $i`
426 Exit_error err_no_source_in_repo $i
431 if [ "$TAG_VERSION" = "yes" ]; then
432 cvs $OPTIONS $TAGVER $SPECFILE
434 if [ -n "$TAG" ]; then
435 cvs $OPTIONS $TAG $SPECFILE
445 echo "CVS branch tag: $TAG"
450 if [ -n "$DEBUG" ]; then
455 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
458 if [ -n "$CVSROOT" ]; then
459 OPTIONS="-d $CVSROOT $OPTIONS"
462 for i in $TAG_FILES; do
463 if [ -f `nourl $i` ]; then
464 cvs $OPTIONS $TAG `nourl $i`
466 Exit_error err_no_source_in_repo $i
470 cvs $OPTIONS $TAG $SPECFILE
478 if [ -n "$DEBUG" ]; then
485 if [ -n "$TRY_UPGRADE" ]; then
487 if [ -n "FLOAT_VERSION" ]; then
488 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
490 TNOTIFY=`./pldnotify.awk $SPECFILE`
493 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
495 if [ -n "$TNEWVER" ]; then
497 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
499 echo "New version found, updating spec file to version " $TNEWVER
501 cp -f $SPECFILE $SPECFILE.bak
505 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
506 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
510 get_files "$SOURCES $PATCHES";
512 unset TOLDVER TNEWVER TNOTIFY
522 BUILD_SWITCH="-ba" ;;
524 BUILD_SWITCH="-bb" ;;
526 BUILD_SWITCH="-bs --nodeps" ;;
528 if [ -n "$LOGFILE" ]; then
529 LOG=`eval echo $LOGFILE`
530 eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
532 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
535 if [ "$?" -ne "0" ]; then
537 if [ -n "$TRY_UPGRADE" ]; then
538 echo "\n!!! Package with new version cannot be build automagically\n"
539 mv -f $SPECFILE.bak $SPECFILE
542 Exit_error err_build_fail;
550 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
552 #---------------------------------------------
555 if [ "$#" = 0 ]; then
560 while test $# -gt 0 ; do
563 DEBUG="yes"; shift ;;
565 COMMAND="version"; shift ;;
567 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
569 COMMAND="build"; shift ;;
570 -bb | --build-binary )
571 COMMAND="build-binary"; shift ;;
572 -bs | --build-source )
573 COMMAND="build-source"; shift ;;
575 COMMAND="branch"; shift; TAG="${1}"; shift;;
577 CLEAN="--clean --rmspec --rmsource"; shift ;;
579 shift; CVSROOT="${1}"; shift ;;
581 COMMAND="get"; shift ;;
583 COMMAND="usage"; shift ;;
585 shift; LOGFILE="${1}"; shift ;;
587 shift; DEF_NICE_LEVEL=${1}; shift ;;
589 COMMAND="mr-proper"; shift ;;
591 NOCVS="yes"; shift ;;
592 -ncs | --no-cvs-spec )
593 NOCVSSPEC="yes"; shift ;;
595 NOMIRRORS="yes"; shift ;;
597 NOURLS="yes"; shift ;;
599 NOSRCS="yes"; shift ;;
600 -ns0 | --no-source0 )
601 NOSOURCE0="yes"; shift ;;
603 shift; RPMOPTS="${1}"; shift ;;
605 BCOND="$BCOND $1 $2" ; shift 2 ;;
607 QUIET="--quiet"; shift ;;
609 CVSDATE="${2}"; shift 2 ;;
611 shift; CVSTAG="${1}"; shift ;;
612 -Tvs | --tag-version-stable )
617 -Tvn | --tag-version-nest )
632 -Tv | --tag-version )
644 BE_VERBOSE="1"; shift ;;
646 TRY_UPGRADE="1"; shift ;;
647 -un | --try-upgrade-with-float-version )
648 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
654 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
657 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
661 if [ -n "$DEBUG" ]; then
667 "build" | "build-binary" | "build-source" )
669 if [ -n "$SPECFILE" ]; then
673 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
674 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
675 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
676 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
678 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
679 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
683 if [ -n "$ICONS" ]; then
687 if [ -n "$NOSOURCE0" ] ; then
688 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
690 get_files "$SOURCES $PATCHES";
693 Exit_error err_no_spec_in_cmdl;
698 if [ -n "$SPECFILE" ]; then
701 if [ -n "$ICONS" ]; then
705 get_files $SOURCES $PATCHES;
706 branch_files $TAG "$SOURCES $PATCHES $ICONS";
708 Exit_error err_no_spec_in_cmdl;
713 if [ -n "$SPECFILE" ]; then
716 if [ -n "$ICONS" ]; then
720 if [ -n "$NOSOURCE0" ] ; then
721 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
723 get_files $SOURCES $PATCHES
725 Exit_error err_no_spec_in_cmdl;
730 if [ -n "$SPECFILE" ]; then
733 if [ -n "$ICONS" ]; then
737 get_files $SOURCES $PATCHES;
738 tag_files "$SOURCES $PATCHES $ICONS";
740 Exit_error err_no_spec_in_cmdl;
744 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE