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