]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
7b3176b5b75bdc76e9d710444310fcf26e3086e1
[packages/rpm-build-tools.git] / builder.sh
1 #!/bin/sh
2 # -----------
3 # $Id$
4 # Exit codes:
5 #       0 - succesful
6 #       1 - help displayed
7 #       2 - no spec file name in cmdl parameters
8 #       3 - spec file not stored in repo
9 #       4 - some source, patch or icon files not stored in repo
10 #       5 - package build failed
11 #       6 - spec file with errors
12 #       7 - wrong source in /etc/poldek.conf
13
14 # Notes (todo):
15 #       - builder -u fetches current version first
16 #       - tries to get new version from distfiles without new md5
17 #       - after fetching new version doesn't update md5
18 #       - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
19 #         when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
20 #       - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov
21 #       - when Icon: field is present, -5 and -a5 doesn't work
22
23 VERSION="\
24 Build package utility from PLD CVS repository
25 V 0.11 (C) 1999-2003 Free Penguins".
26 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
27
28 COMMAND="build"
29
30 SPECFILE=""
31 BE_VERBOSE=""
32 QUIET=""
33 CLEAN=""
34 DEBUG=""
35 NOURLS=""
36 NOCVS=""
37 NOCVSSPEC=""
38 NODIST=""
39 UPDATE=""
40 UPDATE5=""
41 ADD5=""
42 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
43 CVSROOT=""
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 CHMOD="no"
53 CHMOD_MODE="0444"
54 RPMOPTS=""
55 BCOND=""
56 GROUP_BCONDS="no"
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 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
79 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
80
81 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
82 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
83 GETLOCAL="cp -a"
84
85 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
86     RPM="rpm"
87     RPMBUILD="rpm"
88 else
89     RPM="rpm"
90     RPMBUILD="rpmbuild"
91 fi
92
93 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
94 POLDEK_SOURCE="cvs"
95
96 # Example grep cvs /etc/poldek.conf:
97 # source = cvs /home/users/yoshi/rpm/RPMS/
98 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
99         POLDEK_SOURCE_VALIDITY="`grep ${POLDEK_SOURCE} /etc/poldek.conf|grep -v ^#`"
100         if [ "${POLDEK_SOURCE_VALIDITY}" = "" ]; then 
101                 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
102                 echo "Fix it and try to contiune"
103                 exit 7
104         fi
105 fi
106
107 if [ -f ~/etc/builderrc ]; then
108     . ~/etc/builderrc
109 fi
110
111 if [ -n "$HOME_ETC" ]; then
112     USER_CFG=$HOME_ETC/.builderrc
113 else
114     USER_CFG=~/.builderrc
115 fi
116
117 [ -f $USER_CFG ] && . $USER_CFG        
118
119 #---------------------------------------------
120 # functions
121
122 usage()
123 {
124     if [ -n "$DEBUG" ]; then set -xv; fi
125     echo "\
126 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
127
128         [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
129         [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
130         [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
131         [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
132         [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
133         [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version] 
134         [{-Tp|--tag-prefix} <prefix>]
135         [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
136         [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
137
138         -5, --update-md5
139                         - update md5 comments in spec, implies -nd -ncs
140         -a5, --add-md5  - add md5 comments to URL sources, implies -nc -nd -ncs
141         -D, --debug     - enable script debugging mode,
142         -V, --version   - output builder version
143         -a, --as_anon   - get files via pserver as cvs@$CVS_SERVER,
144         -b, -ba,
145         --build         - get all files from CVS repo or HTTP/FTP and build
146                           package from <package>.spec,
147         -bb, --build-binary
148                         - get all files from CVS repo or HTTP/FTP and build
149                           binary only package from <package>.spec,
150         -bs,
151         --build-source  - get all files from CVS repo or HTTP/FTP and only
152                           pack them into src.rpm,
153         -bp, --build-prep
154                         - execute the %prep phase of <package>.spec,
155         -B, --branch    - add branch
156         -c, --clean     - clean all temporarily created files (in BUILD,
157                           SOURCES, SPECS and \$RPM_BUILD_ROOT),
158         -d <cvsroot>, --cvsroot <cvsroot>
159                         - setup \$CVSROOT,
160         --define <macro> <value>
161                         - define a macro <macro> with value <value>,
162         --nodeps        - rpm won't check any dependences
163         -g, --get       - get <package>.spec and all related files from
164                           CVS repo or HTTP/FTP,
165         -h, --help      - this message,
166         --http          - use http instead of ftp,
167         -l <logfile>, --logtofile <logfile>
168                         - log all to file,
169         -m, --mr-proper - only remove all files related to spec file and
170                           all work resources,
171         -nc, --no-cvs   - don't download sources from CVS, if source URL is
172                           given,
173         -ncs, --no-cvs-specs
174                         - don't check specs in CVS
175         -nd, --no-distfiles
176                         - don't download from distfiles
177         -nm, --no-mirrors - don't download from mirror, if source URL is given,
178         -nu, --no-urls  - don't try to download from FTP/HTTP location,
179         -ns, --no-srcs  - don't download Sources
180         -ns0, --no-source0
181                         - don't download Source0
182         --opts <rpm opts>
183                         - additional options for rpm
184         -q, --quiet     - be quiet,
185         --date yyyy-mm-dd
186                         - build package using resources from specified CVS
187                           date,
188         -r <cvstag>, --cvstag <cvstag>
189                         - build package using resources from specified CVS
190                           tag,
191         -R, --fetch-build-requires
192                         - fetch what is BuildRequired,
193         -RB, --remove-build-requires
194                         - remove all you fetched with -R or --fetch-build-requires
195                           remember, this option requires confirmation,
196         -FRB, --force-remove-build-requires
197                         - remove all you fetched with -R or --fetch-build-requires
198                           remember, this option works without confirmation,
199         -T <cvstag> , --tag <cvstag>
200                         - add cvs tag <cvstag> for files,
201         -Tvs, --tag-version-stable
202                         - add cvs tags STABLE and NAME-VERSION-RELESE for files,
203         -Tvn, --tag-version-nest
204                         - add cvs tags NEST and NAME-VERSION-RELESE for files,
205         -Ts, --tag-stable
206                         - add cvs tag STABLE for files,
207         -Tn, --tag-nest
208                         - add cvs tag NEST for files,
209         -Tv, --tag-version
210                         - add cvs tag NAME-VERSION-RELESE for files,
211         -Tp, --tag-prefix <prefix>
212                         - add <prefix> to NAME-VERSION-RELEASE tags,
213         -v, --verbose   - be verbose,
214         -u, --try-upgrade
215                         - check version, and try to upgrade package
216         -un, --try-upgrade-with-float-version
217                         - as above, but allow float version
218         -U, --update
219                         - refetch sources, don't use distfiles, and update md5 
220                           comments
221         -Upi, --update-poldek-indexes 
222                         - refresh or make poldek package index files.
223         --with/--without <feature>
224                         - conditional build package depending on
225                           %_with_<feature>/%_without_<feature> macro
226                           switch. 
227                           You may now use --with feat1 feat2 feat3 --without feat4
228                           feat5 --with feat6 constructions.
229 "
230 }
231
232 cache_rpm_dump () {
233    rpm_dump_cache=`
234         case "$RPMBUILD" in
235         rpm )
236                 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1 
237                 ;;
238         rpmbuild )
239                 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1 
240                 ;;
241         esac`
242 }
243
244 rpm_dump () {
245     if [ -z "$rpm_dump_cache" ] ; then
246         echo "internal error: cache_rpm_dump not called!" 1>&2
247     fi
248     echo "$rpm_dump_cache"
249 }
250
251 parse_spec()
252 {
253     if [ -n "$DEBUG" ]; then
254         set -x;
255         set -v;
256     fi
257
258     cd $SPECS_DIR
259
260     cache_rpm_dump
261
262     if [ "$NOSRCS" != "yes" ]; then
263         SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
264     fi
265     if (rpm_dump | grep -qEi ":.*nosource.*1"); then
266         FAIL_IF_NO_SOURCES="no"
267     fi
268
269     PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
270     ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
271     PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
272     PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
273     PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
274
275     if [ -n "$BE_VERBOSE" ]; then
276         echo "- Sources :  `nourl $SOURCES`"
277         if [ -n "$PATCHES" ]; then
278             echo "- Patches :  `nourl $PATCHES`"
279         else
280             echo "- Patches :  *no patches needed*"
281         fi
282         if [ -n "$ICONS" ]; then
283             echo "- Icon    :  `nourl $ICONS`"
284         else
285             echo "- Icon    :  *no package icon*"
286         fi
287         echo "- Name    : $PACKAGE_NAME"
288         echo "- Version : $PACKAGE_VERSION"
289         echo "- Release : $PACKAGE_RELEASE"
290     fi
291 }
292
293 Exit_error()
294 {
295     if [ -n "$DEBUG" ]; then
296         set -x;
297         set -v;
298     fi
299
300     cd $__PWD
301
302     case "$1" in
303     "err_no_spec_in_cmdl" )
304         remove_build_requires
305         echo "ERROR: spec file name not specified.";
306         exit 2 ;;
307     "err_no_spec_in_repo" )
308         remove_build_requires
309         echo "Error: spec file not stored in CVS repo.";
310         exit 3 ;;
311     "err_no_source_in_repo" )
312         remove_build_requires
313         echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
314         exit 4 ;;
315     "err_build_fail" )
316         remove_build_requires
317         echo "Error: package build failed. (${2:-no more info})";
318         exit 5 ;;
319     esac
320 }
321
322 init_builder()
323 {
324     if [ -n "$DEBUG" ]; then
325         set -x;
326         set -v;
327     fi
328
329     SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
330     SPECS_DIR="`$RPM --eval '%{_specdir}'`"
331
332     __PWD=`pwd`
333 }
334
335 get_spec()
336 {
337     if [ -n "$DEBUG" ]; then
338         set -x;
339         set -v;
340     fi
341
342     if [ "$NOCVSSPEC" != "yes" ]; then
343         cd $SPECS_DIR
344
345         OPTIONS="up "
346
347         if [ -n "$CVSROOT" ]; then
348             OPTIONS="-d $CVSROOT $OPTIONS"
349         else
350             if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
351                 echo "warning: No cvs access defined - using local .spec file"
352                 NOCVSSPEC="yes"
353             fi
354         fi
355
356         if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
357             OPTIONS="$OPTIONS -A"
358         else
359             if [ -n "$CVSDATE" ]; then
360                 OPTIONS="$OPTIONS -D $CVSDATE"
361             fi
362             if [ -n "$CVSTAG" ]; then
363                 OPTIONS="$OPTIONS -r $CVSTAG"
364             fi
365         fi
366
367         result=1
368         retries_counter=0
369         while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
370             retries_counter=$(( $retries_counter + 1 ))
371             output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
372             result=$?
373             [ -n "$output" ] && echo "$output"
374             if [ "$result" -ne "0" ]; then
375                 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
376                     echo "Trying again [$SPECFILE]... ($retries_counter)"
377                     sleep 2
378                     continue
379                 fi
380                 Exit_error err_no_spec_in_repo;
381             fi
382         done
383     fi
384     if [ ! -f "$SPECFILE" ]; then
385         Exit_error err_no_spec_in_repo;
386     fi
387
388     if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
389         chmod $CHMOD_MODE $SPECFILE
390     fi
391     unset OPTIONS
392     grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
393 }
394
395 find_mirror(){
396
397     cd "$SPECS_DIR"
398     url="$1"
399     if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
400         cvs update mirrors >&2
401     fi
402
403     IFS="|"
404     while read origin mirror name rest; do
405         ol=`echo -n "$origin"|wc -c`
406         prefix="`echo -n "$url" | head -c $ol`"
407         if [ "$prefix" = "$origin" ] ; then
408             suffix="`echo "$url"|cut -b $ol-`"
409             echo -n "$mirror$suffix"
410             return 0
411         fi
412     done < mirrors
413     echo "$url"
414 }
415
416 src_no ()
417 {
418     cd $SPECS_DIR
419     rpm_dump | \
420         grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
421         sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
422         head -1 | xargs
423 }
424
425 src_md5 ()
426 {
427     no=$(src_no "$1")
428     [ -z "$no" ] && return
429     cd $SPECS_DIR
430     spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
431     if [ -z "$spec_rev" ]; then
432         spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
433     fi
434     spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
435     md5=$(grep -s -v '^#' additional-md5sums | \
436         grep -E "[      ]$(basename "$1")[      ]+${spec}([     ,]|\$)" | \
437         sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
438         grep -E '^[0-9a-f]{32}$')
439     if [ X"$md5" = X"" ] ; then
440         grep -i "#[     ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://' | xargs
441     else
442         if [ $(echo "$md5" | wc -l) != 1 ] ; then
443             echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
444         fi
445         echo "$md5" | tail -1
446     fi
447 }
448
449 distfiles_url ()
450 {
451     echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
452 }
453
454 good_md5 ()
455 {
456     md5=$(src_md5 "$1")
457     [ "$md5" = "" ] || \
458     [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
459 }
460
461 get_files()
462 {
463     GET_FILES="$@"
464
465     if [ -n "$DEBUG" ]; then
466         set -x;
467         set -v;
468     fi
469
470     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
471         cd $SOURCE_DIR
472
473         OPTIONS="up "
474         if [ -n "$CVSROOT" ]; then
475             OPTIONS="-d $CVSROOT $OPTIONS"
476         else
477             if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
478                 echo "warning: No cvs access defined for SOURCES"
479                 NOCVS="yes"
480             fi
481         fi
482         if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
483             OPTIONS="$OPTIONS -A"
484         else
485             if [ -n "$CVSDATE" ]; then
486                 OPTIONS="$OPTIONS -D $CVSDATE"
487             fi
488             if [ -n "$CVSTAG" ]; then
489                 OPTIONS="$OPTIONS -r $CVSTAG"
490             fi
491         fi
492         for i in $GET_FILES; do
493             if [ -n "$UPDATE5" ]; then
494                 if [ -n "$ADD5" ]; then
495                     [ `nourl $i` = "$i" ] && continue
496                     grep -qiE '^#[      ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE && continue
497                 else
498                     grep -qiE '^#[      ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE || continue
499                 fi
500             fi
501             FROM_DISTFILES=0
502             if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
503                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
504                     echo "Warning: no URL given for $i"
505                 fi
506
507                 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
508                     if good_md5 "$i"; then
509                         echo "$(nourl "$i") having proper md5sum already exists"
510                         continue
511                     fi
512                     target=$(nourl "$i")
513                     url=$(distfiles_url "$i")
514                     if [ `echo $url | grep -E '^(\.|/)'` ]; then
515                         ${GETLOCAL} $url $target
516                     else
517                         FROM_DISTFILES=1
518                         if [ -z "$NOMIRRORS" ]; then
519                             url="`find_mirror "$url"`"
520                         fi
521                         ${GETURI} -O "$target" "$url" || \
522                             if [ `echo $url | grep -E 'ftp://'` ]; then
523                                 ${GETURI2} -O "$target" "$url"
524                             fi
525                         if ! test -s "$target"; then
526                             rm -f "$target"
527                             FROM_DISTFILES=0
528                         fi
529                     fi
530                 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
531                     # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
532                     result=1
533                     retries_counter=0
534                     while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
535                         retries_counter=$(( $retries_counter + 1 ))
536                         output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
537                         result=$?
538                         [ -n "$output" ] && echo "$output"
539                         if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
540                                 echo "Trying again [`nourl $i`]... ($retries_counter)"
541                                 sleep 2
542                                 continue
543                         else
544                                 break
545                         fi
546                     done
547                 fi
548
549                 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
550                     if [ -z "$NOMIRRORS" ]; then
551                         im="`find_mirror "$i"`"
552                     else
553                         im="$i"
554                     fi
555                     ${GETURI} "$im" || \
556                         if [ `echo $im | grep -E 'ftp://'` ]; then ${GETURI2} "$im" ; fi
557                 fi
558
559
560             fi
561             srcno=$(src_no $i)
562             if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
563                 Exit_error err_no_source_in_repo $i;
564             elif [ -n "$UPDATE5" ] && \
565                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
566                     [ -z "$(grep -E -i '^NoSource[      ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
567                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
568             then
569                 echo "Updating source-$srcno md5."
570                 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
571                 perl -i -ne '
572                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
573                                 print "# Source'$srcno'-md5:\t'$md5'\n" 
574                                         if /^Source'$srcno'\s*:\s+/;
575                                 ' \
576                                 $SPECS_DIR/$SPECFILE
577             fi
578
579             if good_md5 "$i"; then
580                 :
581             elif [ "$FROM_DISTFILES" = 1 ]; then
582                 # wrong md5 from distfiles: remove the file and try again
583                 # but only once ...
584                 echo "MD5 sum mismatch. Trying full fetch."
585                 FROM_DISTFILES=2
586                 rm -f $target
587                 ${GETURI} -O "$target" "$url" || \
588                     if [ `echo $url | grep -E 'ftp://'` ]; then
589                         ${GETURI2} -O "$target" "$url"
590                     fi
591                 test -s "$target" || rm -f "$target"
592             fi
593
594             if good_md5 "$i"; then
595                 :
596             else
597                 echo "MD5 sum mismatch.  Use -U to refetch sources,"
598                 echo "or -5 to update md5 sums, if you're sure files are correct."
599                 Exit_error err_no_source_in_repo $i
600             fi
601         done
602
603         if [ "$CHMOD" = "yes" ]; then
604             CHMOD_FILES="`nourl $GET_FILES`"
605             if [ -n "$CHMOD_FILES" ]; then
606                 chmod $CHMOD_MODE $CHMOD_FILES
607             fi
608         fi
609         unset OPTIONS
610     fi
611 }
612
613 tag_files()
614 {
615     TAG_FILES="$@"
616
617     if [ -n "$DEBUG" ]; then
618         set -x;
619         set -v;
620     fi
621
622     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
623         echo "Version: $PACKAGE_VERSION"
624         echo "Release: $PACKAGE_RELEASE"
625         # Check whether first character of PACKAGE_NAME is legal for tag name
626         if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
627             TAG_PREFIX=tag_
628         fi
629         TAGVER=$TAG_PREFIX$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
630         # Remove #kernel.version_release from TAGVER because tagging sources
631         # could occur with different kernel-headers than kernel-headers used at build time.
632         TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
633         if [ "$TAG_VERSION" = "yes" ]; then
634             echo "CVS tag: $TAGVER"
635         fi
636         if [ -n "$TAG" ]; then
637             echo "CVS tag: $TAG"
638         fi
639
640         OPTIONS="tag -F"
641         if [ -n "$CVSROOT" ]; then
642             OPTIONS="-d $CVSROOT $OPTIONS"
643         fi
644
645         cd $SOURCE_DIR
646         for i in $TAG_FILES; do
647             # don't tag non cvs files (ie. stored on distfiles)
648             [ "`nourl $i`" != "$i" ] && continue
649             if [ -f "`nourl $i`" ]; then
650                 if [ "$TAG_VERSION" = "yes" ]; then
651                     cvs $OPTIONS $TAGVER `nourl $i`
652                 fi
653                 if [ -n "$TAG" ]; then
654                     cvs $OPTIONS $TAG `nourl $i`
655                 fi
656             else
657                 Exit_error err_no_source_in_repo $i
658             fi
659         done
660
661         cd $SPECS_DIR
662         if [ "$TAG_VERSION" = "yes" ]; then
663             cvs $OPTIONS $TAGVER $SPECFILE
664         fi
665         if [ -n "$TAG" ]; then
666             cvs $OPTIONS $TAG $SPECFILE
667         fi
668
669         unset OPTIONS
670     fi
671 }
672
673 branch_files()
674 {
675     TAG=$1
676     echo "CVS branch tag: $TAG"
677     shift;
678
679     TAG_FILES="$@"
680
681     if [ -n "$DEBUG" ]; then
682         set -x;
683         set -v;
684     fi
685
686     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
687
688         OPTIONS="tag -b"
689         if [ -n "$CVSROOT" ]; then
690             OPTIONS="-d $CVSROOT $OPTIONS"
691         fi
692         cd $SOURCE_DIR
693         for i in $TAG_FILES; do
694             if [ -f `nourl $i` ]; then
695                 cvs $OPTIONS $TAG `nourl $i`
696             else
697                 Exit_error err_no_source_in_repo $i
698             fi
699         done
700         cd $SPECS_DIR
701         cvs $OPTIONS $TAG $SPECFILE
702
703         unset OPTIONS
704     fi
705 }
706
707
708
709 build_package()
710 {
711     if [ -n "$DEBUG" ]; then
712         set -x;
713         set -v;
714     fi
715
716     cd $SPECS_DIR
717
718     if [ -n "$TRY_UPGRADE" ]; then
719
720         if [ -n "$FLOAT_VERSION" ]; then
721             TNOTIFY=`./pldnotify.awk $SPECFILE -n`
722         else
723             TNOTIFY=`./pldnotify.awk $SPECFILE`
724         fi
725
726         TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
727
728         if [ -n "$TNEWVER" ]; then
729
730             TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
731
732             echo "New version found, updating spec file to version " $TNEWVER
733
734             cp -f $SPECFILE $SPECFILE.bak
735
736             chmod +w $SPECFILE
737
738             eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
739             eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
740
741             parse_spec;
742
743             get_files "$SOURCES $PATCHES";
744
745             unset TOLDVER TNEWVER TNOTIFY
746         fi
747
748     fi
749
750
751     cd $SPECS_DIR
752
753     case "$COMMAND" in
754         build )
755             BUILD_SWITCH="-ba" ;;
756         build-binary )
757             BUILD_SWITCH="-bb" ;;
758         build-source )
759             BUILD_SWITCH="-bs --nodeps" ;;
760         build-prep )
761             BUILD_SWITCH="-bp --nodeps" ;;
762     esac
763     if [ -n "$LOGFILE" ]; then
764         LOG=`eval echo $LOGFILE`
765         if [ -n "$LASTLOG_FILE" ]; then
766             echo "LASTLOG=$LOG" > $LASTLOG_FILE
767         fi
768         RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
769         (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
770         RETVAL=`cat $RES_FILE`
771         rm $RES_FILE
772         if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
773             if [ "$RETVAL" -eq "0" ]; then
774                 mv $LOG $LOGDIROK
775             else
776                 mv $LOG $LOGDIRFAIL
777             fi
778         fi
779     else
780         eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
781         RETVAL=$?
782     fi
783
784     if [ "$RETVAL" -ne "0" ]; then
785
786         if [ -n "$TRY_UPGRADE" ]; then
787             echo "\n!!! Package with new version cannot be build automagically\n"
788             mv -f $SPECFILE.bak $SPECFILE
789         fi
790
791         Exit_error err_build_fail;
792     fi
793
794     unset BUILD_SWITCH
795 }
796
797 nourl()
798 {
799     echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
800 }
801
802 set_bconds_values()
803 {
804 AVAIL_BCONDS_WITHOUT=""
805 AVAIL_BCONDS_WITH=""
806 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
807 do
808         AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
809         if [ "`echo $BCOND|grep -- "--without $AVAIL_BCOND_WITHOUT"`" != "" ];then
810                 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
811         else
812                 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
813         fi
814 done
815
816 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
817 do
818         AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
819         if [ "`echo $BCOND|grep -- "--with $AVAIL_BCOND_WITH"`" != "" ];then
820                 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
821         else
822                 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
823         fi
824 done
825 }
826
827 run_sub_builder()
828 {
829                                                 package_name="${1}"
830                                                 echo -ne "Package installation failed:\t$package_name\n"
831                                                 #
832                                                 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
833                                                 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
834                                                 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
835                                                 # jakby nie bylo tego kawalka kodu.
836                                                 #
837                                                 # y0shi.
838
839                                                 parent_spec_name=''
840
841                                                 # Istnieje taki spec? ${package}.spec
842                                                 if [ -f "${POLDEK_INDEX_DIR}/SPECS/${package}.spec" ]; then
843                                                         parent_spec_name=${package}.spec
844                                                 else            
845                                                         minus_pos=`echo $package_name | sed 's/[^-]//g' |tr -d "\n" | wc -c|awk '{print $1}'`
846                                                         if [ "${minus_pos}" != "" ]; then
847                                                                 if [ "${minus_pos}" != "0" ]; then
848                                                                         parent_pkg_name=`echo $package_name|cut -d - -f $minus_pos`
849                                                                         if [ -f "${POLDEK_INDEX_DIR}/SPECS/${parent_pkg_name}.spec" ]; then
850                                                                                 parent_spec_name="${parent_pkg_name}.spec"
851                                                                         fi
852                                                                 fi
853                                                         else
854                                                                 for provides_line in `grep ^Provides:.*$package  ${POLDEK_INDEX_DIR}/ -R`
855                                                                 do
856                                                                         echo $provides_line
857                                                                 done
858                                                         fi
859                                                 fi
860
861                                                 if [ "${parent_spec_name}" != "" ]; then
862                                                         sub_builder_opts=''
863                                                         if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
864                                                                 sub_builder_opts="${sub_builder_opts} -R"
865                                                         fi
866                                                         if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
867                                                                 sub_builder_opts="${sub_builder_opts} -RB"
868                                                         elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
869                                                                 sub_builder_opts="${sub_builder_opts} -FRB"
870                                                         fi
871                                                         if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
872                                                                 sub_builder_opts="${sub_builder_opts} -Upi"
873                                                         fi
874                                                         cd "${POLDEK_INDEX_DIR}/SPECS"
875                                                         ./builder ${sub_builder_opts} ${parent_spec_name}
876                                                 fi
877
878
879                                                 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
880
881 }
882
883 remove_build_requires()
884 {
885     if [ "$INSTALLED_PACKAGES" != "" ]; then
886             case "$REMOVE_BUILD_REQUIRES" in
887                     "force")
888                         poldek --noask -e $INSTALLED_PACKAGES
889                     ;;
890                     "nice")
891                         poldek --ask -e $INSTALLED_PACKAGES
892                     ;;
893                     *)
894                             echo You may want to manually remove following BuildRequires fetched:
895                             echo $INSTALLED_PACKAGES
896                             echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
897                     ;;
898             esac
899     fi
900 }
901
902 display_bconds()
903 {
904 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
905         echo -ne "We are going to build $SPECFILE with the following conditional flags:\n"
906         if [ "$BCOND" != "" ]; then
907                 echo -ne "$BCOND"
908         else
909                 echo -ne "No --with || --without conditions passed to $0!"
910         fi
911         echo -ne "\n\nfrom available:\n\n"
912         echo -ne "--with   :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
913 fi
914 }
915
916 fetch_build_requires()
917 {
918 if [ "$FETCH_BUILD_REQUIRES" = "yes" ]; then
919             echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
920             echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
921             echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
922             echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
923             echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
924             for package_item in `cat $SPECFILE|grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'|sed -e s,\(.*\),,g -e s,%{,,g`
925             do
926                 package_item="`echo $package_item|sed -e s,rpmbuild,rpm-build,g |sed -e s,__perl,perl,g |sed -e s,gasp,binutils-gasp,g |sed -e s,apxs,apache,g|sed -e s,apache\(EAPI\)-devel,apache-devel,g`"
927                 GO="yes"
928                 package=`basename "$package_item"|sed -e "s/}$//g"`
929                 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
930                 mach=`uname -m`
931                 
932                 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
933                 if [ "`echo $COND_TST|grep '^BuildRequires:'`" != "" ]; then
934                         if [ "$COND_ARCH_TST" != "" ] && [ "`echo $COND_ARCH_TST|sed -e "s/i.86/ix86/g"`" != "`echo $mach|sed -e "s/i.86/ix86/g"`" ]; then
935                                 GO="yes"
936                         fi
937                 # bcond:
938                 else
939                         COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
940                         GO=""
941                         # %{without}
942                         if [ "`echo $COND_TST|grep 'without_'`" != "" ]; then
943                                 COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
944                                 if [ "`echo $COND_TST|grep !`" != "" ]; then
945                                         COND_STATE="with"
946                                 else
947                                         COND_STATE="wout"
948                                 fi
949                                 if [ "`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`" != "" ]; then
950                                         COND_ARGV="wout"
951                                 else
952                                         COND_ARGV="with"
953                                 fi
954                         # %{with}
955                         elif [ "`echo $COND_TST|grep 'with_'`" != "" ]; then
956                                 COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
957                                 if [ "`echo $COND_TST|grep !`" != "" ]; then
958                                         COND_STATE="wout"
959                                 else
960                                         COND_STATE="with"
961                                 fi                                      
962                                 if [ "`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`" != "" ]; then
963                                         COND_ARGV="with"
964                                 else
965                                         COND_ARGV="wout"
966                                 fi      
967                         fi
968                         RESULT="${COND_STATE}-${COND_ARGV}"
969                         case "$RESULT" in 
970                                 "with-wout" | "wout-with" )
971                                         GO=""
972                                         ;;
973                                 "wout-wout" | "with-with" )
974                                         GO="yes"
975                                         ;;
976                                 * )
977                                         echo "Action '$RESULT' was not defined for package '$package_item'"
978                                         ;;
979                         esac
980
981                 fi
982                
983                 if [ "$GO" = "yes" ]; then
984                         if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
985                                 echo "Testing if $package has subrequirements..."
986                                 poldek -t -i $package --dumpn=".$package-req.txt"
987                                 if [ -f ".$package-req.txt" ]; then
988                                         for package_name in `cat ".$package-req.txt"|grep -v ^#`
989                                         do 
990                                                 if [ "$package_name" = "$package" ]; then
991                                                         echo -ne "Installing BuildRequired package:\t$package_name\n"
992                                                         export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
993                                                         poldek -i $package_name
994                                                 else
995                                                         echo -ne "Installing (sub)Required package:\t$package_name\n"
996                                                         export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
997                                                         poldek -i $package_name
998                                                 fi
999                                                 case $? in
1000                                                 0)
1001                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1002                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1003                                                         ;;
1004                                                 *)
1005                                                         run_sub_builder $package_name
1006                                                         ;;
1007                                                 esac
1008                                         done
1009                                         rm -f ".$package-req.txt"
1010                                 else
1011                                         run_sub_builder $package
1012                                 fi
1013                         else
1014                                 echo "Package $package is already installed. BuildRequirement satisfied."
1015                         fi
1016                 fi
1017             done
1018             export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1019             if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1020                     echo "Nie uda³o siê zainstalowaæ nastêpuj±cych pakietów i ich zale¿no¶ci:"
1021                     for pkg in "$NOT_INSTALLED_PACKAGES"
1022                     do
1023                             echo $pkg
1024                     done
1025                     remove_build_requires
1026                     exit 1
1027             fi
1028 fi
1029 }
1030
1031 #---------------------------------------------
1032 # main()
1033
1034 if [ "$#" = 0 ]; then
1035     usage;
1036     exit 1
1037 fi
1038
1039 while test $# -gt 0 ; do
1040     case "${1}" in
1041         -5 | --update-md5 )
1042             COMMAND="get";
1043             NODIST="yes"
1044             NOCVSSPEC="yes"
1045             UPDATE5="yes"
1046             shift ;;
1047         -a5 | --add-md5 )
1048             COMMAND="get";
1049             NODIST="yes"
1050             NOCVS="yes"
1051             NOCVSSPEC="yes"
1052             UPDATE5="yes"
1053             ADD5="yes"
1054             shift ;;
1055         -D | --debug )
1056             DEBUG="yes"; shift ;;
1057         -V | --version )
1058             COMMAND="version"; shift ;;
1059         -a | --as_anon )
1060             CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1061         -b | -ba | --build )
1062             COMMAND="build"; shift ;;
1063         -bb | --build-binary )
1064             COMMAND="build-binary"; shift ;;
1065         -bs | --build-source )
1066             COMMAND="build-source"; shift ;;
1067         -bp | --build-prep )
1068             COMMAND="build-prep"; shift ;;
1069         -B | --branch )
1070             COMMAND="branch"; shift; TAG="${1}"; shift;;
1071         -c | --clean )
1072             CLEAN="--clean --rmspec --rmsource"; shift ;;
1073         -d | --cvsroot )
1074             shift; CVSROOT="${1}"; shift ;;
1075         -g | --get )
1076             COMMAND="get"; shift ;;
1077         -h | --help )
1078             COMMAND="usage"; shift ;;
1079         --http )
1080             PROTOCOL="http"; shift ;;
1081         -l | --logtofile )
1082             shift; LOGFILE="${1}"; shift ;;
1083         -ni| --nice )
1084             shift; DEF_NICE_LEVEL=${1}; shift ;;
1085         -m | --mr-proper )
1086             COMMAND="mr-proper"; shift ;;
1087         -nc | --no-cvs )
1088             NOCVS="yes"; shift ;;
1089         -ncs | --no-cvs-specs )
1090             NOCVSSPEC="yes"; shift ;;
1091         -nd | --no-distfiles )
1092             NODIST="yes"; shift ;;
1093         -nm | --no-mirrors )
1094             NOMIRRORS="yes"; shift ;;
1095         -nu | --no-urls )
1096             NOURLS="yes"; shift ;;
1097         -ns | --no-srcs )
1098             NOSRCS="yes"; shift ;;
1099         -ns0 | --no-source0 )
1100             NOSOURCE0="yes"; shift ;;
1101         --opts )
1102             shift; RPMOPTS="${1}"; shift ;;
1103         --with | --without )
1104             case $GROUP_BCONDS in
1105                 "yes")
1106                         COND=${1}
1107                         shift
1108                         while [ "`echo ${1}|grep ^-`" = "" ] && [ "`echo ${1}|grep spec`" = "" ]
1109                         do
1110                                 BCOND="$BCOND $COND $1"
1111                                 shift
1112                         done;;
1113                 "no")
1114                         BCOND="$BCOND $1 $2" ; shift 2 ;;
1115             esac
1116             ;;
1117         -q | --quiet )
1118             QUIET="--quiet"; shift ;;
1119         --date )
1120             CVSDATE="${2}"; shift 2 ;;
1121         -r | --cvstag )
1122             shift; CVSTAG="${1}"; shift ;;
1123         -R | --fetch-build-requires)
1124             FETCH_BUILD_REQUIRES="yes"
1125             #UPDATE_POLDEK_INDEXES="yes"
1126             NOT_INSTALLED_PACKAGES=
1127             shift ;;
1128         -RB | --remove-build-requires)
1129             REMOVE_BUILD_REQUIRES="nice"
1130             shift ;;
1131         -FRB | --force-remove-build-requires)
1132             REMOVE_BUILD_REQUIRES="force"
1133             shift ;;
1134         -Tvs | --tag-version-stable )
1135             COMMAND="tag";
1136             TAG="STABLE"
1137             TAG_VERSION="yes"
1138             shift;;
1139         -Tvn | --tag-version-nest )
1140             COMMAND="tag";
1141             TAG="NEST"
1142             TAG_VERSION="yes"
1143             shift;;
1144         -Ts | --tag-stable )
1145             COMMAND="tag";
1146             TAG="STABLE"
1147             TAG_VERSION="no"
1148             shift;;
1149         -Tn | --tag-nest )
1150             COMMAND="tag";
1151             TAG="NEST"
1152             TAG_VERSION="no"
1153             shift;;
1154         -Tv | --tag-version )
1155             COMMAND="tag";
1156             TAG=""
1157             TAG_VERSION="yes"
1158             shift;;
1159         -Tp | --tag-prefix )
1160             TAG_PREFIX="$2"
1161             shift 2;;
1162         -T | --tag )
1163             COMMAND="tag";
1164             shift
1165             TAG="$1"
1166             TAG_VERSION="no"
1167             shift;;
1168         -U | --update )
1169             COMMAND="get"
1170             UPDATE="yes"
1171             NOCVSSPEC="yes"
1172             NODIST="yes"
1173             UPDATE5="yes"
1174             shift ;;
1175         -Upi | --update-poldek-indexes )
1176             UPDATE_POLDEK_INDEXES="yes"
1177             shift ;;
1178         -u | --try-upgrade )
1179             TRY_UPGRADE="1"; shift ;;
1180         -un | --try-upgrade-with-float-version )
1181             TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1182         -v | --verbose )
1183             BE_VERBOSE="1"; shift ;;
1184         --define)
1185             shift
1186             MACRO="${1}"
1187             VALUE="${2}"
1188             shift 2
1189             RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1190             ;;
1191         --nodeps)
1192             shift
1193             RPMOPTS="${RPMOPTS} --nodeps"
1194             ;;
1195         * )
1196             SPECFILE="`basename ${1} .spec`.spec"; 
1197             export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1198             shift ;;
1199     esac
1200 done
1201
1202 if [ -n "$DEBUG" ]; then
1203     set -x;
1204     set -v;
1205 fi
1206
1207 case "$COMMAND" in
1208     "build" | "build-binary" | "build-source" | "build-prep" )
1209         init_builder;
1210         if [ -n "$SPECFILE" ]; then
1211             get_spec;
1212             set_bconds_values;
1213             display_bconds;
1214             fetch_build_requires;
1215             parse_spec;
1216
1217             if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
1218                 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1219                 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
1220                 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1221
1222                 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
1223                     Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
1224                 fi
1225             fi
1226
1227             if [ -n "$ICONS" ]; then
1228                 get_files $ICONS;
1229                 parse_spec;
1230             fi
1231             if [ -n "$NOSOURCE0" ] ; then
1232                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1233             fi
1234             get_files "$SOURCES $PATCHES";
1235             build_package;
1236             if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1237                     poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1238                     poldek --sn ${POLDEK_SOURCE} --up
1239             fi
1240             remove_build_requires;
1241         else
1242             Exit_error err_no_spec_in_cmdl;
1243         fi
1244         ;;
1245     "branch" )
1246         init_builder;
1247         if [ -n "$SPECFILE" ]; then
1248                 get_spec;
1249                 parse_spec;
1250                 if [ -n "$ICONS" ]; then
1251                         get_files $ICONS
1252                         parse_spec;
1253                 fi
1254                 get_files $SOURCES $PATCHES;
1255                 branch_files $TAG "$SOURCES $PATCHES $ICONS";
1256         else
1257                 Exit_error err_no_spec_in_cmdl;
1258         fi
1259         ;;
1260     "get" )
1261         init_builder;
1262         if [ -n "$SPECFILE" ]; then
1263             get_spec;
1264             parse_spec;
1265             if [ -n "$ICONS" ]; then
1266                 get_files $ICONS
1267                 parse_spec;
1268             fi
1269             if [ -n "$NOSOURCE0" ] ; then
1270                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1271             fi
1272             get_files $SOURCES $PATCHES
1273         else
1274             Exit_error err_no_spec_in_cmdl;
1275         fi
1276         ;;
1277     "tag" )
1278         init_builder;
1279         if [ -n "$SPECFILE" ]; then
1280             get_spec;
1281             parse_spec;
1282             if [ -n "$ICONS" ]; then
1283                 get_files $ICONS
1284                 parse_spec;
1285             fi
1286             # don't fetch sources from remote locations
1287             new_SOURCES=""
1288             for file in $SOURCES; do
1289                 [ "`nourl $file`" != "$file" ] && continue
1290                 new_SOURCES="$new_SOURCES $file"
1291             done
1292             SOURCES="$new_SOURCES"
1293             get_files $SOURCES $PATCHES;
1294             tag_files "$SOURCES $PATCHES $ICONS";
1295         else
1296             Exit_error err_no_spec_in_cmdl;
1297         fi
1298         ;;
1299     "mr-proper" )
1300         $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1301         ;;
1302     "usage" )
1303         usage;;
1304     "version" )
1305         echo "$VERSION";;
1306 esac
1307 cd $__PWD
This page took 0.146041 seconds and 2 git commands to generate.