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