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