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