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