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