]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
- Removed LTAG
[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 CHMOD="no"
55 CHMOD_MODE="0444"
56 RPMOPTS=""
57 BCOND=""
58
59 PATCHES=""
60 SOURCES=""
61 ICONS=""
62 PACKAGE_RELEASE=""
63 PACKAGE_VERSION=""
64 PACKAGE_NAME=""
65 PROTOCOL="ftp"
66 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
67 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
68
69 CVSTAG=""
70 RES_FILE=""
71
72 CVS_SERVER="cvs.pld-linux.org"
73 DISTFILES_SERVER="://distfiles.pld-linux.org"
74
75 DEF_NICE_LEVEL=0
76
77 FAIL_IF_NO_SOURCES="yes"
78
79 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
80 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
81 GETLOCAL="cp -a"
82
83 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
84     RPM="rpm"
85     RPMBUILD="rpm"
86 else
87     RPM="rpm"
88     RPMBUILD="rpmbuild"
89 fi
90
91 if [ -f ~/etc/builderrc ]; then
92     . ~/etc/builderrc
93 elif [ -f ~/.builderrc ]; then
94     . ~/.builderrc
95 fi
96
97 #---------------------------------------------
98 # functions
99
100 usage()
101 {
102     if [ -n "$DEBUG" ]; then set -xv; fi
103     echo "\
104 Usage: 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
192 cache_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
204 rpm_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
211 parse_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
253 Exit_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
278 init_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
291 get_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
351 find_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
372 src_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
381 src_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
405 distfiles_url ()
406 {
407     echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
408 }
409
410 good_md5 ()
411 {
412     md5=$(src_md5 "$1")
413     [ "$md5" = "" ] || \
414     [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
415 }
416
417 get_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                         if ! test -s "$target"; then
482                             rm -f "$target"
483                             FROM_DISTFILES=0
484                         fi
485                     fi
486                 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
487                     # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
488                     result=1
489                     retries_counter=0
490                     while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
491                         retries_counter=$(( $retries_counter + 1 ))
492                         output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
493                         result=$?
494                         [ -n "$output" ] && echo "$output"
495                         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
496                                 echo "Trying again [`nourl $i`]... ($retries_counter)"
497                                 sleep 2
498                                 continue
499                         else
500                                 break
501                         fi
502                     done
503                 fi
504
505                 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
506                     if [ -z "$NOMIRRORS" ]; then
507                         im="`find_mirror "$i"`"
508                     else
509                         im="$i"
510                     fi
511                     ${GETURI} "$im" || \
512                         if [ `echo $im | grep -E 'ftp://'` ]; then ${GETURI2} "$im" ; fi
513                 fi
514
515
516             fi
517             srcno=$(src_no $i)
518             if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
519                 Exit_error err_no_source_in_repo $i;
520             elif [ -n "$UPDATE5" ] && \
521                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
522                     [ -z "$(grep -E -i '^NoSource[      ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
523                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
524             then
525                 echo "Updating source-$srcno md5."
526                 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
527                 perl -i -ne '
528                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
529                                 print "# Source'$srcno'-md5:\t'$md5'\n" 
530                                         if /^Source'$srcno'\s*:\s+/;
531                                 ' \
532                                 $SPECS_DIR/$SPECFILE
533             fi
534
535             if good_md5 "$i"; then
536                 :
537             elif [ "$FROM_DISTFILES" = 1 ]; then
538                 # wrong md5 from distfiles: remove the file and try again
539                 # but only once ...
540                 echo "MD5 sum mismatch. Trying full fetch."
541                 FROM_DISTFILES=2
542                 rm -f $target
543                 ${GETURI} -O "$target" "$url" || \
544                     if [ `echo $url | grep -E 'ftp://'` ]; then
545                         ${GETURI2} -O "$target" "$url"
546                     fi
547                 test -s "$target" || rm -f "$target"
548             fi
549
550             if good_md5 "$i"; then
551                 :
552             else
553                 echo "MD5 sum mismatch.  Use -U to refetch sources,"
554                 echo "or -5 to update md5 sums, if you're sure files are correct."
555                 Exit_error err_no_source_in_repo $i
556             fi
557         done
558
559         if [ "$CHMOD" = "yes" ]; then
560             CHMOD_FILES="`nourl $GET_FILES`"
561             if [ -n "$CHMOD_FILES" ]; then
562                 chmod $CHMOD_MODE $CHMOD_FILES
563             fi
564         fi
565         unset OPTIONS
566     fi
567 }
568
569 tag_files()
570 {
571     TAG_FILES="$@"
572
573     if [ -n "$DEBUG" ]; then
574         set -x;
575         set -v;
576     fi
577
578     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
579         echo "Version: $PACKAGE_VERSION"
580         echo "Release: $PACKAGE_RELEASE"
581         TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
582         if [ "$TAG_VERSION" = "yes" ]; then
583             echo "CVS tag: $TAGVER"
584         fi
585         if [ -n "$TAG" ]; then
586             echo "CVS tag: $TAG"
587         fi
588
589         OPTIONS="tag -F"
590         if [ -n "$CVSROOT" ]; then
591             OPTIONS="-d $CVSROOT $OPTIONS"
592         fi
593
594         cd $SOURCE_DIR
595         for i in $TAG_FILES; do
596             if [ -f `nourl $i` ]; then
597                 if [ "$TAG_VERSION" = "yes" ]; then
598                     cvs $OPTIONS $TAGVER `nourl $i`
599                 fi
600                 if [ -n "$TAG" ]; then
601                     cvs $OPTIONS $TAG `nourl $i`
602                 fi
603             else
604                 Exit_error err_no_source_in_repo $i
605             fi
606         done
607
608         cd $SPECS_DIR
609         if [ "$TAG_VERSION" = "yes" ]; then
610             cvs $OPTIONS $TAGVER $SPECFILE
611         fi
612         if [ -n "$TAG" ]; then
613             cvs $OPTIONS $TAG $SPECFILE
614         fi
615
616         unset OPTIONS
617     fi
618 }
619
620 branch_files()
621 {
622     TAG=$1
623     echo "CVS branch tag: $TAG"
624     shift;
625
626     TAG_FILES="$@"
627
628     if [ -n "$DEBUG" ]; then
629         set -x;
630         set -v;
631     fi
632
633     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
634
635         OPTIONS="tag -b"
636         if [ -n "$CVSROOT" ]; then
637             OPTIONS="-d $CVSROOT $OPTIONS"
638         fi
639         cd $SOURCE_DIR
640         for i in $TAG_FILES; do
641             if [ -f `nourl $i` ]; then
642                 cvs $OPTIONS $TAG `nourl $i`
643             else
644                 Exit_error err_no_source_in_repo $i
645             fi
646         done
647         cd $SPECS_DIR
648         cvs $OPTIONS $TAG $SPECFILE
649
650         unset OPTIONS
651     fi
652 }
653
654
655
656 build_package()
657 {
658     if [ -n "$DEBUG" ]; then
659         set -x;
660         set -v;
661     fi
662
663     cd $SPECS_DIR
664
665     if [ -n "$TRY_UPGRADE" ]; then
666
667         if [ -n "FLOAT_VERSION" ]; then
668             TNOTIFY=`./pldnotify.awk $SPECFILE -n`
669         else
670             TNOTIFY=`./pldnotify.awk $SPECFILE`
671         fi
672
673         TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
674
675         if [ -n "$TNEWVER" ]; then
676
677             TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
678
679             echo "New version found, updating spec file to version " $TNEWVER
680
681             cp -f $SPECFILE $SPECFILE.bak
682
683             chmod +w $SPECFILE
684
685             eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
686             eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
687
688             parse_spec;
689
690             get_files "$SOURCES $PATCHES";
691
692             unset TOLDVER TNEWVER TNOTIFY
693         fi
694
695     fi
696
697
698     cd $SPECS_DIR
699
700     case "$COMMAND" in
701         build )
702             BUILD_SWITCH="-ba" ;;
703         build-binary )
704             BUILD_SWITCH="-bb" ;;
705         build-source )
706             BUILD_SWITCH="-bs --nodeps" ;;
707     esac
708     if [ -n "$LOGFILE" ]; then
709         LOG=`eval echo $LOGFILE`
710         if [ -n "$LASTLOG_FILE" ]; then
711             echo "LASTLOG=$LOG" > $LASTLOG_FILE
712         fi
713         RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
714         (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
715         RETVAL=`cat $RES_FILE`
716         rm $RES_FILE
717         if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
718             if [ "$RETVAL" -eq "0" ]; then
719                 mv $LOG $LOGDIROK
720             else
721                 mv $LOG $LOGDIRFAIL
722             fi
723         fi
724     else
725         eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
726         RETVAL=$?
727     fi
728
729     if [ "$RETVAL" -ne "0" ]; then
730
731         if [ -n "$TRY_UPGRADE" ]; then
732             echo "\n!!! Package with new version cannot be build automagically\n"
733             mv -f $SPECFILE.bak $SPECFILE
734         fi
735
736         Exit_error err_build_fail;
737     fi
738
739     unset BUILD_SWITCH
740 }
741
742 nourl()
743 {
744     echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
745 }
746
747 #---------------------------------------------
748 # main()
749
750 if [ "$#" = 0 ]; then
751     usage;
752     exit 1
753 fi
754
755 while test $# -gt 0 ; do
756     case "${1}" in
757         -5 | --update-md5 )
758             COMMAND="get";
759             NODIST="yes"
760             NOCVSSPEC="yes"
761             UPDATE5="yes"
762             shift ;;
763         -a5 | --add-md5 )
764             COMMAND="get";
765             NODIST="yes"
766             NOCVS="yes"
767             NOCVSSPEC="yes"
768             UPDATE5="yes"
769             ADD5="yes"
770             shift ;;
771         -D | --debug )
772             DEBUG="yes"; shift ;;
773         -V | --version )
774             COMMAND="version"; shift ;;
775         -a | --as_anon )
776             CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
777         -b | -ba | --build )
778             COMMAND="build"; shift ;;
779         -bb | --build-binary )
780             COMMAND="build-binary"; shift ;;
781         -bs | --build-source )
782             COMMAND="build-source"; shift ;;
783         -B | --branch )
784             COMMAND="branch"; shift; TAG="${1}"; shift;;
785         -c | --clean )
786             CLEAN="--clean --rmspec --rmsource"; shift ;;
787         -d | --cvsroot )
788             shift; CVSROOT="${1}"; shift ;;
789         -g | --get )
790             COMMAND="get"; shift ;;
791         -h | --help )
792             COMMAND="usage"; shift ;;
793         --http )
794             PROTOCOL="http"; shift ;;
795         -l | --logtofile )
796             shift; LOGFILE="${1}"; shift ;;
797         -ni| --nice )
798             shift; DEF_NICE_LEVEL=${1}; shift ;;
799         -m | --mr-proper )
800             COMMAND="mr-proper"; shift ;;
801         -nc | --no-cvs )
802             NOCVS="yes"; shift ;;
803         -ncs | --no-cvs-specs )
804             NOCVSSPEC="yes"; shift ;;
805         -nd | --no-distfiles )
806             NODIST="yes"; shift ;;
807         -nm | --no-mirrors )
808             NOMIRRORS="yes"; shift ;;
809         -nu | --no-urls )
810             NOURLS="yes"; shift ;;
811         -ns | --no-srcs )
812             NOSRCS="yes"; shift ;;
813         -ns0 | --no-source0 )
814             NOSOURCE0="yes"; shift ;;
815         --opts )
816             shift; RPMOPTS="${1}"; shift ;;
817         --with | --without )
818             BCOND="$BCOND $1 $2" ; shift 2 ;;
819         -q | --quiet )
820             QUIET="--quiet"; shift ;;
821         --date )
822             CVSDATE="${2}"; shift 2 ;;
823         -r | --cvstag )
824             shift; CVSTAG="${1}"; shift ;;
825         -Tvs | --tag-version-stable )
826             COMMAND="tag";
827             TAG="STABLE"
828             TAG_VERSION="yes"
829             shift;;
830         -Tvn | --tag-version-nest )
831             COMMAND="tag";
832             TAG="NEST"
833             TAG_VERSION="yes"
834             shift;;
835         -Ts | --tag-stable )
836             COMMAND="tag";
837             TAG="STABLE"
838             TAG_VERSION="no"
839             shift;;
840         -Tn | --tag-nest )
841             COMMAND="tag";
842             TAG="NEST"
843             TAG_VERSION="no"
844             shift;;
845         -Tv | --tag-version )
846             COMMAND="tag";
847             TAG=""
848             TAG_VERSION="yes"
849             shift;;
850         -T | --tag )
851             COMMAND="tag";
852             shift
853             TAG="$1"
854             TAG_VERSION="no"
855             shift;;
856         -U | --update )
857             COMMAND="get"
858             UPDATE="yes"
859             NODIST="yes"
860             UPDATE5="yes"
861             shift ;;
862         -u | --try-upgrade )
863             TRY_UPGRADE="1"; shift ;;
864         -un | --try-upgrade-with-float-version )
865             TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
866         -v | --verbose )
867             BE_VERBOSE="1"; shift ;;
868         --define)
869             shift
870             MACRO="${1}"
871             VALUE="${2}"
872             shift 2
873             RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
874             ;;
875         * )
876             SPECFILE="`basename ${1} .spec`.spec"; shift ;;
877     esac
878 done
879
880 if [ -n "$DEBUG" ]; then
881     set -x;
882     set -v;
883 fi
884
885 case "$COMMAND" in
886     "build" | "build-binary" | "build-source" )
887         init_builder;
888         if [ -n "$SPECFILE" ]; then
889             get_spec;
890             parse_spec;
891
892             if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
893                 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
894                 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
895                 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
896
897                 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
898                     Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
899                 fi
900             fi
901
902             if [ -n "$ICONS" ]; then
903                 get_files $ICONS;
904                 parse_spec;
905             fi
906             if [ -n "$NOSOURCE0" ] ; then
907                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
908             fi
909             get_files "$SOURCES $PATCHES";
910             build_package;
911         else
912             Exit_error err_no_spec_in_cmdl;
913         fi
914         ;;
915     "branch" )
916         init_builder;
917         if [ -n "$SPECFILE" ]; then
918                 get_spec;
919                 parse_spec;
920                 if [ -n "$ICONS" ]; then
921                         get_files $ICONS
922                         parse_spec;
923                 fi
924                 get_files $SOURCES $PATCHES;
925                 branch_files $TAG "$SOURCES $PATCHES $ICONS";
926         else
927                 Exit_error err_no_spec_in_cmdl;
928         fi
929         ;;
930     "get" )
931         init_builder;
932         if [ -n "$SPECFILE" ]; then
933             get_spec;
934             parse_spec;
935             if [ -n "$ICONS" ]; then
936                 get_files $ICONS
937                 parse_spec;
938             fi
939             if [ -n "$NOSOURCE0" ] ; then
940                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
941             fi
942             get_files $SOURCES $PATCHES
943         else
944             Exit_error err_no_spec_in_cmdl;
945         fi
946         ;;
947     "tag" )
948         init_builder;
949         if [ -n "$SPECFILE" ]; then
950             get_spec;
951             parse_spec;
952             if [ -n "$ICONS" ]; then
953                 get_files $ICONS
954                 parse_spec;
955             fi
956             get_files $SOURCES $PATCHES;
957             tag_files "$SOURCES $PATCHES $ICONS";
958         else
959             Exit_error err_no_spec_in_cmdl;
960         fi
961         ;;
962     "mr-proper" )
963         $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
964         ;;
965     "usage" )
966         usage;;
967     "version" )
968         echo "$VERSION";;
969 esac
970
971 cd $__PWD
This page took 0.087419 seconds and 4 git commands to generate.