]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
659f727ab3d73f67944e82d73c087402af7d6078
[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 -ncs
117         -a5, --add-md5  - add md5 comments to URL sources, implies -nc -nd -ncs
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             NOCVSSPEC="yes"
752             UPDATE5="yes"
753             shift ;;
754         -a5 | --add-md5 )
755             COMMAND="get";
756             NODIST="yes"
757             NOCVS="yes"
758             NOCVSSPEC="yes"
759             UPDATE5="yes"
760             ADD5="yes"
761             shift ;;
762         -D | --debug )
763             DEBUG="yes"; shift ;;
764         -V | --version )
765             COMMAND="version"; shift ;;
766         -a | --as_anon )
767             CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
768         -b | -ba | --build )
769             COMMAND="build"; shift ;;
770         -bb | --build-binary )
771             COMMAND="build-binary"; shift ;;
772         -bs | --build-source )
773             COMMAND="build-source"; shift ;;
774         -B | --branch )
775             COMMAND="branch"; shift; TAG="${1}"; shift;;
776         -c | --clean )
777             CLEAN="--clean --rmspec --rmsource"; shift ;;
778         -d | --cvsroot )
779             shift; CVSROOT="${1}"; shift ;;
780         -g | --get )
781             COMMAND="get"; shift ;;
782         -h | --help )
783             COMMAND="usage"; shift ;;
784         --http )
785             PROTOCOL="http"; shift ;;
786         -l | --logtofile )
787             shift; LOGFILE="${1}"; shift ;;
788         -ni| --nice )
789             shift; DEF_NICE_LEVEL=${1}; shift ;;
790         -m | --mr-proper )
791             COMMAND="mr-proper"; shift ;;
792         -nc | --no-cvs )
793             NOCVS="yes"; shift ;;
794         -ncs | --no-cvs-specs )
795             NOCVSSPEC="yes"; shift ;;
796         -nd | --no-distfiles )
797             NODIST="yes"; shift ;;
798         -nm | --no-mirrors )
799             NOMIRRORS="yes"; shift ;;
800         -nu | --no-urls )
801             NOURLS="yes"; shift ;;
802         -ns | --no-srcs )
803             NOSRCS="yes"; shift ;;
804         -ns0 | --no-source0 )
805             NOSOURCE0="yes"; shift ;;
806         --opts )
807             shift; RPMOPTS="${1}"; shift ;;
808         --with | --without )
809             BCOND="$BCOND $1 $2" ; shift 2 ;;
810         -q | --quiet )
811             QUIET="--quiet"; shift ;;
812         --date )
813             CVSDATE="${2}"; shift 2 ;;
814         -r | --cvstag )
815             shift; CVSTAG="${1}"; shift ;;
816         -Tvs | --tag-version-stable )
817             COMMAND="tag";
818             TAG="STABLE"
819             TAG_VERSION="yes"
820             shift;;
821         -Tvn | --tag-version-nest )
822             COMMAND="tag";
823             TAG="NEST"
824             TAG_VERSION="yes"
825             shift;;
826         -Ts | --tag-stable )
827             COMMAND="tag";
828             TAG="STABLE"
829             TAG_VERSION="no"
830             shift;;
831         -Tn | --tag-nest )
832             COMMAND="tag";
833             TAG="NEST"
834             TAG_VERSION="no"
835             shift;;
836         -Tv | --tag-version )
837             COMMAND="tag";
838             TAG=""
839             TAG_VERSION="yes"
840             shift;;
841         -T | --tag )
842             COMMAND="tag";
843             shift
844             TAG="$1"
845             TAG_VERSION="no"
846             shift;;
847         -U | --update )
848             COMMAND="get"
849             UPDATE="yes"
850             NODIST="yes"
851             UPDATE5="yes"
852             shift ;;
853         -u | --try-upgrade )
854             TRY_UPGRADE="1"; shift ;;
855         -un | --try-upgrade-with-float-version )
856             TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
857         -v | --verbose )
858             BE_VERBOSE="1"; shift ;;
859         --define)
860             shift
861             MACRO="${1}"
862             VALUE="${2}"
863             shift 2
864             RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
865             ;;
866         * )
867             SPECFILE="`basename ${1} .spec`.spec"; shift ;;
868     esac
869 done
870
871 if [ -n "$DEBUG" ]; then
872     set -x;
873     set -v;
874 fi
875
876 case "$COMMAND" in
877     "build" | "build-binary" | "build-source" )
878         init_builder;
879         if [ -n "$SPECFILE" ]; then
880             get_spec;
881             parse_spec;
882
883             if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
884                 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
885                 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
886                 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
887
888                 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
889                     Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
890                 fi
891             fi
892
893             if [ -n "$ICONS" ]; then
894                 get_files $ICONS;
895                 parse_spec;
896             fi
897             if [ -n "$NOSOURCE0" ] ; then
898                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
899             fi
900             get_files "$SOURCES $PATCHES";
901             build_package;
902         else
903             Exit_error err_no_spec_in_cmdl;
904         fi
905         ;;
906     "branch" )
907         init_builder;
908         if [ -n "$SPECFILE" ]; then
909                 get_spec;
910                 parse_spec;
911                 if [ -n "$ICONS" ]; then
912                         get_files $ICONS
913                         parse_spec;
914                 fi
915                 get_files $SOURCES $PATCHES;
916                 branch_files $TAG "$SOURCES $PATCHES $ICONS";
917         else
918                 Exit_error err_no_spec_in_cmdl;
919         fi
920         ;;
921     "get" )
922         init_builder;
923         if [ -n "$SPECFILE" ]; then
924             get_spec;
925             parse_spec;
926             if [ -n "$ICONS" ]; then
927                 get_files $ICONS
928                 parse_spec;
929             fi
930             if [ -n "$NOSOURCE0" ] ; then
931                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
932             fi
933             get_files $SOURCES $PATCHES
934         else
935             Exit_error err_no_spec_in_cmdl;
936         fi
937         ;;
938     "tag" )
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             get_files $SOURCES $PATCHES;
948             tag_files "$SOURCES $PATCHES $ICONS";
949         else
950             Exit_error err_no_spec_in_cmdl;
951         fi
952         ;;
953     "mr-proper" )
954         $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
955         ;;
956     "usage" )
957         usage;;
958     "version" )
959         echo "$VERSION";;
960 esac
961
962 cd $__PWD
This page took 0.176274 seconds and 3 git commands to generate.