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