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