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