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 (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 -nu, --no-urls - don't try to download from FTP/HTTP location,
111 -ns, --no-srcs - don't downland Sources
113 - don't downland Source0
115 - additional options for rpm
116 -q, --quiet - be quiet,
117 -r <cvstag>, --cvstag <cvstag>
118 - build package using resources from specified CVS
120 -T <cvstag> , --tag <cvstag>
121 - add cvs tag <cvstag> for files,
122 -Tvs, --tag-version-stable
123 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
124 -Tvd, --tag-version-devel
125 - add cvs tags DEVEL and NAME-VERSION-RELESE for files,
127 - add cvs tag STABLE for files,
129 - add cvs tag DEVEL for files,
131 - add cvs tag NAME-VERSION-RELESE for files,
132 -v, --verbose - be verbose,
133 --define - define a macro
140 if [ -n "$DEBUG" ]; then
147 if [ "$NOSRCS" != "yes" ]; then
148 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
149 if [ -z "$SOURCES" ]; then
150 SOURCES="`$RPMBUILD -bp $BCOND --define 'setup %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
153 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
154 FAIL_IF_NO_SOURCES="no"
157 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
158 if [ -z "$PATCHES" ]; then
159 PATCHES="`$RPMBUILD -bp $BCOND --define 'setup %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
161 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
162 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
163 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
164 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
166 if [ -n "$BE_VERBOSE" ]; then
167 echo "- Sources : `nourl $SOURCES`"
168 if [ -n "$PATCHES" ]; then
169 echo "- Patches : `nourl $PATCHES`"
171 echo "- Patches : *no patches needed*"
173 if [ -n "$ICONS" ]; then
174 echo "- Icon : `nourl $ICONS`"
176 echo "- Icon : *no package icon*"
178 echo "- Name : $PACKAGE_NAME"
179 echo "- Version : $PACKAGE_VERSION"
180 echo "- Release : $PACKAGE_RELEASE"
186 if [ -n "$DEBUG" ]; then
194 "err_no_spec_in_cmdl" )
195 echo "ERROR: spec file name not specified.";
197 "err_no_spec_in_repo" )
198 echo "Error: spec file not stored in CVS repo.";
200 "err_no_source_in_repo" )
201 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
204 echo "Error: package build failed.";
211 if [ -n "$DEBUG" ]; then
216 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
217 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
224 if [ -n "$DEBUG" ]; then
233 if [ -n "$CVSROOT" ]; then
234 OPTIONS="-d $CVSROOT $OPTIONS"
236 if [ -n "$CVSTAG" ]; then
237 OPTIONS="$OPTIONS -r $CVSTAG"
239 OPTIONS="$OPTIONS -A"
242 cvs $OPTIONS $SPECFILE
243 if [ "$?" -ne "0" ]; then
244 Exit_error err_no_spec_in_repo;
246 if [ ! -f "$SPECFILE" ]; then
247 Exit_error err_no_spec_in_repo;
250 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
251 chmod $CHMOD_MODE $SPECFILE
254 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
261 if [ -n "$DEBUG" ]; then
266 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
270 if [ -n "$CVSROOT" ]; then
271 OPTIONS="-d $CVSROOT $OPTIONS"
273 if [ -n "$CVSTAG" ]; then
274 OPTIONS="$OPTIONS -r $CVSTAG"
276 OPTIONS="$OPTIONS -A"
278 for i in $GET_FILES; do
279 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
280 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
281 echo "Warning: no URL given for $i"
284 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
285 cvs $OPTIONS `nourl $i`
288 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
292 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
293 Exit_error err_no_source_in_repo $i;
298 if [ "$CHMOD" = "yes" ]; then
299 CHMOD_FILES="`nourl $GET_FILES`"
300 if [ -n "$CHMOD_FILES" ]; then
301 chmod $CHMOD_MODE $CHMOD_FILES
312 if [ -n "$DEBUG" ]; then
317 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
318 echo $PACKAGE_VERSION
319 echo $PACKAGE_RELEASE
320 TAG=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
324 if [ -n "$CVSROOT" ]; then
325 OPTIONS="-d $CVSROOT $OPTIONS"
329 for i in $TAG_FILES; do
330 if [ -f `nourl $i` ]; then
331 cvs $OPTIONS $TAG `nourl $i`
332 cvs $OPTIONS STABLE `nourl $i`
334 Exit_error err_no_source_in_repo $i
339 cvs $OPTIONS $TAG $SPECFILE
340 cvs $OPTIONS STABLE $SPECFILE
349 echo "CVS branch tag: $TAG"
354 if [ -n "$DEBUG" ]; then
359 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
362 if [ -n "$CVSROOT" ]; then
363 OPTIONS="-d $CVSROOT $OPTIONS"
366 for i in $TAG_FILES; do
367 if [ -f `nourl $i` ]; then
368 cvs $OPTIONS $TAG `nourl $i`
370 Exit_error err_no_source_in_repo $i
374 cvs $OPTIONS $TAG $SPECFILE
382 if [ -n "$DEBUG" ]; then
390 BUILD_SWITCH="-ba" ;;
392 BUILD_SWITCH="-bb" ;;
394 BUILD_SWITCH="-bs --nodeps" ;;
396 if [ -n "$LOGFILE" ]; then
397 LOG=`eval echo $LOGFILE`
398 eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
400 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
403 if [ "$?" -ne "0" ]; then
404 Exit_error err_build_fail;
411 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
413 #---------------------------------------------
416 if [ "$#" = 0 ]; then
421 while test $# -gt 0 ; do
424 DEBUG="yes"; shift ;;
426 COMMAND="version"; shift ;;
428 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
430 COMMAND="build"; shift ;;
431 -bb | --build-binary )
432 COMMAND="build-binary"; shift ;;
433 -bs | --build-source )
434 COMMAND="build-source"; shift ;;
436 COMMAND="branch"; shift; TAG="${1}"; shift;;
438 CLEAN="--clean --rmspec --rmsource"; shift ;;
440 shift; CVSROOT="${1}"; shift ;;
442 COMMAND="get"; shift ;;
444 COMMAND="usage"; shift ;;
446 shift; LOGFILE="${1}"; shift ;;
448 shift; DEF_NICE_LEVEL=${1}; shift ;;
450 COMMAND="mr-proper"; shift ;;
452 NOCVS="yes"; shift ;;
454 NOURLS="yes"; shift ;;
456 NOSRCS="yes"; shift ;;
457 -ns0 | --no-source0 )
458 NOSOURCE0="yes"; shift ;;
460 shift; RPMOPTS="${1}"; shift ;;
462 BCOND="$BCOND $1 $2" ; shift 2 ;;
464 QUIET="--quiet"; shift ;;
466 shift; CVSTAG="${1}"; shift ;;
467 -Tvs | --tag-version-stable )
472 -Tvd | --tag-version-devel )
487 -Tv | --tag-version )
498 BE_VERBOSE="1"; shift ;;
504 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
507 SPECFILE="${1}"; shift ;;
511 if [ -n "$DEBUG" ]; then
517 "build" | "build-binary" | "build-source" )
519 if [ -n "$SPECFILE" ]; then
522 if [ -n "$ICONS" ]; then
526 get_files "$SOURCES $PATCHES";
529 Exit_error err_no_spec_in_cmdl;
534 if [ -n "$SPECFILE" ]; then
537 if [ -n "$ICONS" ]; then
541 get_files $SOURCES $PATCHES;
542 branch_files $TAG "$SOURCES $PATCHES $ICONS";
544 Exit_error err_no_spec_in_cmdl;
549 if [ -n "$SPECFILE" ]; then
552 if [ -n "$ICONS" ]; then
556 if [ -n "$NOSOURCE0" ] ; then
557 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
559 get_files $SOURCES $PATCHES
561 Exit_error err_no_spec_in_cmdl;
566 if [ -n "$SPECFILE" ]; then
569 if [ -n "$ICONS" ]; then
573 get_files $SOURCES $PATCHES;
574 tag_files "$SOURCES $PATCHES $ICONS";
576 Exit_error err_no_spec_in_cmdl;
580 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE