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