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