]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame_incremental - builder.sh
- cosmetics
[packages/rpm-build-tools.git] / builder.sh
... / ...
CommitLineData
1#!/bin/sh
2# -----------
3# $Id$
4# Exit codes:
5# 0 - succesful
6# 1 - help dispayed
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
11
12# Notes (todo):
13# - builder -u fetches current version first
14# - tries to get new version from distfiles without new md5
15# - after fetching new version doesn't update md5
16# - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
17# when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
18
19VERSION="\
20Build package utility from PLD CVS repository
21V 0.11 (C) 1999-2003 Free Penguins".
22PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
23
24COMMAND="build"
25
26SPECFILE=""
27BE_VERBOSE=""
28QUIET=""
29CLEAN=""
30DEBUG=""
31NOURLS=""
32NOCVS=""
33NOCVSSPEC=""
34NODIST=""
35UPDATE=""
36UPDATE5=""
37ADD5=""
38ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
39if [ -s CVS/Root ]; then
40 CVSROOT=$(cat CVS/Root)
41else
42 CVSROOT=${CVSROOT:-""}
43fi
44# Example: LOGFILE='../log.$PACKAGE_NAME'
45# Yes, you can use variable name! Note _single_ quotes!
46LOGFILE=''
47
48LOGDIR=""
49LOGDIROK=""
50LOGDIRFAIL=""
51LASTLOG_FILE=""
52LTAG=""
53CHMOD="no"
54CHMOD_MODE="0444"
55RPMOPTS=""
56BCOND=""
57
58PATCHES=""
59SOURCES=""
60ICONS=""
61PACKAGE_RELEASE=""
62PACKAGE_VERSION=""
63PACKAGE_NAME=""
64WGET_RETRIES=${MAX_WGET_RETRIES:-0}
65CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
66
67CVSTAG=""
68RES_FILE=""
69
70CVS_SERVER="cvs.pld-linux.org"
71DISTFILES_SERVER="ftp://distfiles.pld-linux.org"
72
73DEF_NICE_LEVEL=0
74
75FAIL_IF_NO_SOURCES="yes"
76
77GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
78GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
79GETLOCAL="cp -a"
80
81if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
82 RPM="rpm"
83 RPMBUILD="rpm"
84else
85 RPM="rpm"
86 RPMBUILD="rpmbuild"
87fi
88
89if [ -f ~/etc/builderrc ]; then
90 . ~/etc/builderrc
91elif [ -f ~/.builderrc ]; then
92 . ~/.builderrc
93fi
94
95#---------------------------------------------
96# functions
97
98usage()
99{
100 if [ -n "$DEBUG" ]; then set -xv; fi
101 echo "\
102Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
103
104 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
105 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
106 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
107 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
108 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
109 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
110 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
111 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
112
113 -5, --update-md5
114 - update md5 comments in spec, implies -nd
115 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd
116 -D, --debug - enable script debugging mode,
117 -V, --version - output builder version
118 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
119 -b, -ba,
120 --build - get all files from CVS repo or HTTP/FTP and build
121 package from <package>.spec,
122 -bb, --build-binary
123 - get all files from CVS repo or HTTP/FTP and build
124 binary only package from <package>.spec,
125 -bs,
126 --build-source - get all files from CVS repo or HTTP/FTP and only
127 pack them into src.rpm,
128 -B, --branch - add branch
129 -c, --clean - clean all temporarily created files (in BUILD,
130 SOURCES, SPECS and \$RPM_BUILD_ROOT),
131 -d <cvsroot>, --cvsroot <cvsroot>
132 - setup \$CVSROOT,
133 --define <macro> <value>
134 - define a macro <macro> with value <value>,
135 -g, --get - get <package>.spec and all related files from
136 CVS repo or HTTP/FTP,
137 -h, --help - this message,
138 -l <logfile>, --logtofile <logfile>
139 - log all to file,
140 -m, --mr-proper - only remove all files related to spec file and
141 all work resources,
142 -nc, --no-cvs - don't download sources from CVS, if source URL is
143 given,
144 -ncs, --no-cvs-specs
145 - don't check specs in CVS
146 -nd, --no-distfiles
147 - don't download from distfiles
148 -nm, --no-mirrors - don't download from mirror, if source URL is given,
149 -nu, --no-urls - don't try to download from FTP/HTTP location,
150 -ns, --no-srcs - don't download Sources
151 -ns0, --no-source0
152 - don't download Source0
153 --opts <rpm opts>
154 - additional options for rpm
155 -q, --quiet - be quiet,
156 --date yyyy-mm-dd
157 - build package using resources from specified CVS
158 date,
159 -r <cvstag>, --cvstag <cvstag>
160 - build package using resources from specified CVS
161 tag,
162 -T <cvstag> , --tag <cvstag>
163 - add cvs tag <cvstag> for files,
164 -Tvs, --tag-version-stable
165 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
166 -Tvn, --tag-version-nest
167 - add cvs tags NEST and NAME-VERSION-RELESE for files,
168 -Ts, --tag-stable
169 - add cvs tag STABLE for files,
170 -Tn, --tag-nest
171 - add cvs tag NEST for files,
172 -Tv, --tag-version
173 - add cvs tag NAME-VERSION-RELESE for files,
174 -v, --verbose - be verbose,
175 -u, --try-upgrade
176 - check version, and try to upgrade package
177 -un, --try-upgrade-with-float-version
178 - as above, but allow float version
179 -U, --update
180 - refetch sources, don't use distfiles, and update md5
181 comments
182 --with/--without <feature>
183 - conditional build package depending on
184 %_with_<feature>/%_without_<feature> macro
185 switch
186"
187}
188
189rpm_dump () {
190 case "$RPMBUILD" in
191 rpm )
192 rpm -bp --define 'prep %dump' $BCOND $SPECFILE 2>&1
193 ;;
194 rpmbuild )
195 rpmbuild --define 'prep %dump' $BCOND $SPECFILE 2>&1
196 ;;
197 esac
198}
199
200parse_spec()
201{
202 if [ -n "$DEBUG" ]; then
203 set -x;
204 set -v;
205 fi
206
207 cd $SPECS_DIR
208 if [ "$NOSRCS" != "yes" ]; then
209 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
210 fi
211 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
212 FAIL_IF_NO_SOURCES="no"
213 fi
214
215 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
216 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
217 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
218 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
219 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
220
221 if [ -n "$BE_VERBOSE" ]; then
222 echo "- Sources : `nourl $SOURCES`"
223 if [ -n "$PATCHES" ]; then
224 echo "- Patches : `nourl $PATCHES`"
225 else
226 echo "- Patches : *no patches needed*"
227 fi
228 if [ -n "$ICONS" ]; then
229 echo "- Icon : `nourl $ICONS`"
230 else
231 echo "- Icon : *no package icon*"
232 fi
233 echo "- Name : $PACKAGE_NAME"
234 echo "- Version : $PACKAGE_VERSION"
235 echo "- Release : $PACKAGE_RELEASE"
236 fi
237}
238
239Exit_error()
240{
241 if [ -n "$DEBUG" ]; then
242 set -x;
243 set -v;
244 fi
245
246 cd $__PWD
247
248 case "$1" in
249 "err_no_spec_in_cmdl" )
250 echo "ERROR: spec file name not specified.";
251 exit 2 ;;
252 "err_no_spec_in_repo" )
253 echo "Error: spec file not stored in CVS repo.";
254 exit 3 ;;
255 "err_no_source_in_repo" )
256 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
257 exit 4 ;;
258 "err_build_fail" )
259 echo "Error: package build failed. (${2:-no more info})";
260 exit 5 ;;
261 esac
262}
263
264init_builder()
265{
266 if [ -n "$DEBUG" ]; then
267 set -x;
268 set -v;
269 fi
270
271 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
272 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
273
274 __PWD=`pwd`
275}
276
277get_spec()
278{
279 if [ -n "$DEBUG" ]; then
280 set -x;
281 set -v;
282 fi
283
284 if [ "$NOCVSSPEC" != "yes" ]; then
285 cd $SPECS_DIR
286
287 OPTIONS="up "
288
289 if [ -n "$CVSROOT" ]; then
290 OPTIONS="-d $CVSROOT $OPTIONS"
291 else
292 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
293 echo "warning: No cvs access defined - using local .spec file"
294 NOCVSSPEC="yes"
295 fi
296 fi
297
298 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
299 OPTIONS="$OPTIONS -A"
300 else
301 if [ -n "$CVSDATE" ]; then
302 OPTIONS="$OPTIONS -D $CVSDATE"
303 fi
304 if [ -n "$CVSTAG" ]; then
305 OPTIONS="$OPTIONS -r $CVSTAG"
306 fi
307 fi
308
309 result=1
310 retries_counter=0
311 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
312 retries_counter=$(( $retries_counter + 1 ))
313 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
314 result=$?
315 [ -n "$output" ] && echo "$output"
316 if [ "$result" -ne "0" ]; then
317 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
318 echo "Trying again [$SPECFILE]... ($retries_counter)"
319 sleep 2
320 continue
321 fi
322 Exit_error err_no_spec_in_repo;
323 fi
324 done
325 fi
326 if [ ! -f "$SPECFILE" ]; then
327 Exit_error err_no_spec_in_repo;
328 fi
329
330 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
331 chmod $CHMOD_MODE $SPECFILE
332 fi
333 unset OPTIONS
334 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
335}
336
337find_mirror(){
338
339 cd "$SPECS_DIR"
340 url="$1"
341 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
342 cvs update mirrors >&2
343 fi
344
345 IFS="|"
346 while read origin mirror name rest; do
347 ol=`echo -n "$origin"|wc -c`
348 prefix="`echo -n "$url" | head -c $ol`"
349 if [ "$prefix" = "$origin" ] ; then
350 suffix="`echo "$url"|cut -b $ol-`"
351 echo -n "$mirror$suffix"
352 return 0
353 fi
354 done < mirrors
355 echo "$url"
356}
357
358src_no ()
359{
360 cd $SPECS_DIR
361 rpm_dump | \
362 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
363 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
364 head -1 | xargs
365}
366
367src_md5 ()
368{
369 no=$(src_no "$1")
370 [ -z "$no" ] && return
371 cd $SPECS_DIR
372 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
373 if [ -z "$spec_rev" ]; then
374 spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
375 fi
376 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
377 md5=$(grep -s -v '^#' additional-md5sums | \
378 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
379 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
380 grep -E '^[0-9a-f]{32}$')
381 if [ X"$md5" = X"" ] ; then
382 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
383 else
384 if [ $(echo "$md5" | wc -l) != 1 ] ; then
385 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
386 fi
387 echo "$md5" | tail -1
388 fi
389}
390
391distfiles_url ()
392{
393 echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
394}
395
396good_md5 ()
397{
398 md5=$(src_md5 "$1")
399 [ "$md5" = "" ] || \
400 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
401}
402
403get_files()
404{
405 GET_FILES="$@"
406
407 if [ -n "$DEBUG" ]; then
408 set -x;
409 set -v;
410 fi
411
412 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
413 cd $SOURCE_DIR
414
415 OPTIONS="up "
416 if [ -n "$CVSROOT" ]; then
417 OPTIONS="-d $CVSROOT $OPTIONS"
418 else
419 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
420 echo "warning: No cvs access defined for SOURCES"
421 NOCVS="yes"
422 fi
423 fi
424 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
425 OPTIONS="$OPTIONS -A"
426 else
427 if [ -n "$CVSDATE" ]; then
428 OPTIONS="$OPTIONS -D $CVSDATE"
429 fi
430 if [ -n "$CVSTAG" ]; then
431 OPTIONS="$OPTIONS -r $CVSTAG"
432 fi
433 fi
434 for i in $GET_FILES; do
435 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
436 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
437 echo "Warning: no URL given for $i"
438 fi
439
440 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
441 if good_md5 "$i"; then
442 echo "$(nourl "$i") having proper md5sum already exists"
443 continue
444 fi
445 target=$(nourl "$i")
446 url=$(distfiles_url "$i")
447 if [ `echo $url | grep -E '^(\.|/)'` ] ; then
448 ${GETLOCAL} $url $target
449 else
450 if [ -z "$NOMIRRORS" ] ; then
451 url="`find_mirror "$url"`"
452 fi
453 ${GETURI} -O "$target" "$url" || \
454 if [ `echo $url | grep -E 'ftp://'` ]; then
455 ${GETURI2} -O "$target" "$url"
456 fi
457 test -s "$target" || rm -f "$target"
458 fi
459 elif [ -z "$(src_md5 "$i")" ] && \
460 ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then
461 result=1
462 retries_counter=0
463 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
464 retries_counter=$(( $retries_counter + 1 ))
465 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
466 result=$?
467 [ -n "$output" ] && echo "$output"
468 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
469 echo "Trying again [`nourl $i`]... ($retries_counter)"
470 sleep 2
471 continue
472 else
473 break
474 fi
475 done
476 fi
477
478 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
479 if [ -z "$NOMIRRORS" ] ; then
480 im="`find_mirror "$i"`"
481 else
482 im="$i"
483 fi
484 ${GETURI} "$im" || \
485 if [ `echo $im | grep -E 'ftp://'` ]; then ${GETURI2} "$im" ; fi
486 fi
487
488
489 fi
490 srcno=$(src_no $i)
491 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
492 Exit_error err_no_source_in_repo $i;
493 elif [ -n "$UPDATE5" ] && \
494 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
495 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
496 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
497 then
498 echo "Updating source-$srcno md5."
499 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
500 perl -i -ne '
501 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
502 print "# Source'$srcno'-md5:\t'$md5'\n"
503 if /^Source'$srcno'\s*:\s+/;
504 ' \
505 $SPECS_DIR/$SPECFILE
506 fi
507
508 if good_md5 "$i"; then
509 :
510 else
511 echo "MD5 sum mismatch. Use -U to refetch sources,"
512 echo "or -5 to update md5 sums, if you're sure files are correct."
513 Exit_error err_no_source_in_repo $i
514 fi
515 done
516
517 if [ "$CHMOD" = "yes" ]; then
518 CHMOD_FILES="`nourl $GET_FILES`"
519 if [ -n "$CHMOD_FILES" ]; then
520 chmod $CHMOD_MODE $CHMOD_FILES
521 fi
522 fi
523 unset OPTIONS
524 fi
525}
526
527tag_files()
528{
529 TAG_FILES="$@"
530
531 if [ -n "$DEBUG" ]; then
532 set -x;
533 set -v;
534 fi
535
536 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
537 echo "Version: $PACKAGE_VERSION"
538 echo "Release: $PACKAGE_RELEASE"
539 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
540 if [ "$TAG_VERSION" = "yes" ]; then
541 echo "CVS tag: $TAGVER"
542 fi
543 if [ -n "$TAG" ]; then
544 echo "CVS tag: $TAG"
545 fi
546
547 OPTIONS="tag -F"
548 if [ -n "$CVSROOT" ]; then
549 OPTIONS="-d $CVSROOT $OPTIONS"
550 fi
551
552 cd $SOURCE_DIR
553 for i in $TAG_FILES; do
554 if [ -f `nourl $i` ]; then
555 if [ "$TAG_VERSION" = "yes" ]; then
556 cvs $OPTIONS $TAGVER `nourl $i`
557 fi
558 if [ -n "$TAG" ]; then
559 cvs $OPTIONS $TAG `nourl $i`
560 fi
561 else
562 Exit_error err_no_source_in_repo $i
563 fi
564 done
565
566 cd $SPECS_DIR
567 if [ "$TAG_VERSION" = "yes" ]; then
568 cvs $OPTIONS $TAGVER $SPECFILE
569 fi
570 if [ -n "$TAG" ]; then
571 cvs $OPTIONS $TAG $SPECFILE
572 fi
573
574 unset OPTIONS
575 fi
576}
577
578branch_files()
579{
580 TAG=$1
581 echo "CVS branch tag: $TAG"
582 shift;
583
584 TAG_FILES="$@"
585
586 if [ -n "$DEBUG" ]; then
587 set -x;
588 set -v;
589 fi
590
591 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
592
593 OPTIONS="tag -b"
594 if [ -n "$CVSROOT" ]; then
595 OPTIONS="-d $CVSROOT $OPTIONS"
596 fi
597 cd $SOURCE_DIR
598 for i in $TAG_FILES; do
599 if [ -f `nourl $i` ]; then
600 cvs $OPTIONS $TAG `nourl $i`
601 else
602 Exit_error err_no_source_in_repo $i
603 fi
604 done
605 cd $SPECS_DIR
606 cvs $OPTIONS $TAG $SPECFILE
607
608 unset OPTIONS
609 fi
610}
611
612
613
614build_package()
615{
616 if [ -n "$DEBUG" ]; then
617 set -x;
618 set -v;
619 fi
620
621 cd $SPECS_DIR
622
623 if [ -n "$TRY_UPGRADE" ]; then
624
625 if [ -n "FLOAT_VERSION" ]; then
626 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
627 else
628 TNOTIFY=`./pldnotify.awk $SPECFILE`
629 fi
630
631 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
632
633 if [ -n "$TNEWVER" ]; then
634
635 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
636
637 echo "New version found, updating spec file to version " $TNEWVER
638
639 cp -f $SPECFILE $SPECFILE.bak
640
641 chmod +w $SPECFILE
642
643 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
644 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
645
646 parse_spec;
647
648 get_files "$SOURCES $PATCHES";
649
650 unset TOLDVER TNEWVER TNOTIFY
651 fi
652
653 fi
654
655
656 cd $SPECS_DIR
657
658 case "$COMMAND" in
659 build )
660 BUILD_SWITCH="-ba" ;;
661 build-binary )
662 BUILD_SWITCH="-bb" ;;
663 build-source )
664 BUILD_SWITCH="-bs --nodeps" ;;
665 esac
666 if [ -n "$LOGFILE" ]; then
667 if [ -n "$CVSTAG" ]; then
668 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
669 else
670 LTAG=""
671 fi
672 LOG=`eval echo $LOGFILE`
673 if [ -n "$LASTLOG_FILE" ]; then
674 echo "LASTLOG=$LOG" > $LASTLOG_FILE
675 fi
676 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
677 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
678 RETVAL=`cat $RES_FILE`
679 rm $RES_FILE
680 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
681 if [ "$RETVAL" -eq "0" ]; then
682 mv $LOG $LOGDIROK
683 else
684 mv $LOG $LOGDIRFAIL
685 fi
686 fi
687 else
688 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
689 RETVAL=$?
690 fi
691
692 if [ "$RETVAL" -ne "0" ]; then
693
694 if [ -n "$TRY_UPGRADE" ]; then
695 echo "\n!!! Package with new version cannot be build automagically\n"
696 mv -f $SPECFILE.bak $SPECFILE
697 fi
698
699 Exit_error err_build_fail;
700 fi
701
702 unset BUILD_SWITCH
703}
704
705nourl()
706{
707 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
708}
709#---------------------------------------------
710# main()
711
712if [ "$#" = 0 ]; then
713 usage;
714 exit 1
715fi
716
717while test $# -gt 0 ; do
718 case "${1}" in
719 -5 | --update-md5 )
720 COMMAND="get";
721 NODIST="yes"
722 UPDATE5="yes"
723 shift ;;
724 -a5 | --add-md5 )
725 COMMAND="get";
726 NODIST="yes"
727 NOCVS="yes"
728 UPDATE5="yes"
729 ADD5="yes"
730 shift ;;
731 -D | --debug )
732 DEBUG="yes"; shift ;;
733 -V | --version )
734 COMMAND="version"; shift ;;
735 -a | --as_anon )
736 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
737 -b | -ba | --build )
738 COMMAND="build"; shift ;;
739 -bb | --build-binary )
740 COMMAND="build-binary"; shift ;;
741 -bs | --build-source )
742 COMMAND="build-source"; shift ;;
743 -B | --branch )
744 COMMAND="branch"; shift; TAG="${1}"; shift;;
745 -c | --clean )
746 CLEAN="--clean --rmspec --rmsource"; shift ;;
747 -d | --cvsroot )
748 shift; CVSROOT="${1}"; shift ;;
749 -g | --get )
750 COMMAND="get"; shift ;;
751 -h | --help )
752 COMMAND="usage"; shift ;;
753 -l | --logtofile )
754 shift; LOGFILE="${1}"; shift ;;
755 -ni| --nice )
756 shift; DEF_NICE_LEVEL=${1}; shift ;;
757 -m | --mr-proper )
758 COMMAND="mr-proper"; shift ;;
759 -nc | --no-cvs )
760 NOCVS="yes"; shift ;;
761 -ncs | --no-cvs-specs )
762 NOCVSSPEC="yes"; shift ;;
763 -nd | --no-distfiles )
764 NODIST="yes"; shift ;;
765 -nm | --no-mirrors )
766 NOMIRRORS="yes"; shift ;;
767 -nu | --no-urls )
768 NOURLS="yes"; shift ;;
769 -ns | --no-srcs )
770 NOSRCS="yes"; shift ;;
771 -ns0 | --no-source0 )
772 NOSOURCE0="yes"; shift ;;
773 --opts )
774 shift; RPMOPTS="${1}"; shift ;;
775 --with | --without )
776 BCOND="$BCOND $1 $2" ; shift 2 ;;
777 -q | --quiet )
778 QUIET="--quiet"; shift ;;
779 --date )
780 CVSDATE="${2}"; shift 2 ;;
781 -r | --cvstag )
782 shift; CVSTAG="${1}"; shift ;;
783 -Tvs | --tag-version-stable )
784 COMMAND="tag";
785 TAG="STABLE"
786 TAG_VERSION="yes"
787 shift;;
788 -Tvn | --tag-version-nest )
789 COMMAND="tag";
790 TAG="NEST"
791 TAG_VERSION="yes"
792 shift;;
793 -Ts | --tag-stable )
794 COMMAND="tag";
795 TAG="STABLE"
796 TAG_VERSION="no"
797 shift;;
798 -Tn | --tag-nest )
799 COMMAND="tag";
800 TAG="NEST"
801 TAG_VERSION="no"
802 shift;;
803 -Tv | --tag-version )
804 COMMAND="tag";
805 TAG=""
806 TAG_VERSION="yes"
807 shift;;
808 -T | --tag )
809 COMMAND="tag";
810 shift
811 TAG="$1"
812 TAG_VERSION="no"
813 shift;;
814 -U | --update )
815 UPDATE="yes"
816 NODIST="yes"
817 UPDATE5="yes"
818 COMMAND="get"
819 shift ;;
820 -u | --try-upgrade )
821 TRY_UPGRADE="1"; shift ;;
822 -un | --try-upgrade-with-float-version )
823 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
824 -v | --verbose )
825 BE_VERBOSE="1"; shift ;;
826 --define)
827 shift
828 MACRO="${1}"
829 VALUE="${2}"
830 shift 2
831 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
832 ;;
833 * )
834 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
835 esac
836done
837
838if [ -n "$DEBUG" ]; then
839 set -x;
840 set -v;
841fi
842
843case "$COMMAND" in
844 "build" | "build-binary" | "build-source" )
845 init_builder;
846 if [ -n "$SPECFILE" ]; then
847 get_spec;
848 parse_spec;
849
850 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
851 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
852 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
853 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
854
855 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
856 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
857 fi
858 fi
859
860 if [ -n "$ICONS" ]; then
861 get_files $ICONS;
862 parse_spec;
863 fi
864 if [ -n "$NOSOURCE0" ] ; then
865 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
866 fi
867 get_files "$SOURCES $PATCHES";
868 build_package;
869 else
870 Exit_error err_no_spec_in_cmdl;
871 fi
872 ;;
873 "branch" )
874 init_builder;
875 if [ -n "$SPECFILE" ]; then
876 get_spec;
877 parse_spec;
878 if [ -n "$ICONS" ]; then
879 get_files $ICONS
880 parse_spec;
881 fi
882 get_files $SOURCES $PATCHES;
883 branch_files $TAG "$SOURCES $PATCHES $ICONS";
884 else
885 Exit_error err_no_spec_in_cmdl;
886 fi
887 ;;
888 "get" )
889 init_builder;
890 if [ -n "$SPECFILE" ]; then
891 get_spec;
892 parse_spec;
893 if [ -n "$ICONS" ]; then
894 get_files $ICONS
895 parse_spec;
896 fi
897 if [ -n "$NOSOURCE0" ] ; then
898 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
899 fi
900 get_files $SOURCES $PATCHES
901 else
902 Exit_error err_no_spec_in_cmdl;
903 fi
904 ;;
905 "tag" )
906 init_builder;
907 if [ -n "$SPECFILE" ]; then
908 get_spec;
909 parse_spec;
910 if [ -n "$ICONS" ]; then
911 get_files $ICONS
912 parse_spec;
913 fi
914 get_files $SOURCES $PATCHES;
915 tag_files "$SOURCES $PATCHES $ICONS";
916 else
917 Exit_error err_no_spec_in_cmdl;
918 fi
919 ;;
920 "mr-proper" )
921 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
922 ;;
923 "usage" )
924 usage;;
925 "version" )
926 echo "$VERSION";;
927esac
928
929cd $__PWD
This page took 0.056146 seconds and 4 git commands to generate.