]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
- message added
[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 --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             FROM_DISTFILES=0
439             if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
440                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
441                     echo "Warning: no URL given for $i"
442                 fi
443
444                 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
445                     if good_md5 "$i"; then
446                         echo "$(nourl "$i") having proper md5sum already exists"
447                         continue
448                     fi
449                     target=$(nourl "$i")
450                     url=$(distfiles_url "$i")
451                     if [ `echo $url | grep -E '^(\.|/)'` ]; then
452                         ${GETLOCAL} $url $target
453                     else
454                         FROM_DISTFILES=1
455                         if [ -z "$NOMIRRORS" ]; then
456                             url="`find_mirror "$url"`"
457                         fi
458                         ${GETURI} -O "$target" "$url" || \
459                             if [ `echo $url | grep -E 'ftp://'` ]; then
460                                 ${GETURI2} -O "$target" "$url"
461                             fi
462                         test -s "$target" || rm -f "$target"
463                     fi
464                 elif [ -z "$(src_md5 "$i")" ] && \
465                      ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then
466                     result=1
467                     retries_counter=0
468                     while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
469                         retries_counter=$(( $retries_counter + 1 ))
470                         output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
471                         result=$?
472                         [ -n "$output" ] && echo "$output"
473                         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
474                                 echo "Trying again [`nourl $i`]... ($retries_counter)"
475                                 sleep 2
476                                 continue
477                         else
478                                 break
479                         fi
480                     done
481                 fi
482
483                 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
484                     if [ -z "$NOMIRRORS" ]; then
485                         im="`find_mirror "$i"`"
486                     else
487                         im="$i"
488                     fi
489                     ${GETURI} "$im" || \
490                         if [ `echo $im | grep -E 'ftp://'` ]; then ${GETURI2} "$im" ; fi
491                 fi
492
493
494             fi
495             srcno=$(src_no $i)
496             if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
497                 Exit_error err_no_source_in_repo $i;
498             elif [ -n "$UPDATE5" ] && \
499                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
500                     [ -z "$(grep -E -i '^NoSource[      ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
501                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
502             then
503                 echo "Updating source-$srcno md5."
504                 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
505                 perl -i -ne '
506                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
507                                 print "# Source'$srcno'-md5:\t'$md5'\n" 
508                                         if /^Source'$srcno'\s*:\s+/;
509                                 ' \
510                                 $SPECS_DIR/$SPECFILE
511             fi
512
513             if good_md5 "$i"; then
514                 :
515             elif [ "$FROM_DISTFILES" = 1 ]; then
516                 # wrong md5 from distfiles: remove the file and try again
517                 # but only once ...
518                 echo "MD5 sum mismatch. Trying full fetch."
519                 FROM_DISTFILES=2
520                 rm -f $target
521                 ${GETURI} -O "$target" "$url" || \
522                     if [ `echo $url | grep -E 'ftp://'` ]; then
523                         ${GETURI2} -O "$target" "$url"
524                     fi
525                 test -s "$target" || rm -f "$target"
526             fi
527
528             if good_md5 "$i"; then
529                 :
530             else
531                 echo "MD5 sum mismatch.  Use -U to refetch sources,"
532                 echo "or -5 to update md5 sums, if you're sure files are correct."
533                 Exit_error err_no_source_in_repo $i
534             fi
535         done
536
537         if [ "$CHMOD" = "yes" ]; then
538             CHMOD_FILES="`nourl $GET_FILES`"
539             if [ -n "$CHMOD_FILES" ]; then
540                 chmod $CHMOD_MODE $CHMOD_FILES
541             fi
542         fi
543         unset OPTIONS
544     fi
545 }
546
547 tag_files()
548 {
549     TAG_FILES="$@"
550
551     if [ -n "$DEBUG" ]; then
552         set -x;
553         set -v;
554     fi
555
556     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
557         echo "Version: $PACKAGE_VERSION"
558         echo "Release: $PACKAGE_RELEASE"
559         TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
560         if [ "$TAG_VERSION" = "yes" ]; then
561             echo "CVS tag: $TAGVER"
562         fi
563         if [ -n "$TAG" ]; then
564             echo "CVS tag: $TAG"
565         fi
566
567         OPTIONS="tag -F"
568         if [ -n "$CVSROOT" ]; then
569             OPTIONS="-d $CVSROOT $OPTIONS"
570         fi
571
572         cd $SOURCE_DIR
573         for i in $TAG_FILES; do
574             if [ -f `nourl $i` ]; then
575                 if [ "$TAG_VERSION" = "yes" ]; then
576                     cvs $OPTIONS $TAGVER `nourl $i`
577                 fi
578                 if [ -n "$TAG" ]; then
579                     cvs $OPTIONS $TAG `nourl $i`
580                 fi
581             else
582                 Exit_error err_no_source_in_repo $i
583             fi
584         done
585
586         cd $SPECS_DIR
587         if [ "$TAG_VERSION" = "yes" ]; then
588             cvs $OPTIONS $TAGVER $SPECFILE
589         fi
590         if [ -n "$TAG" ]; then
591             cvs $OPTIONS $TAG $SPECFILE
592         fi
593
594         unset OPTIONS
595     fi
596 }
597
598 branch_files()
599 {
600     TAG=$1
601     echo "CVS branch tag: $TAG"
602     shift;
603
604     TAG_FILES="$@"
605
606     if [ -n "$DEBUG" ]; then
607         set -x;
608         set -v;
609     fi
610
611     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
612
613         OPTIONS="tag -b"
614         if [ -n "$CVSROOT" ]; then
615             OPTIONS="-d $CVSROOT $OPTIONS"
616         fi
617         cd $SOURCE_DIR
618         for i in $TAG_FILES; do
619             if [ -f `nourl $i` ]; then
620                 cvs $OPTIONS $TAG `nourl $i`
621             else
622                 Exit_error err_no_source_in_repo $i
623             fi
624         done
625         cd $SPECS_DIR
626         cvs $OPTIONS $TAG $SPECFILE
627
628         unset OPTIONS
629     fi
630 }
631
632
633
634 build_package()
635 {
636     if [ -n "$DEBUG" ]; then
637         set -x;
638         set -v;
639     fi
640
641     cd $SPECS_DIR
642
643     if [ -n "$TRY_UPGRADE" ]; then
644
645         if [ -n "FLOAT_VERSION" ]; then
646             TNOTIFY=`./pldnotify.awk $SPECFILE -n`
647         else
648             TNOTIFY=`./pldnotify.awk $SPECFILE`
649         fi
650
651         TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
652
653         if [ -n "$TNEWVER" ]; then
654
655             TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
656
657             echo "New version found, updating spec file to version " $TNEWVER
658
659             cp -f $SPECFILE $SPECFILE.bak
660
661             chmod +w $SPECFILE
662
663             eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
664             eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
665
666             parse_spec;
667
668             get_files "$SOURCES $PATCHES";
669
670             unset TOLDVER TNEWVER TNOTIFY
671         fi
672
673     fi
674
675
676     cd $SPECS_DIR
677
678     case "$COMMAND" in
679         build )
680             BUILD_SWITCH="-ba" ;;
681         build-binary )
682             BUILD_SWITCH="-bb" ;;
683         build-source )
684             BUILD_SWITCH="-bs --nodeps" ;;
685     esac
686     if [ -n "$LOGFILE" ]; then
687         if [ -n "$CVSTAG" ]; then
688             LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
689         else
690             LTAG=""
691         fi
692         LOG=`eval echo $LOGFILE`
693         if [ -n "$LASTLOG_FILE" ]; then
694             echo "LASTLOG=$LOG" > $LASTLOG_FILE
695         fi
696         RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
697         (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
698         RETVAL=`cat $RES_FILE`
699         rm $RES_FILE
700         if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
701             if [ "$RETVAL" -eq "0" ]; then
702                 mv $LOG $LOGDIROK
703             else
704                 mv $LOG $LOGDIRFAIL
705             fi
706         fi
707     else
708         eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
709         RETVAL=$?
710     fi
711
712     if [ "$RETVAL" -ne "0" ]; then
713
714         if [ -n "$TRY_UPGRADE" ]; then
715             echo "\n!!! Package with new version cannot be build automagically\n"
716             mv -f $SPECFILE.bak $SPECFILE
717         fi
718
719         Exit_error err_build_fail;
720     fi
721
722     unset BUILD_SWITCH
723 }
724
725 nourl()
726 {
727     echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
728 }
729 #---------------------------------------------
730 # main()
731
732 if [ "$#" = 0 ]; then
733     usage;
734     exit 1
735 fi
736
737 while test $# -gt 0 ; do
738     case "${1}" in
739         -5 | --update-md5 )
740             COMMAND="get";
741             NODIST="yes"
742             UPDATE5="yes"
743             shift ;;
744         -a5 | --add-md5 )
745             COMMAND="get";
746             NODIST="yes"
747             NOCVS="yes"
748             UPDATE5="yes"
749             ADD5="yes"
750             shift ;;
751         -D | --debug )
752             DEBUG="yes"; shift ;;
753         -V | --version )
754             COMMAND="version"; shift ;;
755         -a | --as_anon )
756             CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
757         -b | -ba | --build )
758             COMMAND="build"; shift ;;
759         -bb | --build-binary )
760             COMMAND="build-binary"; shift ;;
761         -bs | --build-source )
762             COMMAND="build-source"; shift ;;
763         -B | --branch )
764             COMMAND="branch"; shift; TAG="${1}"; shift;;
765         -c | --clean )
766             CLEAN="--clean --rmspec --rmsource"; shift ;;
767         -d | --cvsroot )
768             shift; CVSROOT="${1}"; shift ;;
769         -g | --get )
770             COMMAND="get"; shift ;;
771         -h | --help )
772             COMMAND="usage"; shift ;;
773         --http )
774             PROTOCOL="http"; shift ;;
775         -l | --logtofile )
776             shift; LOGFILE="${1}"; shift ;;
777         -ni| --nice )
778             shift; DEF_NICE_LEVEL=${1}; shift ;;
779         -m | --mr-proper )
780             COMMAND="mr-proper"; shift ;;
781         -nc | --no-cvs )
782             NOCVS="yes"; shift ;;
783         -ncs | --no-cvs-specs )
784             NOCVSSPEC="yes"; shift ;;
785         -nd | --no-distfiles )
786             NODIST="yes"; shift ;;
787         -nm | --no-mirrors )
788             NOMIRRORS="yes"; shift ;;
789         -nu | --no-urls )
790             NOURLS="yes"; shift ;;
791         -ns | --no-srcs )
792             NOSRCS="yes"; shift ;;
793         -ns0 | --no-source0 )
794             NOSOURCE0="yes"; shift ;;
795         --opts )
796             shift; RPMOPTS="${1}"; shift ;;
797         --with | --without )
798             BCOND="$BCOND $1 $2" ; shift 2 ;;
799         -q | --quiet )
800             QUIET="--quiet"; shift ;;
801         --date )
802             CVSDATE="${2}"; shift 2 ;;
803         -r | --cvstag )
804             shift; CVSTAG="${1}"; shift ;;
805         -Tvs | --tag-version-stable )
806             COMMAND="tag";
807             TAG="STABLE"
808             TAG_VERSION="yes"
809             shift;;
810         -Tvn | --tag-version-nest )
811             COMMAND="tag";
812             TAG="NEST"
813             TAG_VERSION="yes"
814             shift;;
815         -Ts | --tag-stable )
816             COMMAND="tag";
817             TAG="STABLE"
818             TAG_VERSION="no"
819             shift;;
820         -Tn | --tag-nest )
821             COMMAND="tag";
822             TAG="NEST"
823             TAG_VERSION="no"
824             shift;;
825         -Tv | --tag-version )
826             COMMAND="tag";
827             TAG=""
828             TAG_VERSION="yes"
829             shift;;
830         -T | --tag )
831             COMMAND="tag";
832             shift
833             TAG="$1"
834             TAG_VERSION="no"
835             shift;;
836         -U | --update )
837             UPDATE="yes"
838             NODIST="yes"
839             UPDATE5="yes"
840             COMMAND="get"
841             shift ;;
842         -u | --try-upgrade )
843             TRY_UPGRADE="1"; shift ;;
844         -un | --try-upgrade-with-float-version )
845             TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
846         -v | --verbose )
847             BE_VERBOSE="1"; shift ;;
848         --define)
849             shift
850             MACRO="${1}"
851             VALUE="${2}"
852             shift 2
853             RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
854             ;;
855         * )
856             SPECFILE="`basename ${1} .spec`.spec"; shift ;;
857     esac
858 done
859
860 if [ -n "$DEBUG" ]; then
861     set -x;
862     set -v;
863 fi
864
865 case "$COMMAND" in
866     "build" | "build-binary" | "build-source" )
867         init_builder;
868         if [ -n "$SPECFILE" ]; then
869             get_spec;
870             parse_spec;
871
872             if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
873                 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
874                 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
875                 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
876
877                 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
878                     Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
879                 fi
880             fi
881
882             if [ -n "$ICONS" ]; then
883                 get_files $ICONS;
884                 parse_spec;
885             fi
886             if [ -n "$NOSOURCE0" ] ; then
887                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
888             fi
889             get_files "$SOURCES $PATCHES";
890             build_package;
891         else
892             Exit_error err_no_spec_in_cmdl;
893         fi
894         ;;
895     "branch" )
896         init_builder;
897         if [ -n "$SPECFILE" ]; then
898                 get_spec;
899                 parse_spec;
900                 if [ -n "$ICONS" ]; then
901                         get_files $ICONS
902                         parse_spec;
903                 fi
904                 get_files $SOURCES $PATCHES;
905                 branch_files $TAG "$SOURCES $PATCHES $ICONS";
906         else
907                 Exit_error err_no_spec_in_cmdl;
908         fi
909         ;;
910     "get" )
911         init_builder;
912         if [ -n "$SPECFILE" ]; then
913             get_spec;
914             parse_spec;
915             if [ -n "$ICONS" ]; then
916                 get_files $ICONS
917                 parse_spec;
918             fi
919             if [ -n "$NOSOURCE0" ] ; then
920                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
921             fi
922             get_files $SOURCES $PATCHES
923         else
924             Exit_error err_no_spec_in_cmdl;
925         fi
926         ;;
927     "tag" )
928         init_builder;
929         if [ -n "$SPECFILE" ]; then
930             get_spec;
931             parse_spec;
932             if [ -n "$ICONS" ]; then
933                 get_files $ICONS
934                 parse_spec;
935             fi
936             get_files $SOURCES $PATCHES;
937             tag_files "$SOURCES $PATCHES $ICONS";
938         else
939             Exit_error err_no_spec_in_cmdl;
940         fi
941         ;;
942     "mr-proper" )
943         $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
944         ;;
945     "usage" )
946         usage;;
947     "version" )
948         echo "$VERSION";;
949 esac
950
951 cd $__PWD
This page took 0.126832 seconds and 4 git commands to generate.