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