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