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