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