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