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