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