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] [-u|--try-upgrade]
78 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
79 [-h|--help] [{-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] [-nu|--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 -u, --try-upgrade - check version, and try to upgrade package
135 --define - define a macro
142 if [ -n "$DEBUG" ]; then
149 if [ "$NOSRCS" != "yes" ]; then
150 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
152 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
153 FAIL_IF_NO_SOURCES="no"
156 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
157 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
158 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
159 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
160 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
162 if [ -n "$BE_VERBOSE" ]; then
163 echo "- Sources : `nourl $SOURCES`"
164 if [ -n "$PATCHES" ]; then
165 echo "- Patches : `nourl $PATCHES`"
167 echo "- Patches : *no patches needed*"
169 if [ -n "$ICONS" ]; then
170 echo "- Icon : `nourl $ICONS`"
172 echo "- Icon : *no package icon*"
174 echo "- Name : $PACKAGE_NAME"
175 echo "- Version : $PACKAGE_VERSION"
176 echo "- Release : $PACKAGE_RELEASE"
182 if [ -n "$DEBUG" ]; then
190 "err_no_spec_in_cmdl" )
191 echo "ERROR: spec file name not specified.";
193 "err_no_spec_in_repo" )
194 echo "Error: spec file not stored in CVS repo.";
196 "err_no_source_in_repo" )
197 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
200 echo "Error: package build failed.";
207 if [ -n "$DEBUG" ]; then
212 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
213 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
220 if [ -n "$DEBUG" ]; then
229 if [ -n "$CVSROOT" ]; then
230 OPTIONS="-d $CVSROOT $OPTIONS"
232 if [ -n "$CVSTAG" ]; then
233 OPTIONS="$OPTIONS -r $CVSTAG"
235 OPTIONS="$OPTIONS -A"
238 cvs $OPTIONS $SPECFILE
239 if [ "$?" -ne "0" ]; then
240 Exit_error err_no_spec_in_repo;
242 if [ ! -f "$SPECFILE" ]; then
243 Exit_error err_no_spec_in_repo;
246 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
247 chmod $CHMOD_MODE $SPECFILE
250 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
257 if [ ! -f "mirrors" ] ; then
258 cvs update mirrors >&2
262 while read origin mirror name rest; do
263 ol=`echo -n "$origin"|wc -c`
264 prefix="`echo -n "$url" | head -c $ol`"
265 if [ "$prefix" = "$origin" ] ; then
266 suffix="`echo "$url"|cut -b $ol-`"
267 echo -n "$mirror$suffix"
278 if [ -n "$DEBUG" ]; then
283 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
287 if [ -n "$CVSROOT" ]; then
288 OPTIONS="-d $CVSROOT $OPTIONS"
290 if [ -n "$CVSTAG" ]; then
291 OPTIONS="$OPTIONS -r $CVSTAG"
293 OPTIONS="$OPTIONS -A"
295 for i in $GET_FILES; do
296 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
297 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
298 echo "Warning: no URL given for $i"
301 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
302 cvs $OPTIONS `nourl $i`
305 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
306 if [ -z "$NOMIRRORS" ] ; then
307 i="`find_mirror "$i"`"
312 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
313 Exit_error err_no_source_in_repo $i;
318 if [ "$CHMOD" = "yes" ]; then
319 CHMOD_FILES="`nourl $GET_FILES`"
320 if [ -n "$CHMOD_FILES" ]; then
321 chmod $CHMOD_MODE $CHMOD_FILES
332 if [ -n "$DEBUG" ]; then
337 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
338 echo $PACKAGE_VERSION
339 echo $PACKAGE_RELEASE
340 TAG=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
344 if [ -n "$CVSROOT" ]; then
345 OPTIONS="-d $CVSROOT $OPTIONS"
349 for i in $TAG_FILES; do
350 if [ -f `nourl $i` ]; then
351 cvs $OPTIONS $TAG `nourl $i`
352 cvs $OPTIONS STABLE `nourl $i`
354 Exit_error err_no_source_in_repo $i
359 cvs $OPTIONS $TAG $SPECFILE
360 cvs $OPTIONS STABLE $SPECFILE
369 echo "CVS branch tag: $TAG"
374 if [ -n "$DEBUG" ]; then
379 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
382 if [ -n "$CVSROOT" ]; then
383 OPTIONS="-d $CVSROOT $OPTIONS"
386 for i in $TAG_FILES; do
387 if [ -f `nourl $i` ]; then
388 cvs $OPTIONS $TAG `nourl $i`
390 Exit_error err_no_source_in_repo $i
394 cvs $OPTIONS $TAG $SPECFILE
402 if [ -n "$DEBUG" ]; then
409 if [ -n "$TRY_UPGRADE" ]; then
411 TNOTIFY=`./pldnotify.awk $SPECFILE`
413 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
415 if [ -n "$TNEWVER" ]; then
417 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
419 echo "New version found, updating spec file to version " $TNEWVER
421 cp -f $SPECFILE $SPECFILE.bak
425 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
426 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
430 get_files "$SOURCES $PATCHES";
432 unset TOLDVER TNEWVER TNOTIFY
442 BUILD_SWITCH="-ba" ;;
444 BUILD_SWITCH="-bb" ;;
446 BUILD_SWITCH="-bs --nodeps" ;;
448 if [ -n "$LOGFILE" ]; then
449 LOG=`eval echo $LOGFILE`
450 eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
452 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
455 if [ "$?" -ne "0" ]; then
457 if [ -n "$TRY_UPGRADE" ]; then
458 echo "\n!!! Package with new version cannot be build automagically\n"
459 mv -f $SPECFILE.bak $SPECFILE
462 Exit_error err_build_fail;
470 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
472 #---------------------------------------------
475 if [ "$#" = 0 ]; then
480 while test $# -gt 0 ; do
483 DEBUG="yes"; shift ;;
485 COMMAND="version"; shift ;;
487 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
489 COMMAND="build"; shift ;;
490 -bb | --build-binary )
491 COMMAND="build-binary"; shift ;;
492 -bs | --build-source )
493 COMMAND="build-source"; shift ;;
495 COMMAND="branch"; shift; TAG="${1}"; shift;;
497 CLEAN="--clean --rmspec --rmsource"; shift ;;
499 shift; CVSROOT="${1}"; shift ;;
501 COMMAND="get"; shift ;;
503 COMMAND="usage"; shift ;;
505 shift; LOGFILE="${1}"; shift ;;
507 shift; DEF_NICE_LEVEL=${1}; shift ;;
509 COMMAND="mr-proper"; shift ;;
511 NOCVS="yes"; shift ;;
513 NOMIRRORS="yes"; shift ;;
515 NOURLS="yes"; shift ;;
517 NOSRCS="yes"; shift ;;
518 -ns0 | --no-source0 )
519 NOSOURCE0="yes"; shift ;;
521 shift; RPMOPTS="${1}"; shift ;;
523 BCOND="$BCOND $1 $2" ; shift 2 ;;
525 QUIET="--quiet"; shift ;;
527 shift; CVSTAG="${1}"; shift ;;
528 -Tvs | --tag-version-stable )
533 -Tvd | --tag-version-devel )
548 -Tv | --tag-version )
559 BE_VERBOSE="1"; shift ;;
561 TRY_UPGRADE="1"; shift ;;
567 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
570 SPECFILE="${1}"; shift ;;
574 if [ -n "$DEBUG" ]; then
580 "build" | "build-binary" | "build-source" )
582 if [ -n "$SPECFILE" ]; then
585 if [ -n "$ICONS" ]; then
589 get_files "$SOURCES $PATCHES";
592 Exit_error err_no_spec_in_cmdl;
597 if [ -n "$SPECFILE" ]; then
600 if [ -n "$ICONS" ]; then
604 get_files $SOURCES $PATCHES;
605 branch_files $TAG "$SOURCES $PATCHES $ICONS";
607 Exit_error err_no_spec_in_cmdl;
612 if [ -n "$SPECFILE" ]; then
615 if [ -n "$ICONS" ]; then
619 if [ -n "$NOSOURCE0" ] ; then
620 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
622 get_files $SOURCES $PATCHES
624 Exit_error err_no_spec_in_cmdl;
629 if [ -n "$SPECFILE" ]; then
632 if [ -n "$ICONS" ]; then
636 get_files $SOURCES $PATCHES;
637 tag_files "$SOURCES $PATCHES $ICONS";
639 Exit_error err_no_spec_in_cmdl;
643 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE