]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
- fixed updating from distfiles to a version with different md5 and same filename
[packages/rpm-build-tools.git] / builder.sh
1 #!/bin/sh
2 # -----------
3 # $Id$
4 # Exit codes:
5 #       0 - succesful
6 #       1 - help dispayed
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
12 # Notes (todo):
13 #       - builder -u fetches current version first
14 #       - tries to get new version from distfiles without new md5
15 #       - after fetching new version doesn't update md5
16 #       - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
17 #         when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
18 #       - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov
19
20 VERSION="\
21 Build package utility from PLD CVS repository
22 V 0.11 (C) 1999-2003 Free Penguins".
23 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
24
25 COMMAND="build"
26
27 SPECFILE=""
28 BE_VERBOSE=""
29 QUIET=""
30 CLEAN=""
31 DEBUG=""
32 NOURLS=""
33 NOCVS=""
34 NOCVSSPEC=""
35 NODIST=""
36 UPDATE=""
37 UPDATE5=""
38 ADD5=""
39 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
40 if [ -s CVS/Root ]; then
41     CVSROOT=$(cat CVS/Root)
42 else
43     CVSROOT=${CVSROOT:-""}
44 fi
45 # Example: LOGFILE='../log.$PACKAGE_NAME'
46 # Yes, you can use variable name! Note _single_ quotes!
47 LOGFILE=''
48
49 LOGDIR=""
50 LOGDIROK=""
51 LOGDIRFAIL=""
52 LASTLOG_FILE=""
53 LTAG=""
54 CHMOD="no"
55 CHMOD_MODE="0444"
56 RPMOPTS=""
57 BCOND=""
58
59 PATCHES=""
60 SOURCES=""
61 ICONS=""
62 PACKAGE_RELEASE=""
63 PACKAGE_VERSION=""
64 PACKAGE_NAME=""
65 PROTOCOL="ftp"
66 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
67 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
68
69 CVSTAG=""
70 RES_FILE=""
71
72 CVS_SERVER="cvs.pld-linux.org"
73 DISTFILES_SERVER="://distfiles.pld-linux.org"
74
75 DEF_NICE_LEVEL=0
76
77 FAIL_IF_NO_SOURCES="yes"
78
79 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
80 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
81 GETLOCAL="cp -a"
82
83 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
84     RPM="rpm"
85     RPMBUILD="rpm"
86 else
87     RPM="rpm"
88     RPMBUILD="rpmbuild"
89 fi
90
91 if [ -f ~/etc/builderrc ]; then
92     . ~/etc/builderrc
93 elif [ -f ~/.builderrc ]; then
94     . ~/.builderrc
95 fi
96
97 #---------------------------------------------
98 # functions
99
100 usage()
101 {
102     if [ -n "$DEBUG" ]; then set -xv; fi
103     echo "\
104 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
105
106         [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
107         [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
108         [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
109         [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
110         [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
111         [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
112         [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
113         [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
114
115         -5, --update-md5
116                         - update md5 comments in spec, implies -nd
117         -a5, --add-md5  - add md5 comments to URL sources, implies -nc -nd
118         -D, --debug     - enable script debugging mode,
119         -V, --version   - output builder version
120         -a, --as_anon   - get files via pserver as cvs@$CVS_SERVER,
121         -b, -ba,
122         --build         - get all files from CVS repo or HTTP/FTP and build
123                           package from <package>.spec,
124         -bb, --build-binary
125                         - get all files from CVS repo or HTTP/FTP and build
126                           binary only package from <package>.spec,
127         -bs,
128         --build-source  - get all files from CVS repo or HTTP/FTP and only
129                           pack them into src.rpm,
130         -B, --branch    - add branch
131         -c, --clean     - clean all temporarily created files (in BUILD,
132                           SOURCES, SPECS and \$RPM_BUILD_ROOT),
133         -d <cvsroot>, --cvsroot <cvsroot>
134                         - setup \$CVSROOT,
135         --define <macro> <value>
136                         - define a macro <macro> with value <value>,
137         -g, --get       - get <package>.spec and all related files from
138                           CVS repo or HTTP/FTP,
139         -h, --help      - this message,
140         --http          - use http instead of ftp,
141         -l <logfile>, --logtofile <logfile>
142                         - log all to file,
143         -m, --mr-proper - only remove all files related to spec file and
144                           all work resources,
145         -nc, --no-cvs   - don't download sources from CVS, if source URL is
146                           given,
147         -ncs, --no-cvs-specs
148                         - don't check specs in CVS
149         -nd, --no-distfiles
150                         - don't download from distfiles
151         -nm, --no-mirrors - don't download from mirror, if source URL is given,
152         -nu, --no-urls  - don't try to download from FTP/HTTP location,
153         -ns, --no-srcs  - don't download Sources
154         -ns0, --no-source0
155                         - don't download Source0
156         --opts <rpm opts>
157                         - additional options for rpm
158         -q, --quiet     - be quiet,
159         --date yyyy-mm-dd
160                         - build package using resources from specified CVS
161                           date,
162         -r <cvstag>, --cvstag <cvstag>
163                         - build package using resources from specified CVS
164                           tag,
165         -T <cvstag> , --tag <cvstag>
166                         - add cvs tag <cvstag> for files,
167         -Tvs, --tag-version-stable
168                         - add cvs tags STABLE and NAME-VERSION-RELESE for files,
169         -Tvn, --tag-version-nest
170                         - add cvs tags NEST and NAME-VERSION-RELESE for files,
171         -Ts, --tag-stable
172                         - add cvs tag STABLE for files,
173         -Tn, --tag-nest
174                         - add cvs tag NEST for files,
175         -Tv, --tag-version
176                         - add cvs tag NAME-VERSION-RELESE for files,
177         -v, --verbose   - be verbose,
178         -u, --try-upgrade
179                         - check version, and try to upgrade package
180         -un, --try-upgrade-with-float-version
181                         - as above, but allow float version
182         -U, --update
183                         - refetch sources, don't use distfiles, and update md5 
184                           comments
185         --with/--without <feature>
186                         - conditional build package depending on
187                           %_with_<feature>/%_without_<feature> macro
188                           switch
189 "
190 }
191
192 rpm_dump () {
193         case "$RPMBUILD" in
194         rpm )
195                 rpm -bp --define 'prep %dump' $BCOND $SPECFILE 2>&1 
196                 ;;
197         rpmbuild )
198                 rpmbuild --define 'prep %dump' $BCOND $SPECFILE 2>&1 
199                 ;;
200         esac
201 }
202
203 parse_spec()
204 {
205     if [ -n "$DEBUG" ]; then
206         set -x;
207         set -v;
208     fi
209
210     cd $SPECS_DIR
211     if [ "$NOSRCS" != "yes" ]; then
212         SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
213     fi
214     if (rpm_dump | grep -qEi ":.*nosource.*1"); then
215         FAIL_IF_NO_SOURCES="no"
216     fi
217
218     PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
219     ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
220     PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
221     PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
222     PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
223
224     if [ -n "$BE_VERBOSE" ]; then
225         echo "- Sources :  `nourl $SOURCES`"
226         if [ -n "$PATCHES" ]; then
227             echo "- Patches :  `nourl $PATCHES`"
228         else
229             echo "- Patches :  *no patches needed*"
230         fi
231         if [ -n "$ICONS" ]; then
232             echo "- Icon    :  `nourl $ICONS`"
233         else
234             echo "- Icon    :  *no package icon*"
235         fi
236         echo "- Name    : $PACKAGE_NAME"
237         echo "- Version : $PACKAGE_VERSION"
238         echo "- Release : $PACKAGE_RELEASE"
239     fi
240 }
241
242 Exit_error()
243 {
244     if [ -n "$DEBUG" ]; then
245         set -x;
246         set -v;
247     fi
248
249     cd $__PWD
250
251     case "$1" in
252     "err_no_spec_in_cmdl" )
253         echo "ERROR: spec file name not specified.";
254         exit 2 ;;
255     "err_no_spec_in_repo" )
256         echo "Error: spec file not stored in CVS repo.";
257         exit 3 ;;
258     "err_no_source_in_repo" )
259         echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
260         exit 4 ;;
261     "err_build_fail" )
262         echo "Error: package build failed. (${2:-no more info})";
263         exit 5 ;;
264     esac
265 }
266
267 init_builder()
268 {
269     if [ -n "$DEBUG" ]; then
270         set -x;
271         set -v;
272     fi
273
274     SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
275     SPECS_DIR="`$RPM --eval '%{_specdir}'`"
276
277     __PWD=`pwd`
278 }
279
280 get_spec()
281 {
282     if [ -n "$DEBUG" ]; then
283         set -x;
284         set -v;
285     fi
286
287     if [ "$NOCVSSPEC" != "yes" ]; then
288         cd $SPECS_DIR
289
290         OPTIONS="up "
291
292         if [ -n "$CVSROOT" ]; then
293             OPTIONS="-d $CVSROOT $OPTIONS"
294         else
295             if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
296                 echo "warning: No cvs access defined - using local .spec file"
297                 NOCVSSPEC="yes"
298             fi
299         fi
300
301         if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
302             OPTIONS="$OPTIONS -A"
303         else
304             if [ -n "$CVSDATE" ]; then
305                 OPTIONS="$OPTIONS -D $CVSDATE"
306             fi
307             if [ -n "$CVSTAG" ]; then
308                 OPTIONS="$OPTIONS -r $CVSTAG"
309             fi
310         fi
311
312         result=1
313         retries_counter=0
314         while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
315             retries_counter=$(( $retries_counter + 1 ))
316             output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
317             result=$?
318             [ -n "$output" ] && echo "$output"
319             if [ "$result" -ne "0" ]; then
320                 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
321                     echo "Trying again [$SPECFILE]... ($retries_counter)"
322                     sleep 2
323                     continue
324                 fi
325                 Exit_error err_no_spec_in_repo;
326             fi
327         done
328     fi
329     if [ ! -f "$SPECFILE" ]; then
330         Exit_error err_no_spec_in_repo;
331     fi
332
333     if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
334         chmod $CHMOD_MODE $SPECFILE
335     fi
336     unset OPTIONS
337     grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
338 }
339
340 find_mirror(){
341
342     cd "$SPECS_DIR"
343     url="$1"
344     if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
345         cvs update mirrors >&2
346     fi
347
348     IFS="|"
349     while read origin mirror name rest; do
350         ol=`echo -n "$origin"|wc -c`
351         prefix="`echo -n "$url" | head -c $ol`"
352         if [ "$prefix" = "$origin" ] ; then
353             suffix="`echo "$url"|cut -b $ol-`"
354             echo -n "$mirror$suffix"
355             return 0
356         fi
357     done < mirrors
358     echo "$url"
359 }
360
361 src_no ()
362 {
363     cd $SPECS_DIR
364     rpm_dump | \
365         grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
366         sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
367         head -1 | xargs
368 }
369
370 src_md5 ()
371 {
372     no=$(src_no "$1")
373     [ -z "$no" ] && return
374     cd $SPECS_DIR
375     spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
376     if [ -z "$spec_rev" ]; then
377         spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
378     fi
379     spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
380     md5=$(grep -s -v '^#' additional-md5sums | \
381         grep -E "[      ]$(basename "$1")[      ]+${spec}([     ,]|\$)" | \
382         sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
383         grep -E '^[0-9a-f]{32}$')
384     if [ X"$md5" = X"" ] ; then
385         grep -i "#[     ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://' | xargs
386     else
387         if [ $(echo "$md5" | wc -l) != 1 ] ; then
388             echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
389         fi
390         echo "$md5" | tail -1
391     fi
392 }
393
394 distfiles_url ()
395 {
396     echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
397 }
398
399 good_md5 ()
400 {
401     md5=$(src_md5 "$1")
402     [ "$md5" = "" ] || \
403     [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
404 }
405
406 get_files()
407 {
408     GET_FILES="$@"
409
410     if [ -n "$DEBUG" ]; then
411         set -x;
412         set -v;
413     fi
414
415     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
416         cd $SOURCE_DIR
417
418         OPTIONS="up "
419         if [ -n "$CVSROOT" ]; then
420             OPTIONS="-d $CVSROOT $OPTIONS"
421         else
422             if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
423                 echo "warning: No cvs access defined for SOURCES"
424                 NOCVS="yes"
425             fi
426         fi
427         if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
428             OPTIONS="$OPTIONS -A"
429         else
430             if [ -n "$CVSDATE" ]; then
431                 OPTIONS="$OPTIONS -D $CVSDATE"
432             fi
433             if [ -n "$CVSTAG" ]; then
434                 OPTIONS="$OPTIONS -r $CVSTAG"
435             fi
436         fi
437         for i in $GET_FILES; do
438             FROM_DISTFILES=0
439             if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
440                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
441                     echo "Warning: no URL given for $i"
442                 fi
443
444                 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
445                     if good_md5 "$i"; then
446                         echo "$(nourl "$i") having proper md5sum already exists"
447                         continue
448                     fi
449                     target=$(nourl "$i")
450                     url=$(distfiles_url "$i")
451                     if [ `echo $url | grep -E '^(\.|/)'` ]; then
452                         ${GETLOCAL} $url $target
453                     else
454                         FROM_DISTFILES=1
455                         if [ -z "$NOMIRRORS" ]; then
456                             url="`find_mirror "$url"`"
457                         fi
458                         ${GETURI} -O "$target" "$url" || \
459                             if [ `echo $url | grep -E 'ftp://'` ]; then
460                                 ${GETURI2} -O "$target" "$url"
461                             fi
462                         test -s "$target" || rm -f "$target"
463                     fi
464                 elif [ -z "$(src_md5 "$i")" ] && \
465                      ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then
466                     result=1
467                     retries_counter=0
468                     while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
469                         retries_counter=$(( $retries_counter + 1 ))
470                         output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
471                         result=$?
472                         [ -n "$output" ] && echo "$output"
473                         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
474                                 echo "Trying again [`nourl $i`]... ($retries_counter)"
475                                 sleep 2
476                                 continue
477                         else
478                                 break
479                         fi
480                     done
481                 fi
482
483                 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
484                     if [ -z "$NOMIRRORS" ]; then
485                         im="`find_mirror "$i"`"
486                     else
487                         im="$i"
488                     fi
489                     ${GETURI} "$im" || \
490                         if [ `echo $im | grep -E 'ftp://'` ]; then ${GETURI2} "$im" ; fi
491                 fi
492
493             fi
494             srcno=$(src_no $i)
495             if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
496                 Exit_error err_no_source_in_repo $i;
497             elif [ -n "$UPDATE5" ] && \
498                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
499                     [ -z "$(grep -E -i '^NoSource[      ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
500                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
501             then
502                 echo "Updating source-$srcno md5."
503                 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
504                 perl -i -ne '
505                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
506                                 print "# Source'$srcno'-md5:\t'$md5'\n" 
507                                         if /^Source'$srcno'\s*:\s+/;
508                                 ' \
509                                 $SPECS_DIR/$SPECFILE
510             fi
511
512             if good_md5 "$i"; then
513                 :
514             elif [ "$FROM_DISTFILES" = 1 ]; then
515                 # wrong md5 from distfiles: remove the file and try again
516                 # but only once ...
517                 FROM_DISTFILES=2
518                 rm -f $target
519                 ${GETURI} -O "$target" "$url" || \
520                     if [ `echo $url | grep -E 'ftp://'` ]; then
521                         ${GETURI2} -O "$target" "$url"
522                     fi
523                 test -s "$target" || rm -f "$target"
524             fi
525
526             if good_md5 "$i"; then
527                 :
528
529 VERSION="\
530 Build package utility from PLD CVS repository
531 V 0.11 (C) 1999-2003 Free Penguins".
532 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
533
534 COMMAND="build"
535
536 SPECFILE=""
537 BE_VERBOSE=""
538 QUIET=""
539 CLEAN=""
540 DEBUG=""
541 NOURLS=""
542 NOCVS=""
543 NOCVSSPEC=""
544 NODIST=""
545 UPDATE=""
546 UPDATE5=""
547 ADD5=""
548 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
549 if [ -s CVS/Root ]; then
550     CVSROOT=$(cat CVS/Root)
551 else
552     CVSROOT=${CVSROOT:-""}
553 fi
554 # Example: LOGFILE='../log.$PACKAGE_NAME'
555 # Yes, you can use variable name! Note _single_ quotes!
556 LOGFILE=''
557
558 LOGDIR=""
559 LOGDIROK=""
560 LOGDIRFAIL=""
561 LASTLOG_FILE=""
562 LTAG=""
563 CHMOD="no"
564 CHMOD_MODE="0444"
565 RPMOPTS=""
566 BCOND=""
567
568 PATCHES=""
569 SOURCES=""
570 ICONS=""
571 PACKAGE_RELEASE=""
572 PACKAGE_VERSION=""
573 PACKAGE_NAME=""
574 PROTOCOL="ftp"
575 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
576 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
577
578 CVSTAG=""
579 RES_FILE=""
580
581 CVS_SERVER="cvs.pld-linux.org"
582 DISTFILES_SERVER="://distfiles.pld-linux.org"
583
584 DEF_NICE_LEVEL=0
585
586 FAIL_IF_NO_SOURCES="yes"
587
588 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
589 GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
590 GETLOCAL="cp -a"
591
592 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
593     RPM="rpm"
594     RPMBUILD="rpm"
595 else
596     RPM="rpm"
597     RPMBUILD="rpmbuild"
598 fi
599
600 if [ -f ~/etc/builderrc ]; then
601     . ~/etc/builderrc
602 elif [ -f ~/.builderrc ]; then
603     . ~/.builderrc
604 fi
605
606 #---------------------------------------------
607 # functions
608
609 usage()
610 {
611     if [ -n "$DEBUG" ]; then set -xv; fi
612     echo "\
613 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
614
615         [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
616         [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
617         [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
618         [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
619         [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
620         [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
621         [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
622         [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
623
624         -5, --update-md5
625                         - update md5 comments in spec, implies -nd
626         -a5, --add-md5  - add md5 comments to URL sources, implies -nc -nd
627         -D, --debug     - enable script debugging mode,
628         -V, --version   - output builder version
629         -a, --as_anon   - get files via pserver as cvs@$CVS_SERVER,
630         -b, -ba,
631         --build         - get all files from CVS repo or HTTP/FTP and build
632                           package from <package>.spec,
633         -bb, --build-binary
634                         - get all files from CVS repo or HTTP/FTP and build
635                           binary only package from <package>.spec,
636         -bs,
637         --build-source  - get all files from CVS repo or HTTP/FTP and only
638                           pack them into src.rpm,
639         -B, --branch    - add branch
640         -c, --clean     - clean all temporarily created files (in BUILD,
641                           SOURCES, SPECS and \$RPM_BUILD_ROOT),
642         -d <cvsroot>, --cvsroot <cvsroot>
643                         - setup \$CVSROOT,
644         --define <macro> <value>
645                         - define a macro <macro> with value <value>,
646         -g, --get       - get <package>.spec and all related files from
647                           CVS repo or HTTP/FTP,
648         -h, --help      - this message,
649         --http          - use http instead of ftp,
650         -l <logfile>, --logtofile <logfile>
651                         - log all to file,
652         -m, --mr-proper - only remove all files related to spec file and
653                           all work resources,
654         -nc, --no-cvs   - don't download sources from CVS, if source URL is
655                           given,
656         -ncs, --no-cvs-specs
657                         - don't check specs in CVS
658         -nd, --no-distfiles
659                         - don't download from distfiles
660         -nm, --no-mirrors - don't download from mirror, if source URL is given,
661         -nu, --no-urls  - don't try to download from FTP/HTTP location,
662         -ns, --no-srcs  - don't download Sources
663         -ns0, --no-source0
664                         - don't download Source0
665         --opts <rpm opts>
666                         - additional options for rpm
667         -q, --quiet     - be quiet,
668         --date yyyy-mm-dd
669                         - build package using resources from specified CVS
670                           date,
671         -r <cvstag>, --cvstag <cvstag>
672                         - build package using resources from specified CVS
673                           tag,
674         -T <cvstag> , --tag <cvstag>
675                         - add cvs tag <cvstag> for files,
676         -Tvs, --tag-version-stable
677                         - add cvs tags STABLE and NAME-VERSION-RELESE for files,
678         -Tvn, --tag-version-nest
679                         - add cvs tags NEST and NAME-VERSION-RELESE for files,
680         -Ts, --tag-stable
681                         - add cvs tag STABLE for files,
682         -Tn, --tag-nest
683                         - add cvs tag NEST for files,
684         -Tv, --tag-version
685                         - add cvs tag NAME-VERSION-RELESE for files,
686         -v, --verbose   - be verbose,
687         -u, --try-upgrade
688                         - check version, and try to upgrade package
689         -un, --try-upgrade-with-float-version
690                         - as above, but allow float version
691         -U, --update
692                         - refetch sources, don't use distfiles, and update md5 
693                           comments
694         --with/--without <feature>
695                         - conditional build package depending on
696                           %_with_<feature>/%_without_<feature> macro
697                           switch
698 "
699 }
700
701 rpm_dump () {
702         case "$RPMBUILD" in
703         rpm )
704                 rpm -bp --define 'prep %dump' $BCOND $SPECFILE 2>&1 
705                 ;;
706         rpmbuild )
707                 rpmbuild --define 'prep %dump' $BCOND $SPECFILE 2>&1 
708                 ;;
709         esac
710 }
711
712 parse_spec()
713 {
714     if [ -n "$DEBUG" ]; then
715         set -x;
716         set -v;
717     fi
718
719     cd $SPECS_DIR
720     if [ "$NOSRCS" != "yes" ]; then
721         SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
722     fi
723     if (rpm_dump | grep -qEi ":.*nosource.*1"); then
724         FAIL_IF_NO_SOURCES="no"
725     fi
726
727     PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
728     ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
729     PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
730     PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
731     PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
732
733     if [ -n "$BE_VERBOSE" ]; then
734         echo "- Sources :  `nourl $SOURCES`"
735         if [ -n "$PATCHES" ]; then
736             echo "- Patches :  `nourl $PATCHES`"
737         else
738             echo "- Patches :  *no patches needed*"
739         fi
740         if [ -n "$ICONS" ]; then
741             echo "- Icon    :  `nourl $ICONS`"
742         else
743             echo "- Icon    :  *no package icon*"
744         fi
745         echo "- Name    : $PACKAGE_NAME"
746         echo "- Version : $PACKAGE_VERSION"
747         echo "- Release : $PACKAGE_RELEASE"
748     fi
749 }
750
751 Exit_error()
752 {
753     if [ -n "$DEBUG" ]; then
754         set -x;
755         set -v;
756     fi
757
758     cd $__PWD
759
760     case "$1" in
761     "err_no_spec_in_cmdl" )
762         echo "ERROR: spec file name not specified.";
763         exit 2 ;;
764     "err_no_spec_in_repo" )
765         echo "Error: spec file not stored in CVS repo.";
766         exit 3 ;;
767     "err_no_source_in_repo" )
768         echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
769         exit 4 ;;
770     "err_build_fail" )
771         echo "Error: package build failed. (${2:-no more info})";
772         exit 5 ;;
773     esac
774 }
775
776 init_builder()
777 {
778     if [ -n "$DEBUG" ]; then
779         set -x;
780         set -v;
781     fi
782
783     SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
784     SPECS_DIR="`$RPM --eval '%{_specdir}'`"
785
786     __PWD=`pwd`
787 }
788
789 get_spec()
790 {
791     if [ -n "$DEBUG" ]; then
792         set -x;
793         set -v;
794     fi
795
796     if [ "$NOCVSSPEC" != "yes" ]; then
797         cd $SPECS_DIR
798
799         OPTIONS="up "
800
801         if [ -n "$CVSROOT" ]; then
802             OPTIONS="-d $CVSROOT $OPTIONS"
803         else
804             if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
805                 echo "warning: No cvs access defined - using local .spec file"
806                 NOCVSSPEC="yes"
807             fi
808         fi
809
810         if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
811             OPTIONS="$OPTIONS -A"
812         else
813             if [ -n "$CVSDATE" ]; then
814                 OPTIONS="$OPTIONS -D $CVSDATE"
815             fi
816             if [ -n "$CVSTAG" ]; then
817                 OPTIONS="$OPTIONS -r $CVSTAG"
818             fi
819         fi
820
821         result=1
822         retries_counter=0
823         while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
824             retries_counter=$(( $retries_counter + 1 ))
825             output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
826             result=$?
827             [ -n "$output" ] && echo "$output"
828             if [ "$result" -ne "0" ]; then
829                 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
830                     echo "Trying again [$SPECFILE]... ($retries_counter)"
831                     sleep 2
832                     continue
833                 fi
834                 Exit_error err_no_spec_in_repo;
835             fi
836         done
837     fi
838     if [ ! -f "$SPECFILE" ]; then
839         Exit_error err_no_spec_in_repo;
840     fi
841
842     if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
843         chmod $CHMOD_MODE $SPECFILE
844     fi
845     unset OPTIONS
846     grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
847 }
848
849 find_mirror(){
850
851     cd "$SPECS_DIR"
852     url="$1"
853     if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
854         cvs update mirrors >&2
855     fi
856
857     IFS="|"
858     while read origin mirror name rest; do
859         ol=`echo -n "$origin"|wc -c`
860         prefix="`echo -n "$url" | head -c $ol`"
861         if [ "$prefix" = "$origin" ] ; then
862             suffix="`echo "$url"|cut -b $ol-`"
863             echo -n "$mirror$suffix"
864             return 0
865         fi
866     done < mirrors
867     echo "$url"
868 }
869
870 src_no ()
871 {
872     cd $SPECS_DIR
873     rpm_dump | \
874         grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
875         sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
876         head -1 | xargs
877 }
878
879 src_md5 ()
880 {
881     no=$(src_no "$1")
882     [ -z "$no" ] && return
883     cd $SPECS_DIR
884     spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
885     if [ -z "$spec_rev" ]; then
886         spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
887     fi
888     spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
889     md5=$(grep -s -v '^#' additional-md5sums | \
890         grep -E "[      ]$(basename "$1")[      ]+${spec}([     ,]|\$)" | \
891         sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
892         grep -E '^[0-9a-f]{32}$')
893     if [ X"$md5" = X"" ] ; then
894         grep -i "#[     ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://' | xargs
895     else
896         if [ $(echo "$md5" | wc -l) != 1 ] ; then
897             echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
898         fi
899         echo "$md5" | tail -1
900     fi
901 }
902
903 distfiles_url ()
904 {
905     echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
906 }
907
908 good_md5 ()
909 {
910     md5=$(src_md5 "$1")
911     [ "$md5" = "" ] || \
912     [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
913 }
914
915 get_files()
916 {
917     GET_FILES="$@"
918
919     if [ -n "$DEBUG" ]; then
920         set -x;
921         set -v;
922     fi
923
924     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
925         cd $SOURCE_DIR
926
927         OPTIONS="up "
928         if [ -n "$CVSROOT" ]; then
929             OPTIONS="-d $CVSROOT $OPTIONS"
930         else
931             if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
932                 echo "warning: No cvs access defined for SOURCES"
933                 NOCVS="yes"
934             fi
935         fi
936         if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
937             OPTIONS="$OPTIONS -A"
938         else
939             if [ -n "$CVSDATE" ]; then
940                 OPTIONS="$OPTIONS -D $CVSDATE"
941             fi
942             if [ -n "$CVSTAG" ]; then
943                 OPTIONS="$OPTIONS -r $CVSTAG"
944             fi
945         fi
946         for i in $GET_FILES; do
947             FROM_DISTFILES=0
948             if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
949                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
950                     echo "Warning: no URL given for $i"
951                 fi
952
953                 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
954                     if good_md5 "$i"; then
955                         echo "$(nourl "$i") having proper md5sum already exists"
956                         continue
957                     fi
958                     target=$(nourl "$i")
959                     url=$(distfiles_url "$i")
960                     if [ `echo $url | grep -E '^(\.|/)'` ]; then
961                         ${GETLOCAL} $url $target
962                     else
963                         FROM_DISTFILES=1
964                         if [ -z "$NOMIRRORS" ]; then
965                             url="`find_mirror "$url"`"
966                         fi
967                         ${GETURI} -O "$target" "$url" || \
968                             if [ `echo $url | grep -E 'ftp://'` ]; then
969                                 ${GETURI2} -O "$target" "$url"
970                             fi
971                         test -s "$target" || rm -f "$target"
972                     fi
973                 elif [ -z "$(src_md5 "$i")" ] && \
974                      ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then
975                     result=1
976                     retries_counter=0
977                     while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
978                         retries_counter=$(( $retries_counter + 1 ))
979                         output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
980                         result=$?
981                         [ -n "$output" ] && echo "$output"
982                         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
983                                 echo "Trying again [`nourl $i`]... ($retries_counter)"
984                                 sleep 2
985                                 continue
986                         else
987                                 break
988                         fi
989                     done
990                 fi
991
992                 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
993                     if [ -z "$NOMIRRORS" ]; then
994                         im="`find_mirror "$i"`"
995                     else
996                         im="$i"
997                     fi
998                     ${GETURI} "$im" || \
999                         if [ `echo $im | grep -E 'ftp://'` ]; then ${GETURI2} "$im" ; fi
1000                 fi
1001
1002             fi
1003             srcno=$(src_no $i)
1004             if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1005                 Exit_error err_no_source_in_repo $i;
1006             elif [ -n "$UPDATE5" ] && \
1007                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
1008                     [ -z "$(grep -E -i '^NoSource[      ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
1009                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
1010             then
1011                 echo "Updating source-$srcno md5."
1012                 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
1013                 perl -i -ne '
1014                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
1015                                 print "# Source'$srcno'-md5:\t'$md5'\n" 
1016                                         if /^Source'$srcno'\s*:\s+/;
1017                                 ' \
1018                                 $SPECS_DIR/$SPECFILE
1019             fi
1020
1021             if good_md5 "$i"; then
1022                 :
1023             elif [ "$FROM_DISTFILES" = 1 ]; then
1024                 # wrong md5 from distfiles: remove the file and try again
1025                 # but only once ...
1026                 FROM_DISTFILES=2
1027                 rm -f $target
1028                 ${GETURI} -O "$target" "$url" || \
1029                     if [ `echo $url | grep -E 'ftp://'` ]; then
1030                         ${GETURI2} -O "$target" "$url"
1031                     fi
1032                 test -s "$target" || rm -f "$target"
1033             fi
1034
1035             if good_md5 "$i"; then
1036                 :
1037             else
1038                 echo "MD5 sum mismatch.  Use -U to refetch sources,"
1039                 echo "or -5 to update md5 sums, if you're sure files are correct."
1040                 Exit_error err_no_source_in_repo $i
1041             fi
1042         done
1043
1044         if [ "$CHMOD" = "yes" ]; then
1045             CHMOD_FILES="`nourl $GET_FILES`"
1046             if [ -n "$CHMOD_FILES" ]; then
1047                 chmod $CHMOD_MODE $CHMOD_FILES
1048             fi
1049         fi
1050         unset OPTIONS
1051     fi
1052 }
1053
1054 tag_files()
1055 {
1056     TAG_FILES="$@"
1057
1058     if [ -n "$DEBUG" ]; then
1059         set -x;
1060         set -v;
1061     fi
1062
1063     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
1064         echo "Version: $PACKAGE_VERSION"
1065         echo "Release: $PACKAGE_RELEASE"
1066         TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1067         if [ "$TAG_VERSION" = "yes" ]; then
1068             echo "CVS tag: $TAGVER"
1069         fi
1070         if [ -n "$TAG" ]; then
1071             echo "CVS tag: $TAG"
1072         fi
1073
1074         OPTIONS="tag -F"
1075         if [ -n "$CVSROOT" ]; then
1076             OPTIONS="-d $CVSROOT $OPTIONS"
1077         fi
1078
1079         cd $SOURCE_DIR
1080         for i in $TAG_FILES; do
1081             if [ -f `nourl $i` ]; then
1082                 if [ "$TAG_VERSION" = "yes" ]; then
1083                     cvs $OPTIONS $TAGVER `nourl $i`
1084                 fi
1085                 if [ -n "$TAG" ]; then
1086                     cvs $OPTIONS $TAG `nourl $i`
1087                 fi
1088             else
1089                 Exit_error err_no_source_in_repo $i
1090             fi
1091         done
1092
1093         cd $SPECS_DIR
1094         if [ "$TAG_VERSION" = "yes" ]; then
1095             cvs $OPTIONS $TAGVER $SPECFILE
1096         fi
1097         if [ -n "$TAG" ]; then
1098             cvs $OPTIONS $TAG $SPECFILE
1099         fi
1100
1101         unset OPTIONS
1102     fi
1103 }
1104
1105 branch_files()
1106 {
1107     TAG=$1
1108     echo "CVS branch tag: $TAG"
1109     shift;
1110
1111     TAG_FILES="$@"
1112
1113     if [ -n "$DEBUG" ]; then
1114         set -x;
1115         set -v;
1116     fi
1117
1118     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
1119
1120         OPTIONS="tag -b"
1121         if [ -n "$CVSROOT" ]; then
1122             OPTIONS="-d $CVSROOT $OPTIONS"
1123         fi
1124         cd $SOURCE_DIR
1125         for i in $TAG_FILES; do
1126             if [ -f `nourl $i` ]; then
1127                 cvs $OPTIONS $TAG `nourl $i`
1128             else
1129                 Exit_error err_no_source_in_repo $i
1130             fi
1131         done
1132         cd $SPECS_DIR
1133         cvs $OPTIONS $TAG $SPECFILE
1134
1135         unset OPTIONS
1136     fi
1137 }
1138
1139
1140
1141 build_package()
1142 {
1143     if [ -n "$DEBUG" ]; then
1144         set -x;
1145         set -v;
1146     fi
1147
1148     cd $SPECS_DIR
1149
1150     if [ -n "$TRY_UPGRADE" ]; then
1151
1152         if [ -n "FLOAT_VERSION" ]; then
1153             TNOTIFY=`./pldnotify.awk $SPECFILE -n`
1154         else
1155             TNOTIFY=`./pldnotify.awk $SPECFILE`
1156         fi
1157
1158         TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
1159
1160         if [ -n "$TNEWVER" ]; then
1161
1162             TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1163
1164             echo "New version found, updating spec file to version " $TNEWVER
1165
1166             cp -f $SPECFILE $SPECFILE.bak
1167
1168             chmod +w $SPECFILE
1169
1170             eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
1171             eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
1172
1173             parse_spec;
1174
1175             get_files "$SOURCES $PATCHES";
1176
1177             unset TOLDVER TNEWVER TNOTIFY
1178         fi
1179
1180     fi
1181
1182
1183     cd $SPECS_DIR
1184
1185     case "$COMMAND" in
1186         build )
1187             BUILD_SWITCH="-ba" ;;
1188         build-binary )
1189             BUILD_SWITCH="-bb" ;;
1190         build-source )
1191             BUILD_SWITCH="-bs --nodeps" ;;
1192     esac
1193     if [ -n "$LOGFILE" ]; then
1194         if [ -n "$CVSTAG" ]; then
1195             LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
1196         else
1197             LTAG=""
1198         fi
1199         LOG=`eval echo $LOGFILE`
1200         if [ -n "$LASTLOG_FILE" ]; then
1201             echo "LASTLOG=$LOG" > $LASTLOG_FILE
1202         fi
1203         RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
1204         (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
1205         RETVAL=`cat $RES_FILE`
1206         rm $RES_FILE
1207         if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1208             if [ "$RETVAL" -eq "0" ]; then
1209                 mv $LOG $LOGDIROK
1210             else
1211                 mv $LOG $LOGDIRFAIL
1212             fi
1213         fi
1214     else
1215         eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
1216         RETVAL=$?
1217     fi
1218
1219     if [ "$RETVAL" -ne "0" ]; then
1220
1221         if [ -n "$TRY_UPGRADE" ]; then
1222             echo "\n!!! Package with new version cannot be build automagically\n"
1223             mv -f $SPECFILE.bak $SPECFILE
1224         fi
1225
1226         Exit_error err_build_fail;
1227     fi
1228
1229     unset BUILD_SWITCH
1230 }
1231
1232 nourl()
1233 {
1234     echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1235 }
1236 #---------------------------------------------
1237 # main()
1238
1239 if [ "$#" = 0 ]; then
1240     usage;
1241     exit 1
1242 fi
1243
1244 while test $# -gt 0 ; do
1245     case "${1}" in
1246         -5 | --update-md5 )
1247             COMMAND="get";
1248             NODIST="yes"
1249             UPDATE5="yes"
1250             shift ;;
1251         -a5 | --add-md5 )
1252             COMMAND="get";
1253             NODIST="yes"
1254             NOCVS="yes"
1255             UPDATE5="yes"
1256             ADD5="yes"
1257             shift ;;
1258         -D | --debug )
1259             DEBUG="yes"; shift ;;
1260         -V | --version )
1261             COMMAND="version"; shift ;;
1262         -a | --as_anon )
1263             CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1264         -b | -ba | --build )
1265             COMMAND="build"; shift ;;
1266         -bb | --build-binary )
1267             COMMAND="build-binary"; shift ;;
1268         -bs | --build-source )
1269             COMMAND="build-source"; shift ;;
1270         -B | --branch )
1271             COMMAND="branch"; shift; TAG="${1}"; shift;;
1272         -c | --clean )
1273             CLEAN="--clean --rmspec --rmsource"; shift ;;
1274         -d | --cvsroot )
1275             shift; CVSROOT="${1}"; shift ;;
1276         -g | --get )
1277             COMMAND="get"; shift ;;
1278         -h | --help )
1279             COMMAND="usage"; shift ;;
1280         --http )
1281             PROTOCOL="http"; shift ;;
1282         -l | --logtofile )
1283             shift; LOGFILE="${1}"; shift ;;
1284         -ni| --nice )
1285             shift; DEF_NICE_LEVEL=${1}; shift ;;
1286         -m | --mr-proper )
1287             COMMAND="mr-proper"; shift ;;
1288         -nc | --no-cvs )
1289             NOCVS="yes"; shift ;;
1290         -ncs | --no-cvs-specs )
1291             NOCVSSPEC="yes"; shift ;;
1292         -nd | --no-distfiles )
1293             NODIST="yes"; shift ;;
1294         -nm | --no-mirrors )
1295             NOMIRRORS="yes"; shift ;;
1296         -nu | --no-urls )
1297             NOURLS="yes"; shift ;;
1298         -ns | --no-srcs )
1299             NOSRCS="yes"; shift ;;
1300         -ns0 | --no-source0 )
1301             NOSOURCE0="yes"; shift ;;
1302         --opts )
1303             shift; RPMOPTS="${1}"; shift ;;
1304         --with | --without )
1305             BCOND="$BCOND $1 $2" ; shift 2 ;;
1306         -q | --quiet )
1307             QUIET="--quiet"; shift ;;
1308         --date )
1309             CVSDATE="${2}"; shift 2 ;;
1310         -r | --cvstag )
1311             shift; CVSTAG="${1}"; shift ;;
1312         -Tvs | --tag-version-stable )
1313             COMMAND="tag";
1314             TAG="STABLE"
1315             TAG_VERSION="yes"
1316             shift;;
1317         -Tvn | --tag-version-nest )
1318             COMMAND="tag";
1319             TAG="NEST"
1320             TAG_VERSION="yes"
1321             shift;;
1322         -Ts | --tag-stable )
1323             COMMAND="tag";
1324             TAG="STABLE"
1325             TAG_VERSION="no"
1326             shift;;
1327         -Tn | --tag-nest )
1328             COMMAND="tag";
1329             TAG="NEST"
1330             TAG_VERSION="no"
1331             shift;;
1332         -Tv | --tag-version )
1333             COMMAND="tag";
1334             TAG=""
1335             TAG_VERSION="yes"
1336             shift;;
1337         -T | --tag )
1338             COMMAND="tag";
1339             shift
1340             TAG="$1"
1341             TAG_VERSION="no"
1342             shift;;
1343         -U | --update )
1344             UPDATE="yes"
1345             NODIST="yes"
1346             UPDATE5="yes"
1347             COMMAND="get"
1348             shift ;;
1349         -u | --try-upgrade )
1350             TRY_UPGRADE="1"; shift ;;
1351         -un | --try-upgrade-with-float-version )
1352             TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1353         -v | --verbose )
1354             BE_VERBOSE="1"; shift ;;
1355         --define)
1356             shift
1357             MACRO="${1}"
1358             VALUE="${2}"
1359             shift 2
1360             RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1361             ;;
1362         * )
1363             SPECFILE="`basename ${1} .spec`.spec"; shift ;;
1364     esac
1365 done
1366
1367 if [ -n "$DEBUG" ]; then
1368     set -x;
1369     set -v;
1370 fi
1371
1372 case "$COMMAND" in
1373     "build" | "build-binary" | "build-source" )
1374         init_builder;
1375         if [ -n "$SPECFILE" ]; then
1376             get_spec;
1377             parse_spec;
1378
1379             if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
1380                 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1381                 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
1382                 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1383
1384                 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
1385                     Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
1386                 fi
1387             fi
1388
1389             if [ -n "$ICONS" ]; then
1390                 get_files $ICONS;
1391                 parse_spec;
1392             fi
1393             if [ -n "$NOSOURCE0" ] ; then
1394                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1395             fi
1396             get_files "$SOURCES $PATCHES";
1397             build_package;
1398         else
1399             Exit_error err_no_spec_in_cmdl;
1400         fi
1401         ;;
1402     "branch" )
1403         init_builder;
1404         if [ -n "$SPECFILE" ]; then
1405                 get_spec;
1406                 parse_spec;
1407                 if [ -n "$ICONS" ]; then
1408                         get_files $ICONS
1409                         parse_spec;
1410                 fi
1411                 get_files $SOURCES $PATCHES;
1412                 branch_files $TAG "$SOURCES $PATCHES $ICONS";
1413         else
1414                 Exit_error err_no_spec_in_cmdl;
1415         fi
1416         ;;
1417     "get" )
1418         init_builder;
1419         if [ -n "$SPECFILE" ]; then
1420             get_spec;
1421             parse_spec;
1422             if [ -n "$ICONS" ]; then
1423                 get_files $ICONS
1424                 parse_spec;
1425             fi
1426             if [ -n "$NOSOURCE0" ] ; then
1427                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1428             fi
1429             get_files $SOURCES $PATCHES
1430         else
1431             Exit_error err_no_spec_in_cmdl;
1432         fi
1433         ;;
1434     "tag" )
1435         init_builder;
1436         if [ -n "$SPECFILE" ]; then
1437             get_spec;
1438             parse_spec;
1439             if [ -n "$ICONS" ]; then
1440                 get_files $ICONS
1441                 parse_spec;
1442             fi
1443             get_files $SOURCES $PATCHES;
1444             tag_files "$SOURCES $PATCHES $ICONS";
1445         else
1446             Exit_error err_no_spec_in_cmdl;
1447         fi
1448         ;;
1449     "mr-proper" )
1450         $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1451         ;;
1452     "usage" )
1453         usage;;
1454     "version" )
1455         echo "$VERSION";;
1456 esac
1457
1458 cd $__PWD
This page took 0.144166 seconds and 4 git commands to generate.