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 --passive-ftp -c -nd -t$WGET_RETRIES"
55 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
63 if [ -f ~/etc/builderrc ]; then
65 elif [ -f ~/.builderrc ]; then
69 #---------------------------------------------
74 if [ -n "$DEBUG" ]; then set -xv; fi
76 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
77 [-bb|--build-binary] [-bs|--build-source] [{-B|--branch} <branch>]
78 [{-d|--cvsroot} <cvsroot>] [-g|--get] [-h|--help]
79 [{-l,--logtofile} <logfile>] [-m|--mr-proper] [-q|--quiet]
80 [-r <cvstag>] [{-T--tag <cvstag>] [-Tvs|--tag-version-stable]
81 [-Tvd|--tag-version-devel] [-Ts|--tag-stable] [-Td|--tag-devel]
82 [-Tv|--tag-version] [-u|--no-urls] [-v|--verbose] [--opts <rpm opts>]
83 [--with/--without pkg] [--define <macro> <value>] <package>.spec
85 -D, --debug - enable script debugging mode,
86 -V, --version - output builder version
87 -a, --as_anon - get files via pserver as cvs@anoncvs.pld.org.pl,
89 --build - get all files from CVS repo or HTTP/FTP and build
90 package from <package>.spec,
92 - get all files from CVS repo or HTTP/FTP and build
93 binary only package from <package>.spec,
95 --build-source - get all files from CVS repo or HTTP/FTP and only
96 pack them into src.rpm,
97 -B, --branch - add branch
98 -c, --clean - clean all temporarily created files (in BUILD,
99 SOURCES, SPECS and \$RPM_BUILD_ROOT),
100 -d <cvsroot>, --cvsroot <cvsroot>
102 -g, --get - get <package>.spec and all related files from
103 CVS repo or HTTP/FTP,
104 -h, --help - this message,
105 -l <logfile>, --logtofile <logfile>
107 -m, --mr-proper - only remove all files related to spec file and
109 -nc, --no-cvs - don't download from CVS, if source URL is given,
110 -nm, --no-mirrors - don't download from mirror, if source URL is given,
111 -nu, --no-urls - don't try to download from FTP/HTTP location,
112 -ns, --no-srcs - don't downland Sources
114 - don't downland Source0
116 - additional options for rpm
117 -q, --quiet - be quiet,
118 -r <cvstag>, --cvstag <cvstag>
119 - build package using resources from specified CVS
121 -T <cvstag> , --tag <cvstag>
122 - add cvs tag <cvstag> for files,
123 -Tvs, --tag-version-stable
124 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
125 -Tvd, --tag-version-devel
126 - add cvs tags DEVEL and NAME-VERSION-RELESE for files,
128 - add cvs tag STABLE for files,
130 - add cvs tag DEVEL for files,
132 - add cvs tag NAME-VERSION-RELESE for files,
133 -v, --verbose - be verbose,
134 --define - define a macro
141 if [ -n "$DEBUG" ]; then
148 if [ "$NOSRCS" != "yes" ]; then
149 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
150 if [ -z "$SOURCES" ]; then
151 SOURCES="`$RPMBUILD -bp $BCOND --define 'setup %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
154 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
155 FAIL_IF_NO_SOURCES="no"
158 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
159 if [ -z "$PATCHES" ]; then
160 PATCHES="`$RPMBUILD -bp $BCOND --define 'setup %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
162 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
163 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
164 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
165 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
167 if [ -n "$BE_VERBOSE" ]; then
168 echo "- Sources : `nourl $SOURCES`"
169 if [ -n "$PATCHES" ]; then
170 echo "- Patches : `nourl $PATCHES`"
172 echo "- Patches : *no patches needed*"
174 if [ -n "$ICONS" ]; then
175 echo "- Icon : `nourl $ICONS`"
177 echo "- Icon : *no package icon*"
179 echo "- Name : $PACKAGE_NAME"
180 echo "- Version : $PACKAGE_VERSION"
181 echo "- Release : $PACKAGE_RELEASE"
187 if [ -n "$DEBUG" ]; then
195 "err_no_spec_in_cmdl" )
196 echo "ERROR: spec file name not specified.";
198 "err_no_spec_in_repo" )
199 echo "Error: spec file not stored in CVS repo.";
201 "err_no_source_in_repo" )
202 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
205 echo "Error: package build failed.";
212 if [ -n "$DEBUG" ]; then
217 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
218 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
225 if [ -n "$DEBUG" ]; then
234 if [ -n "$CVSROOT" ]; then
235 OPTIONS="-d $CVSROOT $OPTIONS"
237 if [ -n "$CVSTAG" ]; then
238 OPTIONS="$OPTIONS -r $CVSTAG"
240 OPTIONS="$OPTIONS -A"
243 cvs $OPTIONS $SPECFILE
244 if [ "$?" -ne "0" ]; then
245 Exit_error err_no_spec_in_repo;
247 if [ ! -f "$SPECFILE" ]; then
248 Exit_error err_no_spec_in_repo;
251 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
252 chmod $CHMOD_MODE $SPECFILE
255 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
262 if [ ! -f "mirrors" ] ; then
263 cvs update mirrors >&2
267 while read origin mirror name rest; do
268 ol=`echo -n "$origin"|wc -c`
269 prefix="`echo -n "$url" | head -c $ol`"
270 if [ "$prefix" = "$origin" ] ; then
271 suffix="`echo "$url"|cut -b $ol-`"
272 echo -n "$mirror$suffix"
283 if [ -n "$DEBUG" ]; then
288 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
292 if [ -n "$CVSROOT" ]; then
293 OPTIONS="-d $CVSROOT $OPTIONS"
295 if [ -n "$CVSTAG" ]; then
296 OPTIONS="$OPTIONS -r $CVSTAG"
298 OPTIONS="$OPTIONS -A"
300 for i in $GET_FILES; do
301 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
302 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
303 echo "Warning: no URL given for $i"
306 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
307 cvs $OPTIONS `nourl $i`
310 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
311 if [ -z "$NOMIRRORS" ] ; then
312 i="`find_mirror "$i"`"
317 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
318 Exit_error err_no_source_in_repo $i;
323 if [ "$CHMOD" = "yes" ]; then
324 CHMOD_FILES="`nourl $GET_FILES`"
325 if [ -n "$CHMOD_FILES" ]; then
326 chmod $CHMOD_MODE $CHMOD_FILES
337 if [ -n "$DEBUG" ]; then
342 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
343 echo $PACKAGE_VERSION
344 echo $PACKAGE_RELEASE
345 TAG=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
349 if [ -n "$CVSROOT" ]; then
350 OPTIONS="-d $CVSROOT $OPTIONS"
354 for i in $TAG_FILES; do
355 if [ -f `nourl $i` ]; then
356 cvs $OPTIONS $TAG `nourl $i`
357 cvs $OPTIONS STABLE `nourl $i`
359 Exit_error err_no_source_in_repo $i
364 cvs $OPTIONS $TAG $SPECFILE
365 cvs $OPTIONS STABLE $SPECFILE
374 echo "CVS branch tag: $TAG"
379 if [ -n "$DEBUG" ]; then
384 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
387 if [ -n "$CVSROOT" ]; then
388 OPTIONS="-d $CVSROOT $OPTIONS"
391 for i in $TAG_FILES; do
392 if [ -f `nourl $i` ]; then
393 cvs $OPTIONS $TAG `nourl $i`
395 Exit_error err_no_source_in_repo $i
399 cvs $OPTIONS $TAG $SPECFILE
407 if [ -n "$DEBUG" ]; then
415 BUILD_SWITCH="-ba" ;;
417 BUILD_SWITCH="-bb" ;;
419 BUILD_SWITCH="-bs --nodeps" ;;
421 if [ -n "$LOGFILE" ]; then
422 LOG=`eval echo $LOGFILE`
423 eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
425 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
428 if [ "$?" -ne "0" ]; then
429 Exit_error err_build_fail;
436 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
438 #---------------------------------------------
441 if [ "$#" = 0 ]; then
446 while test $# -gt 0 ; do
449 DEBUG="yes"; shift ;;
451 COMMAND="version"; shift ;;
453 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
455 COMMAND="build"; shift ;;
456 -bb | --build-binary )
457 COMMAND="build-binary"; shift ;;
458 -bs | --build-source )
459 COMMAND="build-source"; shift ;;
461 COMMAND="branch"; shift; TAG="${1}"; shift;;
463 CLEAN="--clean --rmspec --rmsource"; shift ;;
465 shift; CVSROOT="${1}"; shift ;;
467 COMMAND="get"; shift ;;
469 COMMAND="usage"; shift ;;
471 shift; LOGFILE="${1}"; shift ;;
473 shift; DEF_NICE_LEVEL=${1}; shift ;;
475 COMMAND="mr-proper"; shift ;;
477 NOCVS="yes"; shift ;;
479 NOMIRRORS="yes"; shift ;;
481 NOURLS="yes"; shift ;;
483 NOSRCS="yes"; shift ;;
484 -ns0 | --no-source0 )
485 NOSOURCE0="yes"; shift ;;
487 shift; RPMOPTS="${1}"; shift ;;
489 BCOND="$BCOND $1 $2" ; shift 2 ;;
491 QUIET="--quiet"; shift ;;
493 shift; CVSTAG="${1}"; shift ;;
494 -Tvs | --tag-version-stable )
499 -Tvd | --tag-version-devel )
514 -Tv | --tag-version )
525 BE_VERBOSE="1"; shift ;;
531 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
534 SPECFILE="${1}"; shift ;;
538 if [ -n "$DEBUG" ]; then
544 "build" | "build-binary" | "build-source" )
546 if [ -n "$SPECFILE" ]; then
549 if [ -n "$ICONS" ]; then
553 get_files "$SOURCES $PATCHES";
556 Exit_error err_no_spec_in_cmdl;
561 if [ -n "$SPECFILE" ]; then
564 if [ -n "$ICONS" ]; then
568 get_files $SOURCES $PATCHES;
569 branch_files $TAG "$SOURCES $PATCHES $ICONS";
571 Exit_error err_no_spec_in_cmdl;
576 if [ -n "$SPECFILE" ]; then
579 if [ -n "$ICONS" ]; then
583 if [ -n "$NOSOURCE0" ] ; then
584 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
586 get_files $SOURCES $PATCHES
588 Exit_error err_no_spec_in_cmdl;
593 if [ -n "$SPECFILE" ]; then
596 if [ -n "$ICONS" ]; then
600 get_files $SOURCES $PATCHES;
601 tag_files "$SOURCES $PATCHES $ICONS";
603 Exit_error err_no_spec_in_cmdl;
607 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE