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