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