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