7 # 2 - no spec file name in cmdl parameters
8 # 3 - spec file not stored in repo
9 # 4 - some source, apatch or icon files not stored in repo
10 # 5 - build package no succed
13 Build package utility from PLD CVS repository
14 V 0.9 (C) 1999-2001 Tomasz K³oczko".
16 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
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}
51 FAIL_IF_NO_SOURCES="yes"
53 GETURI="wget -c -nd -t$WGET_RETRIES"
55 if [ -f ~/etc/builderrc ]; then
57 elif [ -f ~/.builderrc ]; then
61 #---------------------------------------------
66 if [ -n "$DEBUG" ]; then set -xv; fi
68 Usage: builder [-D] [--debug] [-V] [--version] [-a] [--as_anon] [-b] [-ba]
69 [--build] [-bb] [--build-binary] [-bs] [--build-source]
70 [-B <branch>] [--branch <branch>] [-d <cvsroot>] [--cvsroot <cvsroot>]
71 [-g] [--get] [-h] [--help] [-l <logfile>] [-m] [--mr-proper]
72 [--logtofile <logfile>] [-q] [--quiet] [-r <cvstag>] [--cvstag <cvstag>]
73 [-u] [--no-urls] [-v] [--verbose] [--opts <rpm opts>]
74 [--with/--without pkg] [--define <macro> <value>] <package>.spec
76 -D, --debug - enable script debugging mode,
77 -V, --version - output builder version
78 -a, --as_anon - get files via pserver as cvs@anoncvs.pld.org.pl,
80 --build - get all files from CVS repo or HTTP/FTP and build
81 package from <package>.spec,
83 --build-binary - get all files from CVS repo or HTTP/FTP and build
84 binary only package from <package>.spec,
86 --build-source - get all files from CVS repo or HTTP/FTP and only
87 pack them into src.rpm,
88 -B, --branch - add branch
89 -c, --clean - clean all temporarily created files (in BUILD,
90 SOURCES, SPECS and \$RPM_BUILD_ROOT),
91 SOURCES, SPECS and \$RPM_BUILD_ROOT),
92 -d, --cvsroot - setup \$CVSROOT,
93 -g, --get - get <package>.spec and all related files from
95 -h, --help - this message,
96 -l, --logtofile - log all to file,
97 -m, --mr-proper - only remove all files related to spec file and
99 -nc, --no-cvs - don't download from CVS, if source URL is given,
100 -nu, --no-urls - don't try to download from FTP/HTTP location,
101 -ns, --no-srcs - don't downland Sources
102 --opts - additional options for rpm
103 -q, --quiet - be quiet,
104 -r, --cvstag - build package using resources from specified CVS
106 -T, --tag - add cvs tags for files,
107 -v, --verbose - be verbose,
108 --define - define a macro
115 if [ -n "$DEBUG" ]; then
122 # NOTE: "--define 'prep '" causes an error (Macro %prep has empty body)
123 # but rpm output is still useful.
124 # NOTE2: Redefining %prep to %dump isn't best solution because at least
125 # six packages do not containt this section. All packages have
127 DEFINE_AS_DUMP="--define 'prep ' --define 'install %dump'"
129 if [ "$NOSRCS" != "yes" ]; then
130 SOURCES="`eval rpm -bp --nobuild $DEFINE_AS_DUMP $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
132 if (rpm -bp --nobuild --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
133 FAIL_IF_NO_SOURCES="no"
137 PATCHES="`eval rpm -bp --nobuild $DEFINE_AS_DUMP $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
138 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
139 PACKAGE_NAME="`rpm -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
140 PACKAGE_VERSION="`rpm -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
141 PACKAGE_RELEASE="`rpm -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
143 if [ -n "$BE_VERBOSE" ]; then
144 echo "- Sources : `nourl $SOURCES`"
145 if [ -n "$PATCHES" ]; then
146 echo "- Patches : `nourl $PATCHES`"
148 echo "- Patches : *no patches needed*"
150 if [ -n "$ICONS" ]; then
151 echo "- Icon : `nourl $ICONS`"
153 echo "- Icon : *no package icon*"
155 echo "- Name : $PACKAGE_NAME"
156 echo "- Version : $PACKAGE_VERSION"
157 echo "- Release : $PACKAGE_RELEASE"
163 if [ -n "$DEBUG" ]; then
171 "err_no_spec_in_cmdl" )
172 echo "ERROR: spec file name not specified.";
174 "err_no_spec_in_repo" )
175 echo "Error: spec file not stored in CVS repo.";
177 "err_no_source_in_repo" )
178 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
181 echo "Error: package build failed.";
188 if [ -n "$DEBUG" ]; then
193 SOURCE_DIR="`rpm --eval '%{_sourcedir}'`"
194 SPECS_DIR="`rpm --eval '%{_specdir}'`"
201 if [ -n "$DEBUG" ]; then
210 if [ -n "$CVSROOT" ]; then
211 OPTIONS="-d $CVSROOT $OPTIONS"
213 if [ -n "$CVSTAG" ]; then
214 OPTIONS="$OPTIONS -r $CVSTAG"
216 OPTIONS="$OPTIONS -A"
219 cvs $OPTIONS $SPECFILE
220 if [ "$?" -ne "0" ]; then
221 Exit_error err_no_spec_in_repo;
223 if [ ! -f "$SPECFILE" ]; then
224 Exit_error err_no_spec_in_repo;
227 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
228 chmod $CHMOD_MODE $SPECFILE
231 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
238 if [ -n "$DEBUG" ]; then
243 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
247 if [ -n "$CVSROOT" ]; then
248 OPTIONS="-d $CVSROOT $OPTIONS"
250 if [ -n "$CVSTAG" ]; then
251 OPTIONS="$OPTIONS -r $CVSTAG"
253 OPTIONS="$OPTIONS -A"
255 for i in $GET_FILES; do
256 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]
259 echo $i | grep -vE '(http|ftp|https|cvs)://' |\
260 grep -qE '\.(gz|bz2)$'
262 echo "Warning: no URL given for $i"
265 if [ -z "$NOCVS" ]||\
266 [ `echo $i | grep -vE '(ftp|http|https)://'` ]
268 cvs $OPTIONS `nourl $i`
271 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ]&&\
272 [ `echo $i | grep -E 'ftp://|http://|https://'` ]
277 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
278 Exit_error err_no_source_in_repo $i;
283 if [ "$CHMOD" = "yes" ]; then
284 CHMOD_FILES="`nourl $GET_FILES`"
285 if [ -n "$CHMOD_FILES" ]; then
286 chmod $CHMOD_MODE $CHMOD_FILES
297 if [ -n "$DEBUG" ]; then
302 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
303 echo $PACKAGE_VERSION
304 echo $PACKAGE_RELEASE
305 TAG=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
309 if [ -n "$CVSROOT" ]; then
310 OPTIONS="-d $CVSROOT $OPTIONS"
314 for i in $TAG_FILES; do
315 if [ -f `nourl $i` ]; then
316 cvs $OPTIONS $TAG `nourl $i`
317 cvs $OPTIONS STABLE `nourl $i`
319 Exit_error err_no_source_in_repo $i
324 cvs $OPTIONS $TAG $SPECFILE
325 cvs $OPTIONS STABLE $SPECFILE
334 echo "CVS branch tag: $TAG"
339 if [ -n "$DEBUG" ]; then
344 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
347 if [ -n "$CVSROOT" ]; then
348 OPTIONS="-d $CVSROOT $OPTIONS"
351 for i in $TAG_FILES; do
352 if [ -f `nourl $i` ]; then
353 cvs $OPTIONS $TAG `nourl $i`
355 Exit_error err_no_source_in_repo $i
359 cvs $OPTIONS $TAG $SPECFILE
367 if [ -n "$DEBUG" ]; then
375 BUILD_SWITCH="-ba" ;;
377 BUILD_SWITCH="-bb" ;;
379 BUILD_SWITCH="-bs --nodeps" ;;
381 if [ -n "$LOGFILE" ]; then
382 LOG=`eval echo $LOGFILE`
383 eval nice -n ${DEF_NICE_LEVEL} /bin/sh -c "time rpm $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE" 2>&1 | tee $LOG
385 eval nice -n ${DEF_NICE_LEVEL} rpm $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
388 if [ "$?" -ne "0" ]; then
389 Exit_error err_build_fail;
396 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\)://[^ ]*/##g'
398 #---------------------------------------------
401 if [ "$#" = 0 ]; then
406 while test $# -gt 0 ; do
409 DEBUG="yes"; shift ;;
411 COMMAND="version"; shift ;;
413 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
415 COMMAND="build"; shift ;;
416 -bb | --build-binary )
417 COMMAND="build-binary"; shift ;;
418 -bs | --build-source )
419 COMMAND="build-source"; shift ;;
421 COMMAND="branch"; shift; TAG="${1}"; shift;;
423 CLEAN="--clean --rmspec --rmsource"; shift ;;
425 shift; CVSROOT="${1}"; shift ;;
427 COMMAND="get"; shift ;;
429 COMMAND="usage"; shift ;;
431 shift; LOGFILE="${1}"; shift ;;
433 shift; DEF_NICE_LEVEL=${1}; shift ;;
435 COMMAND="mr-proper"; shift ;;
437 NOCVS="yes"; shift ;;
439 NOURLS="yes"; shift ;;
441 NOSRCS="yes"; shift ;;
443 shift; RPMOPTS="${1}"; shift ;;
445 BCOND="$BCOND $1 $2" ; shift 2 ;;
447 QUIET="--quiet"; shift ;;
449 shift; CVSTAG="${1}"; shift ;;
451 COMMAND="tag"; shift;;
453 BE_VERBOSE="1"; shift ;;
459 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
462 SPECFILE="${1}"; shift ;;
466 if [ -n "$DEBUG" ]; then
472 "build" | "build-binary" | "build-source" )
474 if [ -n "$SPECFILE" ]; then
477 if [ -n "$ICONS" ]; then
481 get_files "$SOURCES $PATCHES";
484 Exit_error err_no_spec_in_cmdl;
489 if [ -n "$SPECFILE" ]; then
492 if [ -n "$ICONS" ]; then
496 get_files $SOURCES $PATCHES;
497 branch_files $TAG "$SOURCES $PATCHES $ICONS";
499 Exit_error err_no_spec_in_cmdl;
504 if [ -n "$SPECFILE" ]; then
507 if [ -n "$ICONS" ]; then
511 get_files $SOURCES $PATCHES
513 Exit_error err_no_spec_in_cmdl;
518 if [ -n "$SPECFILE" ]; then
521 if [ -n "$ICONS" ]; then
525 get_files $SOURCES $PATCHES;
526 tag_files "$SOURCES $PATCHES $ICONS";
528 Exit_error err_no_spec_in_cmdl;
532 rpm --clean --rmsource --rmspec --force --nodeps $SPECFILE
543 # Revision 1.90 2002/01/15 17:03:14 misiek
544 # - use grep instead of head
546 # Revision 1.89 2002/01/15 13:20:08 misiek
547 # - display spec revision and date
549 # Revision 1.88 2001/11/23 15:07:05 zagrodzki
550 # - fixed shifting arguments at --define
551 # - use eval when starting rpm
553 # Revision 1.87 2001/11/23 13:53:01 zagrodzki
554 # - added --define option
556 # Revision 1.86 2001/11/20 01:38:01 blues
557 # - small cosmetic fix
559 # Revision 1.85 2001/11/19 23:02:06 blues
560 # - added raw branching support
562 # Revision 1.84 2001/11/07 22:08:48 ankry
563 # - make builder's chmod configurable
565 # Revision 1.83 2001/10/10 08:41:32 misiek
566 # - allow more bconds than one
568 # Revision 1.82 2001/09/18 10:55:37 ankry
569 # - added support for limitting number of wget retries when fetching a file
570 # from ftp/http server via environment variable MAX_WGET_RETRIES.
571 # Defaults to infinite (0).
573 # Revision 1.81 2001/07/06 16:52:30 misiek
574 # - by default use CVSroot from CVS/Root and if it doesn't exist use from CVSROOT variable
576 # Revision 1.80 2001/06/22 18:52:39 misiek
577 # - added support for --with/--without options
579 # Revision 1.79 2001/05/28 14:44:16 baggins
580 # - if file is not in repo TELL which fucking file it is!
582 # Revision 1.78 2001/05/13 19:04:44 misiek
585 # Revision 1.77 2001/05/13 10:51:30 misiek
586 # don't fail if no sources found (hack to allow build nosrc packages)
588 # Revision 1.76 2001/04/19 23:24:06 misiek
591 # Revision 1.75 2001/04/19 23:14:25 misiek
592 # redirect errors from query to /dev/null
594 # Revision 1.74 2001/04/02 15:39:29 misiek
595 # fix problems with get_files when no files passed
597 # Revision 1.73 2001/03/30 14:06:10 wiget
598 # massive typo by kloczek
600 # Revision 1.72 2001/03/26 22:16:22 kloczek
601 # - fixed grabbing name, version and release in parse_spec(),
602 # - added -T option (tag) (temporary it tags also additional STABLE tag - must
603 # be added -Ts for separate tagging as STABLE).
605 # Revision 1.71 2001/03/05 14:12:27 misiek
608 # Revision 1.70 2001/03/03 19:55:42 misiek
609 # workaround for problems with rpm when icons isn't cvs up'ed