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