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