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