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