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