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