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}
52 FAIL_IF_NO_SOURCES="yes"
54 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES"
55 GETURI2="wget -c -nd -t$WGET_RETRIES"
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] [-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 downland Sources
123 - don't downland Source0
125 - additional options for rpm
126 -q, --quiet - be quiet,
127 -r <cvstag>, --cvstag <cvstag>
128 - build package using resources from specified CVS
130 -T <cvstag> , --tag <cvstag>
131 - add cvs tag <cvstag> for files,
132 -Tvs, --tag-version-stable
133 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
134 -Tvn, --tag-version-nest
135 - add cvs tags NEST and NAME-VERSION-RELESE for files,
137 - add cvs tag STABLE for files,
139 - add cvs tag NEST for files,
141 - add cvs tag NAME-VERSION-RELESE for files,
142 -v, --verbose - be verbose,
144 - check version, and try to upgrade package
145 --with/--without <feature>
146 - conditional build package depending on
147 %_with_<feature>/%_without_<feature> macro
154 if [ -n "$DEBUG" ]; then
161 if [ "$NOSRCS" != "yes" ]; then
162 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
164 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
165 FAIL_IF_NO_SOURCES="no"
168 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
169 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
170 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
171 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
172 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
174 if [ -n "$BE_VERBOSE" ]; then
175 echo "- Sources : `nourl $SOURCES`"
176 if [ -n "$PATCHES" ]; then
177 echo "- Patches : `nourl $PATCHES`"
179 echo "- Patches : *no patches needed*"
181 if [ -n "$ICONS" ]; then
182 echo "- Icon : `nourl $ICONS`"
184 echo "- Icon : *no package icon*"
186 echo "- Name : $PACKAGE_NAME"
187 echo "- Version : $PACKAGE_VERSION"
188 echo "- Release : $PACKAGE_RELEASE"
194 if [ -n "$DEBUG" ]; then
202 "err_no_spec_in_cmdl" )
203 echo "ERROR: spec file name not specified.";
205 "err_no_spec_in_repo" )
206 echo "Error: spec file not stored in CVS repo.";
208 "err_no_source_in_repo" )
209 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
212 echo "Error: package build failed. (${2:-no more info})";
219 if [ -n "$DEBUG" ]; then
224 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
225 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
232 if [ -n "$DEBUG" ]; then
237 if [ "$NOCVSSPEC" != "yes" ]; then
242 if [ -n "$CVSROOT" ]; then
243 OPTIONS="-d $CVSROOT $OPTIONS"
245 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
246 echo "warning: No cvs access defined - using local .spec file"
250 if [ -n "$CVSTAG" ]; then
251 OPTIONS="$OPTIONS -r $CVSTAG"
253 OPTIONS="$OPTIONS -A"
256 cvs $OPTIONS $SPECFILE
257 if [ "$?" -ne "0" ]; then
258 Exit_error err_no_spec_in_repo;
261 if [ ! -f "$SPECFILE" ]; then
262 Exit_error err_no_spec_in_repo;
265 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
266 chmod $CHMOD_MODE $SPECFILE
269 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
276 if [ ! -f "mirrors" ] ; then
277 cvs update mirrors >&2
281 while read origin mirror name rest; do
282 ol=`echo -n "$origin"|wc -c`
283 prefix="`echo -n "$url" | head -c $ol`"
284 if [ "$prefix" = "$origin" ] ; then
285 suffix="`echo "$url"|cut -b $ol-`"
286 echo -n "$mirror$suffix"
297 if [ -n "$DEBUG" ]; then
302 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
306 if [ -n "$CVSROOT" ]; then
307 OPTIONS="-d $CVSROOT $OPTIONS"
309 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
310 echo "warning: No cvs access defined for SOURCES"
314 if [ -n "$CVSTAG" ]; then
315 OPTIONS="$OPTIONS -r $CVSTAG"
317 OPTIONS="$OPTIONS -A"
319 for i in $GET_FILES; do
320 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
321 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
322 echo "Warning: no URL given for $i"
325 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
326 cvs $OPTIONS `nourl $i`
329 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
330 if [ -z "$NOMIRRORS" ] ; then
331 i="`find_mirror "$i"`"
334 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
337 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
338 Exit_error err_no_source_in_repo $i;
343 if [ "$CHMOD" = "yes" ]; then
344 CHMOD_FILES="`nourl $GET_FILES`"
345 if [ -n "$CHMOD_FILES" ]; then
346 chmod $CHMOD_MODE $CHMOD_FILES
357 if [ -n "$DEBUG" ]; then
362 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
363 echo $PACKAGE_VERSION
364 echo $PACKAGE_RELEASE
365 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
366 if [ "$TAG_VERSION" = "yes" ]; then
367 echo "CVS tag: $TAGVER"
369 if [ -n "$TAG" ]; then
374 if [ -n "$CVSROOT" ]; then
375 OPTIONS="-d $CVSROOT $OPTIONS"
379 for i in $TAG_FILES; do
380 if [ -f `nourl $i` ]; then
381 if [ "$TAG_VERSION" = "yes" ]; then
382 cvs $OPTIONS $TAGVER `nourl $i`
384 if [ -n "$TAG" ]; then
385 cvs $OPTIONS $TAG `nourl $i`
388 Exit_error err_no_source_in_repo $i
393 if [ "$TAG_VERSION" = "yes" ]; then
394 cvs $OPTIONS $TAGVER $SPECFILE
396 if [ -n "$TAG" ]; then
397 cvs $OPTIONS $TAG $SPECFILE
407 echo "CVS branch tag: $TAG"
412 if [ -n "$DEBUG" ]; then
417 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
420 if [ -n "$CVSROOT" ]; then
421 OPTIONS="-d $CVSROOT $OPTIONS"
424 for i in $TAG_FILES; do
425 if [ -f `nourl $i` ]; then
426 cvs $OPTIONS $TAG `nourl $i`
428 Exit_error err_no_source_in_repo $i
432 cvs $OPTIONS $TAG $SPECFILE
440 if [ -n "$DEBUG" ]; then
447 if [ -n "$TRY_UPGRADE" ]; then
449 TNOTIFY=`./pldnotify.awk $SPECFILE`
451 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
453 if [ -n "$TNEWVER" ]; then
455 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
457 echo "New version found, updating spec file to version " $TNEWVER
459 cp -f $SPECFILE $SPECFILE.bak
463 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
464 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
468 get_files "$SOURCES $PATCHES";
470 unset TOLDVER TNEWVER TNOTIFY
480 BUILD_SWITCH="-ba" ;;
482 BUILD_SWITCH="-bb" ;;
484 BUILD_SWITCH="-bs --nodeps" ;;
486 if [ -n "$LOGFILE" ]; then
487 LOG=`eval echo $LOGFILE`
488 eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
490 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
493 if [ "$?" -ne "0" ]; then
495 if [ -n "$TRY_UPGRADE" ]; then
496 echo "\n!!! Package with new version cannot be build automagically\n"
497 mv -f $SPECFILE.bak $SPECFILE
500 Exit_error err_build_fail;
508 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
510 #---------------------------------------------
513 if [ "$#" = 0 ]; then
518 while test $# -gt 0 ; do
521 DEBUG="yes"; shift ;;
523 COMMAND="version"; shift ;;
525 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
527 COMMAND="build"; shift ;;
528 -bb | --build-binary )
529 COMMAND="build-binary"; shift ;;
530 -bs | --build-source )
531 COMMAND="build-source"; shift ;;
533 COMMAND="branch"; shift; TAG="${1}"; shift;;
535 CLEAN="--clean --rmspec --rmsource"; shift ;;
537 shift; CVSROOT="${1}"; shift ;;
539 COMMAND="get"; shift ;;
541 COMMAND="usage"; shift ;;
543 shift; LOGFILE="${1}"; shift ;;
545 shift; DEF_NICE_LEVEL=${1}; shift ;;
547 COMMAND="mr-proper"; shift ;;
549 NOCVS="yes"; shift ;;
550 -ncs | --no-cvs-spec )
551 NOCVSSPEC="yes"; shift ;;
553 NOMIRRORS="yes"; shift ;;
555 NOURLS="yes"; shift ;;
557 NOSRCS="yes"; shift ;;
558 -ns0 | --no-source0 )
559 NOSOURCE0="yes"; shift ;;
561 shift; RPMOPTS="${1}"; shift ;;
563 BCOND="$BCOND $1 $2" ; shift 2 ;;
565 QUIET="--quiet"; shift ;;
567 shift; CVSTAG="${1}"; shift ;;
568 -Tvs | --tag-version-stable )
573 -Tvn | --tag-version-nest )
588 -Tv | --tag-version )
600 BE_VERBOSE="1"; shift ;;
602 TRY_UPGRADE="1"; shift ;;
608 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
611 SPECFILE="${1}"; shift ;;
615 if [ -n "$DEBUG" ]; then
621 "build" | "build-binary" | "build-source" )
623 if [ -n "$SPECFILE" ]; then
627 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
628 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
629 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
630 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
632 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
633 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
637 if [ -n "$ICONS" ]; then
641 get_files "$SOURCES $PATCHES";
644 Exit_error err_no_spec_in_cmdl;
649 if [ -n "$SPECFILE" ]; then
652 if [ -n "$ICONS" ]; then
656 get_files $SOURCES $PATCHES;
657 branch_files $TAG "$SOURCES $PATCHES $ICONS";
659 Exit_error err_no_spec_in_cmdl;
664 if [ -n "$SPECFILE" ]; then
667 if [ -n "$ICONS" ]; then
671 if [ -n "$NOSOURCE0" ] ; then
672 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
674 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 tag_files "$SOURCES $PATCHES $ICONS";
691 Exit_error err_no_spec_in_cmdl;
695 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE