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