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