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