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