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 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|--build]
69 [-bb|--build-binary] [-bs|--build-source] [{-B|--branch} <branch>]
70 [{-d|--cvsroot} <cvsroot>] [-g|--get] [-h|--help]
71 [{-l,--logtofile} <logfile>] [-m|--mr-proper] [-q|--quiet]
72 [-r <cvstag>] [{-T--tag <cvstag>] [-Tvs|--tag-version-stable]
73 [-Tvd|--tag-version-devel] [-Ts|--tag-stable] [-Td|--tag-devel]
74 [-Tv|--tag-version] [-u|--no-urls] [-v|--verbose] [--opts <rpm opts>]
75 [--with/--without pkg] [--define <macro> <value>] <package>.spec
77 -D, --debug - enable script debugging mode,
78 -V, --version - output builder version
79 -a, --as_anon - get files via pserver as cvs@anoncvs.pld.org.pl,
81 --build - get all files from CVS repo or HTTP/FTP and build
82 package from <package>.spec,
84 - get all files from CVS repo or HTTP/FTP and build
85 binary only package from <package>.spec,
87 --build-source - get all files from CVS repo or HTTP/FTP and only
88 pack them into src.rpm,
89 -B, --branch - add branch
90 -c, --clean - clean all temporarily created files (in BUILD,
91 SOURCES, SPECS and \$RPM_BUILD_ROOT),
92 -d <cvsroot>, --cvsroot <cvsroot>
94 -g, --get - get <package>.spec and all related files from
96 -h, --help - this message,
97 -l <logfile>, --logtofile <logfile>
99 -m, --mr-proper - only remove all files related to spec file and
101 -nc, --no-cvs - don't download from CVS, if source URL is given,
102 -nu, --no-urls - don't try to download from FTP/HTTP location,
103 -ns, --no-srcs - don't downland Sources
105 - don't downland Source0
107 - additional options for rpm
108 -q, --quiet - be quiet,
109 -r <cvstag>, --cvstag <cvstag>
110 - build package using resources from specified CVS
112 -T <cvstag> , --tag <cvstag>
113 - add cvs tag <cvstag> for files,
114 -Tvs, --tag-version-stable
115 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
116 -Tvd, --tag-version-devel
117 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
119 - add cvs tag STABLE for files,
121 - add cvs tag DEVEL for files,
123 - add cvs tag NAME-VERSION-RELESE for files,
124 -v, --verbose - be verbose,
125 --define - define a macro
132 if [ -n "$DEBUG" ]; then
139 if [ "$NOSRCS" != "yes" ]; then
140 SOURCES="`rpmbuild -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
142 if (rpmbuild -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
143 FAIL_IF_NO_SOURCES="no"
146 PATCHES="`rpmbuild -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
147 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
148 PACKAGE_NAME="`rpm -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
149 PACKAGE_VERSION="`rpm -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
150 PACKAGE_RELEASE="`rpm -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
152 if [ -n "$BE_VERBOSE" ]; then
153 echo "- Sources : `nourl $SOURCES`"
154 if [ -n "$PATCHES" ]; then
155 echo "- Patches : `nourl $PATCHES`"
157 echo "- Patches : *no patches needed*"
159 if [ -n "$ICONS" ]; then
160 echo "- Icon : `nourl $ICONS`"
162 echo "- Icon : *no package icon*"
164 echo "- Name : $PACKAGE_NAME"
165 echo "- Version : $PACKAGE_VERSION"
166 echo "- Release : $PACKAGE_RELEASE"
172 if [ -n "$DEBUG" ]; then
180 "err_no_spec_in_cmdl" )
181 echo "ERROR: spec file name not specified.";
183 "err_no_spec_in_repo" )
184 echo "Error: spec file not stored in CVS repo.";
186 "err_no_source_in_repo" )
187 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
190 echo "Error: package build failed.";
197 if [ -n "$DEBUG" ]; then
202 SOURCE_DIR="`rpm --eval '%{_sourcedir}'`"
203 SPECS_DIR="`rpm --eval '%{_specdir}'`"
210 if [ -n "$DEBUG" ]; then
219 if [ -n "$CVSROOT" ]; then
220 OPTIONS="-d $CVSROOT $OPTIONS"
222 if [ -n "$CVSTAG" ]; then
223 OPTIONS="$OPTIONS -r $CVSTAG"
225 OPTIONS="$OPTIONS -A"
228 cvs $OPTIONS $SPECFILE
229 if [ "$?" -ne "0" ]; then
230 Exit_error err_no_spec_in_repo;
232 if [ ! -f "$SPECFILE" ]; then
233 Exit_error err_no_spec_in_repo;
236 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
237 chmod $CHMOD_MODE $SPECFILE
240 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
247 if [ -n "$DEBUG" ]; then
252 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
256 if [ -n "$CVSROOT" ]; then
257 OPTIONS="-d $CVSROOT $OPTIONS"
259 if [ -n "$CVSTAG" ]; then
260 OPTIONS="$OPTIONS -r $CVSTAG"
262 OPTIONS="$OPTIONS -A"
264 for i in $GET_FILES; do
265 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
266 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
267 echo "Warning: no URL given for $i"
270 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
271 cvs $OPTIONS `nourl $i`
274 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
278 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
279 Exit_error err_no_source_in_repo $i;
284 if [ "$CHMOD" = "yes" ]; then
285 CHMOD_FILES="`nourl $GET_FILES`"
286 if [ -n "$CHMOD_FILES" ]; then
287 chmod $CHMOD_MODE $CHMOD_FILES
298 if [ -n "$DEBUG" ]; then
303 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
304 echo $PACKAGE_VERSION
305 echo $PACKAGE_RELEASE
306 TAG=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
310 if [ -n "$CVSROOT" ]; then
311 OPTIONS="-d $CVSROOT $OPTIONS"
315 for i in $TAG_FILES; do
316 if [ -f `nourl $i` ]; then
317 cvs $OPTIONS $TAG `nourl $i`
318 cvs $OPTIONS STABLE `nourl $i`
320 Exit_error err_no_source_in_repo $i
325 cvs $OPTIONS $TAG $SPECFILE
326 cvs $OPTIONS STABLE $SPECFILE
335 echo "CVS branch tag: $TAG"
340 if [ -n "$DEBUG" ]; then
345 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
348 if [ -n "$CVSROOT" ]; then
349 OPTIONS="-d $CVSROOT $OPTIONS"
352 for i in $TAG_FILES; do
353 if [ -f `nourl $i` ]; then
354 cvs $OPTIONS $TAG `nourl $i`
356 Exit_error err_no_source_in_repo $i
360 cvs $OPTIONS $TAG $SPECFILE
368 if [ -n "$DEBUG" ]; then
376 BUILD_SWITCH="-ba" ;;
378 BUILD_SWITCH="-bb" ;;
380 BUILD_SWITCH="-bs --nodeps" ;;
382 if [ -n "$LOGFILE" ]; then
383 LOG=`eval echo $LOGFILE`
384 eval nice -n ${DEF_NICE_LEVEL} time rpmbuild $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
386 eval nice -n ${DEF_NICE_LEVEL} rpmbuild $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
389 if [ "$?" -ne "0" ]; then
390 Exit_error err_build_fail;
397 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\)://[^ ]*/##g'
399 #---------------------------------------------
402 if [ "$#" = 0 ]; then
407 while test $# -gt 0 ; do
410 DEBUG="yes"; shift ;;
412 COMMAND="version"; shift ;;
414 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
416 COMMAND="build"; shift ;;
417 -bb | --build-binary )
418 COMMAND="build-binary"; shift ;;
419 -bs | --build-source )
420 COMMAND="build-source"; shift ;;
422 COMMAND="branch"; shift; TAG="${1}"; shift;;
424 CLEAN="--clean --rmspec --rmsource"; shift ;;
426 shift; CVSROOT="${1}"; shift ;;
428 COMMAND="get"; shift ;;
430 COMMAND="usage"; shift ;;
432 shift; LOGFILE="${1}"; shift ;;
434 shift; DEF_NICE_LEVEL=${1}; shift ;;
436 COMMAND="mr-proper"; shift ;;
438 NOCVS="yes"; shift ;;
440 NOURLS="yes"; shift ;;
442 NOSRCS="yes"; shift ;;
443 -ns0 | --no-source0 )
444 NOSOURCE0="yes"; shift ;;
446 shift; RPMOPTS="${1}"; shift ;;
448 BCOND="$BCOND $1 $2" ; shift 2 ;;
450 QUIET="--quiet"; shift ;;
452 shift; CVSTAG="${1}"; shift ;;
453 -Tvs | --tag-version-stable )
458 -Tvd | --tag-version-devel )
473 -Tv | --tag-version )
484 BE_VERBOSE="1"; shift ;;
490 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
493 SPECFILE="${1}"; shift ;;
497 if [ -n "$DEBUG" ]; then
503 "build" | "build-binary" | "build-source" )
505 if [ -n "$SPECFILE" ]; then
508 if [ -n "$ICONS" ]; then
512 get_files "$SOURCES $PATCHES";
515 Exit_error err_no_spec_in_cmdl;
520 if [ -n "$SPECFILE" ]; then
523 if [ -n "$ICONS" ]; then
527 get_files $SOURCES $PATCHES;
528 branch_files $TAG "$SOURCES $PATCHES $ICONS";
530 Exit_error err_no_spec_in_cmdl;
535 if [ -n "$SPECFILE" ]; then
538 if [ -n "$ICONS" ]; then
542 if [ -n "$NOSOURCE0" ] ; then
543 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
545 get_files $SOURCES $PATCHES
547 Exit_error err_no_spec_in_cmdl;
552 if [ -n "$SPECFILE" ]; then
555 if [ -n "$ICONS" ]; then
559 get_files $SOURCES $PATCHES;
560 tag_files "$SOURCES $PATCHES $ICONS";
562 Exit_error err_no_spec_in_cmdl;
566 rpm --clean --rmsource --rmspec --force --nodeps $SPECFILE