]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
- new feature: add files fetched via distfiles to SOURCES/.cvsignore
[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 distfiles_url ()
487 {
488         echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
489 }
490
491 distfiles_attic_url ()
492 {
493         echo "$PROTOCOL$DISTFILES_SERVER/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
494 }
495
496 good_md5 ()
497 {
498         md5=$(src_md5 "$1")
499         [ "$md5" = "" ] || \
500         [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
501 }
502
503 cvsignore_df ()
504 {
505         if [ "$CVSIGNORE_DF" != "yes" ]; then
506                 return
507         fi
508         cvsignore=${SOURCE_DIR}/.cvsignore
509         if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
510                 echo "$1" >> $cvsignore
511         fi
512 }
513
514 get_files()
515 {
516         GET_FILES="$@"
517
518         if [ -n "$DEBUG" ]; then
519                 set -x;
520                 set -v;
521         fi
522
523         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
524                 cd "$SOURCE_DIR"
525
526                 OPTIONS="up "
527                 if [ -n "$CVSROOT" ]; then
528                         OPTIONS="-d $CVSROOT $OPTIONS"
529                 else
530                         if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
531                                 echo "warning: No cvs access defined for SOURCES"
532                                 NOCVS="yes"
533                         fi
534                 fi
535                 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
536                         OPTIONS="$OPTIONS -A"
537                 else
538                         if [ -n "$CVSDATE" ]; then
539                                 OPTIONS="$OPTIONS -D $CVSDATE"
540                         fi
541                         if [ -n "$CVSTAG" ]; then
542                                 OPTIONS="$OPTIONS -r $CVSTAG"
543                         fi
544                 fi
545                 for i in $GET_FILES
546                 do
547                         if [ -n "$UPDATE5" ]; then
548                                 if [ -n "$ADD5" ]; then
549                                         [ `nourl $i` = "$i" ] && continue
550                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE && continue
551                                 else
552                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE || continue
553                                 fi
554                         fi
555                         FROM_DISTFILES=0
556                         if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
557                                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
558                                         echo "Warning: no URL given for $i"
559                                 fi
560
561                                 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
562                                         if good_md5 "$i"; then
563                                                 echo "$(nourl "$i") having proper md5sum already exists"
564                                                 continue
565                                         fi
566                                         target=$(nourl "$i")
567                                         url=$(distfiles_url "$i")
568                                         url_attic=$(distfiles_attic_url "$i")
569                                         FROM_DISTFILES=1
570                                         if [ `echo $url | grep -E '^(\.|/)'` ]; then
571                                                 ${GETLOCAL} $url $target
572                                         else
573                                                 if [ -z "$NOMIRRORS" ]; then
574                                                         url="`find_mirror "$url"`"
575                                                 fi
576                                                 ${GETURI} -O "$target" "$url" || \
577                                                 if [ `echo $url | grep -E 'ftp://'` ]; then
578                                                         ${GETURI2} -O "$target" "$url"
579                                                 fi
580                                         fi
581                                         if ! test -s "$target"; then
582                                                 rm -f "$target"
583                                                 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
584                                                         ${GETLOCAL} $url_attic $target
585                                                 else
586                                                         if [ -z "$NOMIRRORS" ]; then
587                                                                 url_attic="`find_mirror "$url_attic"`"
588                                                         fi
589                                                         ${GETURI} -O "$target" "$url_attic" || \
590                                                         if [ `echo $url_attic | grep -E 'ftp://'` ]; then
591                                                                 ${GETURI2} -O "$target" "$url_attic"
592                                                         fi
593                                                 fi
594                                         fi
595                                         if test -s "$target"; then
596                                                 cvsignore_df $target
597                                         else
598                                                 rm -f "$target"
599                                                 FROM_DISTFILES=0
600                                         fi
601                                 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
602                                         # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
603                                         result=1
604                                         retries_counter=0
605                                         while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
606                                         do
607                                                 retries_counter=$(( $retries_counter + 1 ))
608                                                 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
609                                                 result=$?
610                                                 [ -n "$output" ] && echo "$output"
611                                                 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
612                                                         echo "Trying again [`nourl $i`]... ($retries_counter)"
613                                                         sleep 2
614                                                         continue
615                                                 else
616                                                         break
617                                                 fi
618                                         done
619                                 fi
620
621                                 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
622                                         if [ -z "$NOMIRRORS" ]; then
623                                                 im="`find_mirror "$i"`"
624                                         else
625                                                 im="$i"
626                                         fi
627                                         ${GETURI} "$im" || \
628                                         if [ `echo $im | grep -E 'ftp://'` ]; then
629                                                 ${GETURI2} "$im"
630                                         fi
631                                 fi
632
633                         fi
634                         srcno=$(src_no $i)
635                         if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
636                                 Exit_error err_no_source_in_repo $i;
637                         elif [ -n "$UPDATE5" ] && \
638                                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
639                                 [ -z "$(grep -E -i '^NoSource[  ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
640                                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
641                         then
642                                 echo "Updating source-$srcno md5."
643                                 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
644                                 perl -i -ne '
645                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
646                                 print "# Source'$srcno'-md5:\t'$md5'\n"
647                                 if /^Source'$srcno'\s*:\s+/;
648                                 ' \
649                                 $SPECS_DIR/$SPECFILE
650                         fi
651         
652                         if good_md5 "$i"; then
653                                 :
654                         elif [ "$FROM_DISTFILES" = 1 ]; then
655                                 # wrong md5 from distfiles: remove the file and try again
656                                 # but only once ...
657                                 echo "MD5 sum mismatch. Trying full fetch."
658                                 FROM_DISTFILES=2
659                                 rm -f $target
660                                 ${GETURI} -O "$target" "$url" || \
661                                 if [ `echo $url | grep -E 'ftp://'` ]; then
662                                         ${GETURI2} -O "$target" "$url"
663                                 fi
664                                 if ! test -s "$target"; then
665                                         rm -f "$target"
666                                         ${GETURI} -O "$target" "$url_attic" || \
667                                         if [ `echo $url_attic | grep -E 'ftp://'` ]; then
668                                                 ${GETURI2} -O "$target" "$url_attic"
669                                         fi
670                                 fi
671                                 test -s "$target" || rm -f "$target"
672                         fi
673
674                         if good_md5 "$i"; then
675                                 :
676                         else
677                                 echo "MD5 sum mismatch.  Use -U to refetch sources,"
678                                 echo "or -5 to update md5 sums, if you're sure files are correct."
679                                 Exit_error err_no_source_in_repo $i
680                         fi
681                 done
682
683                 if [ "$CHMOD" = "yes" ]; then
684                         CHMOD_FILES="`nourl $GET_FILES`"
685                         if [ -n "$CHMOD_FILES" ]; then
686                                 chmod $CHMOD_MODE $CHMOD_FILES
687                         fi
688                 fi
689                 unset OPTIONS
690         fi
691 }
692
693 make_tagver() {
694                 # Check whether first character of PACKAGE_NAME is legal for tag name
695                 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
696                         TAG_PREFIX=tag_
697                 fi
698                 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"`
699                 # Remove #kernel.version_release from TAGVER because tagging sources
700                 # could occur with different kernel-headers than kernel-headers used at build time.
701                 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
702                 echo -n "$TAGVER"
703 }
704
705 tag_files()
706 {
707         TAG_FILES="$@"
708
709         if [ -n "$DEBUG" ]; then
710                 set -x;
711                 set -v;
712         fi
713
714         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
715                 echo "Version: $PACKAGE_VERSION"
716                 echo "Release: $PACKAGE_RELEASE"
717
718                 TAGVER=`make_tagver`
719
720                 if [ "$TAG_VERSION" = "yes" ]; then
721                         echo "CVS tag: $TAGVER"
722                 fi
723                 if [ -n "$TAG" ]; then
724                         echo "CVS tag: $TAG"
725                 fi
726
727                 OPTIONS="tag -F"
728                 if [ -n "$CVSROOT" ]; then
729                         OPTIONS="-d $CVSROOT $OPTIONS"
730                 fi
731
732                 cd "$SOURCE_DIR"
733                 for i in $TAG_FILES
734                 do
735                         # don't tag files stored on distfiles
736                         [ -n "`src_md5 $i`" ] && continue
737                         if [ -f "`nourl $i`" ]; then
738                                 if [ "$TAG_VERSION" = "yes" ]; then
739                                         cvs $OPTIONS $TAGVER `nourl $i`
740                                 fi
741                                 if [ -n "$TAG" ]; then
742                                         cvs $OPTIONS $TAG `nourl $i`
743                                 fi
744                         else
745                                 Exit_error err_no_source_in_repo $i
746                         fi
747                 done
748
749                 cd "$SPECS_DIR"
750                 if [ "$TAG_VERSION" = "yes" ]; then
751                         cvs $OPTIONS $TAGVER $SPECFILE
752                 fi
753                 if [ -n "$TAG" ]; then
754                         cvs $OPTIONS $TAG $SPECFILE
755                 fi
756
757                 unset OPTIONS
758         fi
759 }
760
761 branch_files()
762 {
763         TAG=$1
764         echo "CVS branch tag: $TAG"
765         shift;
766
767         TAG_FILES="$@"
768
769         if [ -n "$DEBUG" ]; then
770                 set -x;
771                 set -v;
772         fi
773
774         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
775
776                 OPTIONS="tag -b"
777                 if [ -n "$CVSROOT" ]; then
778                         OPTIONS="-d $CVSROOT $OPTIONS"
779                 fi
780                 cd "$SOURCE_DIR"
781                 for i in $TAG_FILES
782                 do
783                         if [ -f `nourl $i` ]; then
784                                 cvs $OPTIONS $TAG `nourl $i`
785                         else
786                                 Exit_error err_no_source_in_repo $i
787                         fi
788                 done
789                 cd "$SPECS_DIR"
790                 cvs $OPTIONS $TAG $SPECFILE
791
792                 unset OPTIONS
793         fi
794 }
795
796
797
798 build_package()
799 {
800         if [ -n "$DEBUG" ]; then
801                 set -x;
802                 set -v;
803         fi
804
805         cd "$SPECS_DIR"
806
807         if [ -n "$TRY_UPGRADE" ]; then
808                 if [ -n "$FLOAT_VERSION" ]; then
809                         TNOTIFY=`./pldnotify.awk $SPECFILE -n`
810                 else
811                         TNOTIFY=`./pldnotify.awk $SPECFILE`
812                 fi
813
814                 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
815
816                 if [ -n "$TNEWVER" ]; then
817                         TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
818                         echo "New version found, updating spec file to version " $TNEWVER
819                         cp -f $SPECFILE $SPECFILE.bak
820                         chmod +w $SPECFILE
821                         eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
822                         eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
823                         parse_spec;
824                         get_files "$SOURCES $PATCHES";
825                         unset TOLDVER TNEWVER TNOTIFY
826                 fi
827         fi
828         cd "$SPECS_DIR"
829         
830         if [ -n "$TARGET" ]; then 
831                 TARGET_SWITCH="--target $TARGET"
832         fi
833         
834         case "$COMMAND" in
835                 build )
836                         BUILD_SWITCH="-ba" ;;
837                 build-binary )
838                         BUILD_SWITCH="-bb" ;;
839                 build-source )
840                         BUILD_SWITCH="-bs --nodeps" ;;
841                 build-prep )
842                         BUILD_SWITCH="-bp --nodeps" ;;
843         esac
844         if [ -n "$LOGFILE" ]; then
845                 LOG=`eval echo $LOGFILE`
846                 if [ -d "$LOG" ]; then
847                         echo "Log file $LOG is a directory."
848                         echo "Parse error in the spec?"
849                         Exit_error err_build_fail;
850                 fi
851                 if [ -n "$LASTLOG_FILE" ]; then
852                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
853                 fi
854                 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
855                 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH $TARGET_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
856                 RETVAL=`cat $RES_FILE`
857                 rm $RES_FILE
858                 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
859                         if [ "$RETVAL" -eq "0" ]; then
860                                 mv $LOG $LOGDIROK
861                         else
862                                 mv $LOG $LOGDIRFAIL
863                         fi
864                 fi
865         else
866                 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH $TARGET_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
867                 RETVAL=$?
868         fi
869         if [ "$RETVAL" -ne "0" ]; then
870                 if [ -n "$TRY_UPGRADE" ]; then
871                         echo "\n!!! Package with new version cannot be build automagically\n"
872                         mv -f $SPECFILE.bak $SPECFILE
873                 fi
874                 Exit_error err_build_fail;
875         fi
876         unset BUILD_SWITCH
877         unset TARGET_SWITCH
878 }
879
880 nourl()
881 {
882         echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
883 }
884
885
886 install_required_packages()
887 {
888         run_poldek -vi $1
889         return $?
890 }
891
892 set_bconds_values()
893 {
894         AVAIL_BCONDS_WITHOUT=""
895         AVAIL_BCONDS_WITH=""
896         if `grep -q ^%bcond ${SPECFILE}`; then
897                 BCOND_VERSION="NEW"
898         elif `egrep -q ^#\ *_with ${SPECFILE}`; then
899                 BCOND_VERSION="OLD"
900         else
901                 BCOND_VERSION="NONE"
902         fi
903         case "${BCOND_VERSION}" in
904                  NONE)
905                         :
906                         ;;
907                  OLD)
908                         echo "Warning: This spec has old style bconds. Fix it || die."
909                         for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
910                         do
911                                 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
912                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
913                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
914                                 else
915                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
916                                 fi
917                         done
918                 
919                         for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
920                         do
921                                 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
922                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
923                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
924                                 else
925                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
926                                 fi
927                         done
928                         ;;
929                 NEW)
930                         cond_type="" # with || without
931                         for opt in `$RPMBUILD --bcond $SPECFILE`
932                         do
933                                 case "$opt" in
934                                         _without)
935                                                 cond_type="without"
936                                                 ;;
937                                         _with)
938                                                 cond_type="with"
939                                                 ;;
940                                         *)
941                                                 case "$cond_type" in
942                                                         with)
943                                                                 cond_type=''
944                                                                 AVAIL_BCOND_WITH="$opt"
945                                                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
946                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
947                                                                 else
948                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
949                                                                 fi
950                                                                 ;;
951                                                         without)
952                                                                 cond_type=''
953                                                                 AVAIL_BCOND_WITHOUT="$opt"
954                                                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
955                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
956                                                                 else
957                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
958                                                                 fi
959                                                                 ;;
960                                                 esac
961                                                 ;;
962                                 esac
963                         done
964                         ;;
965         esac
966 }
967
968 run_sub_builder()
969 {
970         package_name="${1}"
971         echo -ne "Package installation failed:\t$package_name\n"
972         #
973         # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
974         # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
975         # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
976         # jakby nie bylo tego kawalka kodu.
977         #
978         # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
979         #         Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
980         #
981         #
982         # y0shi.
983
984         parent_spec_name=''
985
986
987         # Istnieje taki spec? ${package}.spec
988         if [ -f "${SPECS_DIR}${package}.spec" ]; then
989                 parent_spec_name=${package}.spec
990         elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
991                 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
992         else
993                 for provides_line in `grep ^Provides:.*$package  ${SPECS_DIR} -R`
994                 do
995                         echo $provides_line
996                 done
997         fi
998
999         if [ "${parent_spec_name}" != "" ]; then
1000                 sub_builder_opts=''
1001                 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
1002                         sub_builder_opts="${sub_builder_opts} -R"
1003                 fi
1004                 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
1005                         sub_builder_opts="${sub_builder_opts} -RB"
1006                 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
1007                         sub_builder_opts="${sub_builder_opts} -FRB"
1008                 fi
1009                 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
1010                         sub_builder_opts="${sub_builder_opts} -Upi"
1011                 fi
1012                 cd "${SPECS_DIR}"
1013                 ./builder ${sub_builder_opts} ${parent_spec_name}
1014         fi
1015         NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1016 }
1017
1018 remove_build_requires()
1019 {
1020         if [ "$INSTALLED_PACKAGES" != "" ]; then
1021                 case "$REMOVE_BUILD_REQUIRES" in
1022                         "force")
1023                                 run_poldek --noask -ve $INSTALLED_PACKAGES
1024                                 ;;
1025                         "nice")
1026                                 run_poldek --ask -ve $INSTALLED_PACKAGES
1027                                 ;;
1028                         *)
1029                                 echo You may want to manually remove following BuildRequires fetched:
1030                                 echo $INSTALLED_PACKAGES
1031                                 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1032                                 ;;
1033                 esac
1034         fi
1035 }
1036
1037 display_bconds()
1038 {
1039         if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1040                 if [ "$BCOND" != "" ]; then
1041                         echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1042                         echo -ne "$BCOND"
1043                 else
1044                         echo -ne "\nNo conditional flags passed"
1045                 fi
1046                 echo -ne "\n\nfrom available:\n"
1047                 echo -ne "--with   :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1048         fi
1049 }
1050
1051 fetch_build_requires()
1052 {
1053         if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1054                 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1055                          CONF=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print "@" $3 } ' | xargs)
1056                          DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print "@" $3 } ' | xargs)
1057                          if [ -n "$CONF" -o -n "$DEPS" ]; then
1058                                   /usr/bin/poldek --update; /usr/bin/poldek --upa
1059                          fi
1060                          if [ -n "$CONF" ]; then
1061                                   echo "Trying to uninstall conflicting packages ($CONF):"
1062                                   /usr/bin/poldek --noask --nofollow -ev $CONF
1063                          fi
1064                          if [ -n "$DEPS" ]; then
1065                                   echo "Trying to install dependencies ($DEPS):"
1066                                   /usr/bin/poldek --caplookup -uGv $DEPS
1067                          fi
1068                          return
1069                 fi
1070                  
1071                 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1072                 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1073                 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1074                 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1075                 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1076                 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`
1077                 do
1078                         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`"
1079                         GO="yes"
1080                         package=`basename "$package_item"|sed -e "s/}$//g"`
1081                         COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1082                         mach=`uname -m`
1083                 
1084                         COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1085                         if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1086                                 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
1087                                         GO="yes"
1088                                 fi
1089                         # bcond:
1090                         else
1091                                 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1092                                 GO=""
1093                                 # %{without}
1094                                 if `echo $COND_TST|grep -q 'without_'`; then
1095                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1096                                         if `echo $COND_TST|grep -q !`; then
1097                                                 COND_STATE="with"
1098                                         else
1099                                                 COND_STATE="wout"
1100                                         fi
1101                                         if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1102                                                 COND_ARGV="wout"
1103                                         else
1104                                                 COND_ARGV="with"
1105                                         fi
1106                                 # %{with}
1107                                 elif `echo $COND_TST|grep -q 'with_'`; then
1108                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1109                                         if `echo $COND_TST|grep -q !`; then
1110                                                 COND_STATE="wout"
1111                                         else
1112                                                 COND_STATE="with"
1113                                         fi                                      
1114                                         if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1115                                                 COND_ARGV="with"
1116                                         else
1117                                                 COND_ARGV="wout"
1118                                         fi      
1119                                 fi
1120                                 RESULT="${COND_STATE}-${COND_ARGV}"
1121                                 case "$RESULT" in
1122                                         "with-wout" | "wout-with" )
1123                                                 GO=""
1124                                                 ;;
1125                                         "wout-wout" | "with-with" )
1126                                                 GO="yes"
1127                                                 ;;
1128                                         * )
1129                                                 echo "Action '$RESULT' was not defined for package '$package_item'"
1130                                                 GO="yes"
1131                                                 ;;
1132                                 esac
1133                         fi
1134
1135                         if [ "$GO" = "yes" ]; then
1136                                 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1137                                         echo "Testing if $package has subrequirements..."
1138                                         run_poldek -t -i $package --dumpn=".$package-req.txt"
1139                                         if [ -f ".$package-req.txt" ]; then
1140                                                 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1141                                                 do
1142                                                         if [ "$package_name" = "$package" ]; then
1143                                                                 echo -ne "Installing BuildRequired package:\t$package_name\n"
1144                                                                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1145                                                                 install_required_packages $package;
1146                                                         else
1147                                                                 echo -ne "Installing (sub)Required package:\t$package_name\n"
1148                                                                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1149                                                                 install_required_packages $package_name;
1150                                                         fi
1151                                                         case $? in
1152                                                                 0)
1153                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1154                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1155                                                                         ;;
1156                                                                 *)
1157                                                                         echo "Attempting to run spawn sub - builder..."
1158                                                                         run_sub_builder $package_name
1159                                                                         if [ $? -eq 0 ]; then
1160                                                                                 install_required_packages $package_name;
1161                                                                                 case $? in
1162                                                                                         0)
1163                                                                                                 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1164                                                                                                 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1165                                                                                                 ;;
1166                                                                                         *)
1167                                                                                                 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1168                                                                                                 ;;
1169                                                                                 esac
1170                                                                         fi
1171                                                                         ;;
1172                                                         esac
1173                                                 done
1174                                                 rm -f ".$package-req.txt"
1175                                         else
1176                                                 echo "Attempting to run spawn sub - builder..."
1177                                                 run_sub_builder $package
1178                                                 if [ $? -eq 0 ]; then
1179                                                         install_required_packages $package;
1180                                                         case $? in
1181                                                                 0)
1182                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1183                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1184                                                                         ;;
1185                                                                 *)
1186                                                                         NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1187                                                                         ;;
1188                                                         esac
1189                                                 fi
1190                                         fi
1191                                 else
1192                                         echo "Package $package is already installed. BuildRequirement satisfied."
1193                                 fi
1194                         fi
1195                 done
1196                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1197                 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1198                         echo "Unable to install following packages and their dependencies:"
1199                         for pkg in "$NOT_INSTALLED_PACKAGES"
1200                         do
1201                                 echo $pkg
1202                         done
1203                         remove_build_requires
1204                         exit 8
1205                 fi
1206         fi
1207 }
1208
1209 #---------------------------------------------
1210 # main()
1211
1212 if [ "$#" = 0 ]; then
1213         usage;
1214         exit 1
1215 fi
1216
1217 while test $# -gt 0
1218 do
1219         case "${1}" in
1220                 -5 | --update-md5 )
1221                         COMMAND="get";
1222                         NODIST="yes"
1223                         NOCVSSPEC="yes"
1224                         UPDATE5="yes"
1225                         shift ;;
1226                 -a5 | --add-md5 )
1227                         COMMAND="get";
1228                         NODIST="yes"
1229                         NOCVS="yes"
1230                         NOCVSSPEC="yes"
1231                         UPDATE5="yes"
1232                         ADD5="yes"
1233                         shift ;;
1234                 -n5 | --no-md5 )
1235                         NO5="yes"
1236                         shift ;;
1237                 -D | --debug )
1238                         DEBUG="yes"; shift ;;
1239                 -V | --version )
1240                         COMMAND="version"; shift ;;
1241                 -a | --as_anon )
1242                         CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1243                 -b | -ba | --build )
1244                         COMMAND="build"; shift ;;
1245                 -bb | --build-binary )
1246                         COMMAND="build-binary"; shift ;;
1247                 -bs | --build-source )
1248                         COMMAND="build-source"; shift ;;
1249                 -bp | --build-prep )
1250                         COMMAND="build-prep"; shift ;;
1251                 -B | --branch )
1252                         COMMAND="branch"; shift; TAG="${1}"; shift;;
1253                 -c | --clean )
1254                         CLEAN="--clean --rmspec --rmsource"; shift ;;
1255                 -d | --cvsroot )
1256                         shift; CVSROOT="${1}"; shift ;;
1257                 -g | --get )
1258                         COMMAND="get"; shift ;;
1259                 -h | --help )
1260                         COMMAND="usage"; shift ;;
1261                 --http )
1262                         PROTOCOL="http"; shift ;;
1263                 -l | --logtofile )
1264                         shift; LOGFILE="${1}"; shift ;;
1265                 -ni| --nice )
1266                         shift; DEF_NICE_LEVEL=${1}; shift ;;
1267                 -m | --mr-proper )
1268                         COMMAND="mr-proper"; shift ;;
1269                 -nc | --no-cvs )
1270                         NOCVS="yes"; shift ;;
1271                 -ncs | --no-cvs-specs )
1272                         NOCVSSPEC="yes"; shift ;;
1273                 -nd | --no-distfiles )
1274                         NODIST="yes"; shift ;;
1275                 -nm | --no-mirrors )
1276                         NOMIRRORS="yes"; shift ;;
1277                 -nu | --no-urls )
1278                         NOURLS="yes"; shift ;;
1279                 -ns | --no-srcs )
1280                         NOSRCS="yes"; shift ;;
1281                 -ns0 | --no-source0 )
1282                         NOSOURCE0="yes"; shift ;;
1283                 -nn | --no-net )
1284                         NOCVS="yes"
1285                         NOCVSSPEC="yes"
1286                         NODIST="yes"
1287                         NOMIRRORS="yes"
1288                         NOURLS="yes"
1289                         NOSRCS="yes"
1290                         shift;;
1291                 --opts )
1292                         shift; RPMOPTS="${1}"; shift ;;
1293                 --with | --without )
1294                         case $GROUP_BCONDS in
1295                                 "yes")
1296                                         COND=${1}
1297                                         shift
1298                                         while ! `echo ${1}|grep -qE '(^-|spec)'`
1299                                         do
1300                                                 BCOND="$BCOND $COND $1"
1301                                                 shift
1302                                         done;;
1303                                 "no")
1304                                         BCOND="$BCOND $1 $2" ; shift 2 ;;
1305                         esac
1306                         ;;
1307                 --target )
1308                         shift; TARGET="${1}"; shift ;;
1309                 -q | --quiet )
1310                         QUIET="--quiet"; shift ;;
1311                 --date )
1312                         CVSDATE="${2}"; shift 2 ;;
1313                 -r | --cvstag )
1314                         shift; CVSTAG="${1}"; shift ;;
1315                 -R | --fetch-build-requires)
1316                         FETCH_BUILD_REQUIRES="yes"
1317                         NOT_INSTALLED_PACKAGES=
1318                         shift ;;
1319                 -RB | --remove-build-requires)
1320                         REMOVE_BUILD_REQUIRES="nice"
1321                         shift ;;
1322                 -FRB | --force-remove-build-requires)
1323                         REMOVE_BUILD_REQUIRES="force"
1324                         shift ;;
1325                 -Tvs | --tag-version-stable )
1326                         COMMAND="tag";
1327                         TAG="STABLE"
1328                         TAG_VERSION="yes"
1329                         shift;;
1330                 -Tvn | --tag-version-nest )
1331                         COMMAND="tag";
1332                         TAG="NEST"
1333                         TAG_VERSION="yes"
1334                         shift;;
1335                 -Ts | --tag-stable )
1336                         COMMAND="tag";
1337                         TAG="STABLE"
1338                         TAG_VERSION="no"
1339                         shift;;
1340                 -Tn | --tag-nest )
1341                         COMMAND="tag";
1342                         TAG="NEST"
1343                         TAG_VERSION="no"
1344                         shift;;
1345                 -Tv | --tag-version )
1346                         COMMAND="tag";
1347                         TAG=""
1348                         TAG_VERSION="yes"
1349                         shift;;
1350                 -Tp | --tag-prefix )
1351                         TAG_PREFIX="$2"
1352                         shift 2;;
1353                 -tt | --test-tag )
1354                         TEST_TAG="yes"
1355                         shift;;
1356                 -T | --tag )
1357                         COMMAND="tag";
1358                         shift
1359                         TAG="$1"
1360                         TAG_VERSION="no"
1361                         shift;;
1362                 -U | --update )
1363                         COMMAND="get"
1364                         UPDATE="yes"
1365                         NOCVSSPEC="yes"
1366                         NODIST="yes"
1367                         UPDATE5="yes"
1368                         shift ;;
1369                 -Upi | --update-poldek-indexes )
1370                         UPDATE_POLDEK_INDEXES="yes"
1371                         shift ;;
1372                 -u | --try-upgrade )
1373                         TRY_UPGRADE="1"; shift ;;
1374                 -un | --try-upgrade-with-float-version )
1375                         TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1376                 -v | --verbose )
1377                         BE_VERBOSE="1"; shift ;;
1378                 --define)
1379                         shift
1380                         MACRO="${1}"
1381                         VALUE="${2}"
1382                         shift 2
1383                         RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1384                         ;;
1385                 --nodeps)
1386                         shift
1387                         RPMOPTS="${RPMOPTS} --nodeps"
1388                         ;;
1389                 * )
1390                         SPECFILE="${1}"
1391                         export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1392                         shift ;;
1393         esac
1394 done
1395
1396 if [ -n "$DEBUG" ]; then
1397         set -x;
1398         set -v;
1399 fi
1400
1401 case "$COMMAND" in
1402         "build" | "build-binary" | "build-source" | "build-prep" )
1403                 init_builder;
1404                 if [ -n "$SPECFILE" ]; then
1405                 get_spec;
1406                 set_bconds_values;
1407                 display_bconds;
1408                 fetch_build_requires;
1409                 parse_spec;
1410
1411                 if [ -n "$TEST_TAG" ]; then
1412                         TAGVER=`make_tagver`
1413                         echo "Searching for tag $TAGVER..."
1414                         TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1415
1416                         if [ -n "$TAGREL" ]; then
1417                                 Exit_error err_build_fail "Tag $TAGVER already present (spec release: $TAGREL)"
1418                         fi
1419                 fi
1420
1421                 if [ -n "$ICONS" ]; then
1422                         get_files $ICONS;
1423                         parse_spec;
1424                 fi
1425                 if [ -n "$NOSOURCE0" ] ; then
1426                         SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1427                 fi
1428                 get_files "$SOURCES $PATCHES";
1429                 build_package;
1430                 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1431                         run_poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1432                         run_poldek --sn ${POLDEK_SOURCE} --up
1433                 fi
1434                 remove_build_requires;
1435         else
1436                 Exit_error err_no_spec_in_cmdl;
1437         fi
1438         ;;
1439         "branch" )
1440                 init_builder;
1441                 if [ -n "$SPECFILE" ]; then
1442                         get_spec;
1443                         parse_spec;
1444                         if [ -n "$ICONS" ]; then
1445                                 get_files $ICONS
1446                                 parse_spec;
1447                         fi
1448                         get_files $SOURCES $PATCHES;
1449                         branch_files $TAG "$SOURCES $PATCHES $ICONS";
1450                 else
1451                         Exit_error err_no_spec_in_cmdl;
1452                 fi
1453                 ;;
1454         "get" )
1455                 init_builder;
1456                 if [ -n "$SPECFILE" ]; then
1457                         get_spec;
1458                         parse_spec;
1459                         if [ -n "$ICONS" ]; then
1460                                 get_files $ICONS
1461                                 parse_spec;
1462                         fi
1463                         if [ -n "$NOSOURCE0" ] ; then
1464                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1465                         fi
1466                         get_files $SOURCES $PATCHES
1467                 else
1468                         Exit_error err_no_spec_in_cmdl;
1469                 fi
1470                 ;;
1471         "tag" )
1472                 NOURLS=1
1473                 NODIST=1
1474                 init_builder;
1475                 if [ -n "$SPECFILE" ]; then
1476                         get_spec;
1477                         parse_spec;
1478                         if [ -n "$ICONS" ]; then
1479                                 get_files $ICONS
1480                                 parse_spec;
1481                         fi
1482                         # don't fetch sources from remote locations
1483                         new_SOURCES=""
1484                         for file in $SOURCES
1485                         do
1486                                 [ -n "`src_md5 $file`" ] && continue
1487                                 new_SOURCES="$new_SOURCES $file"
1488                         done
1489                         SOURCES="$new_SOURCES"
1490                         get_files $SOURCES $PATCHES;
1491                         tag_files "$SOURCES $PATCHES $ICONS";
1492                 else
1493                         Exit_error err_no_spec_in_cmdl;
1494                 fi
1495                 ;;
1496         "mr-proper" )
1497                 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1498                 ;;
1499         "usage" )
1500                 usage;;
1501         "version" )
1502                 echo "$VERSION";;
1503 esac
1504 test -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES && rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1505 cd "$__PWD"
1506
1507 # vi:syntax=sh:ts=3:sw=4
This page took 0.188902 seconds and 4 git commands to generate.