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