]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder_.sh
- remove (disabled) UTF-8 blocker for AC-branch
[packages/rpm-build-tools.git] / builder_.sh
CommitLineData
ed997e04 1#!/bin/ksh
5efdb475
ER
2#
3# This program is free software, distributed under the terms of
4# the GNU General Public License Version 2.
5#
528b4058 6# -----------
528b4058 7# Exit codes:
6cc67f17
ER
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)
528b4058
JB
20
21# Notes (todo):
f1080274 22# - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
528b4058 23# - when Icon: field is present, -5 and -a5 doesn't work
f1080274 24# - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
528b4058 25
00c7b5f1
ER
26RCSID='$Id$'
27r=${RCSID#* * }
28rev=${r%% *}
5efdb475 29VERSION="v0.20/$rev"
00c7b5f1 30VERSIONSTRING="\
f1080274 31Build package utility from PLD Linux CVS repository
00c7b5f1
ER
32$VERSION (C) 1999-2007 Free Penguins".
33
528b4058
JB
34PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
35
36COMMAND="build"
0b75058f 37TARGET=""
528b4058
JB
38
39SPECFILE=""
40BE_VERBOSE=""
41QUIET=""
42CLEAN=""
43DEBUG=""
44NOURLS=""
45NOCVS=""
46NOCVSSPEC=""
47NODIST=""
0466ad31 48NOINIT=""
477f03e6 49PREFMIRRORS=""
528b4058 50UPDATE=""
528b4058
JB
51ADD5=""
52NO5=""
53ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
54CVSROOT=""
477f03e6 55GREEDSRC=""
528b4058 56
00c7b5f1
ER
57# user agent when fetching files
58USER_AGENT="PLD/Builder($VERSION)"
59
528b4058
JB
60# It can be used i.e. in log file naming.
61# See LOGFILE example.
62DATE=`date +%Y-%m-%d_%H-%M-%S`
63
64# Example: LOGFILE='../log.$PACKAGE_NAME'
65# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
66# Yes, you can use variable name! Note _single_ quotes!
67LOGFILE=''
68
69LOGDIR=""
70LOGDIROK=""
71LOGDIRFAIL=""
72LASTLOG_FILE=""
73
74CHMOD="no"
75CHMOD_MODE="0444"
76RPMOPTS=""
0466ad31 77RPMBUILDOPTS=""
528b4058
JB
78BCOND=""
79GROUP_BCONDS="no"
6cc67f17 80CVSIGNORE_DF="no"
528b4058
JB
81
82PATCHES=""
83SOURCES=""
84ICONS=""
85PACKAGE_RELEASE=""
86PACKAGE_VERSION=""
87PACKAGE_NAME=""
00c7b5f1 88ASSUMED_NAME=""
528b4058
JB
89PROTOCOL="ftp"
90WGET_RETRIES=${MAX_WGET_RETRIES:-0}
91CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
92
93CVSTAG=""
94RES_FILE=""
ed997e04 95CVS_FORCE=""
528b4058
JB
96
97CVS_SERVER="cvs.pld-linux.org"
98DISTFILES_SERVER="://distfiles.pld-linux.org"
6cc67f17 99ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
528b4058 100
6cc67f17 101DEF_NICE_LEVEL=19
0466ad31 102SCHEDTOOL="auto"
528b4058
JB
103
104FAIL_IF_NO_SOURCES="yes"
105
f1080274
ER
106# let get_files skip over files which are present to get those damn files fetched
107SKIP_EXISTING_FILES="no"
108
ed997e04
ER
109TRY_UPGRADE=""
110# should the specfile be restored if upgrade failed?
111REVERT_BROKEN_UPGRADE="yes"
112
6cc67f17 113if [ -x /usr/bin/rpm-getdeps ]; then
0466ad31 114 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
528b4058 115else
0466ad31 116 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
528b4058
JB
117fi
118
528b4058
JB
119# Here we load saved user environment used to
120# predefine options set above, or passed to builder
121# in command line.
122# This one reads global system environment settings:
123if [ -f ~/etc/builderrc ]; then
124 . ~/etc/builderrc
125fi
126# And this one cascades settings using user personal
127# builder settings.
128# Example of ~/.builderrc:
129#
130#UPDATE_POLDEK_INDEXES="yes"
131#FETCH_BUILD_REQUIRES="yes"
132#REMOVE_BUILD_REQUIRES="force"
133#GROUP_BCONDS="yes"
134#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
0466ad31 135#TITLECHANGE=no
528b4058 136#
6cc67f17 137SU_SUDO=""
528b4058
JB
138if [ -n "$HOME_ETC" ]; then
139 USER_CFG="$HOME_ETC/.builderrc"
00c7b5f1 140 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
528b4058
JB
141else
142 USER_CFG=~/.builderrc
00c7b5f1 143 BUILDER_MACROS=~/.builder-rpmmacros
528b4058
JB
144fi
145
146[ -f "$USER_CFG" ] && . "$USER_CFG"
147
0466ad31
ER
148if [ "$SCHEDTOOL" = "auto" ]; then
149 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
150 SCHEDTOOL="schedtool -B -e"
151 else
152 SCHEDTOOL="no"
153 fi
154fi
f1080274 155
6cc67f17
ER
156if [ -n "$USE_PROZILLA" ]; then
157 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
158 GETURI2="$GETURI"
159 OUTFILEOPT="-O"
160elif [ -n "$USE_AXEL" ]; then
161 GETURI="axel -a $AXEL_OPTS"
162 GETURI2="$GETURI"
163 OUTFILEOPT="-o"
164else
0466ad31
ER
165 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
166 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
167 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
00c7b5f1 168 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
f1080274 169
6cc67f17
ER
170 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
171 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
172 OUTFILEOPT="-O"
173fi
174
175GETLOCAL="cp -a"
176
177if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
178 RPM="rpm"
179 RPMBUILD="rpm"
180else
181 RPM="rpm"
182 RPMBUILD="rpmbuild"
183fi
184
185POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
186POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
187
528b4058
JB
188run_poldek()
189{
190 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
191 if [ -n "$LOGFILE" ]; then
192 LOG=`eval echo $LOGFILE`
193 if [ -n "$LASTLOG_FILE" ]; then
194 echo "LASTLOG=$LOG" > $LASTLOG_FILE
195 fi
0466ad31 196 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
528b4058
JB
197 return $exit_pldk
198 else
0466ad31 199 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
528b4058
JB
200 return `cat ${RES_FILE}`
201 rm -rf ${RES_FILE}
202 fi
203}
204
528b4058
JB
205#---------------------------------------------
206# functions
207
208usage()
209{
210 if [ -n "$DEBUG" ]; then set -xv; fi
211 echo "\
00c7b5f1 212Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|-ba|--build]
01a86c2c 213[-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
ed997e04
ER
214[{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
215[-g|--get] [-h|--help] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
216[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
217[-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
477f03e6 218[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] [--use-greed-sources]
01a86c2c 219[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
00c7b5f1 220[--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
01a86c2c 221<package>[.spec][:cvstag]
6cc67f17 222
528b4058
JB
223-5, --update-md5 - update md5 comments in spec, implies -nd -ncs
224-a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
225-n5, --no-md5 - ignore md5 comments in spec
6cc67f17
ER
226-D, --debug - enable builder script debugging mode,
227-debug - produce rpm debug package (same as --opts -debug)
00c7b5f1
ER
228-V, --version - output builder version string
229--short-version - output builder short version
528b4058
JB
230-a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
231-b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
232 from <package>.spec,
233-bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
234 only package from <package>.spec,
f1080274 235-bp, --build-prep - execute the %prep phase of <package>.spec,
01a86c2c
ER
236-bc - execute the %build phase of <package>.spec,
237-bi - execute the %install phase of <package>.spec
238-bl - execute the %files phase of <package>.spec
528b4058
JB
239-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
240 them into src.rpm,
01a86c2c 241--short-circuit - short-circuit build
528b4058
JB
242-B, --branch - add branch
243-c, --clean - clean all temporarily created files (in BUILD, SOURCES,
244 SPECS and \$RPM_BUILD_ROOT),
ed997e04 245-cf, --cvs-force - use -F when tagging (useful when moving branches)
6cc67f17 246-d <cvsroot>, --cvsroot <cvsroot>
528b4058
JB
247 - setup \$CVSROOT,
248--define <macro> <value>
249 - define a macro <macro> with value <value>,
250--nodeps - rpm won't check any dependences
251-g, --get - get <package>.spec and all related files from CVS repo
252 or HTTP/FTP,
253-h, --help - this message,
254--http - use http instead of ftp,
255-l <logfile>, --logtofile <logfile>
256 - log all to file,
257-m, --mr-proper - only remove all files related to spec file and all work
258 resources,
259-nc, --no-cvs - don't download sources from CVS, if source URL is given,
260-ncs, --no-cvs-specs
261 - don't check specs in CVS
262-nd, --no-distfiles - don't download from distfiles
263-nm, --no-mirrors - don't download from mirror, if source URL is given,
264-nu, --no-urls - don't try to download from FTP/HTTP location,
265-ns, --no-srcs - don't download Sources
266-ns0, --no-source0 - don't download Source0
267-nn, --no-net - don't download anything from the net
477f03e6 268-pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES
0466ad31 269--no-init - don't initialize builder paths (SPECS and SOURCES)
f1080274
ER
270-ske,
271--skip-existing-files - skip existing files in get_files
528b4058
JB
272--opts <rpm opts> - additional options for rpm
273-q, --quiet - be quiet,
274--date yyyy-mm-dd - build package using resources from specified CVS date,
275-r <cvstag>, --cvstag <cvstag>
276 - build package using resources from specified CVS tag,
ed997e04 277-A - build package using CVS resources as any sticky tags/date/kopts being reset.
528b4058
JB
278-R, --fetch-build-requires
279 - fetch what is BuildRequired,
280-RB, --remove-build-requires
281 - remove all you fetched with -R or --fetch-build-requires
282 remember, this option requires confirmation,
283-FRB, --force-remove-build-requires
284 - remove all you fetched with -R or --fetch-build-requires
285 remember, this option works without confirmation,
0466ad31
ER
286-sd, --source-distfiles - list sources available from distfiles (intended for offline
287 operations; does not work when Icon field is present
288 but icon file is absent),
00c7b5f1 289-sc, --source-cvs - list sources available from CVS
0466ad31
ER
290-sdp, --source-distfiles-paths - list sources available from distfiles -
291 paths relative to distfiles directory (intended for offline
292 operations; does not work when Icon field is present
293 but icon file is absent),
6cc67f17
ER
294-sf, --source-files - list sources - bare filenames (intended for offline
295 operations; does not work when Icon field is present
0466ad31 296 but icon file is absent),
6cc67f17
ER
297-sp, --source-paths - list sources - filenames with full local paths (intended for
298 offline operations; does not work when Icon field is present
0466ad31 299 but icon file is absent),
f1080274
ER
300-su, --source-urls - list urls - urls to sources and patches
301 intended for copying urls with spec with lots of macros in urls
528b4058
JB
302-T <cvstag> , --tag <cvstag>
303 - add cvs tag <cvstag> for files,
304-Tvs, --tag-version-stable
6cc67f17 305 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
528b4058
JB
306-Ts, --tag-stable
307 - add cvs tag STABLE for files,
528b4058 308-Tv, --tag-version
6cc67f17 309 - add cvs tag NAME-VERSION-RELEASE for files,
528b4058
JB
310-Tp, --tag-prefix <prefix>
311 - add <prefix> to NAME-VERSION-RELEASE tags,
312-tt, --test-tag <prefix>
313 - fail if tag is already present,
6cc67f17
ER
314-ir, --integer-release-only
315 - allow only integer and snapshot releases
528b4058
JB
316-v, --verbose - be verbose,
317-u, --try-upgrade - check version, and try to upgrade package
318-un, --try-upgrade-with-float-version
319 - as above, but allow float version
477f03e6
ER
320--use-greed-sources
321 - try download source from tag head if don't find it in
322 current tag
528b4058
JB
323-U, --update - refetch sources, don't use distfiles, and update md5 comments
324-Upi, --update-poldek-indexes
325 - refresh or make poldek package index files.
f1080274
ER
326-np, --nopatch <patchnumber>
327 - don't apply <patchnumber>
328--show-bconds - show available conditional builds, which can be used
329 - with --with and/or --without switches.
ed997e04
ER
330--show-bcond-args - show active bconds, from ~/.bcondrc. this is used by
331 ./repackage.sh script. in other words, the output is
332 parseable by scripts.
528b4058
JB
333--with/--without <feature>
334 - conditional build package depending on %_with_<feature>/
335 %_without_<feature> macro switch. You may now use
336 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
337 constructions. Set GROUP_BCONDS to yes to make use of it.
6cc67f17 338--target <platform>, --target=<platform>
0466ad31
ER
339 - build for platform <platform>.
340--init-rpm-dir - initialize ~/rpm directory structure
528b4058
JB
341"
342}
343
f1080274
ER
344update_shell_title() {
345 [ -t 1 ] || return
346 local len=${COLUMNS:-80}
347 local msg=$(echo "$*" | cut -c-$len)
348
349 if [ -n "$BE_VERBOSE" ]; then
350 echo >&2 "$(date +%s.%N) $*"
351 fi
352
0466ad31
ER
353 if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then
354 local pkg
355 if [ -n "$PACKAGE_NAME" ]; then
356 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
357 else
358 pkg=${SPECFILE}
359 fi
360
361 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
362 msg="$(echo $msg | tr -d '\n\r')"
363 case "$TERM" in
364 cygwin|xterm*)
365 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
366 ;;
367 screen*)
368 echo >&2 -ne "\033]0;$msg\007"
369 ;;
370 esac
371 fi
f1080274
ER
372}
373
374# set TARGET from BuildArch: from SPECFILE
375set_spec_target() {
0466ad31
ER
376 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
377 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
378 if [ "$tmp" ]; then
01a86c2c 379 target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
f1080274
ER
380 TARGET="$tmp"
381 case "$RPMBUILD" in
382 "rpmbuild")
01a86c2c 383 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
f1080274 384 "rpm")
0466ad31 385 TARGET_SWITCH="--target=$TARGET" ;;
f1080274 386 esac
0466ad31
ER
387 fi
388 fi
f1080274
ER
389}
390
00c7b5f1
ER
391# runs rpm with minimal macroset
392minirpm() {
f1080274
ER
393 # we reset macros not to contain macros.build as all the %() macros are
394 # executed here, while none of them are actually needed.
f1080274 395 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
00c7b5f1
ER
396 safe_macrofiles=$(rpm --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
397
398 # TODO: move these to /usr/lib/rpm/macros
399 cat > $BUILDER_MACROS <<'EOF'
400%x8664 x86_64 amd64 ia32e
01a86c2c
ER
401%alt_kernel %{nil}
402%_alt_kernel %{nil}
f1080274
ER
403%requires_releq_kernel_up %{nil}
404%requires_releq_kernel_smp %{nil}
00c7b5f1 405%requires_releq_kernel %{nil}
f1080274
ER
406%requires_releq() %{nil}
407%pyrequires_eq() %{nil}
408%requires_eq() %{nil}
409%requires_eq_to() %{nil}
410%releq_kernel_up ERROR
411%releq_kernel_smp ERROR
00c7b5f1 412%releq_kernel ERROR
f1080274
ER
413%kgcc_package ERROR
414%_fontsdir ERROR
415%ruby_version ERROR
416%ruby_ver_requires_eq() %{nil}
417%ruby_mod_ver_requires_eq() %{nil}
418%__php_api_requires() %{nil}
419%php_major_version ERROR
420%php_api_version ERROR
5efdb475
ER
421%requires_xorg_xserver_extension %{nil}
422%requires_xorg_xserver_xinput %{nil}
423%requires_xorg_xserver_font %{nil}
424%requires_xorg_xserver_videodrv %{nil}
f1080274 425%py_ver ERROR
ed997e04
ER
426%perl_vendorarch ERROR
427%perl_vendorlib ERROR
01a86c2c
ER
428# damn. need it here! - copied from /usr/lib/rpm/macros.build
429%tmpdir %(echo "${TMPDIR:-/tmp}")
430%patchset_source(f:b:) %(
431 base=%{-b*}%{!-b*:10000};
432 start=$(expr $base + %1);
433 end=$(expr $base + %{?2}%{!?2:%{1}});
434 # we need to call seq twice as it doesn't allow two formats
435 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
436 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
437 paste %{tmpdir}/__ps{1,2};
438 rm -f %{tmpdir}/__ps{1,2};
439) \
440%{nil}
f1080274 441EOF
0466ad31 442 if [ "$NOINIT" = "yes" ] ; then
00c7b5f1 443 cat >> $BUILDER_MACROS <<'EOF'
0466ad31
ER
444%_specdir ./
445%_sourcedir ./
446EOF
447 fi
00c7b5f1
ER
448 eval $RPMBUILD --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $* 2>&1
449}
450
451cache_rpm_dump() {
452 if [ -n "$DEBUG" ]; then
453 set -x
454 set -v
455 fi
456
457 update_shell_title "cache_rpm_dump"
458 local rpm_dump
459 rpm_dump=`
460 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
461 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
462 case "$RPMBUILD" in
463 rpm)
464 ARGS='-bp'
465 ;;
466 rpmbuild)
467 ARGS='--nodigest --nosignature --nobuild'
468 ;;
469 esac
470 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
f1080274
ER
471 `
472 if [ $? -gt 0 ]; then
473 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
474 echo "$error" >&2
ed997e04 475 Exit_error err_build_fail
f1080274
ER
476 fi
477
478 # make small dump cache
479 rpm_dump_cache=`echo "$rpm_dump" | awk '
480 $2 ~ /^SOURCEURL/ {print}
481 $2 ~ /^PATCHURL/ {print}
482 $2 ~ /^nosource/ {print}
483 $2 ~ /^PACKAGE_/ {print}
484 '`
485
486 update_shell_title "cache_rpm_dump: OK!"
528b4058
JB
487}
488
00c7b5f1 489rpm_dump() {
528b4058 490 if [ -z "$rpm_dump_cache" ] ; then
ed997e04 491 echo "internal error: cache_rpm_dump not called! (missing %prep?)" 1>&2
528b4058
JB
492 fi
493 echo "$rpm_dump_cache"
494}
495
f1080274
ER
496get_icons()
497{
498 update_shell_title "get icons"
499 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
500 if [ -z "$ICONS" ]; then
501 return
502 fi
503
ed997e04 504 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
f1080274
ER
505}
506
528b4058
JB
507parse_spec()
508{
f1080274 509 update_shell_title "parsing specfile"
528b4058 510 if [ -n "$DEBUG" ]; then
ed997e04
ER
511 set -x
512 set -v
528b4058
JB
513 fi
514
f1080274 515 # icons are needed for successful spec parse
ed997e04 516 get_icons
528b4058 517
f1080274 518 cd $SPECS_DIR
528b4058
JB
519 cache_rpm_dump
520
521 if [ "$NOSRCS" != "yes" ]; then
522 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
523 fi
f1080274 524
528b4058
JB
525 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
526 FAIL_IF_NO_SOURCES="no"
527 fi
528
529 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
530 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
00c7b5f1
ER
531 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
532 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
533 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
534
535 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
477f03e6 536 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
00c7b5f1 537 fi
6cc67f17 538
528b4058
JB
539 if [ -n "$BE_VERBOSE" ]; then
540 echo "- Sources : `nourl $SOURCES`"
541 if [ -n "$PATCHES" ]; then
542 echo "- Patches : `nourl $PATCHES`"
543 else
544 echo "- Patches : *no patches needed*"
545 fi
546 if [ -n "$ICONS" ]; then
547 echo "- Icon : `nourl $ICONS`"
548 else
549 echo "- Icon : *no package icon*"
550 fi
551 echo "- Name : $PACKAGE_NAME"
552 echo "- Version : $PACKAGE_VERSION"
553 echo "- Release : $PACKAGE_RELEASE"
554 fi
f1080274
ER
555
556 update_shell_title "parse_spec: OK!"
528b4058
JB
557}
558
559Exit_error()
560{
561 if [ -n "$DEBUG" ]; then
ed997e04
ER
562 set -x
563 set -v
528b4058
JB
564 fi
565
566 cd "$__PWD"
567
568 case "$1" in
569 "err_no_spec_in_cmdl" )
570 remove_build_requires
ed997e04 571 echo "ERROR: spec file name not specified."
528b4058 572 exit 2 ;;
01a86c2c
ER
573 "err_invalid_cmdline" )
574 echo "ERROR: invalid command line arg ($2)."
575 exit 2 ;;
528b4058
JB
576 "err_no_spec_in_repo" )
577 remove_build_requires
ed997e04 578 echo "Error: spec file not stored in CVS repo."
528b4058
JB
579 exit 3 ;;
580 "err_no_source_in_repo" )
581 remove_build_requires
ed997e04 582 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)"
528b4058
JB
583 exit 4 ;;
584 "err_build_fail" )
585 remove_build_requires
ed997e04 586 echo "Error: package build failed. (${2:-no more info})"
528b4058 587 exit 5 ;;
6cc67f17
ER
588 "err_no_package_data" )
589 remove_build_requires
590 echo "Error: couldn't get out package name/version/release from spec file."
591 exit 6 ;;
0466ad31 592 "err_tag_exists" )
6cc67f17 593 remove_build_requires
ed997e04 594 echo "Tag ${2} already exists (spec release: ${3})."
6cc67f17 595 exit 9 ;;
0466ad31 596 "err_fract_rel" )
6cc67f17 597 remove_build_requires
ed997e04 598 echo "Release ${2} not integer and not a snapshot."
6cc67f17 599 exit 10 ;;
f1080274
ER
600 "err_branch_exists" )
601 remove_build_requires
ed997e04 602 echo "Tree branch already exists (${2})."
f1080274 603 exit 11 ;;
01a86c2c
ER
604 "err_acl_deny" )
605 remove_build_requires
606 echo "Error: conditions reject building this spec (${2})."
607 exit 12 ;;
528b4058 608 esac
ed997e04
ER
609 echo "Unknown error."
610 exit 100
528b4058
JB
611}
612
613init_builder()
614{
615 if [ -n "$DEBUG" ]; then
ed997e04
ER
616 set -x
617 set -v
528b4058
JB
618 fi
619
0466ad31 620 if [ "$NOINIT" != "yes" ] ; then
477f03e6
ER
621 local extra
622 if [ "$ASSUMED_NAME" ]; then
623 extra="--define 'name $ASSUMED_NAME'"
624 fi
625 SOURCE_DIR="`eval $RPM $RPMOPTS $extra --eval '%{_sourcedir}'`"
626 SPECS_DIR="`eval $RPM $RPMOPTS $extra --eval '%{_specdir}'`"
0466ad31
ER
627 else
628 SOURCE_DIR="."
629 SPECS_DIR="."
630 fi
528b4058
JB
631
632 __PWD="`pwd`"
633}
634
635get_spec()
636{
f1080274
ER
637
638 update_shell_title "get_spec"
639
528b4058 640 if [ -n "$DEBUG" ]; then
ed997e04
ER
641 set -x
642 set -v
528b4058
JB
643 fi
644
645 cd "$SPECS_DIR"
f1080274 646 if [ ! -f "$SPECFILE" ]; then
ed997e04 647 SPECFILE="`basename $SPECFILE .spec`.spec"
528b4058
JB
648 fi
649 if [ "$NOCVSSPEC" != "yes" ]; then
528b4058 650
f1080274
ER
651 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
652 echo "Warning: No CVS access defined - using local .spec file"
653 NOCVSSPEC="yes"
528b4058
JB
654 fi
655
f1080274 656 cvsup "$SPECFILE" || Exit_error err_no_spec_in_repo
528b4058 657 fi
f1080274 658
528b4058 659 if [ ! -f "$SPECFILE" ]; then
ed997e04 660 Exit_error err_no_spec_in_repo
528b4058
JB
661 fi
662
663 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
664 chmod $CHMOD_MODE $SPECFILE
665 fi
666 unset OPTIONS
6cc67f17 667 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
f1080274 668
0466ad31 669 set_spec_target
528b4058
JB
670}
671
672find_mirror()
673{
674 cd "$SPECS_DIR"
0466ad31 675 local url="$1"
528b4058
JB
676 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
677 cvs update mirrors >&2
678 fi
679
680 IFS="|"
0466ad31
ER
681 local origin mirror name rest ol prefix
682 while read origin mirror name rest; do
683 # skip comments and empty lines
684 if [ -z "$origin" ] || [[ $origin == \#* ]]; then
685 continue
686 fi
528b4058
JB
687 ol=`echo -n "$origin"|wc -c`
688 prefix="`echo -n "$url" | head -c $ol`"
689 if [ "$prefix" = "$origin" ] ; then
0466ad31 690 suffix="`echo "$url"|cut -b $((ol+1))-`"
528b4058
JB
691 echo -n "$mirror$suffix"
692 return 0
693 fi
694 done < mirrors
695 echo "$url"
696}
697
ed997e04 698# Warning: unpredictable results if same URL used twice
528b4058
JB
699src_no ()
700{
701 cd $SPECS_DIR
702 rpm_dump | \
703 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
704 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
705 head -n 1 | xargs
706}
707
ed997e04 708src_md5()
528b4058 709{
ed997e04 710 [ "$NO5" = "yes" ] && return
528b4058
JB
711 no=$(src_no "$1")
712 [ -z "$no" ] && return
713 cd $SPECS_DIR
ed997e04
ER
714 local md5
715
716 if [ -f additional-md5sums ]; then
717 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
718 if [ -z "$spec_rev" ]; then
719 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
720 fi
721 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
722 md5=$(grep -s -v '^#' additional-md5sums | \
723 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
724 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
725 grep -E '^[0-9a-f]{32}$')
726
727 if [ "$md5" ]; then
728 if [ $(echo "$md5" | wc -l) != 1 ] ; then
729 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
730 fi
731 echo "$md5" | tail -n 1
732 return
733 fi
734 fi
735
736 source_md5=`grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
737 if [ -n "$source_md5" ]; then
738 echo $source_md5
528b4058 739 else
ed997e04
ER
740 # we have empty SourceX-md5, but it is still possible
741 # that we have NoSourceX-md5 AND NoSource: X
742 nosource_md5=`grep -i "#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
743 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
744 echo $nosource_md5
528b4058 745 fi
528b4058
JB
746 fi
747}
748
0466ad31
ER
749distfiles_path ()
750{
751 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
752}
753
528b4058
JB
754distfiles_url ()
755{
0466ad31 756 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
528b4058
JB
757}
758
759distfiles_attic_url ()
760{
0466ad31 761 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
528b4058
JB
762}
763
764good_md5 ()
765{
766 md5=$(src_md5 "$1")
767 [ "$md5" = "" ] || \
768 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
769}
770
6cc67f17
ER
771good_size ()
772{
0466ad31
ER
773 size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
774 [ -n "$size" -a "$size" -gt 0 ]
6cc67f17
ER
775}
776
777cvsignore_df ()
778{
779 if [ "$CVSIGNORE_DF" != "yes" ]; then
780 return
781 fi
782 cvsignore=${SOURCE_DIR}/.cvsignore
783 if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
784 echo "$1" >> $cvsignore
785 fi
786}
787
f1080274
ER
788cvsup()
789{
0466ad31
ER
790 update_shell_title "cvsup"
791 local OPTIONS="up "
792 if [ -n "$CVSROOT" ]; then
793 OPTIONS="-d $CVSROOT $OPTIONS"
794 fi
f1080274 795
0466ad31
ER
796 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
797 OPTIONS="$OPTIONS -A"
798 else
799 if [ -n "$CVSDATE" ]; then
800 OPTIONS="$OPTIONS -D $CVSDATE"
801 fi
802 if [ -n "$CVSTAG" ]; then
803 OPTIONS="$OPTIONS -r $CVSTAG"
804 fi
805 fi
f1080274 806
0466ad31
ER
807 local result=1
808 local retries_counter=0
809 if [ $# = 1 ]; then
810 update_shell_title "cvsup: $*"
811 else
812 update_shell_title "cvsup: $# files"
813 fi
814 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
815 retries_counter=$(( $retries_counter + 1 ))
816 output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1)
817 result=$?
818 [ -n "$output" ] && echo "$output"
819 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
820 echo "Trying again [$*]... ($retries_counter)"
821 update_shell_title "cvsup: retry #$retries_counter"
822 sleep 2
823 continue
824 else
825 break
826 fi
827 done
828 update_shell_title "cvsup: done!"
829 return $result
f1080274
ER
830}
831
ed997e04
ER
832# returns true if "$1" is ftp, http or https protocol url
833is_url()
834{
835 case "$1" in
836 ftp://*|http://*|https://*)
837 return 0
838 ;;
839 esac
840 return 1
841}
842
843update_md5()
844{
845 if [ $# -eq 0 ]; then
846 return
847 fi
848
849 update_shell_title "update md5"
850 if [ -n "$DEBUG" ]; then
851 set -x
852 set -v
853 fi
854
855 cd "$SOURCE_DIR"
856
857 # pass 1: check files to be fetched
858 local todo
859 local need_files
860 for i in "$@"; do
861 local fp=$(nourl "$i")
862 local srcno=$(src_no "$i")
863 if [ -n "$ADD5" ]; then
864 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
865 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
866 else
867 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
868 fi
869 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
870 need_files="$need_files $i"
871 fi
872 done
873
874 # pass 1a: get needed files
875 if [ "$need_files" ]; then
876 get_files $need_files
877 fi
878
879 # pass 2: proceed with md5 adding or updating
880 for i in "$@"; do
881 local fp=$(nourl "$i")
882 local srcno=$(src_no "$i")
883 local md5=$(grep -iE '^#[ ]*(No)?Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
884 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
885 local tag="Source$srcno-md5"
886 if [[ "$md5" == *NoSource* ]]; then
887 tag="NoSource$srcno-md5"
888 fi
889 md5=$(md5sum "$fp" | cut -f1 -d' ')
890 echo "Updating $tag ($md5: $fp)."
891 perl -i -ne '
892 print unless /^\s*#\s*(No)?Source'$srcno'-md5\s*:/i;
893 print "# '$tag':\t'$md5'\n" if /^Source'$srcno'\s*:\s+/;
894 ' \
895 $SPECS_DIR/$SPECFILE
896 fi
897 done
898}
899
900check_md5()
901{
902 update_shell_title "check md5"
903
904 for i in "$@"; do
905 if good_md5 "$i" && good_size "$i"; then
906 continue
907 fi
908
909 echo "MD5 sum mismatch or 0 size. Use -U to refetch sources,"
910 echo "or -5 to update md5 sums, if you're sure files are correct."
911 Exit_error err_no_source_in_repo $i
912 done
913}
914
528b4058
JB
915get_files()
916{
f1080274 917 update_shell_title "get_files"
528b4058
JB
918
919 if [ -n "$DEBUG" ]; then
ed997e04
ER
920 set -x
921 set -v
528b4058
JB
922 fi
923
f1080274 924 if [ $# -gt 0 ]; then
528b4058
JB
925 cd "$SOURCE_DIR"
926
f1080274
ER
927 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
928 echo "Warning: No CVS access defined for SOURCES"
929 NOCVS="yes"
528b4058 930 fi
f1080274
ER
931
932 local nc=0
933 local get_files_cvs=""
934 for i in "$@"; do
935 nc=$((nc + 1))
936 local cvsup=0
937 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
938 update_shell_title "$i"
939 local fp=`nourl "$i"`
ed997e04 940 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
0466ad31 941 continue
528b4058 942 fi
ed997e04 943
528b4058 944 FROM_DISTFILES=0
ed997e04
ER
945 local srcmd5=$(src_md5 "$i")
946
947 # we know if source/patch is present in cvs/distfiles
948 # - has md5 (in distfiles)
949 # - in cvs... ideas?
950
951 # CHECK: local file didn't exist or always cvs up (first) requested.
f1080274 952 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
528b4058
JB
953 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
954 echo "Warning: no URL given for $i"
955 fi
956
ed997e04 957 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
6cc67f17 958 if good_md5 "$i" && good_size "$i"; then
ed997e04 959 echo "$fp having proper md5sum already exists"
528b4058
JB
960 continue
961 fi
f1080274 962 target="$fp"
01a86c2c 963
477f03e6 964 # optionally prefer mirror over distfiles if there's mirror
01a86c2c 965 # TODO: build url list and then try each url from the list
477f03e6 966 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
01a86c2c
ER
967 url="$im"
968 else
969 url=$(distfiles_url "$i")
970 fi
971
528b4058
JB
972 url_attic=$(distfiles_attic_url "$i")
973 FROM_DISTFILES=1
ed997e04
ER
974 # is $url local file?
975 if [[ "$url" = [./]* ]]; then
f1080274 976 update_shell_title "${GETLOCAL%% *}: $url"
528b4058
JB
977 ${GETLOCAL} $url $target
978 else
979 if [ -z "$NOMIRRORS" ]; then
01a86c2c
ER
980 url=$(find_mirror "$url")
981 fi
982
983 local uri=${url}
984 # make shorter message for distfiles urls
985 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
986 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
987 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
988 uri="df: $uri"
528b4058 989 fi
01a86c2c 990 update_shell_title "${GETURI%% *}: $uri"
6cc67f17 991 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
f1080274
ER
992 if [ "`echo $url | grep -E 'ftp://'`" ]; then
993 update_shell_title "${GETURI2%% *}: $url"
6cc67f17 994 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
528b4058
JB
995 fi
996 fi
ed997e04
ER
997
998 # is it empty file?
999 if [ ! -s "$target" ]; then
528b4058
JB
1000 rm -f "$target"
1001 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
f1080274 1002 update_shell_title "${GETLOCAL%% *}: $url_attic"
528b4058
JB
1003 ${GETLOCAL} $url_attic $target
1004 else
1005 if [ -z "$NOMIRRORS" ]; then
1006 url_attic="`find_mirror "$url_attic"`"
1007 fi
f1080274 1008 update_shell_title "${GETURI%% *}: $url_attic"
6cc67f17 1009 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
f1080274 1010 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
0466ad31 1011 update_shell_title "${GETURI2%% *}: $url_attic"
6cc67f17 1012 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
528b4058
JB
1013 fi
1014 fi
1015 fi
ed997e04
ER
1016
1017 if [ -s "$target" ]; then
6cc67f17
ER
1018 cvsignore_df $target
1019 else
528b4058
JB
1020 rm -f "$target"
1021 FROM_DISTFILES=0
1022 fi
ed997e04 1023 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
f1080274
ER
1024 if [ $# -gt 1 ]; then
1025 get_files_cvs="$get_files_cvs $fp"
1026 update_shell_title "$fp (will cvs up later)"
1027 cvsup=1
1028 else
1029 cvsup $fp
1030 fi
528b4058
JB
1031 fi
1032
f1080274 1033 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
528b4058
JB
1034 if [ -z "$NOMIRRORS" ]; then
1035 im="`find_mirror "$i"`"
1036 else
1037 im="$i"
1038 fi
0466ad31 1039 update_shell_title "${GETURI%% *}: $im"
528b4058 1040 ${GETURI} "$im" || \
f1080274 1041 if [ "`echo $im | grep -E 'ftp://'`" ]; then
0466ad31 1042 update_shell_title "${GETURI2%% *}: $im"
528b4058 1043 ${GETURI2} "$im"
6cc67f17 1044 fi
528b4058
JB
1045 fi
1046
f1080274
ER
1047 if [ "$cvsup" = 1 ]; then
1048 continue
1049 fi
1050
528b4058 1051 fi
ed997e04
ER
1052
1053 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
f1080274 1054 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
477f03e6
ER
1055 if [ -n "GREEDSRC" ]; then
1056 get_greed_sources $i
1057 else
1058 Exit_error err_no_source_in_repo $i
1059 fi
528b4058 1060 fi
6cc67f17 1061
ed997e04 1062 # we check md5 here just only to refetch immediately
6cc67f17 1063 if good_md5 "$i" && good_size "$i"; then
528b4058
JB
1064 :
1065 elif [ "$FROM_DISTFILES" = 1 ]; then
1066 # wrong md5 from distfiles: remove the file and try again
1067 # but only once ...
1068 echo "MD5 sum mismatch. Trying full fetch."
1069 FROM_DISTFILES=2
1070 rm -f $target
f1080274 1071 update_shell_title "${GETURI%% *}: $url"
6cc67f17 1072 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
f1080274 1073 if [ "`echo $url | grep -E 'ftp://'`" ]; then
0466ad31 1074 update_shell_title "${GETURI2%% *}: $url"
6cc67f17 1075 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
528b4058 1076 fi
ed997e04 1077 if [ ! -s "$target" ]; then
528b4058 1078 rm -f "$target"
f1080274 1079 update_shell_title "${GETURI%% *}: $url_attic"
6cc67f17 1080 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
f1080274 1081 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
0466ad31 1082 update_shell_title "${GETURI2%% *}: $url_attic"
6cc67f17 1083 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
528b4058
JB
1084 fi
1085 fi
1086 test -s "$target" || rm -f "$target"
1087 fi
528b4058 1088 done
f1080274
ER
1089 SHELL_TITLE_PREFIX=""
1090
1091 if [ "$get_files_cvs" ]; then
0466ad31 1092 cvsup $get_files_cvs
f1080274 1093 fi
528b4058
JB
1094
1095 if [ "$CHMOD" = "yes" ]; then
f1080274 1096 CHMOD_FILES="`nourl "$@"`"
528b4058
JB
1097 if [ -n "$CHMOD_FILES" ]; then
1098 chmod $CHMOD_MODE $CHMOD_FILES
1099 fi
1100 fi
528b4058
JB
1101 fi
1102}
1103
1104make_tagver() {
0466ad31 1105 if [ -n "$DEBUG" ]; then
ed997e04
ER
1106 set -x
1107 set -v
0466ad31 1108 fi
6cc67f17 1109
0466ad31
ER
1110 # Check whether first character of PACKAGE_NAME is legal for tag name
1111 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1112 TAG_PREFIX=tag_
1113 fi
00c7b5f1
ER
1114
1115 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1116 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]')
1117
0466ad31
ER
1118 # Remove #kernel.version_release from TAGVER because tagging sources
1119 # could occur with different kernel-headers than kernel-headers used at build time.
00c7b5f1
ER
1120 # besides, %{_kernel_ver_str} is not expanded.
1121
1122 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str}
1123 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1124
1125 TAGVER=${TAGVER%#*}
0466ad31 1126 echo -n "$TAGVER"
528b4058
JB
1127}
1128
1129tag_files()
1130{
1131 TAG_FILES="$@"
1132
1133 if [ -n "$DEBUG" ]; then
ed997e04
ER
1134 set -x
1135 set -v
528b4058
JB
1136 fi
1137
ed997e04
ER
1138 echo "Version: $PACKAGE_VERSION"
1139 echo "Release: $PACKAGE_RELEASE"
528b4058 1140
00c7b5f1 1141 local TAGVER
ed997e04 1142 if [ "$TAG_VERSION" = "yes" ]; then
00c7b5f1 1143 TAGVER=`make_tagver`
ed997e04
ER
1144 echo "CVS tag: $TAGVER"
1145 fi
1146 if [ -n "$TAG" ]; then
1147 echo "CVS tag: $TAG"
1148 fi
528b4058 1149
ed997e04
ER
1150 local OPTIONS="tag $CVS_FORCE"
1151 if [ -n "$CVSROOT" ]; then
1152 OPTIONS="-d $CVSROOT $OPTIONS"
1153 fi
528b4058 1154
ed997e04
ER
1155 cd "$SOURCE_DIR"
1156 local tag_files
1157 for i in $TAG_FILES; do
1158 # don't tag files stored on distfiles
1159 [ -n "`src_md5 $i`" ] && continue
1160 local fp=`nourl "$i"`
1161 if [ -f "$fp" ]; then
1162 tag_files="$tag_files $fp"
477f03e6
ER
1163 elif [ -n "GREEDSRC" ]; then
1164 get_greed_sources $i
ed997e04
ER
1165 else
1166 Exit_error err_no_source_in_repo $i
1167 fi
1168 done
528b4058 1169
ed997e04 1170 if [ "$tag_files" ]; then
528b4058 1171 if [ "$TAG_VERSION" = "yes" ]; then
ed997e04 1172 update_shell_title "tag sources: $TAGVER"
5efdb475 1173 printf "Tagging %d files\n" $(echo $tag_files | wc -w)
00c7b5f1 1174 cvs $OPTIONS $TAGVER $tag_files || exit
528b4058
JB
1175 fi
1176 if [ -n "$TAG" ]; then
ed997e04 1177 update_shell_title "tag sources: $TAG"
5efdb475
ER
1178
1179 while [ "$tag_files" ]; do
1180 local chunk=$(echo $tag_files | tr ' ' '\n' | head -n 100)
1181 printf "Tagging %d files\n" $(echo $chunk | wc -w)
1182 cvs $OPTIONS $TAG $chunk || exit
1183 tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101)
1184 done
528b4058 1185 fi
ed997e04 1186 fi
528b4058 1187
ed997e04
ER
1188 cd "$SPECS_DIR"
1189 if [ "$TAG_VERSION" = "yes" ]; then
1190 update_shell_title "tag spec: $TAGVER"
00c7b5f1 1191 cvs $OPTIONS $TAGVER $SPECFILE || exit
ed997e04
ER
1192 fi
1193 if [ -n "$TAG" ]; then
1194 update_shell_title "tag spec: $TAG"
00c7b5f1 1195 cvs $OPTIONS $TAG $SPECFILE || exit
528b4058
JB
1196 fi
1197}
1198
1199branch_files()
1200{
1201 TAG=$1
1202 echo "CVS branch tag: $TAG"
ed997e04 1203 shift
528b4058
JB
1204
1205 TAG_FILES="$@"
1206
1207 if [ -n "$DEBUG" ]; then
ed997e04
ER
1208 set -x
1209 set -v
528b4058
JB
1210 fi
1211
ed997e04
ER
1212 local OPTIONS="tag $CVS_FORCE -b"
1213 if [ -n "$CVSROOT" ]; then
1214 OPTIONS="-d $CVSROOT $OPTIONS"
1215 fi
1216 cd "$SOURCE_DIR"
1217 local tag_files
1218 for i in $TAG_FILES; do
1219 local fp=`nourl "$i"`
1220 if [ -f "$fp" ]; then
1221 tag_files="$tag_files $fp"
477f03e6
ER
1222 elif [ -n "GREEDSRC" ]; then
1223 get_greed_sources $i
ed997e04
ER
1224 else
1225 Exit_error err_no_source_in_repo $i
528b4058 1226 fi
ed997e04
ER
1227 done
1228 if [ "$tag_files" ]; then
00c7b5f1 1229 cvs $OPTIONS $TAG $tag_files || exit
528b4058 1230 fi
ed997e04
ER
1231
1232 cd "$SPECS_DIR"
00c7b5f1 1233 cvs $OPTIONS $TAG $SPECFILE || exit
528b4058
JB
1234}
1235
1236
00c7b5f1
ER
1237# this function should exit early if package can't be built for this arch
1238# this avoids unneccessary BR filling.
1239check_buildarch() {
1240 local out ret
1241 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1242 ret=$?
1243 if [ $ret -ne 0 ]; then
1244 echo >&2 "$out"
1245 exit $ret
1246 fi
1247}
1248
528b4058
JB
1249
1250build_package()
1251{
f1080274 1252 update_shell_title "build_package"
528b4058 1253 if [ -n "$DEBUG" ]; then
ed997e04
ER
1254 set -x
1255 set -v
528b4058
JB
1256 fi
1257
1258 cd "$SPECS_DIR"
1259
1260 if [ -n "$TRY_UPGRADE" ]; then
0466ad31 1261 update_shell_title "build_package: try_upgrade"
528b4058 1262 if [ -n "$FLOAT_VERSION" ]; then
f1080274 1263 TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1
528b4058 1264 else
f1080274 1265 TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1
528b4058
JB
1266 fi
1267
1268 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
1269
1270 if [ -n "$TNEWVER" ]; then
1271 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1272 echo "New version found, updating spec file to version " $TNEWVER
ed997e04
ER
1273 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1274 cp -f $SPECFILE $SPECFILE.bak
1275 fi
528b4058
JB
1276 chmod +w $SPECFILE
1277 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
f1080274 1278 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
ed997e04
ER
1279 parse_spec
1280 NODIST="yes" get_files $SOURCES $PATCHES
1281 update_md5 $SOURCES
1282
528b4058
JB
1283 unset TOLDVER TNEWVER TNOTIFY
1284 fi
1285 fi
1286 cd "$SPECS_DIR"
6cc67f17 1287
528b4058
JB
1288 case "$COMMAND" in
1289 build )
1290 BUILD_SWITCH="-ba" ;;
1291 build-binary )
1292 BUILD_SWITCH="-bb" ;;
1293 build-source )
1294 BUILD_SWITCH="-bs --nodeps" ;;
1295 build-prep )
1296 BUILD_SWITCH="-bp --nodeps" ;;
01a86c2c
ER
1297 build-build )
1298 BUILD_SWITCH="-bc" ;;
1299 build-install )
1300 BUILD_SWITCH="-bi" ;;
1301 build-list )
1302 BUILD_SWITCH="-bl" ;;
1303
528b4058 1304 esac
f1080274
ER
1305
1306 update_shell_title "build_package: $COMMAND"
528b4058
JB
1307 if [ -n "$LOGFILE" ]; then
1308 LOG=`eval echo $LOGFILE`
1309 if [ -d "$LOG" ]; then
1310 echo "Log file $LOG is a directory."
1311 echo "Parse error in the spec?"
ed997e04 1312 Exit_error err_build_fail
528b4058
JB
1313 fi
1314 if [ -n "$LASTLOG_FILE" ]; then
1315 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1316 fi
1317 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
0466ad31 1318 (time eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
528b4058
JB
1319 RETVAL=`cat $RES_FILE`
1320 rm $RES_FILE
1321 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1322 if [ "$RETVAL" -eq "0" ]; then
1323 mv $LOG $LOGDIROK
1324 else
1325 mv $LOG $LOGDIRFAIL
1326 fi
1327 fi
1328 else
0466ad31 1329 eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE
528b4058
JB
1330 RETVAL=$?
1331 fi
1332 if [ "$RETVAL" -ne "0" ]; then
1333 if [ -n "$TRY_UPGRADE" ]; then
0466ad31 1334 echo "\n!!! Package with new version cannot be built automagically\n"
ed997e04
ER
1335 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1336 mv -f $SPECFILE.bak $SPECFILE
1337 fi
528b4058 1338 fi
ed997e04 1339 Exit_error err_build_fail
528b4058
JB
1340 fi
1341 unset BUILD_SWITCH
1342}
1343
1344nourl()
1345{
1346 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1347}
1348
528b4058
JB
1349install_required_packages()
1350{
1351 run_poldek -vi $1
1352 return $?
1353}
1354
f1080274
ER
1355find_spec_bcond() {
1356 # taken from find-spec-bcond, but with just getting the list
1357 local SPEC="$1"
1358 # quick revert hint: '$RPMBUILD --bcond $SPEC'
1359 awk -F"\n" '
1360 /^%changelog/ { exit }
1361 /_with(out)?_[_a-zA-Z0-9]+/{
1362 match($0, /_with(out)?_[_a-zA-Z0-9]+/);
1363 print substr($0, RSTART, RLENGTH);
1364 }
1365 /^%bcond_with/{
1366 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1367 bcond = substr($0, RSTART +5 , RLENGTH -5);
1368 gsub(/[ \t]+/,"_",bcond);
1369 print bcond
1370 }' $SPEC | LC_ALL=C sort -u
1371}
1372
ed997e04 1373process_bcondrc() {
6cc67f17
ER
1374 # expand bconds from ~/.bcondrc
1375 # The file structure is like gentoo's package.use:
1376 # ---
1377 # * -selinux
1378 # samba -mysql -pgsql
1379 # w32codec-installer license_agreement
1380 # php +mysqli
1381 # ---
f1080274 1382 if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
ed997e04
ER
1383 :
1384 else
1385 return
1386 fi
1387
1388 SN=${SPECFILE%%\.spec}
6cc67f17 1389
ed997e04
ER
1390 local bcondrc=$HOME/.bcondrc
1391 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
6cc67f17 1392
ed997e04 1393 local bcond_avail=$(find_spec_bcond $SPECFILE)
6cc67f17 1394
ed997e04
ER
1395 while read pkg flags; do
1396 # ignore comments
1397 [[ "$pkg" == \#* ]] && continue
6cc67f17 1398
ed997e04
ER
1399 # any package or current package?
1400 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1401 for flag in $flags; do
1402 local opt=${flag#[+-]}
1403
1404 # use only flags which are in this package.
1405 if [[ $bcond_avail = *${opt}* ]]; then
1406 if [[ $flag = -* ]]; then
1407 if [[ $BCOND != *--with?${opt}* ]]; then
6cc67f17 1408 BCOND="$BCOND --without $opt"
ed997e04
ER
1409 fi
1410 else
1411 if [[ $BCOND != *--without?${opt}* ]]; then
6cc67f17
ER
1412 BCOND="$BCOND --with $opt"
1413 fi
1414 fi
ed997e04
ER
1415 fi
1416 done
1417 fi
1418 done < $bcondrc
1419 update_shell_title "parse ~/.bcondrc: DONE!"
1420}
1421
1422set_bconds_values()
1423{
1424 update_shell_title "set bcond values"
1425
1426 AVAIL_BCONDS_WITHOUT=""
1427 AVAIL_BCONDS_WITH=""
1428 if `grep -q ^%bcond ${SPECFILE}`; then
1429 BCOND_VERSION="NEW"
1430 elif `egrep -q ^#\ *_with ${SPECFILE}`; then
1431 BCOND_VERSION="OLD"
1432 else
1433 return
6cc67f17
ER
1434 fi
1435
ed997e04
ER
1436 local bcond_avail=$(find_spec_bcond $SPECFILE)
1437 process_bcondrc "$SPECFILE"
1438
f1080274 1439 update_shell_title "parse bconds"
528b4058 1440 case "${BCOND_VERSION}" in
f1080274 1441 NONE)
6cc67f17 1442 :
528b4058 1443 ;;
6cc67f17 1444 OLD)
528b4058 1445 echo "Warning: This spec has old style bconds. Fix it || die."
f1080274 1446 for opt in `echo "$bcond_avail" | grep ^_without_`
528b4058 1447 do
f1080274
ER
1448 AVAIL_BCOND_WITHOUT=${opt#_without_}
1449 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
528b4058
JB
1450 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1451 else
1452 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1453 fi
1454 done
6cc67f17 1455
f1080274 1456 for opt in `echo "$bcond_avail" | grep ^_with_`
528b4058 1457 do
f1080274
ER
1458 AVAIL_BCOND_WITH=${opt#_with_}
1459 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
528b4058
JB
1460 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1461 else
1462 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1463 fi
1464 done
1465 ;;
1466 NEW)
f1080274
ER
1467 local cond_type="" # with || without
1468 for opt in $bcond_avail; do
528b4058
JB
1469 case "$opt" in
1470 _without)
1471 cond_type="without"
1472 ;;
1473 _with)
1474 cond_type="with"
1475 ;;
6cc67f17 1476 _without_*)
f1080274
ER
1477 AVAIL_BCOND_WITHOUT=${opt#_without_}
1478 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
6cc67f17
ER
1479 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1480 else
1481 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1482 fi
1483 ;;
1484 _with_*)
f1080274
ER
1485 AVAIL_BCOND_WITH=${opt#_with_}
1486 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
6cc67f17
ER
1487 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1488 else
1489 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1490 fi
1491 ;;
528b4058
JB
1492 *)
1493 case "$cond_type" in
1494 with)
1495 cond_type=''
1496 AVAIL_BCOND_WITH="$opt"
f1080274 1497 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
528b4058
JB
1498 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1499 else
1500 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1501 fi
6cc67f17 1502 ;;
528b4058
JB
1503 without)
1504 cond_type=''
1505 AVAIL_BCOND_WITHOUT="$opt"
f1080274 1506 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
528b4058
JB
1507 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1508 else
1509 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1510 fi
1511 ;;
1512 esac
1513 ;;
1514 esac
1515 done
1516 ;;
1517 esac
1518}
1519
1520run_sub_builder()
1521{
1522 package_name="${1}"
f1080274 1523 update_shell_title "run_sub_builder $package_name"
528b4058
JB
1524 #
1525