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