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]
78 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
79 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
80 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
81 [-q|--quiet] [-r <cvstag>] [{-T--tag <cvstag>]
82 [-Tvs|--tag-version-stable] [-Tvd|--tag-version-devel]
83 [-Ts|--tag-stable] [-Td|--tag-devel] [-Tv|--tag-version]
84 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
85 [--with/--without <feature>] [--define <macro> <value>] <package>.spec
87 -D, --debug - enable script debugging mode,
88 -V, --version - output builder version
89 -a, --as_anon - get files via pserver as cvs@anoncvs.pld.org.pl,
91 --build - get all files from CVS repo or HTTP/FTP and build
92 package from <package>.spec,
94 - get all files from CVS repo or HTTP/FTP and build
95 binary only package from <package>.spec,
97 --build-source - get all files from CVS repo or HTTP/FTP and only
98 pack them into src.rpm,
99 -B, --branch - add branch
100 -c, --clean - clean all temporarily created files (in BUILD,
101 SOURCES, SPECS and \$RPM_BUILD_ROOT),
102 -d <cvsroot>, --cvsroot <cvsroot>
104 --define <macro> <value>
105 - define a macro <macro> with value <value>,
106 -g, --get - get <package>.spec and all related files from
107 CVS repo or HTTP/FTP,
108 -h, --help - this message,
109 -l <logfile>, --logtofile <logfile>
111 -m, --mr-proper - only remove all files related to spec file and
113 -nc, --no-cvs - don't download from CVS, if source URL is given,
114 -nm, --no-mirrors - don't download from mirror, if source URL is given,
115 -nu, --no-urls - don't try to download from FTP/HTTP location,
116 -ns, --no-srcs - don't downland Sources
118 - don't downland Source0
120 - additional options for rpm
121 -q, --quiet - be quiet,
122 -r <cvstag>, --cvstag <cvstag>
123 - build package using resources from specified CVS
125 -T <cvstag> , --tag <cvstag>
126 - add cvs tag <cvstag> for files,
127 -Tvs, --tag-version-stable
128 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
129 -Tvd, --tag-version-devel
130 - add cvs tags DEVEL and NAME-VERSION-RELESE for files,
132 - add cvs tag STABLE for files,
134 - add cvs tag DEVEL for files,
136 - add cvs tag NAME-VERSION-RELESE for files,
137 -v, --verbose - be verbose,
139 - check version, and try to upgrade package
140 --with/--without <feature>
141 - conditional build package depending on
142 %_with_<feature>/%_without_<feature> macro
149 if [ -n "$DEBUG" ]; then
156 if [ "$NOSRCS" != "yes" ]; then
157 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
159 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
160 FAIL_IF_NO_SOURCES="no"
163 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
164 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
165 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
166 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
167 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
169 if [ -n "$BE_VERBOSE" ]; then
170 echo "- Sources : `nourl $SOURCES`"
171 if [ -n "$PATCHES" ]; then
172 echo "- Patches : `nourl $PATCHES`"
174 echo "- Patches : *no patches needed*"
176 if [ -n "$ICONS" ]; then
177 echo "- Icon : `nourl $ICONS`"
179 echo "- Icon : *no package icon*"
181 echo "- Name : $PACKAGE_NAME"
182 echo "- Version : $PACKAGE_VERSION"
183 echo "- Release : $PACKAGE_RELEASE"
189 if [ -n "$DEBUG" ]; then
197 "err_no_spec_in_cmdl" )
198 echo "ERROR: spec file name not specified.";
200 "err_no_spec_in_repo" )
201 echo "Error: spec file not stored in CVS repo.";
203 "err_no_source_in_repo" )
204 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
207 echo "Error: package build failed.";
214 if [ -n "$DEBUG" ]; then
219 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
220 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
227 if [ -n "$DEBUG" ]; then
236 if [ -n "$CVSROOT" ]; then
237 OPTIONS="-d $CVSROOT $OPTIONS"
239 if [ -n "$CVSTAG" ]; then
240 OPTIONS="$OPTIONS -r $CVSTAG"
242 OPTIONS="$OPTIONS -A"
245 cvs $OPTIONS $SPECFILE
246 if [ "$?" -ne "0" ]; then
247 Exit_error err_no_spec_in_repo;
249 if [ ! -f "$SPECFILE" ]; then
250 Exit_error err_no_spec_in_repo;
253 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
254 chmod $CHMOD_MODE $SPECFILE
257 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
264 if [ ! -f "mirrors" ] ; then
265 cvs update mirrors >&2
269 while read origin mirror name rest; do
270 ol=`echo -n "$origin"|wc -c`
271 prefix="`echo -n "$url" | head -c $ol`"
272 if [ "$prefix" = "$origin" ] ; then
273 suffix="`echo "$url"|cut -b $ol-`"
274 echo -n "$mirror$suffix"
285 if [ -n "$DEBUG" ]; then
290 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
294 if [ -n "$CVSROOT" ]; then
295 OPTIONS="-d $CVSROOT $OPTIONS"
297 if [ -n "$CVSTAG" ]; then
298 OPTIONS="$OPTIONS -r $CVSTAG"
300 OPTIONS="$OPTIONS -A"
302 for i in $GET_FILES; do
303 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
304 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
305 echo "Warning: no URL given for $i"
308 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
309 cvs $OPTIONS `nourl $i`
312 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
313 if [ -z "$NOMIRRORS" ] ; then
314 i="`find_mirror "$i"`"
319 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
320 Exit_error err_no_source_in_repo $i;
325 if [ "$CHMOD" = "yes" ]; then
326 CHMOD_FILES="`nourl $GET_FILES`"
327 if [ -n "$CHMOD_FILES" ]; then
328 chmod $CHMOD_MODE $CHMOD_FILES
339 if [ -n "$DEBUG" ]; then
344 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
345 echo $PACKAGE_VERSION
346 echo $PACKAGE_RELEASE
347 TAG=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
351 if [ -n "$CVSROOT" ]; then
352 OPTIONS="-d $CVSROOT $OPTIONS"
356 for i in $TAG_FILES; do
357 if [ -f `nourl $i` ]; then
358 cvs $OPTIONS $TAG `nourl $i`
359 cvs $OPTIONS STABLE `nourl $i`
361 Exit_error err_no_source_in_repo $i
366 cvs $OPTIONS $TAG $SPECFILE
367 cvs $OPTIONS STABLE $SPECFILE
376 echo "CVS branch tag: $TAG"
381 if [ -n "$DEBUG" ]; then
386 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
389 if [ -n "$CVSROOT" ]; then
390 OPTIONS="-d $CVSROOT $OPTIONS"
393 for i in $TAG_FILES; do
394 if [ -f `nourl $i` ]; then
395 cvs $OPTIONS $TAG `nourl $i`
397 Exit_error err_no_source_in_repo $i
401 cvs $OPTIONS $TAG $SPECFILE
409 if [ -n "$DEBUG" ]; then
416 if [ -n "$TRY_UPGRADE" ]; then
418 TNOTIFY=`./pldnotify.awk $SPECFILE`
420 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
422 if [ -n "$TNEWVER" ]; then
424 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
426 echo "New version found, updating spec file to version " $TNEWVER
428 cp -f $SPECFILE $SPECFILE.bak
432 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
433 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
437 get_files "$SOURCES $PATCHES";
439 unset TOLDVER TNEWVER TNOTIFY
449 BUILD_SWITCH="-ba" ;;
451 BUILD_SWITCH="-bb" ;;
453 BUILD_SWITCH="-bs --nodeps" ;;
455 if [ -n "$LOGFILE" ]; then
456 LOG=`eval echo $LOGFILE`
457 eval nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE 2>&1 | tee $LOG
459 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
462 if [ "$?" -ne "0" ]; then
464 if [ -n "$TRY_UPGRADE" ]; then
465 echo "\n!!! Package with new version cannot be build automagically\n"
466 mv -f $SPECFILE.bak $SPECFILE
469 Exit_error err_build_fail;
477 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
479 #---------------------------------------------
482 if [ "$#" = 0 ]; then
487 while test $# -gt 0 ; do
490 DEBUG="yes"; shift ;;
492 COMMAND="version"; shift ;;
494 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
496 COMMAND="build"; shift ;;
497 -bb | --build-binary )
498 COMMAND="build-binary"; shift ;;
499 -bs | --build-source )
500 COMMAND="build-source"; shift ;;
502 COMMAND="branch"; shift; TAG="${1}"; shift;;
504 CLEAN="--clean --rmspec --rmsource"; shift ;;
506 shift; CVSROOT="${1}"; shift ;;
508 COMMAND="get"; shift ;;
510 COMMAND="usage"; shift ;;
512 shift; LOGFILE="${1}"; shift ;;
514 shift; DEF_NICE_LEVEL=${1}; shift ;;
516 COMMAND="mr-proper"; shift ;;
518 NOCVS="yes"; shift ;;
520 NOMIRRORS="yes"; shift ;;
522 NOURLS="yes"; shift ;;
524 NOSRCS="yes"; shift ;;
525 -ns0 | --no-source0 )
526 NOSOURCE0="yes"; shift ;;
528 shift; RPMOPTS="${1}"; shift ;;
530 BCOND="$BCOND $1 $2" ; shift 2 ;;
532 QUIET="--quiet"; shift ;;
534 shift; CVSTAG="${1}"; shift ;;
535 -Tvs | --tag-version-stable )
540 -Tvd | --tag-version-devel )
555 -Tv | --tag-version )
566 BE_VERBOSE="1"; shift ;;
568 TRY_UPGRADE="1"; shift ;;
574 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
577 SPECFILE="${1}"; shift ;;
581 if [ -n "$DEBUG" ]; then
587 "build" | "build-binary" | "build-source" )
589 if [ -n "$SPECFILE" ]; then
592 if [ -n "$ICONS" ]; then
596 get_files "$SOURCES $PATCHES";
599 Exit_error err_no_spec_in_cmdl;
604 if [ -n "$SPECFILE" ]; then
607 if [ -n "$ICONS" ]; then
611 get_files $SOURCES $PATCHES;
612 branch_files $TAG "$SOURCES $PATCHES $ICONS";
614 Exit_error err_no_spec_in_cmdl;
619 if [ -n "$SPECFILE" ]; then
622 if [ -n "$ICONS" ]; then
626 if [ -n "$NOSOURCE0" ] ; then
627 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
629 get_files $SOURCES $PATCHES
631 Exit_error err_no_spec_in_cmdl;
636 if [ -n "$SPECFILE" ]; then
639 if [ -n "$ICONS" ]; then
643 get_files $SOURCES $PATCHES;
644 tag_files "$SOURCES $PATCHES $ICONS";
646 Exit_error err_no_spec_in_cmdl;
650 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE