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