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