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