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