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