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 [ -f ~/etc/builderrc ]; then
57 elif [ -f ~/.builderrc ]; then
61 #---------------------------------------------
66 if [ -n "$DEBUG" ]; then set -xv; fi
68 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
69 [-bb|--build-binary] [-bs|--build-source] [{-B|--branch} <branch>]
70 [{-d|--cvsroot} <cvsroot>] [-g|--get] [-h|--help]
71 [{-l,--logtofile} <logfile>] [-m|--mr-proper] [-q|--quiet]
72 [-r <cvstag>] [{-T--tag <cvstag>] [-Tvs|--tag-version-stable]
73 [-Tvd|--tag-version-devel] [-Ts|--tag-stable] [-Td|--tag-devel]
74 [-Tv|--tag-version] [-u|--no-urls] [-v|--verbose] [--opts <rpm opts>]
75 [--with/--without pkg] [--define <macro> <value>] <package>.spec
77 -D, --debug - enable script debugging mode,
78 -V, --version - output builder version
79 -a, --as_anon - get files via pserver as cvs@anoncvs.pld.org.pl,
81 --build - get all files from CVS repo or HTTP/FTP and build
82 package from <package>.spec,
84 - get all files from CVS repo or HTTP/FTP and build
85 binary only package from <package>.spec,
87 --build-source - get all files from CVS repo or HTTP/FTP and only
88 pack them into src.rpm,
89 -B, --branch - add branch
90 -c, --clean - clean all temporarily created files (in BUILD,
91 SOURCES, SPECS and \$RPM_BUILD_ROOT),
92 -d <cvsroot>, --cvsroot <cvsroot>
94 -g, --get - get <package>.spec and all related files from
96 -h, --help - this message,
97 -l <logfile>, --logtofile <logfile>
99 -m, --mr-proper - only remove all files related to spec file and
101 -nc, --no-cvs - don't download from CVS, if source URL is given,
102 -nu, --no-urls - don't try to download from FTP/HTTP location,
103 -ns, --no-srcs - don't downland Sources
105 - additional options for rpm
106 -q, --quiet - be quiet,
107 -r <cvstag>, --cvstag <cvstag>
108 - build package using resources from specified CVS
110 -T <cvstag> , --tag <cvstag>
111 - add cvs tag <cvstag> for files,
112 -Tvs, --tag-version-stable
113 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
114 -Tvd, --tag-version-devel
115 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
117 - add cvs tag STABLE for files,
119 - add cvs tag DEVEL for files,
121 - add cvs tag NAME-VERSION-RELESE for files,
122 -v, --verbose - be verbose,
123 --define - define a macro
130 if [ -n "$DEBUG" ]; then
137 if [ "$NOSRCS" != "yes" ]; then
138 SOURCES="`rpm -bp --nobuild $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
140 if (rpm -bp --nobuild $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
141 FAIL_IF_NO_SOURCES="no"
144 PATCHES="`rpm -bp --nobuild $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
145 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
146 PACKAGE_NAME="`rpm -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
147 PACKAGE_VERSION="`rpm -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
148 PACKAGE_RELEASE="`rpm -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
150 if [ -n "$BE_VERBOSE" ]; then
151 echo "- Sources : `nourl $SOURCES`"
152 if [ -n "$PATCHES" ]; then
153 echo "- Patches : `nourl $PATCHES`"
155 echo "- Patches : *no patches needed*"
157 if [ -n "$ICONS" ]; then
158 echo "- Icon : `nourl $ICONS`"
160 echo "- Icon : *no package icon*"
162 echo "- Name : $PACKAGE_NAME"
163 echo "- Version : $PACKAGE_VERSION"
164 echo "- Release : $PACKAGE_RELEASE"
170 if [ -n "$DEBUG" ]; then
178 "err_no_spec_in_cmdl" )
179 echo "ERROR: spec file name not specified.";
181 "err_no_spec_in_repo" )
182 echo "Error: spec file not stored in CVS repo.";
184 "err_no_source_in_repo" )
185 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
188 echo "Error: package build failed.";
195 if [ -n "$DEBUG" ]; then
200 SOURCE_DIR="`rpm --eval '%{_sourcedir}'`"
201 SPECS_DIR="`rpm --eval '%{_specdir}'`"
208 if [ -n "$DEBUG" ]; then
217 if [ -n "$CVSROOT" ]; then
218 OPTIONS="-d $CVSROOT $OPTIONS"
220 if [ -n "$CVSTAG" ]; then
221 OPTIONS="$OPTIONS -r $CVSTAG"
223 OPTIONS="$OPTIONS -A"
226 cvs $OPTIONS $SPECFILE
227 if [ "$?" -ne "0" ]; then
228 Exit_error err_no_spec_in_repo;
230 if [ ! -f "$SPECFILE" ]; then
231 Exit_error err_no_spec_in_repo;
234 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
235 chmod $CHMOD_MODE $SPECFILE
238 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
245 if [ -n "$DEBUG" ]; then
250 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
254 if [ -n "$CVSROOT" ]; then
255 OPTIONS="-d $CVSROOT $OPTIONS"
257 if [ -n "$CVSTAG" ]; then
258 OPTIONS="$OPTIONS -r $CVSTAG"
260 OPTIONS="$OPTIONS -A"
262 for i in $GET_FILES; do
263 if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then
264 if echo $i | grep -vE '(http|ftp|https|cvs)://' | grep -qE '\.(gz|bz2)$']; then
265 echo "Warning: no URL given for $i"
268 if [ -z "$NOCVS" ]|| [ `echo $i | grep -vE '(ftp|http|https)://'` ]; then
269 cvs $OPTIONS `nourl $i`
272 if [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
276 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
277 Exit_error err_no_source_in_repo $i;
282 if [ "$CHMOD" = "yes" ]; then
283 CHMOD_FILES="`nourl $GET_FILES`"
284 if [ -n "$CHMOD_FILES" ]; then
285 chmod $CHMOD_MODE $CHMOD_FILES
296 if [ -n "$DEBUG" ]; then
301 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
302 echo $PACKAGE_VERSION
303 echo $PACKAGE_RELEASE
304 TAG=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g"`
308 if [ -n "$CVSROOT" ]; then
309 OPTIONS="-d $CVSROOT $OPTIONS"
313 for i in $TAG_FILES; do
314 if [ -f `nourl $i` ]; then
315 cvs $OPTIONS $TAG `nourl $i`
316 cvs $OPTIONS STABLE `nourl $i`
318 Exit_error err_no_source_in_repo $i
323 cvs $OPTIONS $TAG $SPECFILE
324 cvs $OPTIONS STABLE $SPECFILE
333 echo "CVS branch tag: $TAG"
338 if [ -n "$DEBUG" ]; then
343 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
346 if [ -n "$CVSROOT" ]; then
347 OPTIONS="-d $CVSROOT $OPTIONS"
350 for i in $TAG_FILES; do
351 if [ -f `nourl $i` ]; then
352 cvs $OPTIONS $TAG `nourl $i`
354 Exit_error err_no_source_in_repo $i
358 cvs $OPTIONS $TAG $SPECFILE
366 if [ -n "$DEBUG" ]; then
374 BUILD_SWITCH="-ba" ;;
376 BUILD_SWITCH="-bb" ;;
378 BUILD_SWITCH="-bs --nodeps" ;;
380 if [ -n "$LOGFILE" ]; then
382 eval nice -n ${DEF_NICE_LEVEL} /bin/sh -c "time rpm $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE" 2>&1 | tee $LOG
384 eval nice -n ${DEF_NICE_LEVEL} rpm $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
387 if [ "$?" -ne "0" ]; then
388 Exit_error err_build_fail;
395 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\)://[^ ]*/##g'
397 #---------------------------------------------
400 if [ "$#" = 0 ]; then
405 while test $# -gt 0 ; do
408 DEBUG="yes"; shift ;;
410 COMMAND="version"; shift ;;
412 CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
414 COMMAND="build"; shift ;;
415 -bb | --build-binary )
416 COMMAND="build-binary"; shift ;;
417 -bs | --build-source )
418 COMMAND="build-source"; shift ;;
420 COMMAND="branch"; shift; TAG="${1}"; shift;;
422 CLEAN="--clean --rmspec --rmsource"; shift ;;
424 shift; CVSROOT="${1}"; shift ;;
426 COMMAND="get"; shift ;;
428 COMMAND="usage"; shift ;;
430 shift; LOGFILE="${1}"; shift ;;
432 shift; DEF_NICE_LEVEL=${1}; shift ;;
434 COMMAND="mr-proper"; shift ;;
436 NOCVS="yes"; shift ;;
438 NOURLS="yes"; shift ;;
440 NOSRCS="yes"; shift ;;
442 shift; RPMOPTS="${1}"; shift ;;
444 BCOND="$BCOND $1 $2" ; shift 2 ;;
446 QUIET="--quiet"; shift ;;
448 shift; CVSTAG="${1}"; shift ;;
449 -Tvs | --tag-version-stable )
454 -Tvd | --tag-version-devel )
469 -Tv | --tag-version )
480 BE_VERBOSE="1"; shift ;;
486 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
489 SPECFILE="${1}"; shift ;;
493 if [ -n "$DEBUG" ]; then
499 "build" | "build-binary" | "build-source" )
501 if [ -n "$SPECFILE" ]; then
504 if [ -n "$ICONS" ]; then
508 get_files "$SOURCES $PATCHES";
511 Exit_error err_no_spec_in_cmdl;
516 if [ -n "$SPECFILE" ]; then
519 if [ -n "$ICONS" ]; then
523 get_files $SOURCES $PATCHES;
524 branch_files $TAG "$SOURCES $PATCHES $ICONS";
526 Exit_error err_no_spec_in_cmdl;
531 if [ -n "$SPECFILE" ]; then
534 if [ -n "$ICONS" ]; then
538 get_files $SOURCES $PATCHES
540 Exit_error err_no_spec_in_cmdl;
545 if [ -n "$SPECFILE" ]; then
548 if [ -n "$ICONS" ]; then
552 get_files $SOURCES $PATCHES;
553 tag_files "$SOURCES $PATCHES $ICONS";
555 Exit_error err_no_spec_in_cmdl;
559 rpm --clean --rmsource --rmspec --force --nodeps $SPECFILE