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