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