]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
- display fetch cvs progress
[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 #         9 - Requested tag already exist
15 #        10 - Refused to build fractional release
16 #       100 - Unknown error (should not happen)
17
18 # Notes (todo):
19 #       - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
20 #       - when Icon: field is present, -5 and -a5 doesn't work
21 #       - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
22
23 VERSION="\
24 Build package utility from PLD Linux CVS repository
25 V 0.13 (C) 1999-2005 Free Penguins".
26 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
27
28 COMMAND="build"
29 TARGET=""
30
31 SPECFILE=""
32 BE_VERBOSE=""
33 QUIET=""
34 CLEAN=""
35 DEBUG=""
36 NOURLS=""
37 NOCVS=""
38 NOCVSSPEC=""
39 NODIST=""
40 UPDATE=""
41 UPDATE5=""
42 ADD5=""
43 NO5=""
44 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
45 CVSROOT=""
46
47 # It can be used i.e. in log file naming.
48 # See LOGFILE example.
49 DATE=`date +%Y-%m-%d_%H-%M-%S`
50
51 # Example: LOGFILE='../log.$PACKAGE_NAME'
52 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
53 # Yes, you can use variable name! Note _single_ quotes!
54 LOGFILE=''
55
56 LOGDIR=""
57 LOGDIROK=""
58 LOGDIRFAIL=""
59 LASTLOG_FILE=""
60
61 CHMOD="no"
62 CHMOD_MODE="0444"
63 RPMOPTS=""
64 BCOND=""
65 GROUP_BCONDS="no"
66 CVSIGNORE_DF="no"
67
68 PATCHES=""
69 SOURCES=""
70 ICONS=""
71 PACKAGE_RELEASE=""
72 PACKAGE_VERSION=""
73 PACKAGE_NAME=""
74 PROTOCOL="ftp"
75 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
76 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
77
78 CVSTAG=""
79 RES_FILE=""
80
81 CVS_SERVER="cvs.pld-linux.org"
82 DISTFILES_SERVER="://distfiles.pld-linux.org"
83 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
84
85 DEF_NICE_LEVEL=19
86
87 FAIL_IF_NO_SOURCES="yes"
88
89 if [ -x /usr/bin/rpm-getdeps ]; then
90          FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
91 else
92          FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
93 fi
94
95 # Here we load saved user environment used to
96 # predefine options set above, or passed to builder
97 # in command line.
98 # This one reads global system environment settings:
99 if [ -f ~/etc/builderrc ]; then
100         . ~/etc/builderrc
101 fi
102 # And this one cascades settings using user personal
103 # builder settings.
104 # Example of ~/.builderrc:
105 #
106 #UPDATE_POLDEK_INDEXES="yes"
107 #FETCH_BUILD_REQUIRES="yes"
108 #REMOVE_BUILD_REQUIRES="force"
109 #GROUP_BCONDS="yes"
110 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
111 #
112 SU_SUDO=""
113 if [ -n "$HOME_ETC" ]; then
114         USER_CFG="$HOME_ETC/.builderrc"
115 else
116         USER_CFG=~/.builderrc
117 fi
118
119 [ -f "$USER_CFG" ] && . "$USER_CFG"
120
121 wget --help 2>&1 | grep -q ' \-\-no-check\-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
122
123 if [ -n "$USE_PROZILLA" ]; then
124         GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
125         GETURI2="$GETURI"
126         OUTFILEOPT="-O"
127 elif [ -n "$USE_AXEL" ]; then
128         GETURI="axel -a $AXEL_OPTS"
129         GETURI2="$GETURI"
130         OUTFILEOPT="-o"
131 else
132         wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
133         wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
134
135         GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
136         GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
137         OUTFILEOPT="-O"
138 fi
139
140 GETLOCAL="cp -a"
141
142 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
143         RPM="rpm"
144         RPMBUILD="rpm"
145 else
146         RPM="rpm"
147         RPMBUILD="rpmbuild"
148 fi
149
150 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
151 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
152
153 run_poldek()
154 {
155         RES_FILE=~/tmp/poldek-exit-status.$RANDOM
156         if [ -n "$LOGFILE" ]; then
157                 LOG=`eval echo $LOGFILE`
158                 if [ -n "$LASTLOG_FILE" ]; then
159                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
160                 fi
161                 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
162                 return $exit_pldk
163         else
164                 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
165                 return `cat ${RES_FILE}`
166                 rm -rf ${RES_FILE}
167         fi
168 }
169
170 #---------------------------------------------
171 # functions
172
173 usage()
174 {
175         if [ -n "$DEBUG" ]; then set -xv; fi
176         echo "\
177 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
178
179 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
180 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
181 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
182 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
183 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
184 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
185 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
186 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
187 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
188
189 -5, --update-md5    - update md5 comments in spec, implies -nd -ncs
190 -a5, --add-md5      - add md5 comments to URL sources, implies -nc -nd -ncs
191 -n5, --no-md5       - ignore md5 comments in spec
192 -D, --debug         - enable builder script debugging mode,
193 -debug              - produce rpm debug package (same as --opts -debug)
194 -V, --version       - output builder version
195 -a, --as_anon       - get files via pserver as cvs@$CVS_SERVER,
196 -b, -ba, --build    - get all files from CVS repo or HTTP/FTP and build package
197                       from <package>.spec,
198 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
199                       only package from <package>.spec,
200 -bp, --build-prep   - execute the %prep phase of <package>.spec,
201 -bc                 - reserved (not implemented)
202 -bi                   reserved (not implemented)
203 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
204                       them into src.rpm,
205 --short-circuit     - reserved (not implemented)
206 -B, --branch        - add branch
207 -c, --clean         - clean all temporarily created files (in BUILD, SOURCES,
208                       SPECS and \$RPM_BUILD_ROOT),
209 -d <cvsroot>, --cvsroot <cvsroot>
210                     - setup \$CVSROOT,
211 --define <macro> <value>
212                     - define a macro <macro> with value <value>,
213 --nodeps            - rpm won't check any dependences
214 -g, --get           - get <package>.spec and all related files from CVS repo
215                       or HTTP/FTP,
216 -h, --help          - this message,
217 --http              - use http instead of ftp,
218 -l <logfile>, --logtofile <logfile>
219                     - log all to file,
220 -m, --mr-proper     - only remove all files related to spec file and all work
221                       resources,
222 -nc, --no-cvs       - don't download sources from CVS, if source URL is given,
223 -ncs, --no-cvs-specs
224                     - don't check specs in CVS
225 -nd, --no-distfiles - don't download from distfiles
226 -nm, --no-mirrors   - don't download from mirror, if source URL is given,
227 -nu, --no-urls      - don't try to download from FTP/HTTP location,
228 -ns, --no-srcs      - don't download Sources
229 -ns0, --no-source0  - don't download Source0
230 -nn, --no-net       - don't download anything from the net
231 --opts <rpm opts>   - additional options for rpm
232 -q, --quiet         - be quiet,
233 --date yyyy-mm-dd   - build package using resources from specified CVS date,
234 -r <cvstag>, --cvstag <cvstag>
235                     - build package using resources from specified CVS tag,
236 -R, --fetch-build-requires
237                     - fetch what is BuildRequired,
238 -RB, --remove-build-requires
239                     - remove all you fetched with -R or --fetch-build-requires
240                       remember, this option requires confirmation,
241 -FRB, --force-remove-build-requires
242                     - remove all you fetched with -R or --fetch-build-requires
243                       remember, this option works without confirmation,
244 -sf, --source-files - list sources - bare filenames (intended for offline
245                       operations; does not work when Icon field is present
246                                                          but icon file is absent),
247 -sp, --source-paths - list sources - filenames with full local paths (intended for
248                       offline operations; does not work when Icon field is present
249                                                          but icon file is absent),
250 -su, --source-urls  - list urls - urls to sources and patches
251                       intended for copying urls with spec with lots of macros in urls
252 -T <cvstag> , --tag <cvstag>
253                     - add cvs tag <cvstag> for files,
254 -Tvs, --tag-version-stable
255                     - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
256 -Tvn, --tag-version-nest
257                     - add cvs tags NEST and NAME-VERSION-RELEASE for files,
258 -Ts, --tag-stable
259                     - add cvs tag STABLE for files,
260 -Tn, --tag-nest
261                     - add cvs tag NEST for files,
262 -Tv, --tag-version
263                     - add cvs tag NAME-VERSION-RELEASE for files,
264 -Tp, --tag-prefix <prefix>
265                     - add <prefix> to NAME-VERSION-RELEASE tags,
266 -tt, --test-tag <prefix>
267                     - fail if tag is already present,
268 -ir, --integer-release-only
269                     - allow only integer and snapshot releases
270 -v, --verbose       - be verbose,
271 -u, --try-upgrade   - check version, and try to upgrade package
272 -un, --try-upgrade-with-float-version
273                     - as above, but allow float version
274 -U, --update        - refetch sources, don't use distfiles, and update md5 comments
275 -Upi, --update-poldek-indexes
276                     - refresh or make poldek package index files.
277 -np, --nopatch <patchnumber>
278                     - don't apply <patchnumber>
279 --show-bconds       - show available conditional builds, which can be used
280                     - with --with and/or --without switches.
281 --with/--without <feature>
282                     - conditional build package depending on %_with_<feature>/
283                       %_without_<feature> macro switch.  You may now use
284                       --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
285                       constructions. Set GROUP_BCONDS to yes to make use of it.
286 --target <platform>, --target=<platform>
287                     - build for platform <platform>.
288 "
289 }
290
291 update_shell_title() {
292         [ -t 1 ] || return
293         local len=${COLUMNS:-80}
294         local msg=$(echo "$*" | cut -c-$len)
295
296         msg="builder[$SPECFILE] $msg"
297         case "$TERM" in
298                 cygwin|xterm*)
299                 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
300         ;;
301                 screen*)
302                 echo >&2 -ne "\033]0;$msg\007"
303         ;;
304         esac
305 }
306
307 # set TARGET from BuildArch: from SPECFILE
308 set_spec_target() {
309          if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
310                   tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
311                   if [ "$tmp" ]; then
312                                 TARGET="$tmp"
313                                 case "$RPMBUILD" in
314                                 "rpmbuild")
315                                          TARGET_SWITCH="--target $TARGET" ;;
316                                 "rpm")
317                                          TARGET_SWITCH="--target=$TARGET" ;;
318                                 esac
319                   fi
320          fi
321 }
322
323 cache_rpm_dump () {
324          if [ -n "$DEBUG" ]; then
325                   set -x;
326                   set -v;
327          fi
328
329 rpm_dump_cache=`
330         case "$RPMBUILD" in
331                 rpm )
332                         rpm -bp --nodeps --define 'prep %dump' $BCOND $TARGET_SWITCH $SPECFILE 2>&1
333                         ;;
334                 rpmbuild )
335                         rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $TARGET_SWITCH $SPECFILE 2>&1
336                         ;;
337         esac`
338 }
339
340 rpm_dump () {
341         if [ -z "$rpm_dump_cache" ] ; then
342                 echo "internal error: cache_rpm_dump not called!" 1>&2
343         fi
344         echo "$rpm_dump_cache"
345 }
346
347 parse_spec()
348 {
349         update_shell_title "parsing specfile"
350         if [ -n "$DEBUG" ]; then
351                 set -x;
352                 set -v;
353         fi
354
355         cd $SPECS_DIR
356
357         cache_rpm_dump
358
359         if [ "$NOSRCS" != "yes" ]; then
360                 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
361         fi
362         if (rpm_dump | grep -qEi ":.*nosource.*1"); then
363                 FAIL_IF_NO_SOURCES="no"
364         fi
365
366         PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
367         ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
368         PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
369         PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -n 1`"
370         PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
371
372 # These variables may be unset after first cache_rpm_dump call
373 # (because of not-yet-retrieved icon file)
374 #
375 #       if [ -z "$PACKAGE_NAME" -o -z "$PACKAGE_VERSION" -o -z "$PACKAGE_RELEASE" ]; then
376 #                Exit_error err_no_package_data;
377 #       fi
378
379         if [ -n "$BE_VERBOSE" ]; then
380                 echo "- Sources :  `nourl $SOURCES`"
381                 if [ -n "$PATCHES" ]; then
382                         echo "- Patches :  `nourl $PATCHES`"
383                 else
384                         echo "- Patches :  *no patches needed*"
385                 fi
386                 if [ -n "$ICONS" ]; then
387                         echo "- Icon    :  `nourl $ICONS`"
388                 else
389                         echo "- Icon    :  *no package icon*"
390                 fi
391                 echo "- Name    : $PACKAGE_NAME"
392                 echo "- Version : $PACKAGE_VERSION"
393                 echo "- Release : $PACKAGE_RELEASE"
394         fi
395 }
396
397 Exit_error()
398 {
399         if [ -n "$DEBUG" ]; then
400                 set -x;
401                 set -v;
402         fi
403
404         cd "$__PWD"
405
406         case "$1" in
407                 "err_no_spec_in_cmdl" )
408                         remove_build_requires
409                         echo "ERROR: spec file name not specified.";
410                         exit 2 ;;
411                 "err_no_spec_in_repo" )
412                         remove_build_requires
413                         echo "Error: spec file not stored in CVS repo.";
414                         exit 3 ;;
415                 "err_no_source_in_repo" )
416                         remove_build_requires
417                         echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
418                         exit 4 ;;
419                 "err_build_fail" )
420                         remove_build_requires
421                         echo "Error: package build failed. (${2:-no more info})";
422                         exit 5 ;;
423                 "err_no_package_data" )
424                         remove_build_requires
425                         echo "Error: couldn't get out package name/version/release from spec file."
426                         exit 6 ;;
427            "err_tag_exists" )
428                         remove_build_requires
429                         echo "Tag ${2} already exists (spec release: ${3}).";
430                         exit 9 ;;
431            "err_fract_rel" )
432                         remove_build_requires
433                         echo "Release ${2} not integer and not a snapshot.";
434                         exit 10 ;;
435                 "err_branch_exists" )
436                         remove_build_requires
437                         echo "Tree branch already exists (${2}).";
438                         exit 11 ;;
439
440         esac
441    echo "Unknown error."
442    exit 100
443 }
444
445 init_builder()
446 {
447         if [ -n "$DEBUG" ]; then
448                 set -x;
449                 set -v;
450         fi
451
452         SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
453         SPECS_DIR="`$RPM --eval '%{_specdir}'`"
454
455         __PWD="`pwd`"
456 }
457
458 get_spec()
459 {
460
461         update_shell_title "get_spec"
462
463         if [ -n "$DEBUG" ]; then
464                 set -x;
465                 set -v;
466         fi
467
468         cd "$SPECS_DIR"
469         if [ \! -f "$SPECFILE" ]; then
470                 SPECFILE="`basename $SPECFILE .spec`.spec";
471         fi
472         if [ "$NOCVSSPEC" != "yes" ]; then
473                 OPTIONS="up "
474
475                 if [ -n "$CVSROOT" ]; then
476                         OPTIONS="-d $CVSROOT $OPTIONS"
477                 else
478                         if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
479                                 echo "warning: No cvs access defined - using local .spec file"
480                                 NOCVSSPEC="yes"
481                         fi
482                 fi
483
484                 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
485                         OPTIONS="$OPTIONS -A"
486                 else
487                         if [ -n "$CVSDATE" ]; then
488                                 OPTIONS="$OPTIONS -D $CVSDATE"
489                         fi
490                         if [ -n "$CVSTAG" ]; then
491                                 OPTIONS="$OPTIONS -r $CVSTAG"
492                         fi
493                 fi
494
495                 result=1
496                 retries_counter=0
497                 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
498                 do
499                         retries_counter=$(( $retries_counter + 1 ))
500                         output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
501                         result=$?
502                         [ -n "$output" ] && echo "$output"
503                         if [ "$result" -ne "0" ]; then
504                                 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
505                                         echo "Trying again [$SPECFILE]... ($retries_counter)"
506                                         sleep 2
507                                         continue
508                                 fi
509                                 Exit_error err_no_spec_in_repo;
510                         fi
511                 done
512         fi
513         if [ ! -f "$SPECFILE" ]; then
514                 Exit_error err_no_spec_in_repo;
515         fi
516
517         if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
518                 chmod $CHMOD_MODE $SPECFILE
519         fi
520         unset OPTIONS
521         [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
522
523          set_spec_target
524 }
525
526 find_mirror()
527 {
528         cd "$SPECS_DIR"
529         url="$1"
530         if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
531                 cvs update mirrors >&2
532         fi
533
534         IFS="|"
535         while read origin mirror name rest
536         do
537                 ol=`echo -n "$origin"|wc -c`
538                 prefix="`echo -n "$url" | head -c $ol`"
539                 if [ "$prefix" = "$origin" ] ; then
540                         suffix="`echo "$url"|cut -b $ol-`"
541                         echo -n "$mirror$suffix"
542                         return 0
543                 fi
544         done < mirrors
545         echo "$url"
546 }
547
548 src_no ()
549 {
550         cd $SPECS_DIR
551         rpm_dump | \
552         grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
553         sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
554         head -n 1 | xargs
555 }
556
557 src_md5 ()
558 {
559         [ X"$NO5" = X"yes" ] && return
560         no=$(src_no "$1")
561         [ -z "$no" ] && return
562         cd $SPECS_DIR
563         spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
564         if [ -z "$spec_rev" ]; then
565                 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
566         fi
567         spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
568         md5=$(grep -s -v '^#' additional-md5sums | \
569         grep -E "[      ]$(basename "$1")[      ]+${spec}([     ,]|\$)" | \
570         sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
571         grep -E '^[0-9a-f]{32}$')
572         if [ X"$md5" = X"" ] ; then
573                 source_md5=`grep -i "#[         ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://'`
574                 if [ ! -z "$source_md5" ] ; then
575                         echo $source_md5;
576                 else
577                         # we have empty SourceX-md5, but it is still possible
578                         # that we have NoSourceX-md5 AND NoSource: X
579                         nosource_md5=`grep -i "#[        ]*NoSource$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
580                         if [ ! -z "$nosource_md5" -a ! X"`grep -i "^NoSource:[   ]*$no$" $SPECFILE`" = X"" ] ; then
581                                 echo $nosource_md5;
582                         fi;
583                 fi;
584         else
585                 if [ $(echo "$md5" | wc -l) != 1 ] ; then
586                         echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
587                 fi
588                 echo "$md5" | tail -n 1
589         fi
590 }
591
592 distfiles_url ()
593 {
594         echo "$PROTOCOL$DISTFILES_SERVER/distfiles/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
595 }
596
597 distfiles_attic_url ()
598 {
599         echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
600 }
601
602 good_md5 ()
603 {
604         md5=$(src_md5 "$1")
605         [ "$md5" = "" ] || \
606         [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
607 }
608
609 good_size ()
610 {
611          size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
612          [ -n "$size" -a "$size" -gt 0 ]
613 }
614
615 cvsignore_df ()
616 {
617         if [ "$CVSIGNORE_DF" != "yes" ]; then
618                 return
619         fi
620         cvsignore=${SOURCE_DIR}/.cvsignore
621         if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
622                 echo "$1" >> $cvsignore
623         fi
624 }
625
626 get_files()
627 {
628         GET_FILES="$@"
629         update_shell_title "fetching sources"
630
631         if [ -n "$DEBUG" ]; then
632                 set -x;
633                 set -v;
634         fi
635
636         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
637                 cd "$SOURCE_DIR"
638
639                 OPTIONS="up "
640                 if [ -n "$CVSROOT" ]; then
641                         OPTIONS="-d $CVSROOT $OPTIONS"
642                 else
643                         if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
644                                 echo "warning: No cvs access defined for SOURCES"
645                                 NOCVS="yes"
646                         fi
647                 fi
648                 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
649                         OPTIONS="$OPTIONS -A"
650                 else
651                         if [ -n "$CVSDATE" ]; then
652                                 OPTIONS="$OPTIONS -D $CVSDATE"
653                         fi
654                         if [ -n "$CVSTAG" ]; then
655                                 OPTIONS="$OPTIONS -r $CVSTAG"
656                         fi
657                 fi
658                 for i in $GET_FILES
659                 do
660                         if [ -n "$UPDATE5" ]; then
661                                 if [ -n "$ADD5" ]; then
662                                         [ `nourl $i` = "$i" ] && continue
663                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE && continue
664                                 else
665                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE || continue
666                                 fi
667                         fi
668                         FROM_DISTFILES=0
669                         if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
670                                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
671                                         echo "Warning: no URL given for $i"
672                                 fi
673
674                                 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
675                                         if good_md5 "$i" && good_size "$i"; then
676                                                 echo "$(nourl "$i") having proper md5sum already exists"
677                                                 continue
678                                         fi
679                                         target=$(nourl "$i")
680                                         url=$(distfiles_url "$i")
681                                         url_attic=$(distfiles_attic_url "$i")
682                                         FROM_DISTFILES=1
683                                         if [ "`echo $url | grep -E '^(\.|/)'`" ]; then
684                                                 update_shell_title "get_files: $url"
685                                                 ${GETLOCAL} $url $target
686                                         else
687                                                 if [ -z "$NOMIRRORS" ]; then
688                                                         url="`find_mirror "$url"`"
689                                                 fi
690                                                 update_shell_title "get_files: $url"
691                                                 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
692                                                 if [ "`echo $url | grep -E 'ftp://'`" ]; then
693                                                         update_shell_title "get_files: $url"
694                                                         ${GETURI2} ${OUTFILEOPT} "$target" "$url"
695                                                 fi
696                                         fi
697                                         if ! test -s "$target"; then
698                                                 rm -f "$target"
699                                                 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
700                                                         update_shell_title "get_files: $url_attic"
701                                                         ${GETLOCAL} $url_attic $target
702                                                 else
703                                                         if [ -z "$NOMIRRORS" ]; then
704                                                                 url_attic="`find_mirror "$url_attic"`"
705                                                         fi
706                                                         update_shell_title "get_files: $url_attic"
707                                                         ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
708                                                         if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
709                                                                  update_shell_title "get_files: $url_attic"
710                                                                 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
711                                                         fi
712                                                 fi
713                                         fi
714                                         if test -s "$target"; then
715                                                 cvsignore_df $target
716                                         else
717                                                 rm -f "$target"
718                                                 FROM_DISTFILES=0
719                                         fi
720                                 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
721                                         # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
722                                         result=1
723                                         retries_counter=0
724                                         while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
725                                         do
726                                                 retries_counter=$(( $retries_counter + 1 ))
727                                                 update_shell_title "get_files: `nourl $i`"
728                                                 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
729                                                 result=$?
730                                                 [ -n "$output" ] && echo "$output"
731                                                 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
732                                                         echo "Trying again [`nourl $i`]... ($retries_counter)"
733                                                         sleep 2
734                                                         continue
735                                                 else
736                                                         break
737                                                 fi
738                                         done
739                                 fi
740
741                                 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
742                                         if [ -z "$NOMIRRORS" ]; then
743                                                 im="`find_mirror "$i"`"
744                                         else
745                                                 im="$i"
746                                         fi
747                                         update_shell_title "get_files: $im"
748                                         ${GETURI} "$im" || \
749                                         if [ "`echo $im | grep -E 'ftp://'`" ]; then
750                                                  update_shell_title "get_files: $im"
751                                                 ${GETURI2} "$im"
752                                         fi
753                                 fi
754
755                         fi
756                         srcno=$(src_no $i)
757                         if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
758                                 Exit_error err_no_source_in_repo $i;
759                         elif [ -n "$UPDATE5" ] && \
760                                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
761                                 [ -z "$(grep -E -i '^NoSource[  ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
762                                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
763                         then
764                                 echo "Updating source-$srcno md5."
765                                 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
766                                 perl -i -ne '
767                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
768                                 print "# Source'$srcno'-md5:\t'$md5'\n"
769                                 if /^Source'$srcno'\s*:\s+/;
770                                 ' \
771                                 $SPECS_DIR/$SPECFILE
772                         fi
773
774                         if good_md5 "$i" && good_size "$i"; then
775                                 :
776                         elif [ "$FROM_DISTFILES" = 1 ]; then
777                                 # wrong md5 from distfiles: remove the file and try again
778                                 # but only once ...
779                                 echo "MD5 sum mismatch. Trying full fetch."
780                                 FROM_DISTFILES=2
781                                 rm -f $target
782                                 update_shell_title "get_files: $url"
783                                 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
784                                 if [ "`echo $url | grep -E 'ftp://'`" ]; then
785                                          update_shell_title "get_files: $url"
786                                         ${GETURI2} ${OUTFILEOPT} "$target" "$url"
787                                 fi
788                                 if ! test -s "$target"; then
789                                         rm -f "$target"
790                                         update_shell_title "get_files: $url_attic"
791                                         ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
792                                         if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
793                                                  update_shell_title "get_files: $url_attic"
794                                                 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
795                                         fi
796                                 fi
797                                 test -s "$target" || rm -f "$target"
798                         fi
799
800                         if good_md5 "$i" && good_size "$i" ; then
801                                 :
802                         else
803                                 echo "MD5 sum mismatch or 0 size.  Use -U to refetch sources,"
804                                 echo "or -5 to update md5 sums, if you're sure files are correct."
805                                 Exit_error err_no_source_in_repo $i
806                         fi
807                 done
808
809                 if [ "$CHMOD" = "yes" ]; then
810                         CHMOD_FILES="`nourl $GET_FILES`"
811                         if [ -n "$CHMOD_FILES" ]; then
812                                 chmod $CHMOD_MODE $CHMOD_FILES
813                         fi
814                 fi
815                 unset OPTIONS
816         fi
817 }
818
819 make_tagver() {
820
821                 if [ -n "$DEBUG" ]; then
822                          set -x;
823                          set -v;
824                 fi
825
826                 # Check whether first character of PACKAGE_NAME is legal for tag name
827                 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
828                         TAG_PREFIX=tag_
829                 fi
830                 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"`
831                 # Remove #kernel.version_release from TAGVER because tagging sources
832                 # could occur with different kernel-headers than kernel-headers used at build time.
833                 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
834                 echo -n "$TAGVER"
835 }
836
837 tag_files()
838 {
839         TAG_FILES="$@"
840
841         if [ -n "$DEBUG" ]; then
842                 set -x;
843                 set -v;
844         fi
845
846         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
847                 echo "Version: $PACKAGE_VERSION"
848                 echo "Release: $PACKAGE_RELEASE"
849
850                 TAGVER=`make_tagver`
851
852                 if [ "$TAG_VERSION" = "yes" ]; then
853                         echo "CVS tag: $TAGVER"
854                 fi
855                 if [ -n "$TAG" ]; then
856                         echo "CVS tag: $TAG"
857                 fi
858
859                 OPTIONS="tag -F"
860                 if [ -n "$CVSROOT" ]; then
861                         OPTIONS="-d $CVSROOT $OPTIONS"
862                 fi
863
864                 cd "$SOURCE_DIR"
865                 for i in $TAG_FILES
866                 do
867                         # don't tag files stored on distfiles
868                         [ -n "`src_md5 $i`" ] && continue
869                         if [ -f "`nourl $i`" ]; then
870                                 if [ "$TAG_VERSION" = "yes" ]; then
871                                         cvs $OPTIONS $TAGVER `nourl $i`
872                                 fi
873                                 if [ -n "$TAG" ]; then
874                                         cvs $OPTIONS $TAG `nourl $i`
875                                 fi
876                         else
877                                 Exit_error err_no_source_in_repo $i
878                         fi
879                 done
880
881                 cd "$SPECS_DIR"
882                 if [ "$TAG_VERSION" = "yes" ]; then
883                         cvs $OPTIONS $TAGVER $SPECFILE
884                 fi
885                 if [ -n "$TAG" ]; then
886                         cvs $OPTIONS $TAG $SPECFILE
887                 fi
888
889                 unset OPTIONS
890         fi
891 }
892
893 branch_files()
894 {
895         TAG=$1
896         echo "CVS branch tag: $TAG"
897         shift;
898
899         TAG_FILES="$@"
900
901         if [ -n "$DEBUG" ]; then
902                 set -x;
903                 set -v;
904         fi
905
906         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
907
908                 OPTIONS="tag -b"
909                 if [ -n "$CVSROOT" ]; then
910                         OPTIONS="-d $CVSROOT $OPTIONS"
911                 fi
912                 cd "$SOURCE_DIR"
913                 for i in $TAG_FILES
914                 do
915                         if [ -f `nourl $i` ]; then
916                                 cvs $OPTIONS $TAG `nourl $i`
917                         else
918                                 Exit_error err_no_source_in_repo $i
919                         fi
920                 done
921                 cd "$SPECS_DIR"
922                 cvs $OPTIONS $TAG $SPECFILE
923
924                 unset OPTIONS
925         fi
926 }
927
928
929
930 build_package()
931 {
932         update_shell_title "build_package"
933         if [ -n "$DEBUG" ]; then
934                 set -x;
935                 set -v;
936         fi
937
938         cd "$SPECS_DIR"
939
940         if [ -n "$TRY_UPGRADE" ]; then
941                   update_shell_title "build_package: try_upgrade"
942                 if [ -n "$FLOAT_VERSION" ]; then
943                         TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1
944                 else
945                         TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1
946                 fi
947
948                 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
949
950                 if [ -n "$TNEWVER" ]; then
951                         TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
952                         echo "New version found, updating spec file to version " $TNEWVER
953                         cp -f $SPECFILE $SPECFILE.bak
954                         chmod +w $SPECFILE
955                         eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
956                         eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
957                         parse_spec;
958                         if [ -n "$ICONS" ]; then
959                                 get_files $ICONS;
960                                 parse_spec;
961                         fi
962                         NODIST="yes" UPDATE5="yes" get_files "$SOURCES $PATCHES";
963                         unset TOLDVER TNEWVER TNOTIFY
964                 fi
965         fi
966         cd "$SPECS_DIR"
967
968         case "$COMMAND" in
969                 build )
970                         BUILD_SWITCH="-ba" ;;
971                 build-binary )
972                         BUILD_SWITCH="-bb" ;;
973                 build-source )
974                         BUILD_SWITCH="-bs --nodeps" ;;
975                 build-prep )
976                         BUILD_SWITCH="-bp --nodeps" ;;
977         esac
978
979         update_shell_title "build_package: $COMMAND"
980         if [ -n "$LOGFILE" ]; then
981                 LOG=`eval echo $LOGFILE`
982                 if [ -d "$LOG" ]; then
983                         echo "Log file $LOG is a directory."
984                         echo "Parse error in the spec?"
985                         Exit_error err_build_fail;
986                 fi
987                 if [ -n "$LASTLOG_FILE" ]; then
988                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
989                 fi
990                 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
991                 (time eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
992                 RETVAL=`cat $RES_FILE`
993                 rm $RES_FILE
994                 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
995                         if [ "$RETVAL" -eq "0" ]; then
996                                 mv $LOG $LOGDIROK
997                         else
998                                 mv $LOG $LOGDIRFAIL
999                         fi
1000                 fi
1001         else
1002                 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE
1003                 RETVAL=$?
1004         fi
1005         if [ "$RETVAL" -ne "0" ]; then
1006                 if [ -n "$TRY_UPGRADE" ]; then
1007                         echo "\n!!! Package with new version cannot be build automagically\n"
1008                         mv -f $SPECFILE.bak $SPECFILE
1009                 fi
1010                 Exit_error err_build_fail;
1011         fi
1012         unset BUILD_SWITCH
1013 }
1014
1015 nourl()
1016 {
1017         echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1018 }
1019
1020 install_required_packages()
1021 {
1022         run_poldek -vi $1
1023         return $?
1024 }
1025
1026 set_bconds_values()
1027 {
1028         update_shell_title "set bcond values"
1029
1030         AVAIL_BCONDS_WITHOUT=""
1031         AVAIL_BCONDS_WITH=""
1032         if `grep -q ^%bcond ${SPECFILE}`; then
1033                 BCOND_VERSION="NEW"
1034         elif `egrep -q ^#\ *_with ${SPECFILE}`; then
1035                 BCOND_VERSION="OLD"
1036         else
1037                 BCOND_VERSION="NONE"
1038         fi
1039
1040         # expand bconds from ~/.bcondrc
1041         # The file structure is like gentoo's package.use:
1042         # ---
1043         # * -selinux
1044         # samba -mysql -pgsql
1045         # w32codec-installer license_agreement
1046         # php +mysqli
1047         # ---
1048         if [ "${BCOND_VERSION}" != "NONE" ] && ( [ -f $HOME/.bcondrc ] || ( [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] ) ) ; then
1049                 # This takes package name, first defined in spec.
1050                 # so consider that when defining flags for package.
1051                 PN=`$RPM -q --qf '%{NAME}\n' --specfile $SPECFILE | head -n 1`
1052                 SN=${SPECFILE%%\.spec}
1053                 AVAIL=`$RPMBUILD --bcond $SPECFILE`
1054
1055                 BCONDRC=$HOME/.bcondrc
1056                 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && BCONDRC=$HOME_ETC/.bcondrc
1057
1058                 while read pkg flags; do
1059                         # ignore comments
1060                         [[ "$pkg" == \#* ]] && continue
1061
1062                         # any package or current package?
1063                         if [ "$pkg" = "*" ] || [ "$pkg" = "$PN" ] || [ "$pkg" = "$SN" ]; then
1064                                 for flag in $flags; do
1065                                         opt=${flag#[+-]}
1066
1067                                         # use only flags which are in this package.
1068                                         if [[ $AVAIL = *${opt}* ]]; then
1069                                                 if [[ $flag = -* ]]; then
1070                                                         BCOND="$BCOND --without $opt"
1071                                                 else
1072                                                         BCOND="$BCOND --with $opt"
1073                                                 fi
1074                                         fi
1075                                 done
1076                         fi
1077                 done < $BCONDRC
1078         fi
1079
1080         case "${BCOND_VERSION}" in
1081                  NONE)
1082                         :
1083                         ;;
1084                 OLD)
1085                         echo "Warning: This spec has old style bconds. Fix it || die."
1086                         for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
1087                         do
1088                                 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
1089                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
1090                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1091                                 else
1092                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1093                                 fi
1094                         done
1095
1096                         for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
1097                         do
1098                                 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
1099                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
1100                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1101                                 else
1102                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1103                                 fi
1104                         done
1105                         ;;
1106                 NEW)
1107                         cond_type="" # with || without
1108                         for opt in `$RPMBUILD --bcond $SPECFILE`
1109                         do
1110                                 case "$opt" in
1111                                         _without)
1112                                                 cond_type="without"
1113                                                 ;;
1114                                         _with)
1115                                                 cond_type="with"
1116                                                 ;;
1117                                         _without_*)
1118                                                 AVAIL_BCOND_WITHOUT="`echo $opt | sed 's/^_without_//g'`"
1119                                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
1120                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1121                                                 else
1122                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1123                                                 fi
1124                                                 ;;
1125                                         _with_*)
1126                                                 AVAIL_BCOND_WITH="`echo $opt | sed 's/^_with_//g'`"
1127                                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
1128                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1129                                                 else
1130                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1131                                                 fi
1132                                                 ;;
1133                                         *)
1134                                                 case "$cond_type" in
1135                                                         with)
1136                                                                 cond_type=''
1137                                                                 AVAIL_BCOND_WITH="$opt"
1138                                                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
1139                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1140                                                                 else
1141                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1142                                                                 fi
1143                                                                 ;;
1144                                                         without)
1145                                                                 cond_type=''
1146                                                                 AVAIL_BCOND_WITHOUT="$opt"
1147                                                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
1148                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1149                                                                 else
1150                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1151                                                                 fi
1152                                                                 ;;
1153                                                 esac
1154                                                 ;;
1155                                 esac
1156                         done
1157                         ;;
1158         esac
1159 }
1160
1161 run_sub_builder()
1162 {
1163         package_name="${1}"
1164         update_shell_title "run_sub_builder $package_name"
1165         #
1166         # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1167         # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1168         # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1169         # jakby nie bylo tego kawalka kodu.
1170         #
1171         # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1172         #         Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1173         #
1174         #
1175         # y0shi.
1176
1177         parent_spec_name=''
1178
1179         # Istnieje taki spec? ${package}.spec
1180         if [ -f "${SPECS_DIR}/${package}.spec" ]; then
1181                 parent_spec_name=${package}.spec
1182         elif [ -f "${SPECS_DIR}/`echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
1183                 parent_spec_name="`echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g`.spec"
1184         else
1185                 for provides_line in `grep ^Provides:.*$package  ${SPECS_DIR} -R`
1186                 do
1187                         echo $provides_line
1188                 done
1189         fi
1190
1191         if [ "${parent_spec_name}" != "" ]; then
1192                 spawn_sub_builder $parent_spec_name
1193         fi
1194         NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1195 }
1196
1197 spawn_sub_builder()
1198 {
1199          package_name="${1}"
1200          update_shell_title "spawn_sub_builder $package_name"
1201
1202          sub_builder_opts=''
1203          if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
1204                   sub_builder_opts="${sub_builder_opts} -R"
1205          fi
1206          if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
1207                   sub_builder_opts="${sub_builder_opts} -RB"
1208          elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
1209                   sub_builder_opts="${sub_builder_opts} -FRB"
1210          fi
1211          if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
1212                   sub_builder_opts="${sub_builder_opts} -Upi"
1213          fi
1214
1215          cd "${SPECS_DIR}"
1216          ./builder ${sub_builder_opts} "$@"
1217 }
1218
1219 remove_build_requires()
1220 {
1221         if [ "$INSTALLED_PACKAGES" != "" ]; then
1222                 case "$REMOVE_BUILD_REQUIRES" in
1223                         "force")
1224                                 run_poldek --noask -ve $INSTALLED_PACKAGES
1225                                 ;;
1226                         "nice")
1227                                 run_poldek --ask -ve $INSTALLED_PACKAGES
1228                                 ;;
1229                         *)
1230                                 echo You may want to manually remove following BuildRequires fetched:
1231                                 echo $INSTALLED_PACKAGES
1232                                 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1233                                 ;;
1234                 esac
1235         fi
1236 }
1237
1238 display_bconds()
1239 {
1240         if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1241                 if [ "$BCOND" != "" ]; then
1242                         echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1243                         echo -ne "$BCOND"
1244                 else
1245                         echo -ne "\nNo conditional flags passed"
1246                 fi
1247                 echo -ne "\n\nfrom available:\n"
1248                 echo -ne "--with   :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1249         fi
1250 }
1251
1252 display_branches()
1253 {
1254          if [ "$NOCVSSPEC" != "yes" ]; then
1255                   echo -ne "Available branches: "
1256                   cvs status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
1257          fi
1258 }
1259
1260 # checks a given list of packages/files/provides agains current rpmdb.
1261 # outputs all dependencies whcih current rpmdb doesn't satisfy.
1262 # input can be either STDIN or parameters
1263 _rpm_prov_check()
1264 {
1265          local DEPS
1266
1267          if [ "$#" -gt 0 ]; then
1268                   DEPS="$@"
1269          else
1270                   DEPS=$(cat)
1271          fi
1272
1273          DEPS=$(rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1274
1275          # packages
1276          echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1277
1278          # other deps (files)
1279          echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1280 }
1281
1282 # checks if given package/files/provides exists in rpmdb.
1283 # inout can be either stdin or parameters
1284 # returns packages wchi hare present in the rpmdb
1285 _rpm_cnfl_check()
1286 {
1287          local DEPS
1288
1289          if [ "$#" -gt 0 ]; then
1290                   DEPS="$@"
1291          else
1292                   DEPS=$(cat)
1293          fi
1294
1295          rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1296 }
1297
1298 fetch_build_requires()
1299 {
1300         if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1301                 update_shell_title "fetch build requires"
1302                 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1303                         local CONF=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1304                         local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1305
1306                         update_shell_title "poldek: update indexes"
1307                         if [ -n "$CONF" ] || [ -n "$DEPS" ]; then
1308                                 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1309                         fi
1310                         if [ -n "$CONF" ]; then
1311                                 update_shell_title "uninstall conflicting packages: $CONF"
1312                                 echo "Trying to uninstall conflicting packages ($CONF):"
1313                                 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CONF
1314                         fi
1315
1316                    while [ "$DEPS" ]; do
1317                                 update_shell_title "install deps: $DEPS"
1318                                 echo "Trying to install dependencies ($DEPS):"
1319                                 local log=.${SPECFILE}_poldek.log
1320                                 $SU_SUDO /usr/bin/poldek --caplookup -uGq $DEPS | tee $log
1321                                 failed=$(awk -F: '/^error:/{print $2}' $log)
1322                                 rm -f $log
1323                                 local ok
1324                                 if [ -n "$failed" ]; then
1325                                          for package in $failed; do
1326                                                   # FIXME: sanitise, deps could be not .spec files
1327                                                   spawn_sub_builder -bb $package && ok="$ok $package"
1328                                          done
1329                                          DEPS="$ok"
1330                                 else
1331                                          DEPS=""
1332                                 fi
1333                    done
1334                         return
1335                 fi
1336
1337                 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1338                 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1339                 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1340                 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1341                 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1342                 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,textutils,coreutils,g -e s,kgcc_package,gcc,g -e s,\),,g`
1343                 do
1344                         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`"
1345                         GO="yes"
1346                         package=`basename "$package_item"|sed -e "s/}$//g"`
1347                         COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1348                         mach=`uname -m`
1349
1350                         COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1351                         if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1352                                 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
1353                                         GO="yes"
1354                                 fi
1355                         # bcond:
1356                         else
1357                                 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1358                                 GO=""
1359                                 # %{without}
1360                                 if `echo $COND_TST|grep -q 'without_'`; then
1361                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1362                                         if `echo $COND_TST|grep -q !`; then
1363                                                 COND_STATE="with"
1364                                         else
1365                                                 COND_STATE="wout"
1366                                         fi
1367                                         COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1368                                         COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1369                                         if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1370                                                 COND_ARGV="wout"
1371                                         else
1372                                                 COND_ARGV="with"
1373                                         fi
1374                                 # %{with}
1375                                 elif `echo $COND_TST|grep -q 'with_'`; then
1376                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1377                                         if `echo $COND_TST|grep -q !`; then
1378                                                 COND_STATE="wout"
1379                                         else
1380                                                 COND_STATE="with"
1381                                         fi
1382                                         COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1383                                         COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1384                                         if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
1385                                                 COND_ARGV="with"
1386                                         else
1387                                                 COND_ARGV="wout"
1388                                         fi
1389                                 fi
1390                                 RESULT="${COND_STATE}-${COND_ARGV}"
1391                                 case "$RESULT" in
1392                                         "with-wout" | "wout-with" )
1393                                                 GO=""
1394                                                 ;;
1395                                         "wout-wout" | "with-with" )
1396                                                 GO="yes"
1397                                                 ;;
1398                                         * )
1399                                                 echo "Action '$RESULT' was not defined for package '$package_item'"
1400                                                 GO="yes"
1401                                                 ;;
1402                                 esac
1403                         fi
1404
1405                         if [ "$GO" = "yes" ]; then
1406                                 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1407                                         echo "Testing if $package has subrequirements..."
1408                                         run_poldek -t -i $package --dumpn=".$package-req.txt"
1409                                         if [ -f ".$package-req.txt" ]; then
1410                                                 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1411                                                 do
1412                                                         if [ "$package_name" = "$package" ]; then
1413                                                                 echo -ne "Installing BuildRequired package:\t$package_name\n"
1414                                                                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1415                                                                 install_required_packages $package;
1416                                                         else
1417                                                                 echo -ne "Installing (sub)Required package:\t$package_name\n"
1418                                                                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1419                                                                 install_required_packages $package_name;
1420                                                         fi
1421                                                         case $? in
1422                                                                 0)
1423                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1424                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1425                                                                         ;;
1426                                                                 *)
1427                                                                         echo "Attempting to run spawn sub - builder..."
1428                                                                         echo -ne "Package installation failed:\t$package_name\n"
1429                                                                         run_sub_builder $package_name
1430                                                                         if [ $? -eq 0 ]; then
1431                                                                                 install_required_packages $package_name;
1432                                                                                 case $? in
1433                                                                                         0)
1434                                                                                                 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1435                                                                                                 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1436                                                                                                 ;;
1437                                                                                         *)
1438                                                                                                 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1439                                                                                                 ;;
1440                                                                                 esac
1441                                                                         fi
1442                                                                         ;;
1443                                                         esac
1444                                                 done
1445                                                 rm -f ".$package-req.txt"
1446                                         else
1447                                                 echo "Attempting to run spawn sub - builder..."
1448                                                 echo -ne "Package installation failed:\t$package\n"
1449                                                 run_sub_builder $package
1450                                                 if [ $? -eq 0 ]; then
1451                                                         install_required_packages $package;
1452                                                         case $? in
1453                                                                 0)
1454                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1455                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1456                                                                         ;;
1457                                                                 *)
1458                                                                         NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1459                                                                         ;;
1460                                                         esac
1461                                                 fi
1462                                         fi
1463                                 else
1464                                         echo "Package $package is already installed. BuildRequirement satisfied."
1465                                 fi
1466                         fi
1467                 done
1468                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1469                 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1470                         echo "Unable to install following packages and their dependencies:"
1471                         for pkg in "$NOT_INSTALLED_PACKAGES"
1472                         do
1473                                 echo $pkg
1474                         done
1475                         remove_build_requires
1476                         exit 8
1477                 fi
1478         fi
1479 }
1480
1481 #---------------------------------------------
1482 # main()
1483
1484 if [ "$#" = 0 ]; then
1485         usage;
1486         exit 1
1487 fi
1488
1489 while test $# -gt 0
1490 do
1491         case "${1}" in
1492                 -5 | --update-md5 )
1493                         COMMAND="get";
1494                         NODIST="yes"
1495                         NOCVSSPEC="yes"
1496                         UPDATE5="yes"
1497                         shift ;;
1498                 -a5 | --add-md5 )
1499                         COMMAND="get";
1500                         NODIST="yes"
1501                         NOCVS="yes"
1502                         NOCVSSPEC="yes"
1503                         UPDATE5="yes"
1504                         ADD5="yes"
1505                         shift ;;
1506                 -n5 | --no-md5 )
1507                         NO5="yes"
1508                         shift ;;
1509                 -D | --debug )
1510                         DEBUG="yes"; shift ;;
1511                 -V | --version )
1512                         COMMAND="version"; shift ;;
1513                 -a | --as_anon )
1514                         CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1515                 -b | -ba | --build )
1516                         COMMAND="build"; shift ;;
1517                 -bb | --build-binary )
1518                         COMMAND="build-binary"; shift ;;
1519                 -bs | --build-source )
1520                         COMMAND="build-source"; shift ;;
1521                 -bp | --build-prep )
1522                         COMMAND="build-prep"; shift ;;
1523                 -B | --branch )
1524                         COMMAND="branch"; shift; TAG="${1}"; shift;;
1525                 -c | --clean )
1526                         CLEAN="--clean --rmspec --rmsource"; shift ;;
1527                 -d | --cvsroot )
1528                         shift; CVSROOT="${1}"; shift ;;
1529                 -g | --get )
1530                         COMMAND="get"; shift ;;
1531                 -h | --help )
1532                         COMMAND="usage"; shift ;;
1533                 --http )
1534                         PROTOCOL="http"; shift ;;
1535                 -l | --logtofile )
1536                         shift; LOGFILE="${1}"; shift ;;
1537                 -ni| --nice )
1538                         shift; DEF_NICE_LEVEL=${1}; shift ;;
1539                 -m | --mr-proper )
1540                         COMMAND="mr-proper"; shift ;;
1541                 -nc | --no-cvs )
1542                         NOCVS="yes"; shift ;;
1543                 -ncs | --no-cvs-specs )
1544                         NOCVSSPEC="yes"; shift ;;
1545                 -nd | --no-distfiles )
1546                         NODIST="yes"; shift ;;
1547                 -nm | --no-mirrors )
1548                         NOMIRRORS="yes"; shift ;;
1549                 -nu | --no-urls )
1550                         NOURLS="yes"; shift ;;
1551                 -ns | --no-srcs )
1552                         NOSRCS="yes"; shift ;;
1553                 -ns0 | --no-source0 )
1554                         NOSOURCE0="yes"; shift ;;
1555                 -nn | --no-net )
1556                         NOCVS="yes"
1557                         NOCVSSPEC="yes"
1558                         NODIST="yes"
1559                         NOMIRRORS="yes"
1560                         NOURLS="yes"
1561                         NOSRCS="yes"
1562                         shift;;
1563                 --opts )
1564                         shift; RPMOPTS="$RPM_OPTS ${1}"; shift ;;
1565                 --nopatch | -np )
1566                         shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
1567                 --with | --without )
1568                         case $GROUP_BCONDS in
1569                                 "yes")
1570                                         COND=${1}
1571                                         shift
1572                                         while ! `echo ${1}|grep -qE '(^-|spec)'`
1573                                         do
1574                                                 BCOND="$BCOND $COND $1"
1575                                                 shift
1576                                         done;;
1577                                 "no")
1578                                         if [[ "$2" = *,* ]]; then
1579                                                  for a in $(echo "$2" | tr , ' '); do
1580                                                           BCOND="$BCOND $1 $a"
1581                                                  done
1582                                         else
1583                                                  BCOND="$BCOND $1 $2"
1584                                         fi
1585                                         shift 2 ;;
1586                         esac
1587                         ;;
1588                 --target )
1589                         shift; TARGET="${1}"; shift ;;
1590                 --target=* )
1591                         TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
1592                 -q | --quiet )
1593                         QUIET="--quiet"; shift ;;
1594                 --date )
1595                         CVSDATE="${2}"; shift 2 ;;
1596                 -r | --cvstag )
1597                         shift; CVSTAG="${1}"; shift ;;
1598                 -R | --fetch-build-requires)
1599                         FETCH_BUILD_REQUIRES="yes"
1600                         NOT_INSTALLED_PACKAGES=
1601                         shift ;;
1602                 -RB | --remove-build-requires)
1603                         REMOVE_BUILD_REQUIRES="nice"
1604                         shift ;;
1605                 -FRB | --force-remove-build-requires)
1606                         REMOVE_BUILD_REQUIRES="force"
1607                         shift ;;
1608                 -sf | --sources-files)
1609                         COMMAND="list-sources-files"
1610                         shift ;;
1611                 -sp | --sources-paths)
1612                         COMMAND="list-sources-local-paths"
1613                         shift ;;
1614                 -su | --sources-urls)
1615                         COMMAND="list-sources-urls"
1616                         shift ;;
1617                 -Tvs | --tag-version-stable )
1618                         COMMAND="tag";
1619                         TAG="STABLE"
1620                         TAG_VERSION="yes"
1621                         shift;;
1622                 -Tvn | --tag-version-nest )
1623                         COMMAND="tag";
1624                         TAG="NEST"
1625                         TAG_VERSION="yes"
1626                         shift;;
1627                 -Ts | --tag-stable )
1628                         COMMAND="tag";
1629                         TAG="STABLE"
1630                         TAG_VERSION="no"
1631                         shift;;
1632                 -Tn | --tag-nest )
1633                         COMMAND="tag";
1634                         TAG="NEST"
1635                         TAG_VERSION="no"
1636                         shift;;
1637                 -Tv | --tag-version )
1638                         COMMAND="tag";
1639                         TAG=""
1640                         TAG_VERSION="yes"
1641                         shift;;
1642                 -Tp | --tag-prefix )
1643                         TAG_PREFIX="$2"
1644                         shift 2;;
1645                 -tt | --test-tag )
1646                         TEST_TAG="yes"
1647                         shift;;
1648                 -T | --tag )
1649                         COMMAND="tag";
1650                         shift
1651                         TAG="$1"
1652                         TAG_VERSION="no"
1653                         shift;;
1654                 -ir | --integer-release-only )
1655                         INTEGER_RELEASE="yes"
1656                         shift;;
1657                 -U | --update )
1658                         COMMAND="get"
1659                         UPDATE="yes"
1660                         NOCVSSPEC="yes"
1661                         NODIST="yes"
1662                         UPDATE5="yes"
1663                         shift ;;
1664                 -Upi | --update-poldek-indexes )
1665                         UPDATE_POLDEK_INDEXES="yes"
1666                         shift ;;
1667                 -u | --try-upgrade )
1668                         TRY_UPGRADE="1"; shift ;;
1669                 -un | --try-upgrade-with-float-version )
1670                         TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1671                 -v | --verbose )
1672                         BE_VERBOSE="1"; shift ;;
1673                 --define)
1674                         shift
1675                         MACRO="${1}"
1676                         VALUE="${2}"
1677                         shift 2
1678                         RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1679                         ;;
1680                 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
1681                         SHOW_BCONDS="yes"
1682                         shift
1683                         ;;
1684                 --nodeps)
1685                         shift
1686                         RPMOPTS="${RPMOPTS} --nodeps"
1687                         ;;
1688                 -debug)
1689                         RPMOPTS="${RPMOPTS} -debug"; shift ;;
1690                 * )
1691                         SPECFILE="${1}"
1692                         export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1693                         shift ;;
1694         esac
1695 done
1696
1697 if [ -n "$DEBUG" ]; then
1698         set -x;
1699         set -v;
1700 fi
1701
1702 if [ -n "$TARGET" ]; then
1703         case "$RPMBUILD" in
1704                 "rpmbuild")
1705                         TARGET_SWITCH="--target $TARGET" ;;
1706                 "rpm")
1707                         TARGET_SWITCH="--target=$TARGET" ;;
1708         esac
1709 fi
1710
1711 update_shell_title "$COMMAND"
1712 case "$COMMAND" in
1713         "build" | "build-binary" | "build-source" | "build-prep" )
1714                 init_builder;
1715                 if [ -n "$SPECFILE" ]; then
1716                         get_spec;
1717                         set_bconds_values;
1718                         display_bconds;
1719                         display_branches;
1720                         [ X"$SHOW_BCONDS" = X"yes" ] && exit 0
1721                         fetch_build_requires;
1722                         parse_spec;
1723                         if [ "$INTEGER_RELEASE" = "yes" ]; then
1724                                 echo "Checking release $PACKAGE_RELEASE..."
1725                                 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
1726                                         Exit_error err_fract_rel "$PACKAGE_RELEASE"
1727                                 fi
1728                         fi
1729
1730                         if [ -n "$TEST_TAG" ]; then
1731                                 TAGVER=`make_tagver`
1732                                 echo "Searching for tag $TAGVER..."
1733                                 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1734                                 if [ -n "$TAGREL" ]; then
1735                                         Exit_error err_tag_exists "$TAGVER" "$TAGREL"
1736                                 fi
1737
1738                                 # - do not allow to build from HEAD when XX-branch exists
1739                                 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
1740                                 if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
1741                                          TAG_BRANCH="${TREE_PREFIX}-branch"
1742                                          TAG_STATUS=$(cvs status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
1743                                          if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
1744                                                   Exit_error err_branch_exists "$TAG_STATUS"
1745                                          fi
1746
1747                                 fi
1748                         fi
1749
1750                         if [ -n "$ICONS" ]; then
1751                                 get_files $ICONS;
1752                                 parse_spec;
1753                         fi
1754                         if [ -n "$NOSOURCE0" ] ; then
1755                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1756                         fi
1757                         get_files "$SOURCES $PATCHES";
1758                         build_package;
1759                         if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
1760                                 run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
1761                         fi
1762                         remove_build_requires;
1763                 else
1764                         Exit_error err_no_spec_in_cmdl;
1765                 fi
1766                 ;;
1767         "branch" )
1768                 init_builder;
1769                 if [ -n "$SPECFILE" ]; then
1770                         get_spec;
1771                         parse_spec;
1772                         if [ -n "$ICONS" ]; then
1773                                 get_files $ICONS
1774                                 parse_spec;
1775                         fi
1776                         get_files $SOURCES $PATCHES;
1777                         branch_files $TAG "$SOURCES $PATCHES $ICONS";
1778                 else
1779                         Exit_error err_no_spec_in_cmdl;
1780                 fi
1781                 ;;
1782         "get" )
1783                 init_builder;
1784                 if [ -n "$SPECFILE" ]; then
1785                         get_spec;
1786                         parse_spec;
1787                         if [ -n "$ICONS" ]; then
1788                                 OLD_UPDATE5=$UPDATE5
1789                                 UPDATE5= get_files $ICONS
1790                                 UPDATE5=$OLD_UPDATE5
1791                                 parse_spec;
1792                         fi
1793                         if [ -n "$NOSOURCE0" ] ; then
1794                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1795                         fi
1796                         get_files $SOURCES $PATCHES
1797                 else
1798                         Exit_error err_no_spec_in_cmdl;
1799                 fi
1800                 ;;
1801         "tag" )
1802                 NOURLS=1
1803                 NODIST="yes"
1804                 init_builder;
1805                 if [ -n "$SPECFILE" ]; then
1806                         get_spec;
1807                         parse_spec;
1808                         if [ -n "$ICONS" ]; then
1809                                 get_files $ICONS
1810                                 parse_spec;
1811                         fi
1812                         # don't fetch sources from remote locations
1813                         new_SOURCES=""
1814                         for file in $SOURCES
1815                         do
1816                                 [ -n "`src_md5 $file`" ] && continue
1817                                 new_SOURCES="$new_SOURCES $file"
1818                         done
1819                         SOURCES="$new_SOURCES"
1820                         get_files $SOURCES $PATCHES;
1821                         tag_files "$SOURCES $PATCHES $ICONS";
1822                 else
1823                         Exit_error err_no_spec_in_cmdl;
1824                 fi
1825                 ;;
1826         "mr-proper" )
1827                 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1828                 ;;
1829         "list-sources-files" )
1830                 init_builder
1831                 NOCVSSPEC="yes"
1832                 DONT_PRINT_REVISION="yes"
1833                 get_spec
1834                 parse_spec
1835                 SAPS="$SOURCES $PATCHES"
1836                 for SAP in $SAPS ; do
1837                          echo $SAP | awk '{gsub(/.*\//,"") ; print}'
1838                 done
1839                 ;;
1840         "list-sources-urls" )
1841                 init_builder
1842                 NOCVSSPEC="yes"
1843                 DONT_PRINT_REVISION="yes"
1844                 get_spec
1845                 parse_spec
1846                 SAPS="$SOURCES $PATCHES"
1847                 for SAP in $SAPS ; do
1848                          echo $SAP
1849                 done
1850                 ;;
1851         "list-sources-local-paths" )
1852                 init_builder
1853                 NOCVSSPEC="yes"
1854                 DONT_PRINT_REVISION="yes"
1855                 get_spec
1856                 parse_spec
1857                 SAPS="$SOURCES $PATCHES"
1858                 for SAP in $SAPS ; do
1859                          echo $SOURCE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
1860                 done
1861                 ;;
1862         "usage" )
1863                 usage;;
1864         "version" )
1865                 echo "$VERSION";;
1866 esac
1867 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
1868         rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1869 fi
1870 cd "$__PWD"
1871
1872 # vi:syntax=sh:ts=3:sw=4
This page took 0.220334 seconds and 4 git commands to generate.