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