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 ALLWAYS_CVSUP=${ALLWAYS_CVSUP:-"yes"}
29 if [ -s CVS/Root ]; then
30 CVSROOT=$(cat CVS/Root)
32 CVSROOT=${CVSROOT:-""}
34 # Example: LOGFILE='../log.$PACKAGE_NAME'
35 # Yes, you can use variable name! Note _single_ quotes!
48 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
52 FAIL_IF_NO_SOURCES="yes"
54 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES"
55 GETURI2="wget -c -nd -t$WGET_RETRIES"
57 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
65 if [ -f ~/etc/builderrc ]; then
67 elif [ -f ~/.builderrc ]; then
71 #---------------------------------------------
76 if [ -n "$DEBUG" ]; then set -xv; fi
78 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
80 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
81 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
82 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
83 [-q|--quiet] [-r <cvstag>] [{-T--tag <cvstag>]
84 [-Tvr|--tag-version-ra] [-Tva|--tag-version-ac]
85 [-Tvn|--tag-version-nest] [-Tr|--tag-ra] [-Ta|--tag-ac]
86 [-Tn|--tag-nest] [-Tv|--tag-version]
87 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
88 [--with/--without <feature>] [--define <macro> <value>] <package>.spec
90 -D, --debug - enable script debugging mode,
91 -V, --version - output builder version
92 -a, --as_anon - get files via pserver as cvs@anoncvs.pld.org.pl,
94 --build - get all files from CVS repo or HTTP/FTP and build
95 package from <package>.spec,
97 - get all files from CVS repo or HTTP/FTP and build
98 binary only package from <package>.spec,
100 --build-source - get all files from CVS repo or HTTP/FTP and only
101 pack them into src.rpm,
102 -B, --branch - add branch
103 -c, --clean - clean all temporarily created files (in BUILD,
104 SOURCES, SPECS and \$RPM_BUILD_ROOT),
105 -d <cvsroot>, --cvsroot <cvsroot>
107 --define <macro> <value>
108 - define a macro <macro> with value <value>,
109 -g, --get - get <package>.spec and all related files from
110 CVS repo or HTTP/FTP,
111 -h, --help - this message,
112 -l <logfile>, --logtofile <logfile>
114 -m, --mr-proper - only remove all files related to spec file and
116 -nc, --no-cvs - don't download sources from CVS, if source URL is
119 - don't check specs in CVS
120 -nm, --no-mirrors - don't download from mirror, if source URL is given,
121 -nu, --no-urls - don't try to download from FTP/HTTP location,
122 -ns, --no-srcs - don't downland Sources
124 - don't downland Source0
126 - additional options for rpm
127 -q, --quiet - be quiet,
128 -r <cvstag>, --cvstag <cvstag>
129 - build package using resources from specified CVS
131 -T <cvstag> , --tag <cvstag>
132 - add cvs tag <cvstag> for files,
133 -Tvr, --tag-version-ra
134 - add cvs tags RA and NAME-VERSION-RELESE for files,
135 -Tva, --tag-version-ac
136 - add cvs tags AC and NAME-VERSION-RELESE for files,
137 -Tvn, --tag-version-nest
138 - add cvs tags NEST and NAME-VERSION-RELESE for files,
140 - add cvs tag RA for files,
142 - add cvs tag AC for files,
144 - add cvs tag NEST for files,
146 - add cvs tag NAME-VERSION-RELESE for files,
147 -v, --verbose - be verbose,
149 - check version, and try to upgrade package
150 --with/--without <feature>
151 - conditional build package depending on
152 %_with_<feature>/%_without_<feature> macro
159 if [ -n "$DEBUG" ]; then
166 if [ "$NOSRCS" != "yes" ]; then
167 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
169 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
170 FAIL_IF_NO_SOURCES="no"
173 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
174 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
175 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
176 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
177 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
179 if [ -n "$BE_VERBOSE" ]; then
180 echo "- Sources : `nourl $SOURCES`"
181 if [ -n "$PATCHES" ]; then
182 echo "- Patches : `nourl $PATCHES`"
184 echo "- Patches : *no patches needed*"
186 if [ -n "$ICONS" ]; then
187 echo "- Icon : `nourl $ICONS`"
189 echo "- Icon : *no package icon*"
191 echo "- Name : $PACKAGE_NAME"
192 echo "- Version : $PACKAGE_VERSION"
193 echo "- Release : $PACKAGE_RELEASE"
199 if [ -n "$DEBUG" ]; then
207 "err_no_spec_in_cmdl" )
208 echo "ERROR: spec file name not specified.";
210 "err_no_spec_in_repo" )
211 echo "Error: spec file not stored in CVS repo.";
213 "err_no_source_in_repo" )
214 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
217 echo "Error: package build failed.";
224 if [ -n "$DEBUG" ]; then
229 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
230 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
237 if [ -n "$DEBUG" ]; then
242 if [ "$NOCVSSPEC" != "yes" ]; then
247 if [ -n "$CVSROOT" ]; then
248 OPTIONS="-d $CVSROOT $OPTIONS"
250 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
251 echo "warning: No cvs access defined - using local .spec file"
255 if [ -n "$CVSTAG" ]; then
256 OPTIONS="$OPTIONS -r $CVSTAG"
258 OPTIONS="$OPTIONS -A"
261 cvs $OPTIONS $SPECFILE
262 if [ "$?" -ne "0" ]; then
263 Exit_error err_no_spec_in_repo;
266 if [ ! -f "$SPECFILE" ]; then
267 Exit_error err_no_spec_in_repo;
270 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
271 chmod $CHMOD_MODE $SPECFILE
274 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
281 if [ ! -f "mirrors" ] ; then
282 cvs update mirrors >&2
286 while read origin mirror name rest; do
287 ol=`echo -n "$origin"|wc -c`
288 prefix="`echo -n "$url" | head -c $ol`"
289 if [ "$prefix" = "$origin" ] ; then
290 suffix="`echo "$url"|cut -b $ol-`"
291 echo -n "$mirror$suffix"
302 if [ -n "$DEBUG" ]; then
307 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
311 if [ -n "$CVSROOT" ]; then
312 OPTIONS="-d $CVSROOT $OPTIONS"
314 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
315 echo "warning: No cvs access defined for SOURCES"
319 if [ -n "$CVSTAG" ]; then
320 OPTIONS="$OPTIONS -r $CVSTAG"
322 OPTIONS="$OPTIONS -A"
324 for i in $GET_FILES; do
325 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
326 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
327 echo "Warning: no URL given for $i"
330 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
331 cvs $OPTIONS `nourl $i`
334 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
335 if [ -z "$NOMIRRORS" ] ; then
336 i="`find_mirror "$i"`"
339 if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi
342 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
343 Exit_error err_no_source_in_repo $i;
348 if [ "$CHMOD" = "yes" ]; then
349 CHMOD_FILES="`nourl $GET_FILES`"
350 if [ -n "$CHMOD_FILES" ]; then
351 chmod $CHMOD_MODE $CHMOD_FILES
362 if [ -n "$DEBUG" ]; then
367 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
368 echo $PACKAGE_VERSION
369 echo $PACKAGE_RELEASE
370 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
371 if [ "$TAG_VERSION" = "yes" ]; then
372 echo "CVS tag: $TAGVER"
374 if [ -n "$TAG" ]; then
379 if [ -n "$CVSROOT" ]; then
380 OPTIONS="-d $CVSROOT $OPTIONS"
384 for i in $TAG_FILES; do
385 if [ -f `nourl $i` ]; then
386 if [ "$TAG_VERSION" = "yes" ]; then
387 cvs $OPTIONS $TAGVER `nourl $i`
389 if [ -n "$TAG" ]; then
390 cvs $OPTIONS $TAG `nourl $i`
393 Exit_error err_no_source_in_repo $i
398 if [ "$TAG_VERSION" = "yes" ]; then
399 cvs $OPTIONS $TAGVER $SPECFILE
401 if [ -n "$TAG" ]; then
402 cvs $OPTIONS $TAG $SPECFILE
412 echo "CVS branch tag: $TAG"
417 if [ -n "$DEBUG" ]; then
422 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
425 if [ -n "$CVSROOT" ]; then
426 OPTIONS="-d $CVSROOT $OPTIONS"
429 for i in $TAG_FILES; do
430 if [ -f `nourl $i` ]; then
431 cvs $OPTIONS $TAG `nourl $i`
433 Exit_error err_no_source_in_repo $i
437 cvs $OPTIONS $TAG $SPECFILE
445 if [ -n "$DEBUG" ]; then
452 if [ -n "$TRY_UPGRADE" ]; then
454 TNOTIFY=`./pldnotify.awk $SPECFILE`
456 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
458 if [ -n "$TNEWVER" ]; then
460 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
462 echo "New version found, updating spec file to version " $TNEWVER
464 cp -f $SPECFILE $SPECFILE.bak
468 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
469 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
473 get_files "$SOURCES $PATCHES";
475 unset TOLDVER TNEWVER TNOTIFY
485 BUILD_SWITCH="-ba" ;;
487 BUILD_SWITCH="-bb" ;;
489 BUILD_SWITCH="-bs --nodeps" ;;
491 if [ -n "$LOGFILE" ]; then
492 LOG=`eval echo $LOGFILE`
493 eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
495 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
498 if [ "$?" -ne "0" ]; then
500 if [ -n "$TRY_UPGRADE" ]; then
501 echo "\n!!! Package with new version cannot be build automagically\n"
502 mv -f $SPECFILE.bak $SPECFILE
505 Exit_error err_build_fail;
513 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
515 #---------------------------------------------
518 if [ "$#" = 0 ]; then
523 while test $# -gt 0 ; do
526 DEBUG="yes"; shift ;;
528 COMMAND="version"; shift ;;
530 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
532 COMMAND="build"; shift ;;
533 -bb | --build-binary )
534 COMMAND="build-binary"; shift ;;
535 -bs | --build-source )
536 COMMAND="build-source"; shift ;;
538 COMMAND="branch"; shift; TAG="${1}"; shift;;
540 CLEAN="--clean --rmspec --rmsource"; shift ;;
542 shift; CVSROOT="${1}"; shift ;;
544 COMMAND="get"; shift ;;
546 COMMAND="usage"; shift ;;
548 shift; LOGFILE="${1}"; shift ;;
550 shift; DEF_NICE_LEVEL=${1}; shift ;;
552 COMMAND="mr-proper"; shift ;;
554 NOCVS="yes"; shift ;;
555 -ncs | --no-cvs-spec )
556 NOCVSSPEC="yes"; shift ;;
558 NOMIRRORS="yes"; shift ;;
560 NOURLS="yes"; shift ;;
562 NOSRCS="yes"; shift ;;
563 -ns0 | --no-source0 )
564 NOSOURCE0="yes"; shift ;;
566 shift; RPMOPTS="${1}"; shift ;;
568 BCOND="$BCOND $1 $2" ; shift 2 ;;
570 QUIET="--quiet"; shift ;;
572 shift; CVSTAG="${1}"; shift ;;
573 -Tvr | --tag-version-ra )
578 -Tva | --tag-version-ac )
583 -Tvn | --tag-version-nest )
603 -Tv | --tag-version )
615 BE_VERBOSE="1"; shift ;;
617 TRY_UPGRADE="1"; shift ;;
623 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
626 SPECFILE="${1}"; shift ;;
630 if [ -n "$DEBUG" ]; then
636 "build" | "build-binary" | "build-source" )
638 if [ -n "$SPECFILE" ]; then
641 if [ -n "$ICONS" ]; then
645 get_files "$SOURCES $PATCHES";
648 Exit_error err_no_spec_in_cmdl;
653 if [ -n "$SPECFILE" ]; then
656 if [ -n "$ICONS" ]; then
660 get_files $SOURCES $PATCHES;
661 branch_files $TAG "$SOURCES $PATCHES $ICONS";
663 Exit_error err_no_spec_in_cmdl;
668 if [ -n "$SPECFILE" ]; then
671 if [ -n "$ICONS" ]; then
675 if [ -n "$NOSOURCE0" ] ; then
676 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
678 get_files $SOURCES $PATCHES
680 Exit_error err_no_spec_in_cmdl;
685 if [ -n "$SPECFILE" ]; then
688 if [ -n "$ICONS" ]; then
692 get_files $SOURCES $PATCHES;
693 tag_files "$SOURCES $PATCHES $ICONS";
695 Exit_error err_no_spec_in_cmdl;
699 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE