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